#include #include #include using namespace std; // A separate representation of a player for use in this assignment // You should not modify the player struct // (In a real project the player would be a subclass of GameObject) struct Player { // Position int x; int y; // Velocity int v_x; int v_y; }; // Implementera dina klasser här. // Vill du filuppdela är det okej att du flyttar ut definitionen av struct player till din h-fil. // Återställ alla ändringar nedanför denna rad innan du skickar in void CHECK_TRUE( bool result, string const& if_true, string const& if_false); void CHECK_POSITION( Player const& p, int x, int y, string const& if_true, string const& if_false); int main() { Player player{12, 8, 3, 2}; CHECK_POSITION( player, 12, 8, "ok1", "fail: player should start at {12,8}"); Bouncer bouncer{12, 8, 2}; // arguments are: x-position, y-position, bounce CHECK_TRUE( bouncer.collides(player), "ok2", "fail: player and bouncer should have collided"); bouncer.affect(player); CHECK_POSITION( player, 6, 4, "ok3", "fail: player should have been bounced to {6,4}"); Portal one_step_portal(6, 4, new Bouncer{16, 10, 3}); CHECK_TRUE( one_step_portal.collides(player), "ok4", "fail: player and one step portal should have collided"); one_step_portal.affect(player); CHECK_POSITION( player, 7, 4, "ok5", "fail: player should have been teleported to {16,10} and then immediately bounced to {7,4}"); Portal two_step_portal(7, 4, new Portal{0,0, new Bouncer{20, 12, 4}}); CHECK_TRUE( two_step_portal.collides(player), "ok6", "fail: player and two step portal should have collided"); two_step_portal.affect(player); CHECK_POSITION( player, 8, 4, "ok7", "fail: player should have been teleported to {20,12} via {0,0} and then immediately bounced to {8,4}"); two_step_portal.affect(player); CHECK_POSITION( player, 8, 4, "ok7", "fail: player should have been teleported to {20,12} via {0,0} and then immediately bounced to {8,4}"); return 0; } void CHECK_TRUE( bool result, string const& if_true, string const& if_false) { if (result) cout << if_true << endl; else cout << if_false << endl; } void CHECK_POSITION( Player const& p, int x, int y, string const& if_true, string const& if_false) { CHECK_TRUE( p.x == x && p.y == y, if_true, if_false); }