示例#1
0
        public void Move(Player player, int numSpaces)
        {
            int modifier = 1;

            if (numSpaces < 0)
            {
                modifier = modifier * -1;
            }

            for (int i = 0; i < Math.Abs(numSpaces); i++)
            {
                Spaces[player.Position].Exit(player);
                if (!player.IsInJail)
                {
                    player.Position = (player.Position + modifier) % Spaces.Count();
                    if (player.Position < 0)
                    {
                        player.Position = Spaces.Count() - 1;
                    }
                    Spaces[player.Position].Enter(player);
                }
            }

            Spaces[player.Position].LandedOnBy(player);
        }
示例#2
0
 public int GetBoardPositionOfSpace(string name)
 {
     for (int i = 0; i < Spaces.Count(); i++)
     {
         if (Spaces[i].Name == name)
         {
             return(i);
         }
     }
     return(-1);
 }
示例#3
0
        public void AddPlayerToBoard(Player player, int boardPosition)
        {
            if (boardPosition > Spaces.Count())
            {
                throw new ArgumentException("Starting position must be less than total spaces on the board.");
            }

            player.Position = boardPosition;
            player.BoardRef = this;

            _logger?.LogInformation("{0} added to the board at {1}.", player.Name, Spaces[boardPosition].Name);
        }
示例#4
0
        private GameState GetGameState()
        {
            for (int i = 0; i < 3; i++)
            {
                if (
                    ((Spaces[i * 3].Marker != Marker.Empty && Spaces[(i * 3)].Marker == Spaces[(i * 3) + 1].Marker && Spaces[(i * 3)].Marker == Spaces[(i * 3) + 2].Marker) ||
                     (Spaces[i].Marker != Marker.Empty && Spaces[i].Marker == Spaces[i + 3].Marker && Spaces[i].Marker == Spaces[i + 6].Marker)))
                {
                    return(GameState.Winner);
                }
            }

            if ((Spaces[0].Marker != Marker.Empty && Spaces[0].Marker == Spaces[4].Marker && Spaces[0].Marker == Spaces[8].Marker) || (Spaces[2].Marker != Marker.Empty && Spaces[2].Marker == Spaces[4].Marker && Spaces[2].Marker == Spaces[6].Marker))
            {
                return(GameState.Winner);
            }

            if (Spaces.Count(x => x.Marker == Marker.Empty) == 0)
            {
                return(GameState.Tie);
            }

            return(GameState.Playing);
        }