Пример #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);
        }
Пример #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;
     }
 }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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));
        }
Пример #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;
            }
        }
Пример #8
0
 public Task <int> SaveGameState(BLL.DTO.GameState gameState)
 {
     return(_stateRepository.SaveGameState(MapFromPage(gameState)));
 }