Skip to content
Snippets Groups Projects
Commit ff2b004d authored by Ian Prins's avatar Ian Prins
Browse files

make level getters return references

parent 325ff34a
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
#include "terrain.h"
#include "random.h"
#include "playerchar.h"
#include "goldpile.h"
#ifndef LEVEL_H
#define LEVEL_H
......@@ -10,14 +11,15 @@
class Level {
public:
Level(Coord, int);
Terrain tileAt(Coord);
Terrain operator[](Coord);
Terrain& tileAt(Coord);
Terrain& operator[](Coord);
void generate(PlayerChar);
private:
const int MAX_ROOMS = 9;
const double GOLD_CHANCE = .333;
std::vector<std::vector<Terrain> > tiles;
std::vector<Mob> mobs;
std::vector<GoldPile> golds;
int genGoldAmount(Generator);
Coord size;
int depth;
......
......@@ -15,16 +15,16 @@ Level::Level(Coord size, int depth)
for (auto x=0; x < size[0]; x++) {
tiles.push_back(std::vector<Terrain>());
for (auto y=0; y < size[1]; y++) {
tiles[x].push_back(Floor());
tiles[x].push_back(Wall());
}
}
}
Terrain Level::operator[](Coord coord) {
Terrain& Level::operator[](Coord coord) {
return tileAt(coord);
}
Terrain Level::tileAt(Coord coord) {
Terrain& Level::tileAt(Coord coord) {
return tiles[coord[0]][coord[1]];
}
......@@ -45,10 +45,12 @@ void Level::generate(PlayerChar player) {
roomPosition = boxTopLeft + positionRand;
} while (roomPosition[1] == 0);
Room curRoom = Room(roomPosition, roomPosition + roomSize);
curRoom.dig(*this);
//put gold in current room
if (gen() < GOLD_CHANCE && (!player.foundAmulet() || depth >= player.maxDelved())) {
Coord goldPos = gen.randPosition(curRoom[0], curRoom[1]);
int goldAmount = genGoldAmount(gen);
golds.push_back(GoldPile(goldPos, goldAmount));
}
//put monsters in current room
}
......
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