blob: d260c582d1b42ea2b68f13145f23ac6be4f8be89 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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 <string>
#include <vector>
#include <QGraphicsScene>
#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<Robot> robots; // the robots
std::vector<Junk> 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
|