Exemplo n.º 1
0
        /// <summary>
        /// This button handles move making, it will read in the users word, target location (x and y from TargetX and TargetY) and
        /// direction. It then checks if its a valid move, if it is it makes the move and then tells the ai to make its turn.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (GameEngine.EndGame == true)
            {
            }
            string Word = ""; int targx = 0; int targy = 0; char Direction = 'H'; string ReturnString = "";//Defines and sets variables to empty

            if (GameHandle.PlayersTurn)
            {
                try
                {
                    Word  = (textBox1.Text).ToUpper();
                    targx = TargetX;
                    targy = TargetY;
                }                                      //tries to get the users inputs
                catch { ReturnString = "FAILINPUTS"; } //Sets the return string to FAILINPUTS so the turn cannot be made

                //Sets the direction based on the track bar value
                if (trackBar1.Value == 1)
                {
                    Direction = 'V';//if trackbar is 1, direction is Vertical
                }
                else
                {
                    Direction = 'H';//if trackbar is 0, direction is Horizontal
                }


                if (Word == "")
                {
                    ReturnString = "FAILNOWORD";//Sets ReturnString to FAILNOWORD
                }//If the users word it empty
                else if (!(GameHandle.Game.UserMakeWord(Word, TargetX, TargetY, Direction)))
                {
                    ReturnString = "FAILCANTMAKEWORD";//Sets ReturnString to FAILCANTMAKEWORD
                }//Checks if the user can make the move with their tiles and the tiles on the board
                else if (targx > 14 || targy > 14)
                {
                    ReturnString = "FAILNOCOORDS";//Sets ReturnString to FAILNOCOORDS
                }//Checks if the user has selected valid coords
                else
                {
                    ReturnString = GameHandle.Game.MoveCheck(Word, targx, targy, Direction);//Sets the the return string to the string produced by movecheck
                }//If it passes the other checks it performs another move check
                if (ReturnString == "PASS")
                {
                    GameHandle.PlayersScore += GameHandle.Game.MakeMove(Word, targx, targy, Direction); //calculates and adds the score of the move ot the players total score
                    TargetX                = 99; TargetY = 99;                                          //Resets the target coordinates to default
                    richTextBox1.Text      = "Move made!";                                              //Writes to the Game chat that the move was made
                    GameHandle.PlayersTurn = false;                                                     //Set the players turn bool to false
                    GameHandle.AiTurn();                                                                //Triggers the ais turn in the game handle
                }//if the return string is true
                else if (ReturnString == "FAILINPUTS")
                {
                    richTextBox1.Text = "Your inputs were invalid! Try again!";//Writes to the Game chat that their inputs were invalid
                }//If return string is FAILINPUTS
                else if (ReturnString == "FAILNOCOORDS")
                {
                    richTextBox1.Text = "Please select a target tile!";//Writes to the Game chat that they have not chosen a tile
                }//If return string is FAILNOCOORDS
                else if (ReturnString == "FAILNOWORD")
                {
                    richTextBox1.Text = "Please write a word!";//Writes to the Game chat that they need to actually write a word
                }//If return string is FAILNOWORD
                else if (ReturnString == "FAILCANTMAKEWORD")
                {
                    richTextBox1.Text = "You cannot make that word with your tiles!";//Writes to the Game chat that they cant make that word with the tiles available
                }//If return string is FAILCANTMAKEWORD
                else
                {
                    richTextBox1.Text = ReturnString;                                      //Writes to the Game chat whatever string is stored in ReturnString
                }//If no other move check events pass
                ImageHandler.HighlightATile(99, 99);                                       //Move the highlight tile off the board
                GameHandle.UpdateBoardTiles(GameHandle.Game, GameHandle.GameImageHandler); //update all tiles to make sure the board is shown correctly
            }//If its the PlayersTurn is true, let the player make a move
            else
            {
                richTextBox1.Text = "Not your turn!"; //Writes to the game chat that its not the players turn
            }//If its not their turn, so the ais turn
            UpdatePlayersTilesAndScores();            //Updates the screen showing the players tiles and scores
        }
Exemplo n.º 2
0
 /// <summary>
 /// Updates the coordinates for the highlight tile, and updates its location on the form.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public static void UpdateCoords(int x, int y)
 {
     TargetX = x;                                   //Sets the TargetX to the parameter x
     TargetY = y;                                   //Sets the TargetY to the parameter y
     ImageHandler.HighlightATile(TargetX, TargetY); //sets the highlight tile location to the coordinates of the users tile
 }