/// <summary> /// Sends both players the boggle board and game length /// </summary> private void InitiateGame() { // Create a BoggleBoard with the specified // string of letters. Random otherwise. if (BoggleServer.CustomBoard == null) { board = new BoggleBoard(); } else { board = new BoggleBoard(BoggleServer.CustomBoard); } // reset timeLeft; use custom gameLength if set if (gameLength == 0) { timeLeft = BoggleServer.GameLength; } else { timeLeft = gameLength; } // Send players the board. Countdown starts after both messages are sent. one.Ss.BeginSend("BOARD " + board.ToString() + " " + timeLeft + "\n", Countdown, one); two.Ss.BeginSend("BOARD " + board.ToString() + " " + timeLeft + "\n", Countdown, two); // Determine all possible words on the current board in another thread. // These words will be sent at the end of the game. ThreadPool.QueueUserWorkItem(x => { PossibleWords(); }); }
private int player2Score; // player 2's score #endregion Fields #region Constructors /// <summary> /// Constructs a new game of boggle. /// </summary> /// <param name="validWords"></param> /// <param name="gameLength"></param> /// <param name="gameBoard"></param> public BoggleGame(SortedSet<string> validWords, int gameLength, BoggleBoard gameBoard) { legalWords = validWords; duration = gameLength; board = gameBoard; player1Name = null; player2Name = null; player1Score = 0; player2Score = 0; p1Illegal = new HashSet<string>(); p2Illegal = new HashSet<string>(); p1Legal = new HashSet<string>(); p2Legal = new HashSet<string>(); }
private PlayerData Player2; // A PlayerData object to holds all data for Player2. #endregion Fields #region Constructors /// <summary> /// Initializes a Game. Creates a BoggleBoard with the OptionalString as /// the letters used in the board. It also initializes GameTime to the /// given time, Player1 and Player2 to their respective global pointers, /// and GameFinished to false. No game operation happens here, only the /// initialization of variables. /// </summary> /// <param name="Player1">The data for the first player.</param> /// <param name="Player2">The data for the second player.</param> /// <param name="GameTime">The length of the game (in seconds).</param> /// <param name="OptionalString">The string given via the command line that /// indicates which letters should be used for the game board.</param> public Game(PlayerData Player1, PlayerData Player2, int GameTime, HashSet<string> DictionaryWords, String OptionalString) { // Create a BoggleBoard with or without the OptionalString according to what was given. if(object.ReferenceEquals(OptionalString, null)) this.GameBoard = new BoggleBoard(); else this.GameBoard = new BoggleBoard(OptionalString); // Intialize all other instance variables. this.Player1 = Player1; this.Player2 = Player2; this.GameTime = GameTime; this.DictionaryWords = DictionaryWords; this.GameFinished = false; this.WordPlayedLock = new object(); }
/// <summary> /// Finds all of the legal words of a given BoggleBoard based on the dictionary /// that was supplied. /// </summary> /// <param name="GameboardString">The randomly generated string representing the /// current Gameboard.</param> private static HashSet<string> FindXLetterWords(string GameboardString, int StringLength) { lock (XLetterWordsLock) { BoggleBoard GameBoard = new BoggleBoard(GameboardString); HashSet<string> LegalWords = new HashSet<string>(); foreach (string s in DictionaryWords) { if (GameBoard.CanBeFormed(s) && s.Length == StringLength) LegalWords.Add(s); } return LegalWords; } }
/// <summary> /// Finds all of the illegal words of a given BoggleBoard based on the dictionary /// that was supplied. /// </summary> /// <param name="GameboardString">The randomly generated string representing the /// current Gameboard.</param> private static HashSet<string> FindIllegalWords(string GameboardString) { lock (IllegalWordsLock) { BoggleBoard GameBoard = new BoggleBoard(GameboardString); HashSet<string> IllegalWords = new HashSet<string>(); foreach (string s in DictionaryWords) { if (!GameBoard.CanBeFormed(s) && s.Length > 2) IllegalWords.Add(s); } return IllegalWords; } }
/// <summary> /// Creates a new boggle game /// </summary> private void createNewGame() { lock (setupGame) { BoggleBoard newBoard; if (customBoard == null) newBoard = new BoggleBoard(); else newBoard = new BoggleBoard(customBoard); setupGame = new BoggleGame(legalWords, gameLength, newBoard); } }