Skip to content
Snippets Groups Projects
Commit 6c44df6e authored by Jake Feddersen's avatar Jake Feddersen
Browse files

Clean up the code a bit

parent cbd2862b
No related branches found
No related tags found
No related merge requests found
......@@ -65,8 +65,7 @@ int monster::has_characteristic(int bit) {
// Erratic tunneling monsters don't care about anything but the border
position monster::next_monster_move_tunnel_erratic(dungeon &d) {
position next_move;
next_move.x = pos.x;
next_move.y = pos.y;
next_move = pos;
while(next_move.x == pos.x && next_move.y == pos.y) {
next_move.x = randrange(max(1, pos.x - 1), min(MAP_WIDTH-2, pos.x + 1));
......@@ -79,8 +78,7 @@ position monster::next_monster_move_tunnel_erratic(dungeon &d) {
// Erratic non-tunneling monsters have to pick a random open space
position monster::next_monster_move_erratic(dungeon &d) {
position next_move;
next_move.x = pos.x;
next_move.y = pos.y;
next_move = pos;
while(next_move.x == pos.x && next_move.y == pos.y && !d.hardness[next_move.y][next_move.x]) {
next_move.x = randrange(max(1, pos.x - 1), min(MAP_WIDTH-2, pos.x + 1));
......
......@@ -475,10 +475,8 @@ int dungeon::targeting_mode() {
character *c = characters[player_pos.y][player_pos.x];
characters[player_pos.y][player_pos.x] = NULL;
characters[targeting_pointer.y][targeting_pointer.x] = c;
player_pos.x = targeting_pointer.x;
player_pos.y = targeting_pointer.y;
c->pos.x = targeting_pointer.x;
c->pos.y = targeting_pointer.y;
player_pos = targeting_pointer;
c->pos = targeting_pointer;
target_mode = false;
return 0;
......
......@@ -27,6 +27,10 @@ class room {
class dungeon {
public:
uint8_t hardness[MAP_HEIGHT][MAP_WIDTH];
bool hardness_dirty;
uint8_t pc_sight[MAP_HEIGHT][MAP_WIDTH];
char terrain[MAP_HEIGHT][MAP_WIDTH];
......
......@@ -190,7 +190,7 @@ int main(int argc, char* argv[]) {
if (key == '<') {
for (i = 0; i < d.upstair_count; i++) {
if (d.upstair_list[i].x == d.player_pos.x && d.upstair_list[i].y == d.player_pos.y) {
if (d.upstair_list[i] == d.player_pos) {
regen_dungeon(d, &h, args.nummon);
handled_move = 2;
d.draw();
......@@ -222,7 +222,7 @@ int main(int argc, char* argv[]) {
if (d.hardness[next_move.y][next_move.x] && d.hardness[next_move.y][next_move.x] < 255 && c->has_characteristic(TUNNEL)) {
if (d.hardness[next_move.y][next_move.x] > 85) {
d.hardness[next_move.y][next_move.x] -= 85;
} else {
} else if (d.hardness[next_move.y][next_move.x] > 0) {
d.hardness[next_move.y][next_move.x] = 0;
}
......@@ -234,11 +234,9 @@ int main(int argc, char* argv[]) {
if (d.hardness[next_move.y][next_move.x] == 0) {
d.characters[c->pos.y][c->pos.x] = NULL;
d.characters[next_move.y][next_move.x] = c;
c->pos.x = next_move.x;
c->pos.y = next_move.y;
c->pos = next_move;
if (c->is_player()) {
d.player_pos.x = next_move.x;
d.player_pos.y = next_move.y;
d.player_pos = next_move;
}
} else if (c->is_player()) {
display_message("%s", "Ouch, that was a wall.");
......
......@@ -66,3 +66,13 @@ void parse_args(int argc, char *argv[], args *args) {
exit(1);
}
}
int position::operator==(const position &p) {
return (x == p.x && y == p.y);
}
position &position::operator=(const position &p) {
x = p.x;
y = p.y;
return *this;
}
......@@ -43,6 +43,8 @@ class position {
public:
uint8_t x;
uint8_t y;
int operator==(const position &p);
position &operator=(const position &p);
};
/**
......
cin.peek() // look at next character without consuming
cin.get() // return and consume next character
cin.getline(char *, i) // read to string, read to max number of bytes or end of line
// newline included if read
getline(cin, string &, [char delim]) // uses std::string
// newline not included
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment