我的第一个游戏,不喜勿喷
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
string di[5]= {"ETO","水滴","智子","三体元首","歌者"};
int num=0,money=0,attack,hp=100,your_hp=100,your_attack=17,n,b=0,a=0,c=0,d=0;
int dizhichui=0;
char input;
string tu[7]= {
" *",
" &^& *",
" / o | *",
" ^// }==*",
"// }",
" # //\\\\",
" // \\\\"
};
string tu_attack[7]= {
" ",
" &^&",
" / o |",
"********==^// }",
"// }",
" # //\\\\",
" // \\\\"
};
string tu_dodge[7]= {"","","","","","",""};
string hu[7]= {
" _",
" / \\/^\\",
" \\\'/",
" //#==",
" # \\\\",
" l //",
" _//"
};
string hu_attack[7]= {
" _",
" / \\/^\\",
" \\\'/",
"() ===//#==",
" # \\\\",
" l //",
" _//"
};
string hu_dodge[7]= {
" _",
" / \\/^\\",
" \\\'/",
" --0===//#==",
" # \\\\",
" l //",
" _//"
};
string tu_a="威慑",tu_d="计划的一部分",hu_a="陨石子弹",hu_d="自然选择前进四";
string me[7],me_attack[7],me_dodge[7],me_a,me_d;
string waterdrop[7]= {
" /\\ ",
" / \\ ",
" / \\ ",
" | | ",
" \\ / ",
" \\__/ ",
" "
};
string waterdrop_attack[10]= {
" /\\两千响 ",
" / \\ ",
"/ \\ ",
"| | ",
"\\ / 像鞭炮一样炸完",
" \\__/ ",
"liang qian xiang "
};
string miko[7]= {
" ____ ",
" / \\ ",
" / \\ ",
" | | ",
" \\ / ",
" \\____/ ",
" "
};
string miko_attack[7]= {
" ____ 你",
" / You\\ 们",
" / Are \\ 都",
" | Bugs | 是",
" \\!!!!!!/ 虫 ",
" \\____/ 子",
" ! "
};
string you[7]= {" / \\ "," \\^/- "," //^\\\\ "," //| |\\\\ "," # | | #-----> "," //^^\\\\ "," // \\\\ "};
string you_attack[7]= {" / \\ "," \\^/- "," //^\\\\ "," //| |\\\\ "," # | | \\\\=======#----->"," //^^\\\\ "," // \\\\ "};
char das[100]= {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
string playerName;
void readrf(){
FILE * fp;
//num,money,attack,hp,n,b,a,c,d,dizhichui;
fp=fopen("save.save","r");
fscanf(fp,"%d\n","&num");
fscanf(fp,"%d\n","&money");
fscanf(fp,"%d\n","&attack");
fscanf(fp,"%d\n","&hp");
fscanf(fp,"%d\n","&a");
fscanf(fp,"%d\n","&b");
fscanf(fp,"%d\n","&c");
fscanf(fp,"%d\n","&d");
fscanf(fp,"%d\n","&dizhichui");
fclose(fp);
}
void writerf(){
FILE * fp;
fp=fopen("save.save","w");
fscanf(fp,"%d\n","&num");
fscanf(fp,"%d\n","&money");
fscanf(fp,"%d\n","&attack");
fscanf(fp,"%d\n","&hp");
fscanf(fp,"%d\n","&a");
fscanf(fp,"%d\n","&b");
fscanf(fp,"%d\n","&c");
fscanf(fp,"%d\n","&d");
fscanf(fp,"%d\n","&dizhichui");
fclose(fp);
}
void color1() {
system("color f0");
system("color f1");
system("color b2");
system("color b3");
system("color b9");
system("color ba");
system("color bc");
system("color bd");
system("color f4");
system("color f5");
system("color f6");
system("color f7");
system("color f8");
system("color f9");
system("color fa");
system("color fb");
system("color fc");
system("color fd");
system("color fe");
system("color e0");
system("color e1");
system("color e2");
system("color e3");
system("color e4");
system("color e5");
system("color e6");
system("color e7");
system("color e8");
system("color e9");
system("color ea");
system("color eb");
system("color ec");
system("color ed");
system("color ef");
system("color be");
system("color bf");
system("color a0");
system("color a1");
system("color a2");
system("color a3");
system("color a4");
system("color a5");
system("color a6");
system("color a7");
system("color a8");
system("color a9");
system("color ab");
system("color ac");
system("color ad");
system("color ae");
system("color af");
system("color 90");
system("color 91");
system("color 92");
system("color c2");
system("color f2");
system("color f3");
system("color d0");
system("color d1");
system("color d2");
system("color d3");
system("color d4");
system("color d5");
system("color d6");
system("color d7");
system("color d8");
system("color d9");
system("color da");
system("color db");
system("color dc");
system("color de");
system("color df");
system("color c0");
system("color c1");
system("color c6");
system("color c7");
system("color c8");
system("color c9");
system("color ca");
system("color cb");
system("color cd");
system("color ce");
system("color cf");
system("color b0");
system("color b1");
system("color c3");
system("color c4");
system("color c5");
system("color 9b");
system("color 9c");
system("color 9d");
system("color 9e");
system("color 9f");
system("color 80");
system("color 81");
system("color 82");
system("color b4");
system("color b5");
system("color b6");
system("color b7");
system("color b8");
system("color 83");
system("color 84");
system("color 85");
system("color 86");
system("color 87");
system("color 89");
system("color 8a");
system("color 8b");
system("color 8c");
system("color 8d");
system("color 8e");
system("color 70");
system("color 71");
system("color 7a");
system("color 7b");
system("color 7c");
system("color 60");
system("color 61");
system("color 62");
system("color 78");
system("color 79");
system("color 6c");
system("color 93");
system("color 94");
system("color 95");
system("color 96");
system("color 97");
system("color 98");
system("color 9a");
system("color 6d");
system("color 6e");
system("color 50");
system("color 51");
system("color 52");
system("color 53");
system("color 54");
system("color 65");
system("color 66");
system("color 0f");
system("color 2b");
system("color 2c");
system("color 2d");
system("color 2e");
system("color 2f");
system("color 10");
system("color 12");
system("color 13");
system("color 14");
system("color 15");
system("color 16");
system("color 17");
system("color 18");
system("color 19");
system("color 1a");
system("color 1b");
system("color 1c");
system("color 1d");
system("color 1e");
system("color 1f");
system("color 7d");
system("color 7e");
system("color 7f");
system("color 5f");
system("color 63");
system("color 64");
system("color 47");
system("color 48");
system("color 67");
system("color 68");
system("color 69");
system("color 6a");
system("color 6b");
system("color 72");
system("color 73");
system("color 74");
system("color 75");
system("color 76");
system("color 40");
system("color 41");
system("color 42");
system("color 43");
system("color 45");
system("color 46");
system("color 36");
system("color 37");
system("color 38");
system("color 39");
system("color 3a");
system("color 3b");
system("color 3c");
system("color 3d");
system("color 3e");
system("color 3f");
system("color 20");
system("color 21");
system("color 23");
system("color 24");
system("color 56");
system("color 57");
system("color 58");
system("color 8f");
system("color 59");
system("color 5a");
system("color 5b");
system("color 5c");
system("color 5d");
system("color 5e");
system("color 4b");
system("color 4c");
system("color 4d");
system("color 4e");
system("color 4f");
system("color 30");
system("color 31");
system("color 32");
system("color 34");
system("color 35");
system("color 25");
system("color 26");
system("color 27");
system("color 28");
system("color 29");
system("color 2a");
system("color 49");
system("color 4a");
system("color 01");
system("color 02");
system("color 03");
system("color 04");
system("color 05");
system("color 06");
system("color 07");
system("color 08");
system("color 09");
system("color 0a");
system("color 0b");
system("color 0c");
system("color 0d");
system("color 0e");
}//this
void Ried() {
printf("请选择角色:\n\t1.罗辑\t2.章北海");
input=getch();
if (input=='1') {
me_a=tu_a;
me_d=tu_d;
for (int i=0; i<7; i++) {
me[i]=tu[i];
me_attack[i]=tu_attack[i];
me_dodge[i]=tu_dodge[i];
}
srand(time(0));
attack=rand()%6+15+a;
} else if (input=='2') {
me_a=hu_a;
me_d=hu_d;
for (int i=0; i<7; i++) {
me[i]=hu[i];
me_attack[i]=hu_attack[i];
me_dodge[i]=hu_dodge[i];
}
srand(time(0));
attack=rand()%11+15+a;
}
hp=100;
your_hp=100;
while (your_hp>0 && hp>0) {
system("cls");
cout<<" "<<your_hp<<"\t\t\t "<<hp<<endl;
///////////////////////////////打印皮肤
if(num==1) {
for (int i=0; i<7; i++) {
cout<<waterdrop[i]<<me[i]<<"\n";
}
}
else if(num==2) {
for (int i=0; i<7; i++) {
cout<<miko[i]<<me[i]<<"\n";
}
}
else {
for (int i=0; i<7; i++) {
cout<<you[i]<<me[i]<<"\n";
}
}
cout<<"____________________________________\n "<<di[num]<<"\t\t 你\n";
cout<<"\t\t请选择\n\t\t 1."<<me_a<<"\n\t\t 2."<<me_d<<"\n";
if (d>0) {
cout<<"\t\t 3.二向箔\n";
}
if(dizhichui==1&&num==1) {
cout<<"\t\t 4.让丁仪用地质锤怒砸水滴一分钟";
}
input=getch();
system("cls");
cout<<" "<<your_hp<<"\t\t\t "<<hp<<endl;
if (input=='1') {
if(num==1) {
for (int i=0; i<7; i++) {
cout<<waterdrop[i]<<me_attack[i]<<"\n";
}
}
else if(num==2) {
for (int i=0; i<7; i++) {
cout<<miko[i]<<me_attack[i]<<"\n";
}
}
else {
for (int i=0; i<7; i++) {
cout<<you[i]<<me_attack[i]<<"\n";
}
}
cout<<"____________________________________\n";
Sleep(500);
your_hp-=attack;
hp-=1;
}
else if(input=='3' && d>0 && num!=4) {
d-=1;
your_hp=0;
printf("\t\t砰!\n");
}
else if(num==1&&input=='4') {
dizhichui=0;
your_hp=0;
printf("\t\t*水滴碎成了碎片。\n");
}
else {
for (int i=0; i<7; i++) {
cout<<you[i]<<me_dodge[i]<<"\n";
}
cout<<"____________________________________\n";
Sleep(500);
hp+=2+b;
continue;
}
///////////////////////////////////////////我方攻击完毕
system("cls");
cout<<" "<<your_hp<<"\t\t\t "<<hp<<endl;
///////////////////////////////////////////对方开始攻击
if(num==1) {
for (int i=0; i<7; i++) {
cout<<waterdrop_attack[i]<<me[i]<<"\n";
}
}
else if(num==2) {
for (int i=0; i<7; i++) {
cout<<miko_attack[i]<<me[i]<<"\n";
}
}
else {
for (int i=0; i<7; i++) {
cout<<you_attack[i]<<me[i]<<"\n";
}
}
cout<<"____________________________________\n";
Sleep(500);
hp-=your_attack;
your_hp-=1;
if (c>0) {
printf("\t你吃卤煮加血!\n");
}
Sleep(500);
hp+=c;
}
if (your_hp>0) {
printf("你输了!");
} else {
printf("你赢了!");
num+=1;
money+=attack;
}
}
void Show() {
printf("\n\t\t\t\t\t\t路线图\n");
Sleep(10);
printf("\t太阳系\n");
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
for (int i=1; i<=5; i++) {
if (i<=num) {
printf("\t●\n");
} else {
printf("\t0\n");
}
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
printf("\t|\n");
Sleep(100);
}
printf("\t三体星系\n");
Sleep(1000);
cout<<"你";
Sleep(200);
cout<<"还";
Sleep(200);
cout<<"有";
Sleep(200);
cout<<5-num;
Sleep(200);
cout<<"光";
Sleep(200);
cout<<"年";
Sleep(200);
cout<<"没";
Sleep(200);
cout<<"过";
Sleep(200);
cout<<"!";
Sleep(200);
}
int main() {
SetConsoleTitle ("三体");
cout<<endl<<endl<<endl;
cout<<"\t\t\t\t _____________/ |"<<endl;
cout<<"\t\t\t\t /___|____"<<endl;
cout<<"\t\t\t\t _____________/| /|\\ "<<endl;
cout<<"\t\t\t\t /|| / | \\"<<endl;
cout<<"\t\t\t\t_____________/ |/____|____\\"<<endl;
cout<<"\t\t\t\t || |"<<endl;
Sleep(1000);
color1();
system("cls");
cout<<"开始游戏前,请确认当前文件夹下是否有文件save.save。如没有,请自行创建。"<<endl;
cout<<"是否读取存档?"<<endl;
input=getch();
if(input==1){
readrf();
}
system("cls");
cout<<"请给你自己取一个名字吧:";
cin>>playerName;
cout<<"welcome,"<<playerName<<"!"<<endl;
Sleep(1000);
system("cls");
Sleep(500);
//cheat system
long long llsohve;
string str;
cout<<"Do you want to cheat?If you want,please enter 1."<<endl;
input=getch();
if(input=='1') {
cout<<"Please enter cheat code!"<<endl;
//,money=0,attack,hp=100,your_hp=100,your_attack=17,
while(cin>>str) {
if(str=="114514") {
cout<<"无限血量!";
hp=999999;
//your_hp=999999;
continue;
} else if(str=="1919810") {
cout<<"无限钱!";
money=999999;
continue;
} else if(str=="llsohve") {
cout<<"无限攻击!";
attack=999999;
continue;
} else {
break;
}
}
}
system("cls");
while (num<5) {
Show();
system("cls");
printf("\n请选择:\n\t1.攻占三体星系\t2.刘慈欣商颠\n");
input=getch();
if (input=='1') {
Ried();
writerf();
} else if (input=='2') {
if (money<=10) printf("没钱,打出去!");
else {
cout<<"你的钱:"<<money<<endl;
printf("你要买什么?\n");
printf("|---1---|---2---|---3---|---4---|---5---|\n");
printf("|A冰冻罗| _ 绿色|l##l 卤|二向箔 |<=+=>地|\n");
printf("|| 非鱼 || |风暴|l##l 煮|?? | | 质|\n");
printf("|| ||_| | || |?? | | 锤|\n");
printf("|10马克 |10马克 |40马克 |20马克 |1马克 |\n");
printf("|-------|-------|-------|-------|-------|\n");
printf("|攻击+2 |回血+2 |每回合 |可以毁 |可以毁 |\n");
printf("| | |可回血 |灭对手 |灭水滴 |\n");
printf("| |10滴 |(对歌者| | |\n");
printf("| | |无效) | | |\n");
printf("|_______|_______|_______|_______|_______|\n");
input=getch();
if (input=='1') {
if (money<10) {
printf("钱不够,打出去!");
} else {
printf("购买成功,攻击增加!");
money-=10;
a+=2;
}
} else if (input=='2') {
if (money<10) {
printf("钱不够,打出去!");
} else {
printf("购买成功,回血量增加!");
money-=10;
b+=2;
}
} else if (input=='3') {
if (money<40) {
printf("钱不够,打出去!");
} else {
printf("购买成功,每回合可回血10滴!");
money-=40;
c=10;
}
} else if (input=='4') {
if (money<20) {
printf("钱不够,打出去!");
} else {
printf("购买成功,二向箔可以毁灭对手(对歌者无效)!");
money-=20;
d+=1;
}
} else if (input=='5') {
if (money<1) {
printf("钱不够,打出去!");
} else {
printf("购买成功,地质锤可以毁灭水滴!");
money-=20;
dizhichui=1;
}
}
}
} else printf("不识字就直说!");
Sleep(2000);
system("cls");
}
printf("你攻入了三体星系!");
exit(0);
}
//ctrl+shift+a
这个游戏是拿ChenYiZhou的《封神演义大乱斗》改的,感谢CYZ写的代码框架