game1(自制小游戏)
2026-08-21 17:33:26
发布于:河南
大家好!最近闲来无事做了一款自己也不知道怎么取名的346行小游戏。
创作时每天只写几行代码,
写 了半年
也是非常的辛苦
算了,直接给大家看代码,觉得好玩扣1!
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
void plane(){
cout<<" ###"<<endl;
cout<<"# ###"<<endl;
cout<<"## ###"<<endl;
cout<<"################"<<endl;
cout<<"#################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" ################"<<endl;
cout<<" #################"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ###"<<endl;
cout<<" ## ###"<<endl;
cout<<" #############"<<endl;
cout<<" #############"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<" ###"<<endl;
cout<<" # ##"<<endl;
cout<<" ## #"<<endl;
cout<<" #########"<<endl;
cout<<" #########"<<endl;
cout<<" ##"<<endl;
cout<<" ###"<<endl;
cout<<" ###"<<endl;
system("cls");
cout<<endl;
cout<<" #"<<endl;
cout<<" ##"<<endl;
cout<<" #####"<<endl;
cout<<" #####"<<endl;
system("cls");
cout<<endl;
cout<<" #"<<endl;
cout<<" #"<<endl;
cout<<" #"<<endl;
cout<<" #"<<endl;
system("cls");
}
void number(){
for(int i=0;i<=10;i++){
cout<<"010101010101010101010101010101010101"<<endl;
cout<<"101010101010101010101010101010101010"<<endl;
cout<<"010101010101010101010101010101010101"<<endl;
cout<<"101010101010101010101010101010101010"<<endl;
cout<<"010101010101010101010101010101010101"<<endl;
system("cls");
cout<<"101010101010101010101010101010101010"<<endl;
cout<<"010101010101010101010101010101010101"<<endl;
cout<<"101010101010101010101010101010101010"<<endl;
cout<<"010101010101010101010101010101010101"<<endl;
cout<<"101010101010101010101010101010101010"<<endl;
system("cls");
}
}
int main(){
int dx=100,wx=100,b,dr=5,wr=5;
float dj=5,wj=5;
string a;
cout<<"游戏现在开始!"<<endl;
cout<<"按下G键攻击,F键防守,H键回血,Z键招揽军马人才!"<<endl;
system("pause");
system("cls");
cout<<"你先来!"<<endl;
system("pause");
system("cls");
for(int i=1;i<=10;i++){
srand(time(NULL));
cout<<"我方血量:"<<wx<<endl;
cout<<"我方人才:"<<wr<<endl;
cout<<"我方军马:"<<wj<<"W"<<endl;
cin>>a;
if(a=="g"||a=="f"){
cout<<"开局前10回合不能使用“攻击 ”或 “防御 ”";
i--;
system("pause");
system("cls");
}else if(a=="h"){
wx+=2;
system("cls");
}else if(a=="z"){
wr=wr+rand()%5+1;
wj=wj+0.2;
cout<<"已招揽军马人才"<<endl;
system("pause");
system("cls");
}else{
cout<<"按下G键攻击,F键防守,H键回血,Z键招揽军马人才!"<<endl;
i--;
system("pause");
system("cls");
}
srand(time(NULL));
int d=rand()%4+1;
switch(d){
case 1:
case 2:
dx+=2;
break;
case 3:
case 4:
srand(time(NULL));
dr=dr+rand()%5+1;
dj=dj+0.2;
}
}
while(1){
if(dx<=0){
system("cls");
cout<<"恭喜你,你赢了!"<<endl;
break;
}else if(wx<=0){
system("pause");
system("cls");
cout<<"真遗憾,你输了"<<endl;
break;
}
cout<<"我方血量:"<<wx<<endl;
cout<<"我方人才:"<<wr<<endl;
cout<<"我方军马:"<<wj<<"W"<<endl;
if(wr%10==0){
cout<<endl;
cout<<"敌方血量:"<<dx<<endl;
cout<<"敌方人才:"<<dr<<endl;
cout<<"敌方军马:"<<dj<<"W"<<endl;
}
cin>>a;
if(a=="g"){
if(wj>0){
srand(time(NULL));
int dd=rand()%2+1;
if(dd==1 && dr>=15){
wj-=0.05;
dj-=0.02;
cout<<"攻击!!!"<<endl;
cout<<"对手防住了"<<endl;
system("pause");
system("cls");
}else{
dx-=5;
dj-=0.2;
wj-=0.05;
number();
cout<<"攻击!!!"<<endl;
cout<<"成功!!!"<<endl<<"已将对手血量减5"<<endl;
system("pause");
system("cls");
}
}else{
cout<<"我方军马小于0!"<<endl<<"损失一次机会!";
system("pause");
system("cls");
}
}else if(a=="f"){
cout<<"对手未攻击时不能使用“防御 ”"<<endl;
cout<<"损失一次机会!"<<endl;
system("pause");
system("cls");
}else if(a=="h"){
wx+=2;
system("cls");
}else if(a=="z"){
wr=wr+rand()%5+1;
wj=wj+0.2;
cout<<"已招揽军马人才"<<endl;
system("pause");
system("cls");
}else{
cout<<"按下G键攻击,F键防守,H键回血,Z键招揽军马人才!"<<endl;
cout<<"损失一次机会!"<<endl;
system("pause");
system("cls");
}
srand(time(NULL));
int d=rand()%4+1;
switch(d){
case 1:
dj-=0.05;
cout<<"警告!"<<endl;
cout<<"敌方攻击!"<<endl;
cin>>a;
if(a=="f"){
cout<<"完美防守!"<<endl;
wj-=0.02;
system("pause");
system("cls");
} else {
plane();
cout<<"糟糕!!"<<endl;
wx-=5;
system("pause");
system("cls");
}
break;
case 2:
dx+=2;
break;
case 3:
break;
case 4:
srand(time(NULL));
dr=dr+rand()%5+1;
dj=dj+0.2;
}
}
return 0;
}
全部评论 3
对手没兵怎么进攻的,对手的兵怎么可以为负数
14小时前 来自 浙江
0他说有木马病毒hyw
昨天 来自 安徽
0hyw(何意味)
19小时前 来自 河南
0放心,我已经试过好几次了,没木马
19小时前 来自 河南
0
19小时前 来自 河南
0
这是本人做的第一个小游戏,共346行,有什么建议或问题欢迎在评论区留言~
3天前 来自 河南
0建议使用编译器DEV-C++体验效果更佳
3天前 来自 河南
0如果觉得还可以请回1
3天前 来自 河南
01
23小时前 来自 上海
1
























有帮助,赞一个