Skip to content

Commit

Permalink
player
Browse files Browse the repository at this point in the history
  • Loading branch information
shirley committed Jul 30, 2019
1 parent 734c136 commit 2d98c74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion easy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
| |
| |--------------------------| |-----------------------| |
| |77777777777777777777777777| |88888888888888888888888| |
| |77777@77777777777777777777+########+88888888888888888888888|-------| |
| |77777777777777777777777777+########+88888888888888888888888|-------| |
| |77777777777777777777777777| # |8888888888888888888888888888888|--| |
| |77777777777777777777777777| # |8888888888888888888888888888888888|--| |
| |----------+---------------| # |----+----------------|888888888888888| |
Expand Down
12 changes: 12 additions & 0 deletions floor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ Floor::Floor(string file) :

Floor::Floor(std::shared_ptr<Player> pc, ifstream &s) {
this->pc = pc;
bool isPlayerSet = false;
vector<shared_ptr<Cell>> row;
vector<shared_ptr<Enemy>> enemies;
vector<shared_ptr<Cell>> playerPos;
for (int y = 0; y < 25; ++y) {
for (int x = 0; x < 80; ++x) {
char c;
Expand Down Expand Up @@ -134,6 +136,7 @@ Floor::Floor(std::shared_ptr<Player> pc, ifstream &s) {
row[x]->attachStuff(enemies.back());
} else if (c == '@'){
row[x]->attachStuff(pc);
isPlayerSet = true;
} else if (c == '/'){
row[x]->attachStuff(make_shared<Stair>());
}
Expand All @@ -145,6 +148,15 @@ Floor::Floor(std::shared_ptr<Player> pc, ifstream &s) {
int index = rand() % enemies.size();
enemies[index]->assignCompass();
}
if (!isPlayerSet) {
for (auto cur : floorTiles) {
if (!cur->getOccupant()) {
playerPos.emplace_back(cur);
}
}
int index = rand() % playerPos.size();
playerPos[index]->attachStuff(pc);
}
}

void Floor::setTD(std::shared_ptr<TextDisplay> t){
Expand Down

0 comments on commit 2d98c74

Please sign in to comment.