回 帖 发 新 帖 刷新版面

主题:新手:做了个小游戏

#include<cstdio>
#include<cstdlib>
#include<map>
#include<windows.h>//Sleep 
#include<string.h>
#include<cmath>
#include<assert.h>
#include<ctype.h>
#include<conio.h>//getch
#include<errno.h>
#include<float.h>
#include<fstream>//ifstream、ofstream 
#include<iomanip>
#include<iostream>//输入输出 
#include<limits.h> 
#include<locale.h>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>//rand() 
#include<wchar.h>
#include<wctype.h>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<functional>
#include<list>
#include<ios>
#include<iosfwd>
#include<ostream>
#include<istream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
//移动 
void move(int x,int y)
{
	COORD c;
	c.X=x;
	c.Y=y;
	HANDLE p=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(p,c);
}
//缓慢打印 
void print(string a)
{
	for(int i=0;i<a.size();i++)
	{
		cout<<a[i];
		Sleep(30);
	}
}
//隐藏光标 
void hide()
{
	HANDLE q=GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO c;
	GetConsoleCursorInfo(q,&c);
	c.bVisible=false;
	SetConsoleCursorInfo(q, &c);
}
//熊猫 
struct player1
{
	int money;
	int level=1;
	int hp=500;
	int x=20;
	int y=10;
	int num=5;
};
player1 n;
//蝴蝶 
struct player2
{
	int money;
	int level=1;
	int hp=500;
	int x=40;
	int y=10;
	int num=3;
};
player2 t;
//颜色设置 
void color(int x)
{
	HANDLE q=GetStdHandle(-11);
	SetConsoleTextAttribute(q,x);
}
//礼包码 
string a="wechat";//金币初级大礼包 
string b="program";//HP值封神大礼包 
string c="system";//金币至尊大礼包
string d="code";
string e="language"; 
string password="3body";
//玩家
string name=" "; 
int main()
{ 
	ifstream fin("money1.txt");
	fin>>t.money;
	fin.close();
	string system1;
	hide();
	char check,input,cin1,in;
	int win=0;
	while(1)
	{
		ifstream fin("info2.txt");
		fin>>system1;
		fin.close();
		hide();
		system("cls");
		cout<<"熊猫戏蝶游戏:\n";
		cout<<"1.开始游戏\n";
		cout<<"2.礼包码兑换\n";
		cout<<"3.查看成就\n";
		cout<<"4.查看信息\n";
		cout<<"5.商城\n"; 
		cout<<"8.关于本游戏及反馈\n";
		cout<<"9.退出游戏\n"; 
		cin>>cin1;
		if(cin1=='1')
		{	
			system("cls");
			hide();
			cout<<"角色一(熊猫)用wasd来控制走位,角色二(蝴蝶)用ijkl来控制走位!\n";
			cout<<"角色一技能——瞬移:用Q键来进行瞬移,只有5次机会\n";
			cout<<"角色二技能——随机瞬移3次:用p键,可随机瞬移到某个地方3次,有3次机会\n";
			cout<<"只要角色一碰到角色二,角色二金币和hp减少100!\n";
			cout<<"如果角色二hp值为0,则角色一获胜!\n";
			Sleep(2000);
			cout<<"按0键开始游戏!\n";
			while((check=getch())!='0') continue;	
			system("cls");
			move(n.x,n.y);
			cout<<"O";
			move(t.x,t.y);
			cout<<"8";
			while(1)
			{
				ifstream fin("money.txt");
				fin>>n.money;
				fin.close();
				hide();
				move(0,30);
				cout<<"熊猫血量:"<<n.hp<<endl;
				cout<<"蝴蝶血量:"<<t.hp; 
				move(100,30);
				cout<<"熊猫金币:"<<n.money;
				move(100,31);
				cout<<"蝴蝶金币:"<<t.money; 
				input=getch();
				switch(input)
				{
					case 'w':
						if(n.y!=0)
						{
							move(n.x,n.y);
							cout<<" ";
							n.y--;
							move(n.x,n.y);
							cout<<"O";
						}
						break;
					case 's':
						if(n.y!=29)
						{
							move(n.x,n.y);
							cout<<" ";
							n.y++;
							move(n.x,n.y);
							cout<<"O";
						}
						break;
					case 'a':
						if(n.x!=0)
						{
							move(n.x,n.y);
							cout<<" ";
							n.x--;
							move(n.x,n.y);
							cout<<"O";
						}
						break;
					case 'd':
						if(n.x!=119)
						{	
							move(n.x,n.y);
							cout<<" ";
							n.x++;
							move(n.x,n.y);
							cout<<"O";
						}
						break;
					case 'q':
						if(n.num>0)
						{
							move(n.x,n.y);
							cout<<" ";
							srand((unsigned)time(NULL));
							srand((unsigned)time(NULL));
							int z;
							z=rand()%30;
							int e;
							e=rand()%30;
							n.x=z;
							n.y=e;
							move(n.x,n.y);
							cout<<"O";
							n.num--;
							n.hp-=20;
							n.money-=50;
						}
						break;	
					
					case 'i':
						if(t.y!=0)
						{
							move(t.x,t.y);
							cout<<" ";
							t.y--;
							move(t.x,t.y);
							cout<<"8";
						}
						break;
					case 'k':
						if(t.y!=29)
						{
							move(t.x,t.y);
							cout<<" ";
							t.y++;
							move(t.x,t.y);
							cout<<"8";
						}
						break;
					case 'j':
						if(n.x!=0)
						{
							move(t.x,t.y);
							cout<<" ";
							t.x--;
							move(t.x,t.y);
							cout<<"8";
						}
						break;
					case 'l':
						if(t.x!=119)
						{
							move(t.x,t.y);
							cout<<" ";
							t.x++;
							move(t.x,t.y);
							cout<<"8";
						}
						break;
					case 'p':
						if(t.num>0)
						{
							for(int i=1;i<=3;i++)
							{
								move(t.x,t.y);
								cout<<" ";
								srand((unsigned)time(NULL));
								srand((unsigned)time(NULL));
								int e,l;
								e=rand()%119;
								l=rand()%30;
								t.x=e;
								t.y=l;
								move(t.x,t.y);
								cout<<"8";
								Sleep(500);
							}
							t.num--;
							t.hp-=50;
							t.money-=50;
						}
						break;				
				}
				if(n.x==t.x&&n.y==t.y) 
				{
					if(t.money>0) t.money-=50;
					if(t.hp>0) t.hp-=50;
				}
				if(t.hp==0||t.money==0) break;
			}
			system("cls");
			cout<<"恭喜恭喜,角色一赢得了胜利!!!\n";
			cout<<"正在存档...";
			ifstream fin("info1.txt");
			fin>>win;
			win++;
			ofstream fout("info1.txt");
			fout<<win;
			fout.close();
			Sleep(5000);
			cout<<"\n";
		} 
		if(cin1=='2')
		{
			string libao;
			char check1;
			system("cls");
			cout<<"请问你是熊猫还是蝴蝶(熊猫扣1,蝴蝶扣2)\t";
			cin>>check1;
			if(check1=='1')
			{
				color(11);
				cout<<"1.金币初级大礼包!\n\n";
				color(2);
				cout<<"2.money封神大礼包!!\n\n";
				color(3);
				cout<<"3.金币至尊大礼包!!!\n\n";
				color(5);
				cout<<"4.金币$$$$大礼包!!!!\n\n";
				color(6);
				cout<<"5.财神贺岁大礼包!!!!!\n\n";
				cin>>in;
				if(in=='1')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(a==libao||password==libao)
					{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币数+100!\n";
						n.money+=100;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}
				} 	
				if(in=='2')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(b==libao||password==libao)
					{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币值+50!\n";
						n.money+=50;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}
				} 
				if(in=='3')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(c==libao||password==libao)
					{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币数+250!\n";
						n.money+=250;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}
				}
				if(in=='4')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(d==libao||password==libao)
						{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币+50!\n";
						n.money+=50;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}	
				} 
				if(in=='5')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(e==libao||password==libao)
					{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币值+200!\n";
						n.money+=200;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}
				}
				ofstream fout("money.txt");
				fout<<n.money;
				fout.close();
			}
			if(check1=='2')
			{
				color(11);
				cout<<"1.金币初级大礼包!\n\n";
				color(2);
				cout<<"2.money封神大礼包!!\n\n";
				color(3);
				cout<<"3.金币至尊大礼包!!!\n\n";
				color(5);
				cout<<"4.金币$$$$大礼包!!!!\n\n";
				color(6);
				cout<<"5.财神贺岁大礼包!!!!!\n\n";
				cin>>in;
				if(in=='1')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(a==libao||password==libao)
					{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币数+100!\n";
						t.money+=100;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}
				} 	
				if(in=='2')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(b==libao||password==libao)
					{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币值+50!\n";
						t.money+=50;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}
				} 
				if(in=='3')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(c==libao||password==libao)
					{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币数+250!\n";
						t.money+=250;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}
				}
				if(in=='4')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(d==libao||password==libao)
						{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币+50!\n";
						t.money+=50;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}	
				} 
				if(in=='5')
				{
					color(15);
					cout<<"请输入礼包码:\n";
					cin>>libao;
					if(e==libao||password==libao)
					{
						cout<<"\n\n";
						cout<<"兑换成功!初始金币值+200!\n";
						t.money+=200;
						Sleep(3000);
					}
					else
					{
						cout<<"礼包码错误,请下次再来!\n";
					}
				}
				ofstream fout("money1.txt");
				fout<<t.money;
				fout.close();
			}
			Sleep(1000);
		}
		
		if(cin1=='3')
		{
			system("cls");
			cout<<"你的成就:\n";
			ifstream fin("info1.txt");
			fin>>win;
			if(win>=3) cout<<"熊猫戏蝶游戏获胜3次!\n\n";
			else cout<<"          无";
			if(win>=5)
			{
				cout<<"恭喜熊猫戏蝶游戏获胜5次!奖励一次升级系统!\n\n";
				if(system1=="GV.2.28")
				{
					system1="GT.3.34";
					ofstream fout("info2.txt");
					fout<<system1;
					fout.close(); 
				} 
				else cout<<"(已升级)";	
			}
			if(win>=7) cout<<"熊猫戏蝶游戏获胜7次!\n\n";
			if(win>=9)
			{
				cout<<"熊猫戏蝶游戏获胜9次!奖励一次升级系统!";
				if(system1=="GT.3.34")
				{
					system1="GD.4.45";
					ofstream fout("info2.txt");
					fout<<system1;
					fout.close();
				}
				else cout<<"(已升级)\n\n";
			}
			Sleep(10000);
		}
		if(cin1=='4')
		{
			ifstream fin("money.txt");
			fin>>n.money;
			fin.close();
			system("cls");
			if(name==" ")
			{
				cout<<"请玩家设置昵称:";
				cin>>name;
				system("cls");
			}
			print("玩家昵称:");
			print(name);
			print("\n\n");
			print("HP值:500\t金币值:");
			cout<<n.money;
			print("\n你的造型:O\t");
			print("系统级别:");
			print(system1);
			Sleep(3000); 
		}
		if(cin1=='5')
		{
			char mall,sd;
			system("cls");
			cout<<"请问你是什么身份?(1.熊猫 2.蝴蝶)\n";
			cin>>sd;
			if(sd=='1')
			{
				color(6);
				print("商城:\n");
				print("\t1.兑换金币\n");
				print("\t2.退出商城\n");
				while(1)
				{
					cin>>mall;
					if(mall=='1')
					{
						system("cls");
						cout<<"您所拥有的金币:"<<n.money<<"\n\n";
						print("兑换金币需要支付您的游戏胜利次数,请谨慎考虑!!!\n");
						Sleep(1000);
						print("想必您已经有了选择,如果确定继续兑换金币的话,请输入ok;否则输入quit!!!\n");
						string strp;
						cin>>strp;
						if(strp=="ok"||strp=="Ok"||strp=="OK")
						{
							system("cls");
							cout<<"你目前的胜利次数:"<<system1;
							cout<<"\n一次胜利可以兑换100金币!\n";
							cout<<"请问你要兑换多少?\n";
							int er;
							cin>>er;
							if(er>system1)
							{
								cout<<"没有这么多!!!\n";
								Sleep(2000);
							}
							else
							{
								cout<<"兑换成功!!!\n";
								Sleep(2000);
								n.money+=er*100;
								system1-=er;
							}
						}
						
					}
					if(mall=='2') break;
				}
			}
			if(sd=='2')
			{
				
				color(6);
				print("商城:\n");
				print("\t1.兑换金币\n");
				print("\t2.退出商城\n");
				while(1)
				{
					cin>>mall;
					if(mall=='1')
					{
						system("cls");
						cout<<"您所拥有的金币:"<<t.money<<"\n\n";
						print("兑换金币需要支付您的游戏胜利次数,请谨慎考虑!!!\n");
						Sleep(1000);
						print("想必您已经有了选择,如果确定继续兑换金币的话,请输入ok;否则输入quit!!!\n");
						string strp;
						cin>>strp;
						if(strp=="ok"||strp=="Ok"||strp=="OK")
						{
							system("cls");
							cout<<"你目前的胜利次数:"<<system1;
							cout<<"\n一次胜利可以兑换100金币!\n";
							cout<<"请问你要兑换多少?\n";
							int er;
							cin>>er;
							if(er>system1)
							{
								cout<<"没有这么多!!!\n";
								Sleep(2000);
							}
							else
							{
								cout<<"兑换成功!!!\n";
								Sleep(2000);
								t.money+=er*100;
								system1-=er;
							}
						}
						
					}
					if(mall=='2')break;
				}
			}
		}
		if(cin1=='6')
		{
			system("cls");
			print("熊猫戏蝶游戏是微软游戏公司开发给6岁以上儿童的益智游戏,本游戏通过wasd键(或ijkl键)控制人物的上下左右移动!");
			print("锻炼6岁以上儿童的空间思维能力,还有临时应变能力,本游戏还设置了两个技能给玩家用,但限制次数!");
			print("为的就是让玩家不要依赖于这两个技能,要会灵活走位,才能取得胜利!本游戏还设置了金币等物品!");
			print("\n\n");
			cout<<"游戏版本:"<<system1;
			Sleep(5000);
		}
		if(cin1=='7') 
		{
			system("cls");
			color(3);
			cout<<"确定不在逗留一会儿吗?( Y || N )\n";
			char oi;
			while(1)
			{
				cin>>oi;
				if(oi=='y'||oi=='Y')
				{
					cout<<"记得下次来玩哦~~";
					Sleep(2000);
					return 0; 
				}
			}
		}
	}
	return 0;
}
//好不容易写好,一大堆报错,现在改了。主要错在ifstream和ofstream上。

回复列表 (共3个回复)

沙发

一半烟火,一半清欢

一半清醒

双色球走势图
澳洲幸运20


开奖网开奖结果

,一半释然

雾气朦胧,本色出演

板凳

yaosicheng.blog.csdn.net

我也做过一些小游戏

3 楼

朋友,你是在献丑吗?你的代码615、625、660、670这几行,拿一个string类型的变量跟一个int类型的变量比大小/相减,编译器一眼报错,然后你在文章中称“一大堆报错,现在改了”,一点意思都没有。

我来回复

您尚未登录,请登录后再回复。点此登录或注册