示例#1
0
        private static void Play(LudoEngine game)
        {
            bool gameHasWinner = false;

            while (!gameHasWinner)
            {
                Console.Clear();
                DrawBoard(game);
                int moves = LetPlayerRollDice(game.CurrentPlayer, game);
                Console.WriteLine($"{game.CurrentPlayer.Name} got a {moves}!");
                Console.WriteLine();
                var moveablePiece = game.GetMoveablePieces(moves);
                if (moveablePiece.Count > 0)
                {
                    var pieceToMove = LetPlayerChoosePiece(moveablePiece, game);
                    if (pieceToMove != null)
                    {
                        bool moved = MovePiece(moves, pieceToMove, game);

                        while (!moved)
                        {
                            pieceToMove = LetPlayerChoosePiece(moveablePiece, game);
                            moved       = MovePiece(moves, pieceToMove, game);
                        }
                    }
                }
                gameHasWinner = game.FindWinner();
                game.SwitchPlayer();
            }
            Console.WriteLine();
            Console.WriteLine($"{game.Winner.Name} won the game!");
        }
示例#2
0
        public void GivenAPlayerHasAllPiecesInNest_WhenDiceRollResultsInLessThan6_Expect0MoveablePieces()
        {
            var         contextMock   = new Mock <LudoDbContext>();
            List <Game> gameToReturn  = new List <Game>();
            List <User> usersToReturn = new List <User>();

            contextMock.Setup(x => x.Games).ReturnsDbSet(gameToReturn);
            contextMock.Setup(x => x.Users).ReturnsDbSet(usersToReturn);

            LudoEngine game = new LudoEngine(contextMock.Object, "testgame1");

            game.AddPlayer(typeof(RedPiece), "playerName");
            var moveablePieces = game.GetMoveablePieces(5);

            Assert.Empty(moveablePieces);
        }