aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/go.cpp
blob: 04528976a7b6e20eb154fffabfccd0f1e263a27d (plain)
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
#include "backend/Location.h"
#include "backend/Dungeon.h"
#include "backend/Exception.h"

#include "../GameController.h"
#include "../strings.h"

using namespace std;

static const unordered_map<string, Direction> direction_map = {
	{ "noord", Direction::NORTH },
	{ "oost",  Direction::EAST },
	{ "zuid",  Direction::SOUTH },
	{ "west",  Direction::WEST },
};

void GameController::cmd_go(string & direction_str) {
	if (direction_str.size() == 0)
		throw Exception("dit commando heeft nog een argument met een richting nodig");
	if (!direction_map.contains(str_lower(direction_str)))
		throw Exception("onbekende richting \"%s\", probeer noord|zuid|oost|west", direction_str.c_str());

	Player & player = this->dungeon->get_player();
	Direction direction = direction_map.at(direction_str);
	Location & next_location = player.get_location().get_exit(direction);

	this->dungeon->update();

	if (!player.is_dead())
		player.set_location(next_location);
}