예제 #1
0
        // TODO: Improve the formatting using the predefined stuff
        public void PrintHighscore(IHighscoreTable highScore)
        {
            Console.WriteLine("---------TOP FIVE CHART-----------");

            for (int i = 0; i < highScore.Table.Count; i++)
            {
                var currentRow = highScore.Table[i];
                Console.WriteLine("{0}. {1} - {2} - {3}", i + 1, currentRow.Name, currentRow.Moves, currentRow.Time);
            }

            Console.WriteLine("----------------------------------");
        }
예제 #2
0
 /// <summary>
 /// Saves a <see cref="IHighscoreTable"/> to a JSON formatted file.
 /// </summary>
 /// <param name="table">The concrete implementation of a table.</param>
 public void Save(IHighscoreTable table)
 {
     string json = JsonConvert.SerializeObject(table.Table.ToArray(), Formatting.Indented);
     try
     {
         File.WriteAllText(this.FileName, json);
     }
     catch (Exception ex)
     {
         Logger.Error("Cannot save highscore in json file.", ex);
         throw;
     }
 }
예제 #3
0
        /// <summary>
        /// Saves a <see cref="IHighscoreTable"/> to a XML formatted file.
        /// </summary>
        /// <param name="table">The concrete implementation of a table.</param>
        public void Save(IHighscoreTable table)
        {
            XDocument highscoreDoc = new XDocument(
                new XElement(
                    "highscoreTable",
                    new XElement(
                        "players",
                        from player in table.Table
                        select new XElement(
                            "player",
                                new XElement("name", player.Name),
                                new XElement("moves", player.Moves),
                                new XElement("time", player.Time)))));

            try
            {
                highscoreDoc.Save(this.FileName);
            }
            catch (Exception ex)
            {
                Logger.Error("Cannot save highscore in xml file.", ex);
                throw;
            }
        }
예제 #4
0
        /// <summary>
        /// Prints the highscore in the rankings section of the view.
        /// </summary>
        /// <param name="table"></param>
        public void PrintHighscore(IHighscoreTable table)
        {
            this.View[ScoreBoxId].Style.Color = ConsoleColor.White;

            var rankings = table.Table;
            for (int i = 0; i < rankings.Count; i++)
            {
                // TODO: extract in resource provider
                var scoreToAdd = new TextElement(rankings[i].Stringify(i + 1));
                scoreToAdd.Style.PaddingTop = (i * PlayerScoreMargin) + 1;

                this.View.AddChildToParent(this.View[ScoreBoxId], scoreToAdd);
                this.View[ScoreBoxId].Style.Height = table.Table.Count * HighscoreTableHeightIncrement;
            }
        }
예제 #5
0
        /// <summary>
        /// Updates the ranking of the view based on the provided IHighscoreTable instance.
        /// </summary>
        /// <param name="table">The highscore table on which the introduced changes are based.</param>
        public void PrintHighscore(IHighscoreTable table)
        {
            this.Window.Rankings.Children.Clear();

            var tableAsMapList = table.ToStringLists();

            int rowIndex = 0;

            tableAsMapList.ForEach(record =>
            {
                int colIndex = 0;

                record.ForEach(infoField =>
                {
                    infoField
                        .WrapInTextBox(this.Resources.HighscoreGridCell.Clone())
                        .WrapInBorder(this.Resources.HighscoreGridBorder.Clone())
                        .SetGridRow(rowIndex)
                        .SetGridCol(colIndex++)
                        .AddAsChildTo(this.Window.Rankings);
                });

                rowIndex++;
            });
        }