I'm trying to write a Blackjack program and I am stuck. HELP!
The rules for game that differ from Blackjack are that aces are always 1. You can't really get a Blackjack but it's for a class and that's what the prof wanted.
Anyway, I can shuffle the cards and deal the numbers (1-52) where I want them to go but I am trying to assign values and suits to them now and I'm stuck.
Here's what I have so far:
Code:
#include <time.h>
#include <iostream>
#include <windows.h>
#include <iomanip>
#include <stdio.h>
#include "gotoxy.h"
using namespace std;
void Header();
void ShuffleDeck(int[]);
void DealTwo (int[]);
int main()
{
const int i=52;
int card[i];
Header();
ShuffleDeck(card);
DealTwo(card);
//printing out headers on screen
gotoxy(35, 2);
printf("Dealer");
gotoxy(4, 7);
cout << "Player 1" << " " << "Player 2" << " " << "Player 3" << " "
<< "Player 4" << " " << "Player 5" << " " << "Player 6" << " "
<< "Player 7";
getchar();
return 0;
}
void Header()
{
cout <<"Welcome To Tom's Casino - Let's Play Blackjack! \n" <<endl;
}
void ShuffleDeck(int cards[])
{
int i, flags[52], value;
srand(time(NULL));
for(i=0; i<52; i++)
flags[i]=0;
for(i=0; i<52; i++)
{
value = rand()%52;
while(flags[value])
value = rand()%52;
cards[i] = value;
flags[value] = 1;
}
return;
}
void DealTwo(int cards[])
{
int i=0;
char ch, pic;
gotoxy(37, 3);
//ch = suitFunc(cards[i], val, pic);
cout << setw(2) << cards[i];
i++;
gotoxy(7, 8);
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
gotoxy(37, 4);
cout << setw(2) << cards[i];
i++;
gotoxy(7, 9);
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
cout << setw(2) << cards[i] << " ";
i++;
return;
}
/*void suitFunc(int [], int val, char pic)
{
card = cards[i];
suitn = card/13;
switch (suitn)
{
case 0: suit = char (3); //heart
case 1: suit = char (4); //diamond
case 2: suit = char (5); //club
case 3: suit = char (6); //spade
cvalue = cards[i];
num = cvalue % 13;
if num == 0
ch = 'A'
truevalue = 1;
if num > 0 && num < 10
truevalue = num + 1;
if num > 9
{
truevalue = 10;
if(num == 10)
ch = 'J'
else if (num == 11)
ch = 'Q'
else if (num == 12)
ch = 'K'
}
}
}
*/
Here is the gotoxy.h code
Code:
#include <windows.h>
#include <stdio.h>
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;
}
I need to get rid of the numbers I have delt and put in the suits and values.