21点
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
void cls() {
std::cout << "\033[2J\033[H" << std::flush;
}
void gotoxy(int x,int y){
COORD pos={(short)x,(short)y};
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
return;
}
void HideCursor(){
CONSOLE_CURSOR_INFO cur={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
int main(){
HideCursor();
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode=0;
GetConsoleMode(hOut,&dwMode);
dwMode|=0x0004;
SetConsoleMode(hOut,dwMode);
srand(time(0));
cout<<"\n欢乐21点\n\n\n按任意键以进入游戏\n";
int x=_getch();
while (true){
start:
int a=1;
while (true){
cls();
if (a)
cout
<<"\n"
<<"> 开始游戏 <\n\n"
<<" 退出游戏\n";
else
cout
<<"\n"
<<" 开始游戏\n\n"
<<"> 退出游戏 <\n";
cout<<"\n\n\n↑↓ 选择 Enter 确定\n";
while (true){
x=_getch();
if (x==0||x==224){
x=_getch();
if (x==72||x==80){
a=(a+1)%2; break;
}
}else if (x==13){
if (a) goto game;
else{
cls();
a=1;
while (true){
cls();
cout<<"\n确定要退出游戏吗?\n\n";
if (a)
cout
<<"\n"
<<"> 否 <\n\n"
<<" 是 \n";
else
cout
<<"\n"
<<" 否 \n\n"
<<"> 是 <\n";
cout<<"\n\n\n↑↓ 选择 Enter 确定\n";
while (true){
x=_getch();
if (x==0||x==224){
x=_getch();
if (x==72||x==80){
a=(a+1)%2; break;
}
}else if (x==13){
if (a) goto start;
else{
cls();
return 0;
}
}
}
}
}
}
}
}
}
game:
cls();
int deal,self;
cout<<"Loading";
deal=rand()%10+1;
Sleep(1003);
cout<<".";
Sleep(1003);
cout<<".";
Sleep(1003);
cout<<".";
self=rand()%10+1;
Sleep(1003);
cout<<"\b\b\b \b\b\b";
Sleep(1003);
cout<<".";
Sleep(1003);
cout<<".";
Sleep(1003);
cout<<".";
Sleep(1500);
cls();
cout<<"按任意按键以进入游戏";
x=_getch();
while (true){
cls();
cout<<"\n";
cout<<"庄家:"<<deal<<"\n\n";
cout<<"自己:"<<self<<"\n\n\n\n";
cout<<"Enter 摸牌\n\n";
cout<<"Esc 停牌";
x=_getch();
if (x==13){
cls();
cout<<"你摸到了一张";
Sleep(101);
for (int i=1;i<=10;i++){
cout<<"."; Sleep(101);
}
int m=rand()%10+1;
cout<<m<<"!\n";
Sleep(1100);
cls();
cout<<"\n";
cout<<"庄家:"<<deal<<"\n\n";
cout<<"自己:"<<self<<"\n\n";
cout<<"\033[32m+"<<m<<"\033[0m";
Sleep(400);
cls();
cout<<"\n";
cout<<"庄家:"<<deal<<"\n\n";
cout<<"自己:"<<self<<"\n";
cout<<"\033[32m+"<<m<<"\033[0m";
Sleep(400);
self+=m;
cls();
cout<<"\n";
cout<<"庄家:"<<deal<<"\n\n";
cout<<"自己:"<<self;
Sleep(1500);
if (self>21){
cls();
cout<<"你的点数超过了21(按任意键)\n";
x=_getch(); cls();
cout<<"\033[31mYou lose!\033[0m";
Sleep(1000);
cout<<"\n\n\033[31m(按任意键)\033[0m";
x=_getch();
goto start;
}
}else if (x==27) break;
}
while (deal<19){
cls();
cout<<"\n庄家:"<<deal<<"\n\n";
int m=rand()%10+1;
cout<<"庄家摸到一张"<<m;
Sleep(1500);
cls();
cout<<"\n庄家:"<<deal<<"\n\n";
cout<<"\033[32m+"<<m<<"\033[0m";
Sleep(400);
cls();
cout<<"\n庄家:"<<deal<<"\n";
cout<<"\033[32m+"<<m<<"\033[0m";
Sleep(400);
deal+=m;
cls();
cout<<"\n庄家:"<<deal;
Sleep(1500);
if (deal>self) break;
}
cls();
if (deal>21){
cout<<"庄家的点数超过了21(按任意键)";
x=_getch();
cls();
cout<<"\033[33mYou win!\033[0m";
Sleep(1000);
cout<<"\n\n\033[33m(按任意键)\033[0m";
x=_getch(); goto start;
}else if (deal>self){
cout<<"庄家的点数超过了你(按任意键)";
x=_getch();
cls();
cout<<"\033[31mYou lose!\033[0m";
Sleep(1000);
cout<<"\n\n\033[31m(按任意键)\033[0m";
x=_getch(); goto start;
}else if (deal<self){
cout<<"你的点数超过了庄家(按任意键)";
x=_getch();
cls();
cout<<"\033[33mYou win!\033[0m";
Sleep(1000);
cout<<"\n\n\033[33m(按任意键)\033[0m";
x=_getch(); goto start;
}else{
cout<<"庄家的点数与你相同(按任意键)";
x=_getch();
cls();
cout<<"\033[32mTie\033[0m";
Sleep(1000);
cout<<"\n\n\033[32m(按任意键)\033[0m";
x=_getch(); goto start;
}
}