当前位置: 首页>>代码示例>>C#>>正文


C# IRenderable.Read方法代码示例

本文整理汇总了C#中IRenderable.Read方法的典型用法代码示例。如果您正苦于以下问题:C# IRenderable.Read方法的具体用法?C# IRenderable.Read怎么用?C# IRenderable.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRenderable的用法示例。


在下文中一共展示了IRenderable.Read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeginGame

        /// <summary>
        /// Method that is responsible for communication between the user and the engine.
        /// Handles user input and outputs game response.
        /// </summary>
        private void BeginGame(IRenderable render)
        {
            ScoreBoard scoreBoard = new ScoreBoard();
            render.PrintField(this.gameField.GetFieldNumbers());
            bool gameIsFinished = false;
            int moves = 0;

            string inputCommand = render.Read("give me command: ").Trim();

            while (inputCommand != "exit")
            {
                switch (inputCommand)
                {
                    case "top":
                        render.PrintScoreboard(scoreBoard.Scores());
                        break;
                    case "restart":
                        this.StartNewGame(render, true);
                        break;
                    default:
                        moves = MoveNumberIfValid(render, moves, inputCommand);
                        break;
                }

                render.PrintField(this.gameField.GetFieldNumbers());
                gameIsFinished = this.gameField.IsSolved();

                if (gameIsFinished)
                {
                    string message = string.Format("Congratulations! You won the game in {0} moves.", moves);
                    render.Write(message);

                    this.AddUserToScoreBoard(scoreBoard, moves, render);
                    moves = 0;
                    this.StartNewGame(render);
                }

                inputCommand = render.Read("give me command: ").Trim();
            }
        }
开发者ID:rosteslav,项目名称:game-fifteen,代码行数:44,代码来源:GameEngine.cs

示例2: AddUserToScoreBoard

 /// <summary>
 /// Adds user to scoreboard, asking his name and getting his score.
 /// </summary>
 /// <param name="score">Number of moves.</param>
 private void AddUserToScoreBoard(ScoreBoard scoreBoard, int score, IRenderable render)
 {
     string name = render.Read("Please enter your name for the top scoreboard: ");
     scoreBoard.Add(name, score);
 }
开发者ID:rosteslav,项目名称:game-fifteen,代码行数:9,代码来源:GameEngine.cs


注:本文中的IRenderable.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。