moved get_direction from *_input.cc to input.h
This commit is contained in:
@ -5,17 +5,6 @@
|
|||||||
console_input::console_input(std::istream &cin):
|
console_input::console_input(std::istream &cin):
|
||||||
in{cin} {}
|
in{cin} {}
|
||||||
|
|
||||||
inline game_command get_direction(std::string &str, const char *COMMANDS[],
|
|
||||||
const int COMMANDS_CNT) {
|
|
||||||
for (int i = 0; i < COMMANDS_CNT; ++i)
|
|
||||||
if (str == COMMANDS[i] &&
|
|
||||||
i >= game_command::move_north &&
|
|
||||||
i <= game_command::move_southeast)
|
|
||||||
return (game_command)i;
|
|
||||||
|
|
||||||
return game_command_panic;
|
|
||||||
}
|
|
||||||
|
|
||||||
game_command console_input::get_command() {
|
game_command console_input::get_command() {
|
||||||
const char *COMMANDS[] = {
|
const char *COMMANDS[] = {
|
||||||
"q", "no", "so", "ea", "we", "ne", "nw", "se", "sw", "u", "a"
|
"q", "no", "so", "ea", "we", "ne", "nw", "se", "sw", "u", "a"
|
||||||
|
@ -5,17 +5,6 @@
|
|||||||
file_input::file_input(std::ifstream &&ifs):
|
file_input::file_input(std::ifstream &&ifs):
|
||||||
in{std::move(ifs)} {}
|
in{std::move(ifs)} {}
|
||||||
|
|
||||||
inline game_command get_direction(std::string &str, const char *COMMANDS[],
|
|
||||||
const int COMMANDS_CNT) {
|
|
||||||
for (int i = 0; i < COMMANDS_CNT; ++i)
|
|
||||||
if (str == COMMANDS[i] &&
|
|
||||||
i >= game_command::move_north &&
|
|
||||||
i <= game_command::move_southeast)
|
|
||||||
return (game_command)i;
|
|
||||||
|
|
||||||
return game_command_panic;
|
|
||||||
}
|
|
||||||
|
|
||||||
game_command file_input::get_command() {
|
game_command file_input::get_command() {
|
||||||
const char *COMMANDS[] = {
|
const char *COMMANDS[] = {
|
||||||
"q", "no", "so", "ea", "we", "ne", "nw", "se", "sw", "u", "a"
|
"q", "no", "so", "ea", "we", "ne", "nw", "se", "sw", "u", "a"
|
||||||
|
12
src/input.cc
Normal file
12
src/input.cc
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
game_command get_direction(std::string &str, const char *COMMANDS[],
|
||||||
|
const int COMMANDS_CNT) {
|
||||||
|
for (int i = 0; i < COMMANDS_CNT; ++i)
|
||||||
|
if (str == COMMANDS[i] &&
|
||||||
|
i >= game_command::move_north &&
|
||||||
|
i <= game_command::move_southeast)
|
||||||
|
return (game_command)i;
|
||||||
|
|
||||||
|
return game_command_panic;
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef __INPUT_H__
|
#ifndef __INPUT_H__
|
||||||
#define __INPUT_H__
|
#define __INPUT_H__
|
||||||
|
#include <string>
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
|
||||||
class input {
|
class input {
|
||||||
@ -8,4 +9,7 @@ public:
|
|||||||
virtual game_command get_command() = 0;
|
virtual game_command get_command() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
game_command get_direction(std::string &str, const char *COMMANDS[],
|
||||||
|
const int COMMANDS_CNT);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user