Difference between revisions of "Count the number of player instructions"
(Created page with "Player instruction counter in order to create a player instruction counter we will first need to define a variable to count this in an area of the program which does not loop...") |
|||
Line 1: | Line 1: | ||
Player instruction counter | Player instruction counter | ||
− | in order to create a player instruction counter we will first need to define a variable to count this in an area of the program which does not loop e.g. | + | in order to create a player instruction counter we will first need to define a variable to count this in an area of the program which does not loop e.g. |
− | you then need to increment and output it. | + | <syntaxhighlight lang=c#> |
− | I chose to put this in the PlayGame method of the program | + | int instructions = 0; |
− | [[ | + | </syntaxhighlight> |
+ | |||
+ | you then need to increment and output it. | ||
+ | <syntaxhighlight lang=c#> | ||
+ | instructions++ | ||
+ | </syntaxhighlight> | ||
+ | and | ||
+ | <syntaxhighlight lang=c#> | ||
+ | Console.Writeline("you have used " + instructions + " moves") | ||
+ | </syntaxhighlight> | ||
+ | I chose to put this in the PlayGame method of the program like this. | ||
+ | |||
+ | <syntaxhighlight lang=c#> | ||
+ | private static void PlayGame(List<Character> characters, List<Item> items, List<Place> places) | ||
+ | { | ||
+ | bool stopGame = false; | ||
+ | int instructions = 0; | ||
+ | string instruction, Command; | ||
+ | bool moved = true; | ||
+ | int resultOfOpenClose; | ||
+ | while (!stopGame) | ||
+ | { | ||
+ | if (moved) | ||
+ | { | ||
+ | Console.WriteLine(); | ||
+ | Console.WriteLine(); | ||
+ | Console.WriteLine(places[characters[0].CurrentLocation - 1].Description); | ||
+ | DisplayGettableItemsInLocation(items, characters[0].CurrentLocation); | ||
+ | moved = false; | ||
+ | } | ||
+ | instruction = GetInstruction(); | ||
+ | instructions++; | ||
+ | Console.WriteLine("you have used " + instructions + " moves"); | ||
+ | Command = ExtractCommand(ref instruction); | ||
+ | switch (Command) | ||
+ | </syntaxhighlight> |
Latest revision as of 10:02, 18 December 2018
Player instruction counter
in order to create a player instruction counter we will first need to define a variable to count this in an area of the program which does not loop e.g.
int instructions = 0;
you then need to increment and output it.
instructions++
and
Console.Writeline("you have used " + instructions + " moves")
I chose to put this in the PlayGame method of the program like this.
private static void PlayGame(List<Character> characters, List<Item> items, List<Place> places)
{
bool stopGame = false;
int instructions = 0;
string instruction, Command;
bool moved = true;
int resultOfOpenClose;
while (!stopGame)
{
if (moved)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(places[characters[0].CurrentLocation - 1].Description);
DisplayGettableItemsInLocation(items, characters[0].CurrentLocation);
moved = false;
}
instruction = GetInstruction();
instructions++;
Console.WriteLine("you have used " + instructions + " moves");
Command = ExtractCommand(ref instruction);
switch (Command)