-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameview.cpp
55 lines (43 loc) · 1.62 KB
/
gameview.cpp
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
#include "gameview.hpp"
#include "player.hpp"
GameView::GameView(stf::smv::BaseModel *model)
: BaseGameView(model)
{}
void GameView::show(stf::Renderer &renderer)
{
for(int y = 1; y < model<GameModel>()->mapSize().y; ++y) {
for(int x = 0; x < model<GameModel>()->mapSize().x; ++x) {
if(x==0||y==1||x==model<GameModel>()->mapSize().x-1||y==model<GameModel>()->mapSize().y-1) {
renderer.drawPixel(stf::Vec2d(x,y), '*');
}
}
}
for(auto food : model<GameModel>()->foodModel().getPossibleFood()) {
renderer.drawPixel(food->pos(), food->symbol());
}
for(auto hunter : model<GameModel>()->hunterModels()) {
hunter->show(renderer, {0,0});
}
const Player* player = dynamic_cast<const Player *>(model<GameModel>()->hunterModels().at(0));
renderer.draw({10, 0}, "SCORE: %d LVL: %d LIFES: %d",
player->score(),
player->lvl(),
player->lifes());
}
PausedGameView::PausedGameView(stf::smv::BaseModel *model)
: BasePausedGameView(model)
{}
void PausedGameView::show(stf::Renderer &renderer)
{
for(auto food : model<GameModel>()->foodModel().getPossibleFood()) {
renderer.drawPixel(food->pos(), food->symbol());
}
for(auto hunter : model<GameModel>()->hunterModels()) {
hunter->show(renderer, {0,0});
}
const Player* player = dynamic_cast<const Player *>(model<GameModel>()->hunterModels().at(0));
renderer.draw({10, 0}, "SCORE: %d LVL: %d LIFES: %d",
player->score(),
player->lvl(),
player->lifes());
}