Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Towards winning the game #723

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 55 additions & 26 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,30 +1181,7 @@ void test_game() //!OCLINT tests may be many
}
#endif // FIX_ISSUE_524

#define FIX_ISSUE_682
#ifdef FIX_ISSUE_682
// A game has a function to check whether the game is over (check end game conditions, currently it only checks max time)
{
const int time_limit = 10;
const game_options g_options{3,
false,
get_random_kam(),
get_random_kam(),
get_random_kam(),
environment_type(),
time_limit
};
game g{g_options};
for (int i = 0; i < time_limit; i++)
{
assert(!g.is_over());
g.increment_n_ticks();
g.check_over();
}
assert(g.is_over());
}

// A game is over when the time limit is reached
// (682) A game is over when the time limit is reached
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful simplification!

{
const int time_limit = 10;
const game_options g_options{3,
Expand All @@ -1222,10 +1199,23 @@ void test_game() //!OCLINT tests may be many
g.tick();
}
assert(g.is_over());
}

#ifdef FIX_ISSUE_716
// (716) Game no longer ticks after game is over
const int n_ticks = g.get_n_ticks();
g.tick();
assert(g.get_n_ticks() == n_ticks);

// and as a result, no further actions are processed
// for example, players are not moved
player& p = g.get_player(0); // ref to player one
const coordinate initial_position = p.get_position();

#endif // FIX_ISSUE_682
add_action(p, action_type::accelerate_forward);
g.tick();
assert(p.get_position() == initial_position);
#endif // FIX_ISSUE_716
}

{
const game g;
Expand All @@ -1234,6 +1224,45 @@ void test_game() //!OCLINT tests may be many
assert(players == v_player);
}

#ifdef FIX_ISSUE_721
// (721) The largest player wins the game
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant win condition!

{
game g;
player &player_two = g.get_player(1);
player_two.grow();
assert(g.who_is_winning() == 1);

player &player_three = g.get_player(2);
player_three.grow();
player_three.grow(); // twice
assert(g.who_is_winning() == 2);
}
#endif // FIX_ISSUE_721

#ifdef FIX_ISSUE_722
// (722) In case of a tie, winner is decided on a coin flip
{
const int a_seed = 5;
const int another_seed = 6; // change if this picks the same winner

game a_game(game_options{a_seed});
player &player_two = a_game.get_player(1);
player_two.grow();
player &player_three = a_game.get_player(2);
player_three.grow();
assert(a_game.who_is_winning() != 0);

game another_game(game_options{another_seed});
player &other_player_two = another_game.get_player(1);
other_player_two.grow();
player &other_player_three = another_game.get_player(2);
other_player_three.grow();
assert(another_game.who_is_winning() != 0);

assert(a_game.who_is_winning != another_game.who_is_winning());
}
#endif // FIX_ISSUE_722

#endif // no tests in release
}

Expand Down
41 changes: 41 additions & 0 deletions src/game_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,47 @@ void test_game_view() //!OCLINT tests may be many
assert(window_size.y == 120);
}

#ifdef FIX_ISSUE_718
// (718) A game_view has a Results screen
{
game_view gv;
gv.get_results_screen();
}
#endif // FIX_ISSUE_718

#ifdef FIX_ISSUE_719
// (719) The results screen is displayed when time is up, not before
{
const int time_limit = 10;
const game_options g_options{3,
false,
get_random_kam(),
get_random_kam(),
get_random_kam(),
environment_type(),
time_limit
};
game_view gv{g_options};
for (int i = 0; i < time_limit; i++)
{
assert(!gv.get_results_screen().is_visible());
gv.get_game().tick();
}
assert(gv.get_results_screen().is_visible());
}
#endif // FIX_ISSUE_719

#ifdef FIX_ISSUE_720
// (720) The results screen knows who is winning
{
game_view gv;
player &player_two = gv.get_game().get_player(1);
player_two.grow();
const int winner = gv.get_results_screen().get_winner();
assert(winner == 1);
}
#endif // FIX_ISSUE_720

#endif //NDEBUG
}

Expand Down
Binary file added stun_rocket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.