-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInterface.h
More file actions
56 lines (46 loc) · 1.79 KB
/
Interface.h
File metadata and controls
56 lines (46 loc) · 1.79 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Interface;
class Game;
// This struct contains the layout for acceptable commands and their appropriate function calls
struct CommandMapping
{
public:
// This line creates a keyword to refer to a function pointer. Now we can use 'FunctionPtr' instead of that nasty function pointer declaration
// QUESTION INT1: What is a function pointer, and why do we use it here?
using FunctionPtr = string(Game::*)(string);
// This function pointer refers to the function the player will be directed to
FunctionPtr Function;
// This array of strings is the list of corresponding inputs the player may give to call the function
vector<string> Inputs;
// This constructor function populates the struct with the input variables
CommandMapping(FunctionPtr InFunction, vector<string> InInputs)
{
Function = InFunction;
Inputs = InInputs;
}
};
// This class manages the conversation between the game and the player
class Interface
{
public:
Interface(Game* InGame);
~Interface() {};
// The parent game this class belongs to
Game* TextAdv = nullptr;
// These are the mappings for the player inputs
vector<CommandMapping> InputMappings;
// This function populates the CommandMapping array
void PopulateCommandArray();
// This functions asks the player for their next move
void PromptPlayer();
// This string is the player's prompt to act
string Prompt = "\nWhat would you like to do?\n";
// This function interprets the player's input into a command for the game, and returns the console text for the output
string ParseInput(string PlayerCommand);
// this is the string that is returned if the player passed in an invalid command
string InvalidCommand = "That didn't quite make sense, why don't you try again?";
};