-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.cpp
34 lines (26 loc) · 1.04 KB
/
Item.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
//
// Created by Daniel Eidlin on 05/08/2020.
//
#include <cstdlib>
#include "Item.h"
Item::Item() {}
Item::Item(std::pair<int, int> spawnCoordinates, char itemChar) : coordinates(spawnCoordinates),
previousCoordinates(spawnCoordinates),
itemChar(itemChar) {}
Item::~Item() {}
std::pair<int, int> Item::getCoordinates() const {
return coordinates;
}
char Item::getItemChar() const {
return itemChar;
}
std::pair<int, int> Item::getPreviousCoordinates() const {
return previousCoordinates;
}
void Item::spawn(int width, int height) {
int randomXCoordinate = 1 + (rand() % (width - 2)); // Random x coordinate in the board's range
int randomYCoordinate = 1 + (rand() % (height - 2)); // Random y coordinate in the board's range
std::pair<int, int> spawnCoordinates = std::pair<int, int>(randomXCoordinate, randomYCoordinate);
previousCoordinates = coordinates;
coordinates = spawnCoordinates;
}