public void FullSinglerPlayerGame_FailingOnThirdLevel()
        {
            var gameBoard = new GameBoard();
            var player = new Player {Id = 1, Name = "Derik"};

            gameBoard.SetupBoard(new List<Player>{player}, DifficultyLevel.Easy);

            // setup the board for the first move
            var moveList = gameBoard.GetMoveList(player);

            var moveResult = gameBoard.HandleMove(player, moveList.Last());
            Assert.AreEqual(AttemptResult.Valid, moveResult);

            // setup for next move
            moveList = gameBoard.GetMoveList(player);

            moveResult = gameBoard.HandleMove(player, moveList.Last());
            Assert.AreEqual(AttemptResult.Valid, moveResult);

            // setup for next move
            moveList = gameBoard.GetMoveList(player);

            moveResult = gameBoard.HandleMove(player, moveList.Last());
            Assert.AreEqual(AttemptResult.Valid, moveResult);
        }
Exemple #2
0
        public IList<GameTile> GetMoveList(Player player)
        {
            if (player == null) { throw new ArgumentNullException("Players was null"); }

            var moveManager = GetMoveManager(player);

            return moveManager.GetSequence();
        }
        public void HandleMove_WhenMoveValid_WillReturnCorrectResult()
        {
            var player = new Player { Id = 1 };
            var gameBoard = new GameBoard();

            gameBoard.SetupBoard(new List<Player> { player }, DifficultyLevel.Medium);
            var moveList = gameBoard.GetMoveList(player);

            var moveResult = gameBoard.HandleMove(player, moveList.Last());

            Assert.AreEqual(AttemptResult.Valid, moveResult);
        }
Exemple #4
0
        public MoveResult HandleMove(Player player, GameTile gameTile)
        {
            if (player == null) { throw new ArgumentNullException("Players was null"); }
            if (gameTile == GameTile.Unknown) { throw new ArgumentOutOfRangeException("GameTile was out of range"); }

            var moveManager = GetMoveManager(player);

            var attemptResult = moveManager.MakeMove(gameTile);
            var isAtEndOfSequence = moveManager.IsAtEndOfSequence;
            var lastMoveIndex = moveManager.LastMoveIndex;

            return new MoveResult
                       {
                           AttemptResult = attemptResult, 
                           IsAtEndOfSequence = isAtEndOfSequence,
                           CurrentLevel = lastMoveIndex
                       };
        }
        public void HandleMove_WhenPlayerNotInList_WillThrowExeption()
        {
            var player = new Player {Id = 1};
            var badPlayer = new Player { Id = 2 };
            var gameBoard = new GameBoard();
            gameBoard.SetupBoard(new List<Player>{player}, DifficultyLevel.Medium);

            try
            {
                gameBoard.HandleMove(badPlayer, GameTile.BottomRight);
            }
            catch (Exception e)
            {
                // all good
                return;
            }

            Assert.Fail("Should have had an exception thrown");
        }
Exemple #6
0
 public void ResetSequenceCounter(Player player)
 {
     var moveManager = GetMoveManager(player);
     moveManager.ResetSequenceCounter();
 }
Exemple #7
0
        private IMoveManager GetMoveManager(Player player)
        {
            if (player == null) { throw new ArgumentNullException("Player was null"); }

            if (!Players.ContainsKey(player)) { throw new KeyNotFoundException(string.Format("Player {0} was not found in the list", player.Id)); }

            return Players[player];
        }
        private async Task HandleButtonPressedAsync(Player player, GameTile gameTilePressed, string successAudioFileName)
        {
            var result = _gameBoardEngine.HandleMove(player, gameTilePressed);

            if (result.AttemptResult == AttemptResult.Valid)
            {
                await _audioManager.Play(successAudioFileName);
                GameLevel = result.CurrentLevel;

                if ( result.IsAtEndOfSequence )
                {
                    _gameBoardEngine.ResetSequenceCounter(Player);

                    //Task.Delay(5000);

                    ShowPlayerSequence();
                }
            }
            else
            {
                await _audioManager.Play("Buzzer.mp3");
                StopGame();

                StartNewGameCommand.RaiseCanExecuteChanged();
            }
        }
        private async void StartNewGame()
        {
            // hard coded to one player
            Player = new Player { Id = 1, Name = "Captain Simon" };

            _gameBoardEngine.SetupBoard(new List<Player> { Player }, DifficultyLevel.Easy);

            await ShowPlayerSequence();
            
            //
            TopLeftButtonPressedCommand.RaiseCanExecuteChanged();
            TopRightButtonPressedCommand.RaiseCanExecuteChanged();
            BottomLeftButtonPressedCommand.RaiseCanExecuteChanged();
            BottomRightButtonPressedCommand.RaiseCanExecuteChanged();
            StartNewGameCommand.RaiseCanExecuteChanged();

        }