タイトルなしで実行しないでください。コードを個別に渡してください。ストロークを確認してください。

#include<iostream>
#include<conio.h>
#include<windows.h>
#include<fstream>
#include<time.h>
using namespace std;

struct game
{
	int coin;
	int HP;
	int wuqi1;
	int wuqi2;
}player;

int index(string arr[],string mubiao)
{
	for(int j=0;j<(sizeof(arr)/sizeof(string));j++)
	{
		if(arr[j]==mubiao)
		{
			return j;
		}
	}
}

void out(string output)
{
	if (output == "endl") cout<<endl;
	else
	{
		for(int i=0;i<output.size();i++)
		{
			cout<<output[i];
			Sleep(50);
		}
	}
}

int main()
{
	system("color F0");
	/*coin初始化*/
	ofstream t("coin.txt");
	t.close();
	ifstream readFile("coin.txt");
	readFile>>player.coin;
	readFile.close();
	/*HP初始化*/
	ofstream te("HP.txt");
	te.close(); 
	ifstream h("HP.txt",ios::in);
	h>>player.HP;
	h.close(); 
	if (player.HP==0)
	{
		ofstream hh("HP.txt");
		player.HP=100;
		hh<<100;
	}
	/*********/
	ofstream wuqi1bianhao("武器1.txt");
	wuqi1bianhao.close();
	ifstream temp;
	temp.open("武器1.txt");
	temp>>player.wuqi1;
	temp.close();
	ofstream wuqi2bianhao("武器2.txt");
	wuqi1bianhao.close();
	ifstream temp1;
	temp1.open("武器2.txt");
	temp1>>player.wuqi2;
	temp1.close();
	/*********/ 
	string diren[15] = {"普通敌军","old six","特种部队","端着电脑的程序员","高级陆战部队" };
	int direnshanghai[15] = {   20    ,   35    ,    30    ,        35        ,       25  };
	int direnxueliang[15] = { 80     ,   160   ,   150    ,       180        ,      100   };
	string wuqi[15] = {"撬棍","镰刀","m1911手枪","m134重机枪","M416突击步枪","RPG火箭筒","AKM突击步枪","uzi冲锋枪","AWM狙击枪","M24狙击枪"};
	int wuqishanghai[15] = {10  ,  10  ,   25      ,    50      ,     45       ,     60    ,      50     ,    40     ,     50 ,    46     };
	int wuqijiage[15] = {100 , 100     ,  250      ,   700      ,     650      ,   1000   ,    700      ,     500   ,      600,      550  };
	string beibao[10];
	/*读取背包*/ 
	ofstream tem("玩家背包.txt");
	tem.close();
    ifstream infile("玩家背包.txt");
    int item=0;
    if (!infile.fail())
    {
        while (!infile.eof())
        {
        	if (infile==0)
        	{
        		break;
			}
            infile >> beibao[item];
            item++;
        }
    }
    infile.close();
	/********/
	s:
		out("欢迎来到{战争游戏}");out("endl");
		out("1.商店");out("endl");
		out("2.战争");out("endl");
		out("3.背包");out("endl");
		out("4.金币");out("endl");
		while (true)
		{
			int ch=getch();
			if (ch=='1')
			{
				system("cls");
				for(int i=0;i<10;i++)
				{
					cout<<wuqi[i]<<" "<<wuqijiage[i]<<"金币"<<endl; 
				}
				cout<<"你的金币:"<<player.coin<<"    "<<"输入0返回,输入武器名称购买";
				string op;
				cin>>op;
				if (op=="0")
				{
					system("cls");
					goto s;
				} 
				if (player.coin>=wuqijiage[index(wuqi,op)])
				{
					ofstream d("coin.txt");
					player.coin-=wuqijiage[index(wuqi,op)];
					d<<player.coin;
					d.close();
					cout<<"购买成功!";
					ofstream sy("玩家背包.txt",ios::app);
					sy<<index(wuqi,op)<<endl;
					Sleep(2000);
					system("cls");
					goto s;
				}
				else
				{
					cout<<"金币不足!";Sleep(2000);
					system("cls");
					goto s;
				}
			} 
			if (ch=='2')
			{
				system("cls");
				srand(time(0));
				int direnbianhao = 0;//rand()%(4-0)+0;
				int huihe = 1;
				int flag=0;
				int zhiling;
				int drxl = direnxueliang[direnbianhao]; 
				if (direnbianhao==0)
				{
					while (flag==0)
					{
						cout<<endl<<"回合:"<<huihe<<endl<<endl;
						cout<<"你遇到了"<<diren[0]<<"!"<<endl;
						cout<<diren[0]<<"属性:"<<endl;
						cout<<"伤害:"<<direnshanghai[0]<<endl;
						cout<<"技能:"<<"无技能"<<endl;
						cout<<"血量:"<<drxl<<endl; 
						cout<<"你的属性:"<<endl;
						cout<<"血量:"<<player.HP<<endl; 
						cout<<"1.进攻 2.打药(药品数量:∞)"<<endl;
						cout<<"请输入:";cin>>zhiling;
						if (zhiling==1)
						{
							int playerzhandouli = (wuqishanghai[player.wuqi1]+wuqishanghai[player.wuqi2]);
							int direndeshanghai = direnshanghai[direnbianhao];
							cout<<endl<<"对敌人造成伤害 "<<playerzhandouli;
							drxl-=playerzhandouli;
							cout<<endl<<"敌人对你造成伤害 "<<direndeshanghai;
							player.HP-=direndeshanghai;
							huihe++;
							Sleep(2000);
							if (player.HP<=0)
							{
								Sleep(1000);
								system("cls");
								ifstream x("HP.txt");
								x>>player.HP;
								x.close();
								cout<<"你死了!";
								Sleep(1000);
								goto s;
							}
							if (drxl<=0)
							{
								Sleep(1000);
								system("cls");
								ifstream x("HP.txt");
								x>>player.HP;
								x.close();
								cout<<"你赢了!";
								cout<<"金币+50";
								player.coin+=50;
								ofstream y("coin.txt");
								y<<player.coin;
								y.close();
								Sleep(1000);
								system("cls");
								goto s;
							}
							system("cls");
						}
						if (zhiling==2)
						{
							int direndeshanghai = direnshanghai[direnbianhao];
							cout<<endl<<"敌人对你造成伤害 "<<direndeshanghai;
							player.HP-=direndeshanghai;
							cout<<endl<<"你的血量+30";
							player.HP+=30;
							Sleep(1000);
							if (player.HP<=0)
							{
								Sleep(1000);
								system("cls");
								ifstream x("HP.txt");
								x>>player.HP;
								x.close();
								cout<<"你死了!";
								Sleep(1000);
								goto s;
							}
							if (drxl<=0)
							{
								Sleep(1000);
								system("cls");
								ifstream x("HP.txt");
								x>>player.HP;
								x.close();
								cout<<"你赢了!";
								cout<<"金币+50";
								player.coin+=50;
								ofstream y("coin.txt");
								y<<player.coin;
								y.close();
								Sleep(1000);
								system("cls");
								goto s;
							}
							system("cls");
						}
					}
				}
			}
		}
		return 0;
}

おすすめ

転載: blog.csdn.net/m0_64036070/article/details/123708132