當前位置:編程學習大全網 - 編程語言 - c++編程模擬21點

c++編程模擬21點

#include <iostream>//需要的頭文件,寫得不完善,只作參考,剩下自己思考吧

#include <time.h>

#include <conio.h>

#pragma comment(lib,"winmm.lib");

srand(timeGetTime());

int iFlag = 0;

int iCount = 2;

bool bIsExit = false;

int iPlayerNum[5] = {0};

while ( !bIsExit )

{

iFlag = 0;

iCount = 2;

memset(iPlayerNum,0,sizeof(int)*5);

while ( iFlag < 3 )

{

if ( iFlag == 0 )

{

cout<<"遊戲開始"<<endl;

iPlayerNum[0] = rand()%10+1;

Sleep(100);

iPlayerNum[1] = rand()%10+1;

cout<<"手牌"<<iPlayerNum[0]<<" "<<iPlayerNum[1]<<endl;

cout<<"玩家當前點數"<<iPlayerNum[0]+iPlayerNum[1]<<endl;

}

cout<<"是否繼續發牌?Y/N"<<endl;

char cA = getch();

if ( cA=='y' || cA=='Y')

{

iPlayerNum[iCount] = rand()%10+1;

iCount++;

int iSum = 0;

for ( int i=0; i<iCount; i++ )

{

iSum += iPlayerNum[i];

cout<<iPlayerNum[i]<<" ";

}

cout<<endl;

cout<<"玩家當前點數"<<iSum<<endl;

}

else if ( cA=='n' || cA=='N' )

{

int iSum = 0;

cout<<"玩家手牌"<<endl;

for ( int i=0; i<iCount; i++ )

{

iSum += iPlayerNum[i];

cout<<iPlayerNum[i]<<" ";

}

cout<<endl;

cout<<"玩家最終點數"<<iSum<<endl;

iFlag = 3;

}

else if ( cA=='q' || cA=='Q')

{

iFlag = 3;

bIsExit = true;

cout<<"退出遊戲"<<endl;

}

iFlag++;

}

}

  • 上一篇:工業過程自動化技術主要知識技能
  • 下一篇:菏澤學院專業有哪些?專業介紹
  • copyright 2024編程學習大全網