-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
36 lines (33 loc) · 1.13 KB
/
Map.cpp
File metadata and controls
36 lines (33 loc) · 1.13 KB
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
#include "Map.h"
Map::Map(int size) : tiles(size, std::vector<char>(size, 'N')) {
tiles[3][3] = 'S'; // Special tile
tiles[1][1] = 'I'; // Island tile
}
void Map::displayMap() const {
for (const auto& row : tiles) {
for (char tile : row) {
std::cout << tile << " ";
}
std::cout << std::endl;
}
}
void Map::movePlayer(int& playerX, int& playerY, int deltaX, int deltaY) {
int newX = std::max(0, std::min(playerX + deltaX, static_cast<int>(tiles.size()) - 1));
int newY = std::max(0, std::min(playerY + deltaY, static_cast<int>(tiles[0].size()) - 1));
playerX = newX;
playerY = newY;
std::cout << "Player moved to (" << newX << ", " << newY << ")\n";
char tileType = tiles[newX][newY];
switch(tileType) {
case 'I':
std::cout << "Landed on an Island tile!" << std::endl;
// Trigger island event
break;
case 'S':
std::cout << "Landed on a Special tile!" << std::endl;
// Trigger special event
break;
default:
std::cout << "Moved to a Normal tile." << std::endl;
}
}