Exemple #1
0
        private void SelectCell(int x, BLL.DTO.GameState gameState)
        {
            var y = (GetLowestFreeCell(x, gameState));

            gameState.Board[y, x] = gameState.PlayerOneTurn ? 1 : 2;
            CheckForWin(gameState);
        }
Exemple #2
0
 private void TurnSwitch(BLL.DTO.GameState gameStateOuter, GameState gameStateInner)
 {
     gameStateOuter.PlayerOneTurn = !gameStateOuter.PlayerOneTurn;
     gameStateInner.Turn          = !gameStateInner.Turn;
     if (CheckIfBoardIsFull(gameStateOuter))
     {
         gameStateOuter.Winner = DTO.GameState.Win.DRAW;
     }
 }
Exemple #3
0
        private int GetLowestFreeCell(int x, BLL.DTO.GameState gameState)
        {
            for (int y = gameState.Height - 1; y >= 0; y--)
            {
                if (gameState.Board[y, x] == 0)
                {
                    return(y);
                }
            }

            return(0);
        }
Exemple #4
0
        private async Task <DTO.GameState> CreateGameState(BLL.DTO.GameState gameState)
        {
            FillArray(gameState.Board);
            if (gameState.GameMode == GameMode.AI_FIRST)
            {
                GenerateAIMove(gameState);
                gameState.PlayerOneTurn = true;
            }

            gameState.StateId = await SaveGameState(gameState);

            return(gameState);
        }
Exemple #5
0
        private DTO.GameState MapFromDb(GameState innerGameState)
        {
            var outerGameState = new BLL.DTO.GameState()
            {
                StateId       = innerGameState.GameStateId,
                Height        = innerGameState.BoardHeight,
                Width         = innerGameState.BoardWidth,
                Board         = DeserializeBoard(innerGameState.BoardJson),
                GameMode      = innerGameState.GameMode,
                PlayerOneTurn = innerGameState.Turn
            };

            return(outerGameState);
        }
Exemple #6
0
        public async Task <BLL.DTO.GameState> CreateGameStateFromSettings()
        {
            var gameSettings = await GetGameSettings();

            var gameState = new BLL.DTO.GameState()
            {
                Height        = gameSettings.BoardHeight,
                Width         = gameSettings.BoardWidth,
                Board         = new int[gameSettings.BoardHeight, gameSettings.BoardWidth],
                PlayerOneTurn = false,
                GameMode      = gameSettings.GameMode
            };

            return(await CreateGameState(gameState));
        }
Exemple #7
0
        private void GenerateAIMove(BLL.DTO.GameState gameState)
        {
            Random r = new Random();

            while (true)
            {
                var rInt = r.Next(0, gameState.Width);
                if (gameState.Board[0, rInt] != 0)
                {
                    continue;
                }
                SelectCell(rInt, gameState);
                break;
            }
        }
Exemple #8
0
 public Task <int> SaveGameState(BLL.DTO.GameState gameState)
 {
     return(_stateRepository.SaveGameState(MapFromPage(gameState)));
 }