Untitled

 avatar
unknown
plain_text
19 days ago
3.6 kB
8
Indexable
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Card {
  public:
    Card(int value) {
      this->value = value;
      this->tokens = 0;
    }

    void operator+(int amount) {
      this->tokens += amount;
    }

    void operator-(int amount) {
      this->tokens -= amount;
    }

    friend int getValue(const Card&);
    friend int getTokens(const Card&);
    friend void addToken(Card&);
    friend void removeToken(Card&);

  private:
    int value;
    int tokens;
};
//TODO - Complete the following functions!

int getValue(const Card& card) {
  return card.value;
}

int getTokens(const Card& card) {
  return card.tokens;
}

void addToken(Card& card) {
  card.tokens += 1;
}

void removeToken(Card& card) {
  card.tokens -= 1;
};

void shuffleDeck(vector<Card>& deck) {
    
}

class Player {

};

//TODO - Complete the following functions!

int getTokens(const Player& player);

void addToken(Player& player, int amount);

void removeToken(Player& player);

void displayGameState(const vector<Player>& players);

void declareWinner(const vector<Player>& players);

int main() {
    
//     Uncomment the code below when you have completed the Card class
//     (You can use CTRL+/ if you have highlighted a bunch of code)
    cout << "Testing Card class..." << endl;
    Card card1(5);
    card1 + 3;
    card1 - 3;
    
    
//     Uncomment the code below when you have completed the Card functions
    cout << "\nTesting functions with Card as parameters..." << endl;
    card1 + 2;
    cout << "Tokens after adding 2: " << getTokens(card1) << endl;
    card1 - 1;
    cout << "Tokens after removing 1: " << getTokens(card1) << endl;
    addToken(card1);
    cout << "Tokens after adding 1 token: " << getTokens(card1) << endl;
    removeToken(card1);
    cout << "Tokens after removing 1 token: " << getTokens(card1) << endl;
//     vector<Card> deck = {Card(1), Card(2), Card(3), Card(5), Card(6), Card(7)};
//     shuffleDeck(deck);
//     cout << "Deck after shuffle: ";
//     for (const Card& card : deck) {
//         cout << getValue(card) << " ";
//     }
//     cout << endl;
    
    
//     Uncomment the code below when you have completed the Player class    
//     cout << "\nTesting Player class..." << endl;
//     Player player1, player2;
//     player1 + 4;
//     player1 - 3;
//     player1.collectCard(Card(4));
//     player1.collectCard(Card(5));
//     player1.collectCard(Card(7)); 
//     player1.collectCard(Card(8)); // Score: 4 + 7 - 1(token) = 10
//     cout << "Player1 score after collecting cards: " << player1.calculateScore() << endl;
//     player2.collectCard(Card(10));
//     player2.collectCard(Card(11));
//     player2.collectCard(Card(12)); // Score: 10
//     cout << "Player2 score after collecting cards: " << player2.calculateScore() << endl;
    
//     Uncomment the code below when you have completed the Player functions
//     cout << "\nTesting functions with Player as parameters..." << endl;
//     player1 + 2;
//     cout << "Player1 Tokens after adding 2: " << getTokens(player1) << endl;
//     player1 - 1;
//     cout << "Player1 Tokens after removing 1: " << getTokens(player1) << endl;
//     addToken(player1, 5);
//     cout << "Player1 Tokens after adding 5: " << getTokens(player1) << endl;
//     removeToken(player1);
//     cout << "Player1 Tokens after removing 1: " << getTokens(player1) << endl;
//     vector<Player> players = {player1, player2};
//     displayGameState(players);
//     declareWinner(players);
    
    return 0;
}
Leave a Comment