我必须创建一个与 7 名玩家和一个庄家一起玩的 BlackJack 程序。我必须对西装类型使用 switch 或 if 语句,并且该语句只能使用一次。
我知道不工作的是 Shuffle() 功能:
当我在没有调试的情况下运行时,它会给我和输出(黑桃A)两次,但我放了一个数组,这样它就不会复制一张卡片。
但是,当我调试它并进入每一行代码时,输出会给我两张不重复的卡片。
我也无法计算玩家总数的要求“编写一个函数以向每个玩家发两张牌。”,如何将两张牌添加到没有确定大小的数组中?
此网络相册包含我项目的全部要求:
#include <iostream>
#include <iomanip>
#include <ctime>
#include <windows.h>
#include <stdio.h>
using namespace std;
void Header();
void Shuffle(int&, char&);
void Dealer();
void Deal();
void Another_Card();
void Fin_Dealer();
void WLT();
void gotoxy(int h, int w)
{
HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
if ( INVALID_HANDLE_VALUE != hConsole )
{
COORD pos = {h, w};
SetConsoleCursorPosition ( hConsole, pos );
}
return;
}
int main()
{
Header();
Dealer();
Deal();
WLT();
gotoxy(0,19);
return 0;
}
void Header()
{
cout <<"\t\t\tWelcome to BlackJack!\n\n";
gotoxy(3,3);
cout <<"Dealer Player1 Player2 Player3 Player4 Player5 Player6 Player7 "<<endl;
return;
}
void Shuffle(int& num, char& suit)
{
int cards[52], dup[52];
int card;
srand(time(NULL));
for(int i = 0; i <52; i++)
dup[i] = 0;
card = rand() % 52;
while(dup[card])
card = rand() % 52;
dup[card] = 1;
suit = char(card/13 + 3); //display suit
num = card % 13;
switch(num)
{
case 0: cout<<setw(6)<<right<<" A"<<suit;
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9: cout<<setw(6)<<right<<" "<<num + 1<<suit;
break;
case 10: cout<<setw(6)<<right<<" J"<<suit;
break;
case 11:cout<<setw(6)<<right<<" Q"<<suit;
break;
case 12:cout<<setw(6)<<right<<" K"<<suit;
break;
default:cout<<setw(6)<<right<<"Error";
break;
}
return;
}
void Dealer()
{
int i = 0;
int num = 0;
char suit;
for(i = 4;i <6; i++)
{
gotoxy(0,i);
Shuffle(num, suit);
}
return;
}
void Deal()
{
int i = 0;
int num = 0;
int row = 4;
char suit;
for(i = 1; i < 8; i++)
{
gotoxy(i*8, row);
Shuffle(num,suit);
}
if(playertotal <=20)
{
Another_Card()
}
return;
}
void Another_Card()
{
return;
}
void Fin_Dealer()
{
return;
}
void WLT()
{
return;
}