From 3686258d2fa6fdffebb57f7d530952fd4dabf366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 21 Sep 2020 16:13:25 +0200 Subject: Given files L4 --- labb4/GameState.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 labb4/GameState.h (limited to 'labb4/GameState.h') diff --git a/labb4/GameState.h b/labb4/GameState.h new file mode 100644 index 0000000..d260c58 --- /dev/null +++ b/labb4/GameState.h @@ -0,0 +1,83 @@ +/** + * Copyright (C) David Wolfe, 1999. All rights reserved. + * Ported to Qt and adapted for TDDD86, 2015. + * + * Maintains the game state: Location of all robots, junk and hero. + * Method isSafe() is used to keep Hero from moving stupidly. + */ + +#ifndef GAMESTATE_H +#define GAMESTATE_H + +#include +#include +#include +#include "Unit.h" +#include "Robot.h" +#include "Junk.h" +#include "Hero.h" + +class GameState { +public: + GameState(); + GameState(int numberOfRobots); + + /* + * Clear and redraw entire playing field + */ + void draw(QGraphicsScene* scene) const; // Clear and redraw entire playing field + + /* + * Teleport hero to random location + */ + void teleportHero(); + + /* + * Move robots one step towards hero + */ + void moveRobots(); + + /* Count colliding robots + * Also converts robots to junk while + * checking collisions + */ + int countCollisions (); + + /* + * Check if any robots are left on playing field + */ + bool anyRobotsLeft () const; + + /* + * Is hero in same place as robot or junk? + */ + bool heroDead() const; + + /* + * Can unit safely reside here? + */ + bool isSafe (const Unit& unit) const; // Can unit safely reside here? + + /* + * Move hero towards dir + */ + void moveHeroTowards (const Unit& dir); + + /* + * Return hero + */ + Hero getHero () const; + +private: + std::vector robots; // the robots + std::vector junks; // robots that have turned to junk + Hero hero; // the hero + + // private helpers + bool isEmpty(const Unit& unit) const; + bool junkAt(const Unit& unit) const; + int countRobotsAt(const Unit& unit) const; + +}; + +#endif // GAMESTATE_H -- cgit v1.2.1