-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntities.h
158 lines (134 loc) · 3.24 KB
/
Entities.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// Entities.h
// Find The Kitten
//
// Created by Ilya Noskov on 4/27/17.
// Copyright © 2017 Ilya Noskov. All rights reserved.
//
#ifndef Entities_h
#define Entities_h
#include <algorithm>
#include <iostream>
#include "Locations.h"
#include "utilities.h"
using namespace std;
class Entity {
public:
char symbol = '2';
string name;
string message;
pair<int, int> position;
Entity() {}
void place_randomly() {
int x = random_x_location(eng);
int y = random_y_location(eng);
this->position = make_pair(x, y);
}
void assign_random_symbol() {
char c;
c = random_symbol(eng);
this->symbol = c;
}
char get_symbol() { return symbol; }
pair<int, int> get_self_position() { return this->position; }
string say() { return this->message; }
};
class Friend : public Entity {
public:
Friend() {
place_randomly();
assign_random_symbol();
}
};
// Funny
// Encouraging
// Helpful
class Enemy : public Entity {
public:
Enemy() {
place_randomly();
assign_random_symbol();
}
};
// Mean
// Stupid
// silent
// the Player
class Robot : public Entity {
public:
bool found_kitten;
Robot() {
found_kitten = false;
// set the moving symbols
v.push_back('O');
v.push_back('o');
// initial position
y = 1;
x = 1;
position = make_pair(x, y);
// initialize empty text field
clear_text_field();
}
void moveUp() {
y++;
position = make_pair(y, x);
}
void moveDown() {
y--;
position = make_pair(y, x);
}
void moveLeft() {
x--;
position = make_pair(y, x);
}
void moveRight() {
x++;
position = make_pair(y, x);
}
void checkLocation() {}
char get_symbol() {
reverse(v.begin(), v.end());
return v[0];
}
void play(char game_field[30][80], pair<int, int> old_location,
pair<int, int> new_location) {
// inspect current location, hashmap look-up
// delete the Robot symbol from the board
game_field[old_location.first][old_location.second] = ' ';
// delete the entity from the hash map
// place the new Robot symbol on the board
game_field[new_location.first][new_location.second] =
this->get_symbol();
print_text_field();
}
private:
vector<char> v;
int x;
int y;
void readMessage(Entity) { cout << Entity::say(); };
char text_field[5][80];
void clear_text_field() {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 80; j++) {
if (i == 0 || i == 4) {
text_field[i][j] = '-';
} else {
if (j == 0 || j == 79) {
text_field[i][j] = '|';
} else {
text_field[i][j] = ' ';
}
}
}
}
}
void print_text_field() {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 80; j++) {
cout << text_field[i][j];
}
cout << "\n";
}
}
};
#endif /* Entities_h */