#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++;
}
}