Files
cc3k/src/input/file_input.cc

52 lines
1.5 KiB
C++

#include "file_input.h"
#include <utility>
#include <string>
#include "../constants.h"
file_input::file_input(std::ifstream &&ifs):
in{std::move(ifs)} {}
game_command file_input::get_command() {
std::string cmd;
in >> cmd;
if (in.eof())
return game_command_terminate;
if (cmd == "q")
return game_command_terminate;
else if (cmd == "f")
return the_world;
else if (cmd == "r")
return game_restart;
else if (cmd == "u" || cmd == "a" || cmd == "t") {
auto cmdtmp = cmd;
in >> cmd;
if (in.eof())
return game_command_panic;
auto tmp = get_direction(cmd);
if (cmdtmp == "u")
return static_cast<game_command>(tmp + apply_north);
else if (cmdtmp == "a")
return static_cast<game_command>(tmp + attack_north);
else
return static_cast<game_command>(tmp + throw_north);
} else if (cmd == "yes") {
return game_command::enter;
} else if (cmd == "i") {
return toggle_inventory;
} else {
auto tmp = get_direction(cmd);
if (tmp != game_command_panic)
return static_cast<game_command>
(tmp + move_north);
}
return game_command_pass;
}