Exemplo n.º 1
0
        /// <summary>
        /// Deploys units to the region.
        /// </summary>
        /// <param name="region"></param>
        /// <param name="bonusArmy">Bonus army to the region.</param>
        public void Deploy(Region region, int bonusArmy)
        {
            if (region == null)
            {
                throw new ArgumentException($"Region cannot be null.");
            }
            if (region.Owner == null)
            {
                throw new ArgumentException($"Region {region.Name} owner cannot be null.");
            }
            if (region.Owner != PlayerOnTurn)
            {
                throw new ArgumentException("You cannot deploy to regions you do not own.");
            }

            var lastTurn = (GameTurn)LastTurn;

            int newArmy = lastTurn.GetRegionArmy(region) + bonusArmy;

            if (bonusArmy > 0 && bonusArmy > PlayerOnTurn.GetArmyLeftToDeploy(lastTurn.Deploying))
            {
                // bonus army > 0 and is more than i can deploy
                throw new ArgumentException($"Cannot deploy. Your limit {PlayerOnTurn.GetIncome()} for deployed units would be exceeded.");
            }
            else if (bonusArmy < 0 && region.Army > newArmy)
            {
                throw new ArgumentException("You cannot deploy less than region had at this round beginning.");
            }
            // if there exists deployment entry => remove that entry and create new one
            lastTurn.Deploying.AddDeployment(region, newArmy);

            ImageProcessor.Deploy(region, newArmy);
        }
Exemplo n.º 2
0
        public PlayerGuessResult GetResult(string numberToGuess, string playersGuessNumber, PlayerOnTurn onTurn)
        {
            if (this.IsPlayerGuessNumberInputValid(playersGuessNumber))
            {
                var bullsAndCowsCount = this.FindBullsAndCows(numberToGuess, playersGuessNumber);
                int bullsCount = bullsAndCowsCount.Item1;
                int cowsCount = bullsAndCowsCount.Item2;

                var playerGuessResult = new PlayerGuessResult(bullsCount, cowsCount);

                if (bullsCount == 4)
                {
                    if (onTurn == PlayerOnTurn.Red)
                    {
                        playerGuessResult.GameResult = GameResult.WonByRed;
                    }
                    else
                    {
                        playerGuessResult.GameResult = GameResult.WonByBlue;
                    }
                }
                else
                {
                    playerGuessResult.GameResult = GameResult.NotFinished;
                }

                return playerGuessResult;
            }
            else
            {
                throw new ArgumentException("Invalid player guess number entered. Guess number should be with exactly 4 digits and they must be different.");
            }
        }
Exemplo n.º 3
0
        public async Task GameTurn(CancellationTokenSource cancellationTokenSource)
        {
            if (PlayerOnTurn.IsAI)
            {
                await(PlayerOnTurn.TryToPlay(GameBoard, cancellationTokenSource));
            }
            if (!cancellationTokenSource.IsCancellationRequested)
            {
                if (!PlayerOnTurn.Finished)
                {
                    await PlayerOnTurn.Selection(ToIntToRow(SelectedPosition), ToIntToCol(SelectedPosition), GameBoard, cancellationTokenSource);

                    if (PlayerOnTurn.PlayerMove[(int)GameConstants.MoveParts.result] == (int)GameConstants.MoveResult.Fail && !PlayerOnTurn.StartPositionSelected)
                    {
                        SelectedPosition = "none - Failed Move, Play again.";
                    }
                }
                if (PlayerOnTurn.Finished)
                {
                    GameHistory.Push(new List <int>(PlayerOnTurn.PlayerMove));
                    PlayerOnTurn.PlayerMove.ForEach(Console.Write);
                    PlayerOnTurn.Finished = false;
                    CheckEndGame();
                    RedoStack.Clear();
                    BestMove = null;
                    EndTurn();
                }
            }
        }
Exemplo n.º 4
0
 public void AutoMoveStone()     //automatický přesun kamene
 {
     if (PlayerOnTurn.UI)
     {
         PlayerOnTurn.AutoMoveStoneUI(this);
     }
     else
     {
         PlayerOnTurn.AutoMoveStone(this);
     }
     board.EraseSelectStone(this);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Help method after guess is made
        /// </summary>
        /// <param name="game">The current game</param>
        /// <param name="guess">User guess</param>
        /// <param name="userId">The current user id</param>
        /// <param name="onTurn">Which is on turn(red or blue player)</param>
        /// <returns></returns>
        private GuessModel GetNewGuessModel(Game game, string guess, string userId, PlayerOnTurn onTurn)
        {
            var user = this.Data.Users.All().FirstOrDefault(u => u.Id == userId);

            var numberToGuess = string.Empty;
            if (onTurn == PlayerOnTurn.Red)
            {
                numberToGuess = game.BluePlayer.NumberToGuess;
            }
            else
            {
                numberToGuess = game.Number;
            }

            var guessResult = this.resultValidator.GetResult(numberToGuess, guess, onTurn);
            var newGuess = new Guess
            {
                BullsCount = guessResult.BullsCount,
                CowsCount = guessResult.CowsCount,
                DateMade = DateTime.Now,
                UserId = userId,
                User = user,
                Game = game,
                GameId = game.GameId,
                Number = guess
            };

            if (onTurn == PlayerOnTurn.Red)
            {
                game.State = GameState.BlueInTurn;
            }
            else if (onTurn == PlayerOnTurn.Blue)
            {
                game.State = GameState.RedInTurn;
            }

            this.Data.Guesses.Add(newGuess);
            this.Data.SaveChanges();

            return GuessModel.FromGuess(newGuess);
        }