Example #1
0
 /// <summary>
 /// Adds player to highscore list
 /// </summary>
 /// <param name="highscoreList"><The highscore list to update/param>
 private void AddPlayerToHighscoreList(IHighscore highscoreList)
 {
     string playerName = this.provider.Renderer.RenderInputMessage();
     this.player.Name = playerName;
     this.player.Moves = this.numberOfMoves.Counter;
     highscoreList.AddPlayer(this.player);
 }
 private EngineFacade()
 {
     this.highscore = new Highscore();
     this.renderer = new ConsoleUIRenderer();
     this.provider = new BasicIOProvider<ConsoleUIRenderer>(this.renderer, this.highscore);
     this.gameEngine = new GameEngine(this.provider);
 }
        /// <summary>
        /// Creates an instance of the <see cref="Highscore"/> class, otherwise - returns the existing instance.
        /// </summary>
        /// <returns>The <see cref="Highscore"/> instance</returns>
        public static IHighscore GetInstance()
        {
            if (instance == null)
            {
                instance = new Highscore();
            }

            return instance;
        }
        /// <summary>
        /// Initializes a new instance of the CommandContext class.
        /// </summary>
        /// <param name="logger">The logger to save messages.</param>
        /// <param name="board">The board object to be used in the game.</param>
        /// <param name="row">The row that needs to be popped.</param>
        /// <param name="col">The column that needs to be popped.</param>
        /// <param name="memory">The memory caretaker where a memento is saved.</param>
        /// <param name="score">The score container.</param>
        /// <param name="highscoreProcessor">The high score processor.</param>
        public CommandContext(ILogger logger, IBoard board, int row, int col, IBoardMemory memory, IHighscore score, IHighscoreProcessor highscoreProcessor)
        {
            this.Logger = logger;
            this.Board = board;
            this.ActiveRow = row;
            this.ActiveCol = col;
            this.Memory = memory;
            this.Score = score;
            this.HighscoreProcessor = highscoreProcessor;
            this.IsOver = false;

            this.CurrentMessage = this.Messages["welcome"];
        }
        /// <summary>
        /// An override of base method - prints the given input high-score
        /// </summary>
        /// <param name="highscore">The high-score to be printed</param>
        public override void PrintHighscore(IHighscore highscore)
        {
            highscore.LoadData();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(GameOutputMessages.HighscoreMainMessage);
            foreach (IPlayer player in highscore.Players)
            {
                string highscoreLine = string.Format(
                    GameOutputMessages.HighscoreUserInformationMessage,
                    highscore.Players.IndexOf(player) + 1,
                    player.Name,
                    player.Moves);

                sb.AppendLine(highscoreLine);
            }

            this.RenderOutputMessage(sb.ToString());
        }
        /// <summary>
        /// Saves high score to an existing file, otherwise one is created and high score is written.
        /// </summary>
        /// <param name="highscore">the score object</param>
        public void SaveHighscore(IHighscore highscore)
        {
            const string RootElementString = "highscores";

            XDocument score;

            if (File.Exists(Path))
            {
                score = XDocument.Load(Path);
            }
            else
            {
                score = new XDocument(new XElement(RootElementString));
            }

            var root = score.Root;

            root.Add(new XElement("score", new XElement("username", highscore.Username), new XElement("points", highscore.CurrentScore)));

            score.Save(Path);
        }
Example #7
0
 public GameData(IRenderer renderer, IHighscore highscore)
 {
     this.Renderer  = renderer;
     this.Highscore = highscore;
 }
 /// <summary>
 /// An abstract method to print the high-score
 /// </summary>
 /// <param name="highscore">The high-score to be printed</param>
 public abstract void PrintHighscore(IHighscore highscore);
 public HighscoreCommand(IBasicUIRenderer renderer, IHighscore highscore)
     : base(renderer)
 {
     this.Highscore = highscore;
 }