First, thanks for any replies that I'll receive.
I'm currently trying to create a simple 1 player(comp vs player) poker game(simple as in minor game errors are allowed).
After I initialize the deck, I shuffle the deck then deal the cards. After dealing the cards, I set the cards for the player as another separate array(player1_hand[]) for easy management.
The problem is when I try to create a different class to test whether the player1_hand[] is a straight. How do I obtain the values for player1_hand.value in a different class?
Deck part
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <time.h>
#include "Deck.h"
using namespace std;
struct Deck::card //structure for a card
{
int symbol;
int value;
};
..........................................//more code in between
void Deck::deal_cards()
{
community[5]; //community card
player1[2]; //2 cards in player 1's hand
player2[2]; //2 cards in player 2's hand
player1_hand[7]; //2 player 1's cards + 5 community cards
player2_hand[7]; //2 player 2's cards + 5 community cards
..........................................//more code in between
for(int array_locationA = 0; array_locationA<=5; array_locationA++)// combine player's cards with community cards into 1 array
{
player1_hand[array_locationA].symbol = community[array_locationA].symbol;
player1_hand[array_locationA].value = community[array_locationA].value;
player2_hand[array_locationA].symbol = community[array_locationA].symbol;
player2_hand[array_locationA].value = community[array_locationA].value;
}
for(int array_locationA = 0; array_locationA<=2; array_locationA++)// combine player's cards with community cards into 1 array
{
int array_locationB = array_locationA + 5;
player1_hand[array_locationB].symbol = player1[array_locationA].symbol;
player1_hand[array_locationB].value = player1[array_locationA].value;
player2_hand[array_locationB].symbol = player2[array_locationA].symbol;
player2_hand[array_locationB].value = player2[array_locationA].value;
}
for(int loop = 0; loop<=7; loop++)//bubble sort(for easy comparison later on)
{
bool swapped = false;
if(player1_hand[loop].value > player1_hand[loop+1].value)
{
int temp = player1_hand[loop].value;
player1_hand[loop].value = player1_hand[loop+1].value;
player1_hand[loop+1].value = temp;
swapped = true;
}
}
for(int loop = 0; loop<=7; loop++)//bubble sort(for easy comparison later on)
{
bool swapped = false;
if(player2_hand[loop].value > player2_hand[loop+1].value)
{
int temp = player2_hand[loop].value;
player2_hand[loop].value = player2_hand[loop+1].value;
player2_hand[loop+1].value = temp;
swapped = true;
}
}
}
]
Checking for straight/flush... etc.
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include "HandCheck.h"
#include "Deck.h"
using namespace std;
bool HandCheck::straight()
{
if(Deck.player1_hand[1].value == Deck.player1_hand[0].value+1 && Deck.player1_hand[2].value == Deck.player1_hand[1].value+1 &&.........)
bool straight = true;
}
................................//More code below
Sorry if the code is messy. Still a programming newbie and I've yet to properly comment/rearrange the codes.