Labyrinth7/Labyrinth7Game — pull request #18 by Enlightment (2014-06-01 00:34:51+00:00)
Title: Creating Ranking class; implement Game States; Initialize and Draw methods

Extracting logic for Top 5 players in a new Singleton class RankingTopPlayers:
Implementing Singleton design pattern (this class should be independent of how many instances of the game are created):

public sealed class RankingTopPlayers
{
private static RankingTopPlayers instance = null;

private List topPlayers = new List();

private RankingTopPlayers()
{
}

public static RankingTopPlayers Instance
{
get
{
if (instance == null)
{
instance = new RankingTopPlayers();
}
return instance;
}
}

Moving methods Add and Player_ to RankingTopPlayers.cs and removing their “static”
Renaming Add() to AddToTopResults()
Renaming Player_() to PrintTopResults()

SuccessfulEscape -> remove “static” to use this.Player
Add this.GameState = GameState.Over; to SuccessfulEscape()

Add private const int numberOfTopPlayers = 5 in RankingTopPlayers class to define the max number of players in Ranking

Rename and move from LabyrinthGame.cs
public static List scores = new List(4);
To RankingTopPlayers.cs

private List topPlayers = new List();

This following code is no more needed because it functions are done by updating Player class and Adding it to Ranking in SuccessfulEscape() method.

while (isEscapedNaturally)
{
Add(scores, currentMoves);
}

isEscapedNaturally is not more needed also, so its removed.
using System.Collections.Generic in LabyrinthGame.cs and in Labyrinth.cs is not needed -> removed

RankingTopPlayers.cs:
public void AddToTopResults(List s, int m)
TO
public void AddToTopResults(IPlayer currentPlayer)

Take care of adding the player to the current list with top players. Changing references to List taken as argument and the list in the class (this.topPlayers);
Exporting common repeating code in a new private method called AddPlayer() and changing it:

Console.WriteLine("Please enter your nickname");
string name = Console.ReadLine();
s.Add(new Table(m, name));
Table_(s);
TO

Console.WriteLine("Please enter your nickname");
string name = Console.ReadLine().Trim();
currentPlayer.Name = name;

this.topPlayers.Add(currentPlayer);

Change field currentMoves to this.Player.Moves in LabyrinthGame.cs and removing currentMoves.

Add method Initialize() required from Interface IGame. Move greeting message for a new game in Initialize();

this.GameState = GameState.New; and this.GameState = GameState.Running; instead of public static fields isPlaying, isInLabyrinth,

Removing while() loop in LabyrinthGame constructor. Replacing it with while() in GameHandler.Game.Instance.Run();

Remove Update() from LabyrinthGame constructor. GameHandler should take care of it.

Add method Draw() required from Interface IGame. Move there Labyrinth.DisplayLabyrinth(labyrinth);