diff --git a/source/client/panels/MainGamePanel.cpp b/source/client/panels/MainGamePanel.cpp index 3a37a8d3dbedc49f5c2c65c63d9e2b925ef80277..fb8a6a1fc7f021ca86f97b2fc6c44d2814a47af1 100644 --- a/source/client/panels/MainGamePanel.cpp +++ b/source/client/panels/MainGamePanel.cpp @@ -131,32 +131,32 @@ void MainGamePanel::buildOthers(game_state* gameState, player* otherPlayer, doub } else{ // STATUS - if(otherPlayer->get_hand()->is_over_21(err)){ - this->buildStaticText( - "Status: LOST ROUND", - labelPosition + wxSize(-100, -18), - wxSize(200, 18), - textAlignment - ); - } - else if(gameState->get_current_player() == otherPlayer && !gameState->everyone_finished()) - { - this->buildStaticText( - "Status: Playing", - labelPosition + wxSize(-100, -18), - wxSize(200, 18), - textAlignment - ); + std::string status_message = "Status: "; + + if(otherPlayer->get_hand()->is_over_21(err)) + status_message += "LOST ROUND" ; + else if(gameState->everyone_finished()){ + std::string err; + int pp = otherPlayer->get_hand()->get_points(err); + int dp = gameState->get_dealers_hand()->get_points(err); + if(pp < dp) status_message += "LOST ROUND"; + else if(pp > dp) status_message += "WON ROUND"; + else status_message += "DRAW WITH DEALER"; + } + else if(gameState->get_current_player() == otherPlayer && !gameState->everyone_finished()) + status_message += "PLAYING"; else - { - this->buildStaticText( - "Status: Waiting", + status_message += "WAITING"; + + this->buildStaticText( + status_message, labelPosition + wxSize(-100, -18), wxSize(200, 18), textAlignment ); - } + + // MONEY this->buildStaticText( "Money:" + std::to_string(otherPlayer->get_money()) + "$", @@ -330,7 +330,29 @@ void MainGamePanel::buildThisPlayer(game_state* gameState, player* me) { // if our player already played, we display that as status // TODO from has_folded make has_played - if (me->has_finished_turn()) { + + if(gameState->everyone_finished()){ + std::string err; + std::string status_message; + int pp = me->get_hand()->get_points(err); + int dp = gameState->get_dealers_hand()->get_points(err); + + if(me->get_hand()->is_over_21(err)) + status_message += "YOU LOST THIS ROUND"; + else if(pp < dp) status_message += "YOU LOST THIS ROUND"; + else if(pp > dp) status_message += "YOU WON THIS ROUND"; + else status_message += "YOU TIED WITH THE DEALER"; + + wxStaticText *playerStatus = buildStaticText( + status_message, + wxDefaultPosition, + wxSize(200, 32), + wxALIGN_CENTER + ); + innerLayout->Add(playerStatus, 0, wxALIGN_CENTER | wxBOTTOM, 8); + + } + else if (me->has_finished_turn()) { wxStaticText *playerStatus = buildStaticText( "You finished your turn", wxDefaultPosition, diff --git a/source/general/game_state/hand.hpp b/source/general/game_state/hand.hpp index 4d76b9a68376cf4e28b6bae6c7c0aaca2395a96b..394ac03af33547cd488ee99b58ca51ee7b81e0a6 100644 --- a/source/general/game_state/hand.hpp +++ b/source/general/game_state/hand.hpp @@ -31,7 +31,7 @@ public: bool add_card(card* card, std::string& err); //checked int get_points(std::string &err); //checked - bool is_over_21(std::string &err); //TODO + bool is_over_21(std::string &err); //checked std::vector<card*>::iterator get_card_iterator(); }; diff --git a/unit-tests/hand.cpp b/unit-tests/hand.cpp index 43eb45975e2e6343977ece9704fa056b9103fa01..7fe7b1832ccaf13971339ce3e13ec15631d31d74 100644 --- a/unit-tests/hand.cpp +++ b/unit-tests/hand.cpp @@ -259,4 +259,61 @@ TEST_F(HandTest, SetupRoundManyCardsWithDuplicates) { player_hand.setup_round(err); std::vector<card*> expected_hand = {}; EXPECT_EQ(expected_hand, player_hand.get_cards()); +} + +// An empty hand will not have a score of over 21 +TEST_F(HandTest, IsOver21NoCards) { + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand with only one card will not have a score of over 21 +TEST_F(HandTest, IsOver21OneCard) { + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand with less than 21 points will not have a score of over 21 +TEST_F(HandTest, IsOver21ManyCardsFalse) { + player_hand.add_card(cards[2][0], err); + player_hand.add_card(cards[7][0], err); + player_hand.add_card(cards[9][0], err); + EXPECT_FALSE(player_hand.is_over_21(err)); +} +// A hand (including an ace) with less than 21 points will not have a score of over 21 +TEST_F(HandTest, IsOver21ManyCardsWithAceFalse) { + player_hand.add_card(cards[1][0], err); + player_hand.add_card(cards[7][0], err); + player_hand.add_card(cards[9][0], err); + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand of 21 points will not have a score of over 21 +TEST_F(HandTest, IsOver21Exactly) { + player_hand.add_card(cards[4][0], err); + player_hand.add_card(cards[7][0], err); + player_hand.add_card(cards[10][0], err); + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand of 21 points (one ace and a face card) will not have a score of over 21 +TEST_F(HandTest, IsOver21ExactlyWithAce) { + player_hand.add_card(cards[1][0], err); + player_hand.add_card(cards[13][0], err); + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand of over 21 points will return true for is_over_21() +TEST_F(HandTest, IsOver21ManyCardsTrue) { + player_hand.add_card(cards[10][0], err); + player_hand.add_card(cards[4][0], err); + player_hand.add_card(cards[13][0], err); + EXPECT_TRUE(player_hand.is_over_21(err)); +} + +// A hand of over 21 points (with ace) will return true for is_over_21() +TEST_F(HandTest, IsOver21TrueWithAce) { + player_hand.add_card(cards[1][0], err); + player_hand.add_card(cards[7][0], err); + player_hand.add_card(cards[13][0], err); + player_hand.add_card(cards[5][0], err); + EXPECT_TRUE(player_hand.is_over_21(err)); } \ No newline at end of file