I am not able to compile the program. I kept getting an error.
What I have tried:
#include "Card.hpp"
Card::Card(char v, char s)
:value{new char(v)}
,suit{new char(s)}
,playerId{new unsigned (0)}
,discard{new bool(false)}
{
}
Card::~Card() {
delete value;
delete suit;
delete playerId;
delete discard;
value = nullptr;
suit = nullptr;
playerId = nullptr;
discard = nullptr;
}
const bool Card::isDiscard() {
}
const unsigned int Card::getPlayerId() {
return *playerId;
}
const char Card::getSuit() {
return *suit;
}
const char Card::getValue() {
return *value;
}
void Card::setPlayerId(unsigned int p) {
}
void Card::flipDiscard() {
*discard = !discard;
}
char Card::intToSuit(int suit){
char suits [4] = {'H', 'D', 'S', 'C'};
return suits[suit];
}
char Card::intToValue(int value) {
char ranks [13] = {'2', '3', '4', '5', '6', '7', '8', '9', '0', 'J', 'Q', 'K', 'A'};
return ranks[value];
}
#ifndef GO_FISH_CARD_HPP
#define GO_FISH_CARD_HPP
class Card {
private:
char* value;
char* suit;
unsigned* playerId;
bool* discard;
public:
Card(char v, char s);
~Card();
const char getValue();
const char getSuit();
const unsigned getPlayerId();
const bool isDiscard();
void setPlayerId(unsigned p);
void flipDiscard();
static char intToSuit(int suit);
static char intToValue(int value);
};
#endif //GO_FISH_CARD_HPP
#include "Card.hpp"
#include "Player.hpp"
#include <cstddef>
#include <iomanip>
#include <iostream>
using namespace std;
bool isGameOver(Card*[], const unsigned);
Card* assignRandomCard(Card*[], const unsigned, Player*);
void checkScore(Card*[], const unsigned, Player*, char);
int main() {
srand(time(0));
const unsigned DECK_SIZE = 52;
Card* deck[DECK_SIZE];
int count = 0;
for(int r=0; r < 13; r++){
for(int S=0; S < 4; S++){
char v = Card::intToValue(r), s = Card::intToSuit(S);
deck[count] = new Card(v, s);
count ++;
}
}
cout << setfill('*') << setw(50) << '\n';
cout << "Welcome to my Go Fish game!\n";
cout << setfill('*') << setw(50) << '\n' << endl;
cout << "Player 1, enter your name:";
string* player1;
cin >> *player1;
cout << "Player 2, enter your name:";
string* player2;
cin >> *player2;
Card* cardPtr = nullptr;
for (unsigned cardNum = 0; cardNum < 7; cardNum++) {
cardPtr = assignRandomCard(deck, DECK_SIZE, player1);
checkScore(deck, DECK_SIZE, player1, cardPtr->getValue());
}
for (unsigned cardNum = 0; cardNum < 7; cardNum++) {
cardPtr = assignRandomCard(deck, DECK_SIZE, player2);
checkScore(deck, DECK_SIZE, player2, cardPtr->getValue());
}
char value = '\0';
bool handFlag = false;
Player* currentPlayer = player1;
Player* otherPlayer = player2;
while (!isGameOver(deck, DECK_SIZE)) {
cout << "\n\n\n\n\n";
cout << "The current player is " << currentPlayer->getName() << endl;
cout << "Your score: " << currentPlayer->getScore() << endl;
handFlag = false;
cout << "Your hand is: ";
for (unsigned i = 0; i < DECK_SIZE; i++) {
if (deck[i]->getPlayerId() == currentPlayer->getId() &&
!deck[i]->isDiscard())
{
handFlag = true;
cout << deck[i]->getValue() << '/' << deck[i]->getSuit() << ' ';
}
}
if (!handFlag) {
cout << "empty!\n";
}
else {
cout << endl;
value = currentPlayer->ask(deck, DECK_SIZE);
}
if (handFlag && otherPlayer->check(deck, DECK_SIZE, value)) {
cout << "Nice, good guess!\n";
checkScore(deck, DECK_SIZE, currentPlayer, value);
}
else {
cout << "Oops, go fish!\n";
cardPtr = assignRandomCard(deck, DECK_SIZE, currentPlayer);
checkScore(deck, DECK_SIZE, currentPlayer, cardPtr->getValue());
if (cardPtr->getValue() == value) {
cout << "Oh wait... you drew the card you wanted! Go again!\n";
continue;
}
}
if (currentPlayer == player1) {
currentPlayer = player2;
otherPlayer = player1;
}
else {
currentPlayer = player1;
otherPlayer = player2;
}
}
cout << "\n\n\n\n\n";
cout << setfill('*') << setw(50) << '\n';
cout << "Final scores!\n";
cout << player1->getName() << " has " << player1->getScore() << " points\n";
cout << player2->getName() << " has " << player2->getScore() << " points\n";
if (player1->getScore() > player2->getScore()) {
cout << player1->getName() << " wins!\n";
}
else if (player1->getScore() < player2->getScore()) {
cout << player2->getName() << " wins!\n";
}
else {
cout << "Wow, a tie, is that even possible?\n";
}
cout << setfill('*') << setw(50) << '\n';
return 0;
}
bool isGameOver(Card*[], const unsigned){
}
Card* assignRandomCard(Card*[], const unsigned, Player*){
}
void checkScore(Card*[], const unsigned, Player*, char){
}
#include "Player.hpp"
int randomNum = 1000 + (rand() % 8999);
Player::Player(std::string n)
:name{new std::string(n)}
,id{new unsigned int(randomNum)}
,score{new unsigned(0)}
{
}
Player::~Player() {
delete name;
delete id;
delete score;
name = nullptr;
id = nullptr;
score = nullptr;
}
const unsigned int Player::getScore() {
return *score;
}
std::string Player::getName() {
return *name;
}
const unsigned int Player::getId() {
return *id;
}
const char Player::ask(int) {
}
const bool Player::check(int) {
}
void Player::updateScore() {
*score = *score + 1;
}
#include "string"
#include <string>
#ifndef GO_FISH_PLAYER_HPP
#define GO_FISH_PLAYER_HPP
class Player {
private:
unsigned int* id;
std::string* name;
unsigned* score;
public:
Player(std::string n);
~Player();
const unsigned getId();
std::string getName();
const unsigned getScore();
void updateScore();
const char ask(deck : Card*[], const unsigned DECK_SIZE);
const bool check(deck : Card*[], const unsigned DECK_SIZE, char value);
};
#endif //GO_FISH_PLAYER_HPP