Count the number of player instructions

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

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)