C++自创棋类小游戏

今天给大家带来我花了1周时间自创的小游戏,博主还是一名小学生,希望大家提提意见。这是我写的最长的C++代码,希望大家喜欢,不要抄袭,代码共1328行,任何编译器都可以。

#include<windows.h>
#include<conio.h>
#include<bits/stdc++.h>
#include <stdlib.h>
using namespace std;
#define Forij(x) for(int i=1;i<=x;i++) for(int j=1;j<=x;j++)
#define N 25 
int v;
char* u;
int fx[4][2]={{1,1},{1,0},{0,1},{1,-1}};
int Q,GG;
string C[20]={"●","○","﹢","═","║","╔","╚","╗","╝","·"};
void color(int a){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);} 
void gotoxy(int x,int y){COORD pos;pos.X=2*x;pos.Y=y;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
struct Gomoku
{
    int m[50][50],nx,ny;
    void reset()
	{
        system("cls");
        memset(m,-1,sizeof(m));
        color(7);
        for (int i=1; i<=N; i++)
		{
            gotoxy(0,i);cout<<C[4]; gotoxy(N+1,i);cout<<C[4];
            gotoxy(i,0);cout<<C[3]; gotoxy(i,N+1);cout<<C[3];
        }
        gotoxy(0,0);cout<<C[5]; gotoxy(0,N+1);cout<<C[6];
        gotoxy(N+1,0);cout<<C[7]; gotoxy(N+1,N+1);cout<<C[8];
        color(3);
        Forij(N){gotoxy(i,j); cout<<C[2];}
        nx=ny=N/2+1; gotoxy(nx,ny);
    }
    void _drop(int x,int i,int j) 
	{
        m[i][j]=x;
        gotoxy(i,j);
        color(15); cout<<C[x];
    }
    int check()
	{
        Forij(N){
            for (int Fx=0,tmp,lst,xx,yy; Fx<4; Fx++) if(m[i][j]!=-1){
                xx=i,yy=j,tmp=0,lst=m[i][j];
                for (int k=1; k<=5; k++){
                    if (xx>N || yy>N) break;
                    if (m[xx][yy]==(lst^1)){break;}
                    if (m[xx][yy]==lst) tmp++;
                    xx+=fx[Fx][0],yy+=fx[Fx][1];
                }
                if (tmp==5){return lst;}
            }
        }
        return -1;
    }
    int arnd(int x,int y)
	{
        int cnt=0;
        for (int i=x-1; i<=x+1; i++) if (i>0 && i<=N)
            for (int j=y-1; j<=y+1; j++) if (j>0 && j<=N)
                if (m[i][j]>-1) cnt++;
    }
    void get_val(int x,int y,int &val)
	{
        val=0;
        Forij(N)
		{
            for (int Fx=0,tmp,tk,xx,yy; Fx<4; Fx++)
			{
                xx=i,yy=j,tmp=tk=0;
                for (int k=1; k<=5; k++)
				{
                    if (xx>N || yy>N){tmp=0; break;}
                    if (m[xx][yy]==(x^1)){tmp=0; break;}
                    if (m[xx][yy]==x) tmp++,tk+=(1<<(k-1));
                    xx+=fx[Fx][0],yy+=fx[Fx][1];
                }
                switch(tmp)
				{
                    case 5:val+=800000000; break; 
                    case 4:val+=1000+350*y; break;
                    case 3:val+=(tk==14)?(300+600*y):(300+200*y); break;
                    case 2:val+=3+2*y; break;
                    case 1:val+=1+y; break;
                }
            }
        }
    }
    void AI(int x)
	{
        int best,brnd,bi,bj,v1,v2,kkk;
        best=-2147483647;brnd=-2147483647;
        Forij(N) 
		if (m[i][j]==-1)
		{
            m[i][j]=x;
            get_val(x,10,v1);get_val(x^1,80,v2);
            if (v1-v2>best) bi=i,bj=j,best=v1-v2;
            if (v1-v2==best)
                if ((kkk=arnd(i,j))>brnd)
                    brnd=kkk,bi=i,bj=j;
            m[i][j]=-1;
        }
        _drop(x,bi,bj);
    }
    void HM(int x)
	{
        char ch=getch();bool t=224;
        for (;;ch=getch())
		{
            if (ch=='w'||ch=='W'||ch==72&&t) {if (ny>1) ny--;}
            else if (ch=='s'||ch=='S'||ch==80&&t) {if (ny<N) ny++;}
            else if (ch=='a'||ch=='A'||ch==75&&t) {if (nx>1) nx--;}
            else if (ch=='d'||ch=='D'||ch==77&&t) {if (nx<N)nx++;}
            else if ((ch==32&&t||ch==13&&t)&&m[nx][ny]==-1){_drop(x,nx,ny); return;}
            gotoxy(nx,ny);
        }
    }
} A;
class Chessboard;
class Chess
{
private:
	int Id;
public:
	Chess(int x) :Id(x) {}
	int Get()                
	{
		return Id;
	}
	virtual bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy) = 0;
	virtual ~Chess() {}
};
class Chessboard
{
private:
	Chess *c[10][11];       
	char Chessword[15][4] = { "兵","炮","车","马","相","仕","帅"," ","将","士","象","馬","車","砲","卒" };
public:
	static int Player;       
	static bool End;         
	Chessboard();
	Chess *Get(int x, int y);
	int Getid(int x, int y);
	bool Move(int startx, int starty, int endx, int endy);	
	void Init();               
	void Show();              
	void Play();              
	~Chessboard();
};
class General :public Chess
{
public:
	General(int i) :Chess((i == 0 ? -1 : 1)) {}
	bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
	{
		int TempX = startx - endx;
		int TempY = starty - endy;
		int S_Id = ch.Getid(startx, starty);
		int E_Id = ch.Getid(endx, endy);
		if ((S_Id*E_Id <= 0) && (TempX*TempX + TempY * TempY == 1) && (endx >= 4 && endx <= 6) && (endy >= 1 && endy <= 3 || endy >= 8 && endy <= 10))
		{
			return true;
		}
		return false;
	}
	~General()
	{
		Chessboard::End = false;
	}
};
class BodyGuard :public Chess
{
public:
	BodyGuard(int i) :Chess((i == 0 ? -2 : 2)) {}
	bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
	{
		int TempX = startx - endx;
		int TempY = starty - endy;
		int S_Id = ch.Getid(startx, starty);
		int E_Id = ch.Getid(endx, endy);
		if ((S_Id*E_Id <= 0) && (TempX*TempX + TempY * TempY == 2) && (endx >= 4 && endx <= 6) && (endy >= 1 && endy <= 3 || endy >= 8 && endy <= 10))
		{
			return true;
		}
		return false;
	}
};
class Chancellor :public Chess
{
public:
	Chancellor(int i) :Chess((i == 0 ? -3 : 3)) {}
	bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
	{
		int TempX = startx - endx;
		int TempY = starty - endy;
		int S_Id = ch.Getid(startx, starty);
		int E_Id = ch.Getid(endx, endy);
		if ((S_Id*E_Id <= 0) && (TempX*TempX + TempY * TempY == 8) && (endx % 2 != 0 && endx >= 1 && endy <= 9) && ((starty - 1) / 5 == (endy - 1) / 5) && !ch.Get(startx + (TempX / 2), starty + (TempY / 2)))
		{
			return true;
		}
		return false;
	}
};
class Horse :public Chess
{
public:
	Horse(int i) :Chess((i == 0 ? -4 : 4)) {}
	bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
	{
		int TempX = startx - endx;
		int TempY = starty - endy;
		int S_Id = ch.Getid(startx, starty);
		int E_Id = ch.Getid(endx, endy);
		if ((S_Id*E_Id <= 0) && (TempX*TempX + TempY * TempY == 5) && !ch.Get(startx + (TempX / 2), starty + (TempY / 2)))
		{
			return true;
		}
		return false;
	}
};
class Chariot :public Chess
{
public:
	Chariot(int i) :Chess((i == 0 ? -5 : 5)) {}
	bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
	{
		int TempX = startx - endx;
		int TempY = starty - endy;
		int S_Id = ch.Getid(startx, starty);
		int E_Id = ch.Getid(endx, endy);
		if ((S_Id*E_Id <= 0) && (!(TempX&&TempY)) && (TempX + TempY))
		{
			if (TempX)
			{
				int Sign = (TempX > 0 ? -1 : 1);
				for (int i = 1; i < fabs(TempX); i++)
				{
					if (ch.Get(startx + Sign * i, starty))
					{
						return false;
					}
				}
			}
			else
			{
				int Sign = (TempY > 0 ? -1 : 1);
				for (int i = 1; i < fabs(TempY); i++)
				{
					if (ch.Get(startx, starty + Sign * i))
					{
						return false;
					}
				}
			}
			return true;
		}
		return false;
	}
};
class Cannon :public Chess
{
public:
	Cannon(int i) :Chess((i == 0 ? -6 : 6)) {}
	bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
	{
		int TempX = startx - endx;
		int TempY = starty - endy;
		int S_Id = ch.Getid(startx, starty);
		int E_Id = ch.Getid(endx, endy);
		if ((S_Id*E_Id <= 0) && (!(TempX&&TempY)) && (TempX + TempY))
		{
			int Tmp = 0;
			if (TempX)
			{
				int Sign = (TempX > 0 ? -1 : 1);
				for (int i = 1; i < fabs(TempX); i++)
				{
					if (ch.Get(startx + Sign * i, starty))
					{
						Tmp++;
					}
				}
			}
			else
			{
				int Sign = (TempY > 0 ? -1 : 1);
				for (int i = 1; i < fabs(TempY); i++)
				{
					if (ch.Get(startx, starty + Sign * i))
					{
						Tmp++;
					}
				}
			}
			if (E_Id)
			{
				if (Tmp == 1)
				{
					return true;
				}
			}
			else
			{
				if (!Tmp)
				{
					return true;
				}
			}
		}
		return false;
	}
};
class Soldier :public Chess
{
public:
	Soldier(int i) :Chess((i == 0 ? -7 : 7)) {}
	bool Judgement(Chessboard& ch, int startx, int starty, int endx, int endy)
	{
		int TempX = startx - endx;
		int TempY = starty - endy;
		int S_Id = ch.Getid(startx, starty);
		int E_Id = ch.Getid(endx, endy);
		if ((S_Id*E_Id <= 0) && (S_Id*TempY <= 0))
		{
			if (fabs(TempY) == 1 && TempX == 0)
			{
				return true;
			}
			if (fabs(TempX) == 1 && TempY == 0)
			{
				if (((starty - 1) / 5 == 0 && S_Id < 0) || ((starty - 1) / 5 == 1 && S_Id > 0))
				{
					return true;
				}
			}
		}
		return false;
	}
};
int Chessboard::Player = -1;
bool Chessboard::End = true;
inline Chessboard::Chessboard()
{
	memset(c, NULL, sizeof(c));
}
inline Chess * Chessboard::Get(int x, int y)
{
	return c[x][y];
}
int Chessboard::Getid(int x, int y)
{
	if (c[x][y] != NULL)
	{
		return c[x][y]->Get();
	}
	return NULL;
}
bool Chessboard::Move(int startx, int starty, int endx, int endy)
{
	if (startx >= 1 && startx <= 9 && starty >= 1 && starty <= 10 && endx >= 1 && endx <= 9 && endy >= 1 && endy <= 10 && Getid(startx, starty) && Getid(startx, starty)*Player > 0 && c[startx][starty]->Judgement(*this, startx, starty, endx, endy))
	{
		if (c[endx][endy] != NULL)
		{
			delete c[endx][endy];           
		}
		c[endx][endy] = c[startx][starty];
		c[startx][starty] = NULL;
		Player *= -1;                       
		return true;
	}
	else
	{
		cout << "走法错误,请重新输入:" << endl;
		return false;
	}
}
void Chessboard::Init()
{
	c[1][1] = new Chariot(1);
	c[9][1] = new Chariot(1);
	c[2][1] = new Horse(1);
	c[8][1] = new Horse(1);
	c[3][1] = new Chancellor(1);
	c[7][1] = new Chancellor(1);
	c[4][1] = new BodyGuard(1);
	c[6][1] = new BodyGuard(1);
	c[5][1] = new General(1);
	c[2][3] = new Cannon(1);
	c[8][3] = new Cannon(1);
	c[1][4] = new Soldier(1);
	c[3][4] = new Soldier(1);
	c[5][4] = new Soldier(1);
	c[7][4] = new Soldier(1);
	c[9][4] = new Soldier(1);
	c[1][10] = new Chariot(0);
	c[9][10] = new Chariot(0);
	c[2][10] = new Horse(0);
	c[8][10] = new Horse(0);
	c[3][10] = new Chancellor(0);
	c[7][10] = new Chancellor(0);
	c[4][10] = new BodyGuard(0);
	c[6][10] = new BodyGuard(0);
	c[5][10] = new General(0);
	c[2][8] = new Cannon(0);
	c[8][8] = new Cannon(0);
	c[1][7] = new Soldier(0);
	c[3][7] = new Soldier(0);
	c[5][7] = new Soldier(0);
	c[7][7] = new Soldier(0);
	c[9][7] = new Soldier(0);
}
void Chessboard::Show()
{
	cout << endl;
	HANDLE handle;
	handle = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(handle, 0xF0);
	cout << "     P2  一 二 三 四 五 六 七 八 九" << endl << endl;
	char num[11][4] = { "零","一","二","三","四","五","六","七","八","九" ,"十" };
	for (int i = 1; i < 11; i++)
	{
		if (i == 6)
		{
			SetConsoleTextAttribute(handle, 0xF0);
			cout << "          ————楚河 汉界————" << endl << endl;
		}
		SetConsoleTextAttribute(handle, 0xF0);
		cout << "     " << num[i] << "  ";
		for (int j = 1; j < 10; j++)
		{
			if (c[j][i] != NULL)
			{
				if (c[j][i]->Get() > 0)
				{
					SetConsoleTextAttribute(handle, 0xF2);
					cout << Chessword[c[j][i]->Get() + 7] << " ";
				}
				else
				{
					SetConsoleTextAttribute(handle, 0xFC);
					cout << Chessword[c[j][i]->Get() + 7] << " ";
				}
			}
			else if ((i == 2 && j == 5) || (i == 9 && j == 5))
			{
				SetConsoleTextAttribute(handle, 0xF0);
				cout << "米" << " ";
			}
			else
			{
				SetConsoleTextAttribute(handle, 0xF0);
				cout << "十" << " ";
			}
		}
		cout << endl << endl;
	}
	SetConsoleTextAttribute(handle, 0xF0);
	cout << "     P1  一 二 三 四 五 六 七 八 九" << endl << endl;
}
void Chessboard::Play()
{
	HANDLE handle;
	handle = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(handle, 0xFC);
	system("cls");
	this->Init();
	this->Show();
	do
	{
		int startx, starty, aimx, aimy, iflag;
		int sid, aid;
		iflag = 0;
		do
		{
			sid = aid = 0;
			if ((Chessboard::Player == 1 ? 2 : 1) == 1)
			{
				SetConsoleTextAttribute(handle, 0xFC);
			}
			else
			{
				SetConsoleTextAttribute(handle, 0xF2);
			}
			cout << "请P" << (Chessboard::Player == 1 ? 2 : 1) << "输入起始棋子位置与目标位置的坐标:" << endl;
			cin >> startx >> starty >> aimx >> aimy;
		} while (!this->Move(startx, starty, aimx, aimy));
		system("cls");
		this->Show();
		for (int i = 4; i < 7; i++)
		{
			for (int j = 1; j < 11; j++)
			{
				if (c[i][j] != NULL)
				{
					if ((int)fabs(c[i][j]->Get()) == 1)
					{
						iflag++;
					}
					else if (iflag != 0 && iflag != 2)
					{
						if ((int)fabs(c[i][j]->Get()) != 1)
						{
							iflag--;
						}
					}
				}
			}
		}
		if (iflag == 2)
		{
			Player *= -1;
			Chessboard::End = false;
		}
	} while (Chessboard::End);
	if ((Chessboard::Player == 1 ? 1 : 2) == 1)
	{
		SetConsoleTextAttribute(handle, 0xFC);
	}
	else
	{
		SetConsoleTextAttribute(handle, 0xF2);
	}
	cout << "结束,赢家是Player" << (Chessboard::Player == 1 ? 1 : 2) << endl;
	
}
Chessboard::~Chessboard()
{
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 11; j++)
		{
			if (c[i][j] != NULL)
			{
				delete c[i][j];
				c[i][j] = NULL;
			}
		}
	}
}
void slowout(char *p)
{
	while(1)
	{
		if(*p!=0)
		{
			printf("%c",*p++);
		}
		else
		{
			break;
		}
		Sleep(125);
	}
	cout<<endl;
}
int main()
{
	const int n=19,rangzi=7;
	int x,y,turn,a[101][101],vis[101][101],vist[101][101],ans,p;char g;bool flag;
	int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
	
	system("color 74");
	Sleep(15); 
	system("color 04");
	Sleep(15); 
	system("color 74");
	Sleep(15); 
	system("color 04");
	Sleep(15); 
	system("color 74");
	Sleep(15); 
	system("color 04");
	Sleep(15); 
	system("color 74");
	Sleep(15); 
	system("color 04");
	Sleep(15);  
	slowout("棋类游戏即将开始,请做好准备!!!");
	cout<<"请选择用户名。"<<endl;
	cout<<"-------------------------------\n";
    cout<<"|          人物               |\n";
    cout<<"|        1.小火龙             |\n";
    cout<<"|        2.妙蛙种子           |\n";
    cout<<"|        3.杰尼龟             |\n"; 
    cout<<"|        4.超梦               |\n"; 
    cout<<"|        5.阿尔宙斯           |\n"; 
    cout<<"|        6.裂空座             |\n";
    cout<<"-------------------------------\n";
    int minzi;
    int fanhui;
    int money=10;
    int gy;
    int gy2; 
    int hq;
    int yonghu;
	cin>>minzi;
	int mima;
	if(minzi==1){
		cout<<"名字:小火龙"<<endl;
	}
	if(minzi==2){
		cout<<"名字:妙蛙种子"<<endl;
	}
	if(minzi==3){
		cout<<"名字:杰尼龟"<<endl;
	}
	if(minzi==4){
		cout<<"名字:超梦"<<endl;
	}
	if(minzi==5){
		cout<<"名字:阿尔宙斯"<<endl;
	}
	if(minzi==6){
		cout<<"名字:裂空座"<<endl;
	}
	int dj;//daoju
	int slk=0;//sheng li ka
	int jqk=0;//jia qian ka
	int jhk=0;//ji hui ka
	int start=0;
	cout<<"----------------------------\n";
    cout<<"|          棋类游戏        |\n";
    cout<<"|        0.“游客”        |\n";
    cout<<"|        1.普通VIP         |\n";
    cout<<"|        2.黄金VIP         |\n"; 
    cout<<"----------------------------\n";
    cin>>gy2;
    if(gy2==0){
    	cout<<"身份:游客"<<endl; 
	}
	if(gy2==1){
		cout<<"请输入密码"<<endl;
		cin>>mima;
		if(mima==5963){
			cout<<"登入成功"<<endl;
			cout<<"身份:普通VIP"<<endl; 
		}
		else{
			cout<<"密码错误"<<endl;
			cout<<"身份:游客"<<endl; 
		}	
	}
	if(gy2==2){
		cout<<"请输入密码"<<endl;
		cin>>mima;
		if(mima==520520){
			cout<<"登入成功"<<endl;
			cout<<"身份:黄金VIP"<<endl; 
		}
		else{
			cout<<"密码错误"<<endl;
			cout<<"身份:游客"<<endl; 
		}	
	} 
	Sleep(1000); 
	system("cls");
	slowout("抵制不良游戏,拒绝盗版游戏。"); 
	slowout("注意自我保护,谨防受骗上当。");
	slowout("适度游戏益脑,沉迷游戏伤身。");
	slowout("合理安排时间,享受健康生活。");
	slowout("…+……loading……+……loading……+……+……loading……+……loading……+……");
	Sleep(1000); 
	system("pause");
	int sy;//shi yong 
	cout<<"-------------------------------\n";
    cout<<"|          棋类游戏           |\n";
    cout<<"|        0.退出               |\n";
    cout<<"|        1.人机对战           |\n";
    cout<<"|        2.双人对战(待开发)   |\n";
    cout<<"|        3.猜数游戏(单人)     |\n"; 
    cout<<"|        4.猜数游戏(人机&多人)|\n"; 
    cout<<"|        5.玩完五子棋关机     |\n"; 
    cout<<"|        6.象棋               |\n";
    cout<<"|        7.道具商店           |\n"; 
    cout<<"|        8.VIP商店            |\n";
    cout<<"|        作者:喷火龙         |\n"; 
    cout<<"-------------------------------\n";
    Sleep(1000);
    MessageBox(NULL,"你好,我是喷火龙,只能输入数字,否则会崩溃!!!","提示",MB_OK);
    if(jqk>0){
    	cout<<"是否使用加钱卡?"<<endl;
		cout<<"1.使用 | 2.不用"<<endl;
		cin>>sy;
		if(sy==1){
			jqk-=1;
			cout<<"购买成功!"<<endl; 
		}
		else{
			cout<<"继续"<<endl; 
		}
	}
	int xx;
    cin>>xx;
    slowout("…+……loading……+……loading……+……loading……+……");
    if(xx==0){
    	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x06);
    	return 0;
   	}
    if(xx==1){ 
    	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x01);
		if(slk>0){
			cout<<"是否使用胜利卡?"<<endl;
			cout<<"1.使用 | 2.不用"<<endl;
			cin>>sy;
			if(sy==1){
				slk--;
				cout<<"使用成功"<<endl; 
				Sleep(2000);
				cout<<"\a";
				printf("你赢了一局!");
				money+=2;
				start+=0.5;
				cout<<"是否返回主页,1=是,2=否"<<endl;
				cin>>fanhui; 
				if(fanhui==1){
					system("cls");
					main();
				} 
				else{
					cout<<"继续"<<endl;
				}
			} 
			else{
				cout<<"继续"<<endl;
			} 
		}
		system("cls");
		cout<<"你想玩几局(范围:1000):"<<endl;
		cin>>v;
		if(v>1000){
			cout<<"It's too long!!!"<<endl;
			cout<<"Your Computer is broke!"<<endl;
			system("pause");
			cout<<"你想玩几局(范围:1000):"<<endl;
			cin>>v;
			if(v>1000){
				cout<<"It's too long!!!"<<endl;
				cout<<"Your Computer is broke";
				cout<<"我必须给你惩罚!!!";
				for(int j=1;j<=5;j++){
					system("color 00");
					cout<<"哈哈!!!"<<endl; 
					system("color 01");
					cout<<"哈哈!!!"<<endl; 
					system("color 02");
					cout<<"哈哈!!!"<<endl; 
					system("color 03");
					cout<<"哈哈!!!"<<endl; 
					system("color 04");
					cout<<"哈哈!!!"<<endl; 
					system("color 05");
					cout<<"哈哈!!!"<<endl; 
					system("color 06");
					cout<<"哈哈!!!"<<endl; 
					system("color 07");
					cout<<"哈哈!!!"<<endl; 
					system("color 08");
					cout<<"哈哈!!!"<<endl; 
					system("color 09");
					cout<<"哈哈!!!"<<endl; 
					Sleep(50);
				}
			}
		} 
		else{
			for (int i=1;i<=v;i++){
	        	A.reset();
		        for (GG=-1;;){
		            gotoxy(A.nx,A.ny);
		            A.HM(0); GG=A.check(); if (GG>-1) break;
		            A.AI(1); GG=A.check(); if (GG>-1) break;
		        }
		        gotoxy(5,N+3);
		        if (GG==0) {
					Sleep(2000);
					cout<<"\a";
					printf("你侥幸赢了一局!");
					money+=2;
					start+=0.5;
					cout<<"是否返回主页,1=是,2=否"<<endl;
					cin>>fanhui; 
					if(fanhui==1){
						system("cls");
						main();
					} 
					else{
						cout<<"继续"<<endl;
					}
				}
		        if (GG==1) {
					Sleep(2000);
					cout<<"\a";
					printf("喷火龙的人工智障赢了!");
					cout<<"是否返回主页,1=是,2=否"<<endl;
					cin>>fanhui; 
					if(fanhui==1){
						system("cls");
						main();
					} 
					else{
						cout<<"继续"<<endl;
					}
				} 
		        while (kbhit()) getch();
		        Sleep(2000);
		        gotoxy(5,N+3);
		        system("pause"); 
			}
		}
	}
	if(xx==2){
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x03);
		cout<<"待开发,敬请期待!!!"<<endl; 
		cout<<"想玩人机输1"<<endl; 
		cout<<"不想玩输0"<<endl; 
		int t;
		cin>>t;
		if(t==1){
        	A.reset();
	        for (GG=-1;;){
	            gotoxy(A.nx,A.ny);
	            A.HM(0); GG=A.check(); if (GG>-1) break;
	            A.AI(1); GG=A.check(); if (GG>-1) break;
	        }
	        gotoxy(5,N+3);
	        if (GG==0) {
				Sleep(2000);
				system("cls");
				cout<<"\a";
				printf("你侥幸赢了一局!");
				money+=2;
				start+=0.5;
				cout<<"是否返回主页,1=是,2=否"<<endl;
				cin>>fanhui; 
				if(fanhui==1){
					system("cls");
					main();
				} 
				else{
					cout<<"继续"<<endl;
				}
			} 
	        if (GG==1) {
				Sleep(2000);
				system("cls");
				cout<<"\a";
				printf("喷火龙的人工智障赢了!");
				cout<<"是否返回主页,1=是,2=否";
				cin>>fanhui; 
				if(fanhui==1){
					system("cls");
					main();
				} 
				else{
					cout<<"继续"<<endl;
				}
			}
	        while (kbhit()) getch();
	        Sleep(2000);
	        gotoxy(5,N+3);
	        system("pause"); 
		}
		else{
			cout<<"by~";
			cout<<"作者:喷火龙"<<endl; 
			return 0;
		}
	}	
	if(xx==3){
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x05);
		cout<<"猜数";
		cout<<endl;
		cout<<"猜数游戏(1-100)"<<endl;
		cout<<"1.普通人员"<<endl;
		cout<<"2.VIP1"<<endl;
		cout<<"3.VIP2"<<endl;
		int qd;
		cin>>qd;
		int mm;
		int mm2;
		int mm3;
		int vip;
		if(qd==1){
			mm=10;
		}
		if(qd==2){
			cout<<"请输入密码:";
			cin>>mm2;
			if(mm2==5963){
				MessageBox(NULL,"你好,我是喷火龙,密码正确,VIP1模式,生命+10!!!","提示",MB_OK);
				mm=20; 
			}
			if(mm2!=5963){
				MessageBox(NULL,"你好,我是喷火龙,密码错误!!!","提示",MB_OK);
				system("cls");
				mm=10; 
				system("pause");
				cout<<"游戏继续"<<endl; 
			}
		} 
		if(qd==3){
			cout<<"请输入密码:";
			cin>>mm3;
			if(mm3==520520){
				MessageBox(NULL,"你好,我是喷火龙,密码正确,VIP2模式,请自定义生命数(猜几次)!!!","提示",MB_OK);
				cin>>mm;
			}
			if(mm3!=520520){
				MessageBox(NULL,"你好,我是喷火龙,密码错误!!!","提示",MB_OK);
				system("cls");
				mm=10; 
				system("pause");
				cout<<"游戏继续"<<endl; 
			}
		}
		system("cls");
		if(jhk>0){
    		cout<<"是否使用机会卡?"<<endl;
			cout<<"1.使用 | 2.不用"<<endl;
			cin>>sy;
			if(sy==1){
				jhk-=1;
				cout<<"使用成功!"<<endl; 
				mm+=3;
				jhk--; 
			}
			else{
				cout<<"继续"<<endl; 
			}
		}
		srand(time(NULL));
		int key=rand()%100+1;
		for(int i=1;i<=mm;i++)
		{
			int x;
			cout<<"请输入一个数字:";
			cin>>x;
			if(x>100||x<1){
				cout<<"浪费机会!!!"; 
			}
			if(x<key)
			{
				cout<<"小了"<<endl;
			} 
			if(x>key)
			{
				cout<<"大了"<<endl;
			} 
		    if(x==key)
			{
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02);
				cout<<"恭喜您,猜对啦!"<<endl;
				money++; 
				start++;
				cout<<"是否返回主页,1=是,2=否";
				cin>>fanhui; 
				if(fanhui==1){
					system("cls");
					main();
				} 
				else{
					cout<<"继续"<<endl;
				}
			} 
		}
		cout<<"10次机会已用完,很遗憾,未猜对!"<<endl;
		cout<<"正确数字是:"<<key<<endl;
		Sleep(1000);
		system("cls");
		cout<<"是否返回主页,1=是,2=否"<<endl;
		cin>>fanhui; 
		if(fanhui==1){
			system("cls");
			main();
		} 
		else{
			cout<<"继续"<<endl;
		}
	}
	if(xx==4){
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x07);
		int n,m;
		bool c[100005];
		cout<<"猜数";
		cout<<endl;
		srand(time(NULL));
	    cout<<"==============================================================\n几人猜数(只支持100000人以内)??";
	    cin>>n;
	    cout<<"==============================================================\n0~几???";
	    cin>>m;
	    for(;;)
	    {
	        cout<<"==============================================================\n开始!!!";
	        int x=rand()%(m+1),y,h=0,e=m,t=rand()%n;
	        bool hh=1,ee=1;
	        do
	        {
	            cout<<"\n==============================================================\n";
	            cout<<h<<"~"<<e<<endl;
	            ++t;
	            t-=t>n?n:0;
	            if(!c[t])
	              cout<<t<<"号猜(电脑帮猜 输1 ,设置TA为电脑 输2):",cin>>y;
	            if(y==2)
	              c[t]=1;
	            if(y==1||c[t])
	            {
	                y=(h+e)/2;
	                cout<<"帮"<<t<<"号猜猜成"<<y<<endl;
	                if(y==x)
	                  break;
	                if(y>x)
	                {
	                    cout<<"大了";
	                    e=y; 
	                    continue;
	                }
	                if(y<x)
	                {
	                    cout<<"小了";
	                    h=y; 
	                    continue;
	                }
	            } 
	            if(y<=h||y>=e)
	            {
	                cout<<"浪费机会!!!";
	                continue;
	                if(!h&&!y)
	                  if(hh)
	                    hh=0;
	                else
	                {
	                    cout<<"浪费机会!!!";
	                    continue;
	                }
	                if(e==m&&y==m)
	                  if(ee)
	                    ee=0;
	                else
	                {
	                    cout<<"浪费机会!!!";
	                    continue;
	                }
	            }
	            if(y>x)
	            {
	                cout<<"大了";
	                e=y; 
	            }
	            if(y<x)
	            {
	                cout<<"小了";
	                h=y; 
	            }
	        }while(x!=y);
	        cout<<t<<"号赢了!!!\n==============================================================\n再来一局吗?\ny/n\n";
	        char a;
	        a=getch();
	        if(a=='n'||a=='N')
	        	break; 
	    }
	    getchar();
	    cout<<"==============================================================\nbyebye!\n==============================================================\n双击任意键结束,单机空格关机!";
	    char a=getch();
	    if(a==' ')
	    {
	        cout<<"\n确定吗??确定点空格一下,否则双击任意键结束。";
	        a=getch();
	        if(a==' ')
	        	system("shutdown -s -t 0");
	    }
	if(xx==5){	
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x01);
		cout<<"范围(1~1000)你想玩几局:"<<endl;
		cin>>v;
		if(v>1000){
			cout<<"It's too long!!!"<<endl;
			cout<<"Your Computer is broke"<<endl;
			system("pause");
			cout<<"范围(1~1000)你想玩几局:"<<endl;
			cin>>v;
			if(v>1000){
				cout<<"It's too long!!!"<<endl;
				cout<<"Your Computer is broke."<<endl;
				cout<<"我必须给你惩罚!!!";
				cout<<"你的money-1,start-0.5"<<endl; 
				money-=1;
				start-=0.5;
			}
			system("cls");	
		}
		else{
			MessageBox(NULL,"你好,我是喷火龙,玩完游戏你的电脑就会关机,请保存好其它东西!!!","提示",MB_OK);
			for (int i=1;i<=v;i++){
	        	A.reset();
		        for (GG=-1;;){
		            gotoxy(A.nx,A.ny);
		            A.HM(0); GG=A.check(); if (GG>-1) break;
		            A.AI(1); GG=A.check(); if (GG>-1) break;
		        }
		        gotoxy(5,N+3);
		        if (GG==0) {
					Sleep(2000);
					cout<<"\a";
					printf("你侥幸赢了一局!");
					money+=2;
					cout<<"是否返回主页,1=是,2=否"<<endl;
					cin>>fanhui; 
					if(fanhui==1){
						system("cls");
						main();
					} 
					else{
						cout<<"继续"<<endl;
					}
				}
		        if (GG==1) {
					Sleep(2000);
					system("cls");
					cout<<"\a";
					printf("喷火龙的人工智障赢了!");
					cout<<"是否返回主页,1=是,2=否"<<endl;
					cin>>fanhui; 
					if(fanhui==1){
						system("cls");
						main();
					} 
					else{
						cout<<"继续"<<endl;
					}
				} 
		        while (kbhit()) getch();
		        Sleep(2000);
		        gotoxy(5,N+3);
		        system("pause"); 
			}
		}
	}
	system("cls");
	if(MessageBox(NULL,"即将关机,最后确定一下","提示",MB_YESNO)==IDYES){  
		Sleep(2000); 
		system ("shutdown -p");	
	}
	else 
		return 0;
}
	if(xx==6){
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0C);
		if(MessageBox(NULL,"是否找到另一个玩家?","提示",MB_YESNO)==IDYES){  
			Sleep(1000); 
			cout<<"象棋游戏开始(横着的数字在前,竖着的数字在后。)"<<endl;
			Sleep(4000);
			Chessboard C;
			C.Play();
			system("pause");
		}
		else{
			cout<<"请找到一个对手吧!"<<endl;
			return 0;
		}
	}
	if(xx==7){
		cout<<"-------------------------------\n";
	    cout<<"|              道具           |\n";
	    cout<<"|            物品       价格  |\n"; 
	    cout<<"|    0.退出商店        | 无   |\n"; 
	    cout<<"|    1.胜利卡(直接胜利)| 3$   |\n";
	    cout<<"|    2.加钱卡(获得10$) | 2☆  |\n";
	    cout<<"|    3.机会卡(多猜3次) | 3$   |\n"; 
	    cout<<"-------------------------------\n";
	    cout<<"你的money:"<<money<<" "<<endl;
	    cout<<"你的start:"<<start<<" "<<endl; 
	    cout<<"要买啥?"<<endl;
		cin>>dj; 
		if(dj==0){
			cout<<"成功退出"<<endl;
			system("cls");
			cout<<"是否返回主页,1=是,2=否"<<endl;
			cin>>fanhui; 
			if(fanhui==1){
				system("cls");
				main();
			} 
			else{
				cout<<"继续"<<endl;
			}
		} 
		if(dj==1){
			if(money>=3){
				money-3;
				cout<<"购买成功!"<<endl;
				slk++;
				main();
			}
			else{
				cout<<"money不够。"<<endl;
				main();
			}
		}
		if(dj==2){
			if(start>=2){
				start-2;
				cout<<"购买成功!"<<endl;
				jqk++;
			}
			else{
				cout<<"start不够。"<<endl;
			}
		}
		if(dj==3){
			if(money>=3){
				money-3;
				cout<<"购买成功!"<<endl;
				jhk++;
			}
			else{
				cout<<"money不够。"<<endl;
			}
		}
		if(dj>3){
			cout<<"无效输出。"<<endl;
		}
	}
	if(xx==8){
		cout<<"-------------------------------\n";
	    cout<<"|          棋类游戏           |\n";
	    cout<<"|        0.退出               |\n";
	    cout<<"|        1.普通VIP(1级10$)  |\n";
	    cout<<"|        2.黄金VIP(2级50$)  |\n"; 
	    cout<<"-------------------------------\n";
	    cout<<"1.购买VIP  |   2.识别VIP";
	    cin>>gy;
	    if(gy==0){
	    	cout<<"成功退出"<<endl;
	    	system("cls");
			cout<<"是否返回主页,1=是,2=否"<<endl;
			cin>>fanhui; 
			if(fanhui==1){
				system("cls");
				main();
			} 
			else{
				return 0;
			} 
		}
		if(gy==1){
			cout<<"你的money:"<<money<<endl;
			cout<<"买哪个VIP,输入0退出";
			cin>>hq;
			if(hq==0){
				main();
			} 
			if(hq==1){
				if(money>=10){
					money-10;
					cout<<"VIP1级已购买成功,密码:5963"<<endl; 
					main();
				}
				else{
					cout<<"money不够"<<endl;
					main();
				}
			}
			if(hq==2){
				if(money>=50){
					money-50;
					cout<<"VIP2级已购买成功,密码:520520"<<endl; 
				}
				else{
					cout<<"money不够"<<endl;
					main();
				}
			}
		} 
	    if(gy==2){
	    	cout<<"1.普通VIP 2.黄金VIP"<<endl;
			cin>>yonghu;
			if(yonghu==1){
				cout<<"请输入密码"<<endl;
				cin>>mima;
				if(mima==5963){
					cout<<"登入成功"<<endl;
					main();
				}
				else{
					cout<<"密码错误"<<endl;
					main(); 
				}	
			}
			if(yonghu==2){
				cout<<"请输入密码"<<endl;
				cin>>mima;
				if(mima==520520){
					cout<<"登入成功"<<endl;
					main();
				}
				else{
					cout<<"密码错误"<<endl;
					main(); 
				}	
			} 
		}
		if(gy>=3){
			system("cls");
			cout<<"是否返回主页,1=是,2=否"<<endl;
			cin>>fanhui; 
			if(fanhui==1){
				system("cls");
				main();
			} 
			else{
				cout<<"继续"<<endl;
			}
		}
	}
	if(xx>8){
		cout<<"超出范围"<<endl;
		if(MessageBox(NULL,"是否回到主页面???","询问",MB_YESNO)==IDYES){
			main();
		}
		else{
			return 0;
		} 
	}	
}

评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喷火龙廖

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值