-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameController.cs
More file actions
87 lines (74 loc) · 3.16 KB
/
Copy pathGameController.cs
File metadata and controls
87 lines (74 loc) · 3.16 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TAScript.Runnable;
namespace TAScript.Player
{
public class GameController
{
// CONSTANTS //
public static readonly int MAX_PREV_TEXT_DISPLAYED = 4;
// FUNCTIONS //
public void PlayGame(Game runnableGame)
{
// Starts the game
runnableGame.StartGame();
// Asks for input to start
ColourConsole.WriteLine("Press ENTER to start!", Program.PROMPT_COLOUR);
Console.ReadLine();
// While the game is active, displays its output and handles input
while(runnableGame.IsGameActive)
{
// Clears what was written before
Console.Clear();
// Displays the already-displayed text
for(int i = 0; i < runnableGame.PreviouslyDisplayedText.Length; i++)
{
if (runnableGame.PreviouslyDisplayedText.Length - i <= MAX_PREV_TEXT_DISPLAYED)
{
ColourConsole.WriteLine(runnableGame.PreviouslyDisplayedText[i], ConsoleColor.Gray);
ColourConsole.WriteLine("", ConsoleColor.DarkGray);
}
}
// Gets the data for the current game block
string currentText = runnableGame.CurrentTitleText;
Option[] currentOptions = runnableGame.AvailableOptions;
UserInputType inputRequired = runnableGame.InputType;
// Displays info for this level
ColourConsole.WriteLine(currentText, ConsoleColor.White);
// If there are options, displays them
if(currentOptions != null)
{
for(int i = 0; i < currentOptions.Length; i++)
{
ColourConsole.Write(i + " > ", ConsoleColor.Cyan);
ColourConsole.WriteLine(currentOptions[i].displayText, ConsoleColor.White);
}
}
// Prompts for input depending on what the input type is
if(inputRequired == UserInputType.None)
{
ColourConsole.WriteLine("Press ENTER to continue...", ConsoleColor.Magenta);
Console.ReadLine();
runnableGame.Continue();
}
else if(inputRequired == UserInputType.Option)
{
ColourConsole.Write("Select an option to continue: ", ConsoleColor.Magenta);
if(int.TryParse(Console.ReadLine(), out int result))
{
if(result >= 0 && result < currentOptions.Length)
{
runnableGame.HandleOptionSelection(currentOptions[result]);
}
}
}
}
// After it is finished, displays the list of blocks and variables
runnableGame.LogBlockGraph();
runnableGame.LogAllVariables();
}
}
}