Exemplo n.º 1
0
        public void TakeLocationCommand(int x, int y)
        {
            logger.Log(LogLevel.Debug, "TakeLocationCommand {x} {y} {ActivePlayer}", x, y, ActivePlayer);

            ValidateLocationCoordinate(x);
            ValidateLocationCoordinate(y);

            if (GameStatus != GameStatus.InProgress)
            {
                return;
            }

            lock (lockObject)
            {
                var location = LocationBoxes.First(box => box.X == x && box.Y == y);

                if (location.TryTakeLocation(ActivePlayer))
                {
                    GameStatus = CheckGameStatus();

                    logger.Log(LogLevel.Debug, "TakeLocationCommand step executed {x} {y} {ActivePlayer} {GameStatus}", x, y, ActivePlayer, GameStatus);

                    if (GameStatus == GameStatus.InProgress)
                    {
                        ActivePlayer = ActivePlayer == PlayerId.X ? PlayerId.O : PlayerId.X;
                    }
                }
            }
        }
 private void InitControlsDefaultValues()
 {
     EventTypeBox.Text    = travelEvent.Name;
     SubEventTypeBox.Text = travelEvent.Type;
     DateTimePickers.InitializeProperty((x, p) => x.Value = p, travelEvent.Dates);
     CurrencyBox.Text   = travelEvent.Cost.Currency.ToString();
     AmountPicker.Value = travelEvent.Cost.Amount;
     LocationBoxes.InitializeProperty((x, p) => x.Text = p, travelEvent.Locations.Select(loc => loc.Name));
 }
Exemplo n.º 3
0
        private bool CheckRowTakenByActivePlayer(Func <ILocationOnBoard, bool> rowSelectorPredicate)
        {
            var row = LocationBoxes.Where(rowSelectorPredicate);

            if (row.All(box => box.TakenBy == ActivePlayer))
            {
                foreach (var box in row)
                {
                    box.BelongsToSuccessRow = true;
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        private GameStatus CheckGameStatus()
        {
            // check each horizontal row
            for (int x = 0; x < size; x++)
            {
                if (CheckRowTakenByActivePlayer(box => box.X == x))
                {
                    return(GameStatus.Finished);
                }
            }

            // check each vertical row
            for (int y = 0; y < size; y++)
            {
                if (CheckRowTakenByActivePlayer(box => box.Y == y))
                {
                    return(GameStatus.Finished);
                }
            }

            // check diagonal row
            if (CheckRowTakenByActivePlayer(box => box.X == box.Y))
            {
                return(GameStatus.Finished);
            }

            // check other diagonal row
            if (CheckRowTakenByActivePlayer(box => box.X + box.Y == size - 1))
            {
                return(GameStatus.Finished);
            }

            if (LocationBoxes.All(x => x.TakenBy.HasValue))
            {
                return(GameStatus.Tie);
            }

            return(GameStatus.InProgress);
        }