Example #1
0
        private void FillLetters(string word)
        {
            Rectangle safeArea = new Rectangle(
                this.Window.ClientBounds.Width / 2 - playerSquare.Width,
                this.Window.ClientBounds.Height / 2 - playerSquare.Height,
                playerSquare.Width * 2,
                playerSquare.Height * 2);

            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            List <Vector2> locations = new List <Vector2>();

            for (int x = 25;
                 x < this.Window.ClientBounds.Width - 50;
                 x += 50)
            {
                for (int y = 25;
                     y < this.Window.ClientBounds.Height - 50;
                     y += 50)
                {
                    Rectangle locationRect = new Rectangle(
                        x,
                        y,
                        (int)letterFont.MeasureString("W").X,
                        (int)letterFont.MeasureString("W").Y);

                    if (!safeArea.Intersects(locationRect))
                    {
                        locations.Add(new Vector2(x, y));
                    }
                }
            }

            letters.Clear();
            for (int x = 0; x < 20; x++)
            {
                GameLetter thisLetter = new GameLetter();

                if (x < word.Length)
                {
                    thisLetter.Letter = word.Substring(x, 1);
                }
                else
                {
                    thisLetter.Letter = alphabet.Substring(
                        rand.Next(0, 26), 1);
                }

                int location = rand.Next(0, locations.Count);
                thisLetter.Position = locations[location];
                thisLetter.WasHit   = false;
                locations.RemoveAt(location);

                letters.Add(thisLetter);
            }
        }
Example #2
0
        private bool FindWinningTile(Board board, IEnumerable <byte> avalableTiles, GameLetter playerLetter)
        {
            foreach (byte TileToCheck in avalableTiles)
            {
                if (board.DoesPlayerWins((byte)(TileToCheck - 1), playerLetter))
                {
                    _tile = TileToCheck;
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        public bool DoesPlayerWins(byte tile, GameLetter playerLetter)
        {
            // check all cobinations for winning
            foreach (byte[] Combination in WinCombinations[tile])
            {
                // If Has player letter in both win combinations positions then player wins
                if ((GetTileValue(Combination[0]) == playerLetter) &&
                    (GetTileValue(Combination[1]) == playerLetter))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #4
0
        private void FillLetters(string word)
        {
            Rectangle safeArea = new Rectangle(
                this.Window.ClientBounds.Width / 2 - playerSquare.Width,
                this.Window.ClientBounds.Height / 2 - playerSquare.Height,
                playerSquare.Width * 2,
                playerSquare.Height * 2);

            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            List<Vector2> locations = new List<Vector2>();

            for (int x = 25;
                x < this.Window.ClientBounds.Width - 50;
                x += 50)
            {
                for (int y = 25;
                    y < this.Window.ClientBounds.Height - 50;
                    y += 50)
                {
                    Rectangle locationRect = new Rectangle(
                        x,
                        y,
                        (int)letterFont.MeasureString("W").X,
                        (int)letterFont.MeasureString("W").Y);

                    if (!safeArea.Intersects(locationRect))
                        locations.Add(new Vector2(x, y));
                }
            }

            letters.Clear();
            for (int x = 0; x < 20; x++)
            {
                GameLetter thisLetter = new GameLetter();

                if (x < word.Length)
                    thisLetter.Letter = word.Substring(x, 1);
                else
                    thisLetter.Letter = alphabet.Substring(
                        rand.Next(0, 26), 1);

                int location = rand.Next(0, locations.Count);
                thisLetter.Position = locations[location];
                thisLetter.WasHit = false;
                locations.RemoveAt(location);

                letters.Add(thisLetter);
            }
        }
Example #5
0
 public ComputerPlayer(Board board, string name, GameLetter playerLetter) : base(board, name, playerLetter)
 {
 }
Example #6
0
 public void SetTileValue(byte tile, GameLetter value)
 {
     Tiles[tile] = value;
 }
Example #7
0
 public Player(Board board, String name, GameLetter playerLetter)
 {
     _board       = board;
     Name         = name;
     PlayerLetter = playerLetter;
 }
Example #8
0
 public HumanPlayer(Board board, string name, GameLetter playerLetter) : base(board, name, playerLetter)
 {
 }