c++实现剧情⼩游戏:哈利波特
(此为作者原创,转载请告知)
#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
#include <fstream>
#include <ctime>
#include <time.h>
#include <stdio.h>
using namespace std;
int D_Of_C, OK, ane, xy, D_Of_C1, OK1, ane1, xy1, nowM, MoralValue;
int ict = 0, nowlevel = 0;
int bag[44] = { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0};
//0抽奖券 1经验⽯R 2经验⽯SR 3经验⽯SSR 4经验⽯SSS 5经验⽯X
//6技能书快快复苏 7技能书铁甲咒 8技能书昏昏倒地 9技能书神锋⽆影 10技能书咒⽴停 11技能书⽯化咒 12技能书恢复咒 13技能书召唤咒 14技能书遗忘咒 15技能书万//19⽣命药⽔ 20防御药⽔ 21攻击药⽔ 22经验药⽔ 23全幅药⽔
//24猫狸⼦胡须 25媚娃头发 26马形⽔怪的鬃⽑ 27龙⼼腱 28雷鸟尾⽻ 29凤凰⽻⽑ 30独⾓兽尾⽑ 31龙神经 32夜骐的尾⽻
//33桦⽊ 34紫衫⽊ 35冬青⽊ 36⼭楂⽊柳条 37橡⽊ 38械⽊ 39⼭⽑榉⽊ 40栗⽊ 41樱桃⽊ 42桃花⼼⽊
//43速度药⽔
string Material1name[9] = { "猫狸⼦胡须","媚娃头发","马形⽔怪的鬃⽑","龙⼼腱","雷鸟尾⽻","凤凰⽻⽑","独⾓兽尾⽑","龙神经","夜骐的尾⽻" };
string Material2name[10] = { "桦⽊","紫衫⽊","冬青⽊","⼭楂⽊柳条","橡⽊","械⽊","⼭⽑榉⽊","栗⽊","樱桃⽊","桃花⼼⽊" };
int health = 1000, maxhealth = 1000, money=0, attack = 250, defense = 10, experience = 0, camp, level = 1, amm = 0, f = 0, speed = 0;
string Nwand = "空⼿";
int LE1 = 1, LE2 = 1, Sl[13];
bool dead = false;
string wandname[100] = { "柳条魔杖","胡桃魔杖","鹅⽿枥⽊魔杖","柳条魔杖","花⼼⽊魔杖","冬青⽊魔杖","紫杉⽊魔杖","⽼魔杖" };
int wandpower[100] = { 200,500,1100,1300,2400,5000,9000,20000 }, wand[100], wandi = 8, wandnamei = 8, wandpoweri = 8;
string name, password;
int choose()
{
system("cls");
cout << "请选择您的阵营。" << endl;
cout << "0, 哈利.HarryPotter" << endl;
cout << "1, 伏地魔 LordVoldemort" << endl;
cin >> camp;
if (camp != 0 && camp != 1) {
cout << "输⼊错误。";
Sleep(250);
choose();
}
else {
if (MessageBox(0, TEXT("你确定?"), TEXT("请选择"), MB_OKCANCEL | MB_ICONINFORMATION) == IDOK) return 0;
choose();
}
return 0;
}
int login()
{
string DN, DPW;
bool isn = false;
cout << "请输⼊账号和密码" << endl;
cout << "账号:";
cin >> name;
cout << "密码:";
cin >> password;
ifstream fin("");
while(fin >> DN) {
if (DN == name) {
fin >> DPW;
if (DPW != password) {
cout << "密码错误!" << endl; isn = true;
system("cls"); login();
}
else {
fin >> money >> attack >> defense >> health >> level >> experience >> LE1 >> LE2  >> camp >> maxhealth;
fin >> D_Of_C >> OK >> ane >> xy >> D_Of_C1 >> OK1 >> ane1 >> xy1 >> nowM;
fin >> bag[0] >> bag[1] >> bag[2] >> bag[3] >> bag[4] >> bag[5] >> bag[6] >> bag[7];
fin >> bag[8] >> bag[9] >> bag[10] >> bag[11] >> bag[12] >> bag[13] >> bag[14] >> bag[15];
fin >> bag[16] >> bag[17] >> bag[18] >> bag[19] >> bag[20] >> bag[21] >> bag[22] >> bag[23];
fin >> bag[24] >> bag[25] >> bag[26] >> bag[27] >> bag[28] >> bag[29] >> bag[30] >> bag[31];
fin >> bag[32] >> bag[33] >> bag[34] >> bag[35] >> bag[36] >> bag[37] >> bag[38] >> bag[39];
fin >> bag[40] >> bag[41] >> bag[42] >> bag[43];
fin >> Sl[0] >> Sl[1] >> Sl[2] >> Sl[3] >> Sl[4] >> Sl[5] >> Sl[6] >> Sl[7] >> Sl[8] >> Sl[9] >> Sl[10] >> Sl[11] >> Sl[12];
for (int i = 0; i < 100; i++) {
fin >> wandname[i];
fin >> wandpower[i];
fin >> wand[i];
}
fin >> Nwand >> amm >> f >> wandi >> wandnamei >> wandpoweri >> ict >> speed >> nowlevel;
isn = true;
}
}
}
if (!isn) {
cout << "⽆此⽤户!" << endl;
login();
}
cout << "登⼊成功!" << endl;
Sleep(1000);
return 0;
}
int save()
{
ofstream outfile("", ios::binary | ios::app | ios::in | ios::out);
outfile << name << " " << password << " " << money << " " << attack << " " << defense << " " << health << " " << level << " " << experience << " " << LE1 << " " << L  outfile << D_Of_C << " " << OK << " " << ane << " " << xy << " " << D_Of_C1 << " " << OK1 << " " << ane1 << " " << xy1 << " " << nowM << " ";
outfile << bag[0] << " " << bag[1] << " " << bag[2] << " " << bag[3] << " " << bag[4] << " " << bag[5] << " " << bag[6] << " " << bag[7] << " ";
outfile << bag[8] << " " << bag[9] << " " << bag[10] << " " << bag[11] << " " << bag[12] << " " << bag[13] << " " << bag[14] << " " << bag[15] << " ";
outfile << bag[16] << " " << bag[17] << " " << bag[18] << " " << bag[19] << " " << bag[20] << " " << bag[21] << " " << bag[22] << " " << bag[23] << " ";
outfile << bag[24] << " " << bag[25] << " " << bag[26] << " " << bag[27] << " " << bag[28] << " " << bag[29] << " " << bag[30] << " " << bag[31] << " ";
outfile << bag[32] << " " << bag[33] << " " << bag[34] << " " << bag[35] << " " << bag[36] << " " << bag[37] << " " << bag[38] << " " << bag[39] << " ";
outfile << bag[40] << " " << bag[41] << " " << bag[42] << " " << bag[43] << " ";
outfile << Sl[0] << " " << Sl[1] << " " << Sl[2] << " " << Sl[3] << " " << Sl[4] << " " << Sl[5] << " " << Sl[6] << " " << Sl[7] << " " << Sl[8] << " " << Sl[9] << " " << Sl[10] << for (int i = 0; i < 100; i++) {
outfile << wandname[i] << " ";
outfile << wandpower[i] << " ";
outfile << wand[i] << " ";
}
outfile << Nwand << " " << amm << " " << f << " " << wandi << " " << wandnamei << " " << wandpoweri << " " << ict << " " << speed << " " << nowlevel << endl;
outfile.close();
return 0;
}
int Reg()
{
string DN, DPW;
cout << "请输⼊账号和密码  " << endl;
cout << "账号:";
cin >> name;
cout << endl << "密码:";
cin >> password;
ifstream fin("");
while(fin >> DN) {
if (DN == name) {
cout << "⽤户名已被使⽤=====请重新起名";
}
}
choose();
return 0;
}
int monsterfight(string Hname, int hisH, int hisA, int hisD, int hisS, int hisSP)
{
int mhealth = 10000, mdefense = 1000, mattack = 10000, mspeed = 500;
int hfaint = 0;
int mfaint = 0;
dead = false;
int ha = hisA;
while (1) {
if (hfaint > 0) hfaint -= 1;
if (mfaint > 0) {
if (rand() % 3 == 0)
{
mfaint = 0;
cout << "⽯怪使⽤技能咒⽴停,停⽌了魔咒!" << endl;
}
else mfaint -= 1;
}
if (mfaint <= 0) {
if (rand() % 3) {
cout << "⽯怪使⽤技能快快复苏⽣命增加200" << endl;
mhealth += 200;
}
if (rand() % 3) {
cout << "⽯怪使⽤技能铁甲护⾝⽣命增加100 防御增加50" << endl;
mhealth += 100;
mdefense += 50;
}
if (rand() % 3) {
cout << "⽯怪使⽤技能神锋⽆影攻击增加200 对⽅扣⾎200滴" << endl;
hisH -= 200;
mattack += 200;
}
Sleep(1000);
int ran = rand() % 40 - 20;
if (rand() % 10000 > hisSP) {
if (attack + ran > hisD) {
cout << "⽯怪发起进攻 " << Hname << "扣⾎" << mattack - hisD + ran << "滴剩余" << hisH - (mattack - hisD + ran) << "滴" << endl;    hisH -= mattack - hisD + ran;
}
else cout << "⽯怪发起进攻 " << Hname << "扣⾎0滴剩余" << hisH << "滴" << endl;
}
else {
if (rand() % 2) cout << "⽯怪⼀脚踹了过去,但没有踢中" << endl;
else {
cout << "⽯怪⼀脚踹了过去,但只擦着了腰" << endl;
if ((mattack / 3) + ran > hisD) {
cout << Hname << "扣⾎" << (mattack / 3) + ran - hisD << "滴剩余" << hisH - ((mattack / 3) + ran - hisD) << "滴" << endl;
hisH -= (mattack / 3) + ran - hisD;
}
else cout << Hname << "扣⾎0滴剩余" << hisH << "滴" << endl;
}
}
}
Sleep(1000);
if (hisH <= 0) {
if (hisS == 20 && rand() % 3 == 0) {
cout << "对⽅发动技能:恢复如初满⾎复活" << endl;
hisH = ha; Sleep(1000);
}
cout << "对⽅死亡" << endl;
return 0;
}
}
if (hfaint <= 0) {
if (hisS != 0) {
if (rand() % 3 == 0) {
if (hisS == 14) {
cout << "对⽅发动技能:快快复苏⽣命加200" << endl;
hisH += 200;
}
if (hisS == 15) {
cout << "对⽅发动技能:盔甲护⾝⽣命加50 防御增加50" << endl;
hisH += 50;
hisD += 50;
}
if (hisS == 17) {
cout << "对⽅发动技能神锋⽆影攻击增加200 扣⾎200滴" << endl;
health -= 200;
hisA += 200;
}
}
Sleep(1000);
}
int ran = rand() % 40 - 20;
if (rand() % 10000 > mspeed) {
if (hisA + ran > defense) {
cout << Hname << "发起进攻 " << "⽯怪扣⾎" << hisA - defense + ran << "滴剩余" << mhealth - (hisA - defense + ran) << "滴" << endl;    mhealth -= hisA - defense + ran;
}
else cout << Hname << "发起进攻 " << "⽯怪扣⾎0滴剩余" << mhealth << "滴" << endl;
}
else {
if (rand() % 2) cout << Hname << "⼀脚踹了过来,但没有踢中" << endl;
else {
cout << "对⽅⼀脚踹了过来,但只擦着了⽯怪的腰" << endl;
if ((hisA / 3) + ran > hisD) {
cout << "⽯怪扣⾎" << (hisA / 3) + ran - defense << "滴剩余" << mhealth - ((hisA / 3) + ran - defense) << "滴" << endl;
mhealth -= ((hisA / 3) + ran - defense);
}
else cout << "⽯怪扣⾎0滴剩余" << mhealth << "滴" << endl;
}
}
Sleep(1000);
if (mhealth <= 0) {
cout << "⽯怪死亡" << endl;
return hisH;
}
}
}
return 0;
}
int fight1(string Hname, int hisH, int hisA, int hisD, int hisS, int hisSP)
{
int hfaint = 0, hhurt = 0, hbeat = 0;
int mfaint = 0, mhurt = 0;
dead = false;
int ha = hisA;
int his = hisA + hisD + hisH;
while (1) {
if (hfaint > 0) {
if (rand() % 3 == 0) {
cout << "对⽅使⽤技能:咒⽴停!停⽌了魔咒" << endl;
hfaint = 1;
hfaint -= 1;
}
if (hbeat == 1) {
if (rand() % 10 == 0) {
cout << "对⽅⼀躲,躲过了你的⽯头" << endl;
hbeat = 0;
}
else {
cout << "对⽅躲闪不急,⽯头正好撞在他的⿐⼦上扣⾎50滴" << endl;
hisH -= 50;
}
}
if (mfaint > 0) {
if (Sl[6]) mfaint = 0;
else mfaint -= 1;
}
if (mhurt > 0) {
if (Sl[6]) mhurt = 0;
else mhurt -= 1;
cout << "你的⼼像被⼀把⼑刺穿了⼀样扣⾎200滴" << endl;
health -= 200;
}
if (mfaint <= 0) {
if (rand() % 3 && Sl[0]) {
cout << "你使⽤技能快快复苏⽣命增加200" << endl;
health += 200;
}
if (rand() % 3 && Sl[1]) {
cout << "你使⽤技能铁甲护⾝⽣命增加100 防御增加50" << endl;
health += 100; defense += 50;
}
if (rand() % 3 && Sl[2]) {
cout << "你使⽤技能昏昏倒地 " << Hname << "⼀回合之内不能攻击" << endl;    hfaint += 1;
}
if (rand() % 3 && Sl[3]) {
cout << "你使⽤技能神锋⽆影攻击增加200 扣⾎200滴" << endl;
hisH -= 200; attack += 200;
}
if (rand() % 3 && Sl[5]) {
if (rand() % 10) {
cout << "你使⽤技能统统⽯化 " << Hname << "⼆回合之内不能攻击" << endl;    hfaint += 2;
}
else {
cout << "你使⽤技能统统⽯化 " << Hname << "⼗回合之内不能攻击" << endl;    hfaint += 10;
}
}
if (rand() % 4 == 0 && Sl[7])
{
cout << "你使⽤技能召唤咒!召唤出⽯怪跟" << Hname << "战⽃" << endl;
hisH = monsterfight(Hname, hisH, hisA, hisD, hisS, hisSP);
if (hisH < 1) return 0;
if (Sl[0]) {
cout << "在对⽅和⽯怪的战⽃中,你已经恢复了2000⽣命" << endl;
faintif (maxhealth < health + 2000) health = maxhealth;
else health += 2000;
}
}
if (rand() % 4 == 0 && Sl[8]) {
cout << "你使⽤技能召唤咒!召唤出⽯怪跟" << Hname << "战⽃" << endl;
}
if (rand() % 3 && Sl[9]) {

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。