- #include <iostream>
- #include <stdlib.h>
- #include <windows.h>
- #include <stdio.h>
- using namespace std;
- void gotoxy(int x,int y)
- {
- COORD coord={x,y};
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
- }
- int main()
- {
- int i;
- while(1)
- {
- system("cls");
- gotoxy(15,4);
- cout<<"**********拿豆子游戏**********"<<endl;
- gotoxy(15,6);
- cout<<"1.游戏说明"<<endl;
- gotoxy(15,8);
- cout<<"2.开始游戏"<<endl;
- gotoxy(15,10);
- cout<<"3.退出"<<endl;
- gotoxy(25,15);
- cout<<"请选择"<<endl;
- cin>>i;
- switch(i)
- {
- case 1:
- {
- system("cls");
- cout<<"每次只能选从a,b,c中拿豆子,每次拿的个数不限,拿到最后一个豆子者输。"<<endl;
- cout<<"(*请等待退出*)"<<endl;
- Sleep(6000);
- break;
- }
- case 2:
- {
- system("cls");
- int x=3,y=5,z=7;
- int p;
- char ch;
- cout<<"-------------------"<<endl;
- cout<<"| "<<x<<"| "<<y<<"| "<<z<<" |"<<endl;
- cout<<"-------------------"<<endl;
- do{
- cout<<"选择豆堆a,b或c"<<endl;
- cin>>ch;
- switch(ch)
- {
- case'a':
- {
- system("cls");
- cout<<"-------------------"<<endl;
- cout<<"|a| "<<x<<"|b| "<<y<<"|c| "<<z<<" |"<<endl;
- cout<<"-------------------"<<endl;
- cout<<"请输入想要拿去的豆子"<<endl;
- cin>>p;
- system("cls");
- x-=p;
- cout<<"-------------------"<<endl;
- cout<<"| "<<x<<"| "<<y<<"| "<<z<<" |"<<endl;
- cout<<"-------------------"<<endl;
- break;
- }
- case'b':
- {
- system("cls");
- cout<<"-------------------"<<endl;
- cout<<"| "<<x<<"| "<<y<<"| "<<z<<" |"<<endl;
- cout<<"-------------------"<<endl;
- cout<<"请输入想要拿去的豆子"<<endl;
- cin>>p;
- system("cls");
- y-=p;
- cout<<"-------------------"<<endl;
- cout<<"| "<<x<<"| "<<y<<"| "<<z<<" |"<<endl;
- cout<<"-------------------"<<endl;
- break;
- }
- case'c':
- {
- system("cls");
- cout<<"-------------------"<<endl;
- cout<<"| "<<x<<"| "<<y<<"| "<<z<<" |"<<endl;
- cout<<"-------------------"<<endl;
- cout<<"请输入想要拿去的豆子"<<endl;
- cin>>p;
- system("cls");
- z-=p;
- cout<<"-------------------"<<endl;
- cout<<"| "<<x<<"| "<<y<<"| "<<z<<" |"<<endl;
- cout<<"-------------------"<<endl;
- break;
- }
- default:;
- }
- }while(x!=0||y!=0||z!=0);
- cout<<"你输了!!!"<<endl;
- }
- case 3:
- exit(0);
- default:
- break;
- }
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2410201410797.html
来源: http://www.codesnippet.cn/detail/2410201410797.html