Hello Im needing help in completing this TicTacToe assignmen

Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help with some coding. Please see the areas with the comment \"NEED HEL HERE\" as well as the parts in bold letters. to view the areas I\'m having a hard time with. I have attached screenshots, I was able to get some of the code to work. The X must be in red when the user wins but for me its only working only when the winner is horizontal. I would appreciate it if you guys could fix my coding to make it work aswell as running it to make sure everything is working before posting the solution, thank you very much!!!

namespace TicTacToe
{
    public partial class TTTForm : Form
    {
        public TTTForm()
        {
            InitializeComponent();
        }

        const string USER_SYMBOL = \"X\";
        const string COMPUTER_SYMBOL = \"O\";
        const string EMPTY = \"\";

        const int SIZE = 5;

        // constants for the 2 diagonals
        const int TOP_LEFT_TO_BOTTOM_RIGHT = 1;
        const int TOP_RIGHT_TO_BOTTOM_LEFT = 2;

        // constants for IsWinner
        const int NONE = -1;
        const int ROW = 1;
        const int COLUMN = 2;
        const int DIAGONAL = 3;

        // This method takes a row and column as parameters and
        // returns a reference to a label on the form in that position
        private Label GetSquare(int row, int column)
        {
            int labelNumber = row * SIZE + column + 1;
            return (Label)(this.Controls[\"label\" + labelNumber.ToString()]);
        }

        // This method does the \"reverse\" process of GetSquare
        // It takes a label on the form as it\'s parameter and
        // returns the row and column of that square as output parameters
        private void GetRowAndColumn(Label l, out int row, out int column)
        {
            int position = int.Parse(l.Name.Substring(5));
            row = (position - 1) / SIZE;
            column = (position - 1) % SIZE;
        }

        // This method takes a row (in the range of 0 - 4) and returns true if
        // the row on the form contains 5 Xs or 5 Os.
        // Use it as a model for writing IsColumnWinner
        private bool IsRowWinner(int row)
        {
            Label square = GetSquare(row, 0);
            string symbol = square.Text;
            for (int col = 1; col < SIZE; col++)
            {
                square = GetSquare(row, col);
                if (symbol == EMPTY || square.Text != symbol)
                    return false;
            }
            return true;
        }

        //* TODO: finish all of these that return true
        private bool IsAnyRowWinner()
        {
            for (int row = 1; row < SIZE; row++)
            {
                if (IsRowWinner(row))
                {
                    return true;
                }
            }
            return false;
        }
        private bool IsColumnWinner(int col)
        {
            Label square = GetSquare(0, col);
            string symbol = square.Text;
            for (int row = 1; row < SIZE; row++)
            {
                square = GetSquare(col, row);
                if (symbol == EMPTY || square.Text != symbol)
                    return false;
            }
            return true;
        }
        //TODO finish all these that return true
        private bool IsAnyColumnWinner()
        {
            for (int col = 1; col < SIZE; col++)
            {
                if (IsColumnWinner(col))
                {
                    return true;
                }
            }
            return false;
        }
        private bool IsanyDaigonal1Winner()
        {
            Label square = GetSquare((SIZE - 1), 0);
            string symbol = square.Text;
            //***NEED HELP HERE, FOR LOOP CAUSING ERROR
            for (int row = SIZE, row = SIZE - 2; col < SIZE; row--, col++)
            {
                square = GetSquare(row, col);////NEED HELP HERE, ERROR MESSAGE does not exist in context
                if (symbol == EMPTY || square.Text != symbol)
                    return false;
            }
            return true;
        }
        private bool IsDiagonal2Winner()
        {
            Label square = GetSquare(0, (SIZE - 1));
            string symbol = square.Text;
            for (int row = 1, col = SIZE - 2; row < SIZE; row++, col--)
            {
                square = GetSquare(row, col);
                if (symbol == EMPTY || square.Text != symbol)
                    return false;
            }
            return true;
        }

        private bool IsAnyDiagonalWinner()
        {
            ///****I NEED HELP HERE WITH CODING, error IsDiagonalWinner does not exist in context
            if (IsDiagonal1Winner)
            {
                return true;
            }
            if (IsDiagonal2Winner)///NEED HELP Here, same error here
            {
                return true;
            }
            return false;
        }

        private bool IsFull()
        {
            ///****I NEED HELP WITH CODING HERE
            return true;
        }

        // This method determines if any row, column or diagonal on the board is a winner.
        // It returns true or false and the output parameters will contain appropriate values
        // when the method returns true. See constant definitions at top of form.
        private bool IsWinner(out int whichDimension, out int whichOne)
        {
            // rows
            for (int row = 0; row < SIZE; row++)
            {
                if (IsRowWinner(row))
                {
                    whichDimension = ROW;
                    whichOne = row;
                    return true;
                }
            }
            // columns
            for (int column = 0; column < SIZE; column++)
            {
                if (IsColumnWinner(column))
                {
                    whichDimension = COLUMN;
                    whichOne = column;
                    return true;
                }
            }
            // diagonals
            if (IsDiagonal1Winner())//ERROR MESSAGE does not exist in context
            {
                whichDimension = DIAGONAL;
                whichOne = TOP_LEFT_TO_BOTTOM_RIGHT;
                return true;
            }
            if (IsDiagonal2Winner())
            {
                whichDimension = DIAGONAL;
                whichOne = TOP_RIGHT_TO_BOTTOM_LEFT;
                return true;
            }
            whichDimension = NONE;
            whichOne = NONE;
            return false;
        }

        // I wrote this method to show you how to call IsWinner
        private bool IsTie()
        {
            int winningDimension, winningValue;
            return (IsFull() && !IsWinner(out winningDimension, out winningValue));
        }

        // This method takes an integer in the range 0 - 4 that represents a column
        // as it\'s parameter and changes the font color of that cell to red.
        private void HighlightColumn(int col)
        {
            for (int row = 0; row < SIZE; row++)
            {
                Label square = GetSquare(row, col);
                square.Enabled = true;
                square.ForeColor = Color.Red;
            }
        }

        // This method changes the font color of the top right to bottom left diagonal to red
        // I did this diagonal because it\'s harder than the other one
        private void HighlightDiagonal2()
        {
            for (int row = 0, col = SIZE - 1; row < SIZE; row++, col--)
            {
                Label square = GetSquare(row, col);
                square.Enabled = true;
                square.ForeColor = Color.Red;
            }
        }

        // This method will highlight either diagonal, depending on the parameter that you pass
        private void HighlightDiagonal(int whichDiagonal)
        {
            if (whichDiagonal == TOP_LEFT_TO_BOTTOM_RIGHT)
                HighlightDiagonal1();
            else
                HighlightDiagonal2();

        }

       //* TODO: finish these 2
        private void HighlightRow(int row)
        {
            for (int col = 0; col < SIZE; col++)

            {
                Label square = GetSquare(row, col);
                square.Enabled = true;
                square.ForeColor = Color.Red;
            }
        }

        private void HighlightDiagonal1()
        {
            for (int row = SIZE - 1, col = 0; row < SIZE; row++, col--)
            {
                Label square = GetSquare(row, col);
                square.Enabled = true;
                square.ForeColor = Color.Red;
            }
        }
        //TODO
        private void HighlightWinner(string player,
            int winningDimension, int winningValue)
        {
            switch (winningDimension)
            {
                case ROW:
                    HighlightRow(winningValue);
                    resultLabel.Text = (player + \" wins!\");

                    break;
                case COLUMN:
                    HighlightColumn(winningValue);
                    resultLabel.Text = (player + \" wins!\");

                    break;
                case DIAGONAL:
                    HighlightDiagonal(winningValue);
                    resultLabel.Text = (player + \" wins!\");
                    break;
            }
        }

        //* TODO: finish these 2
        private void ResetSquares()
        {
            ///****I NEED HELP WITH CODING HERE
        }

        private void MakeComputerMove()
        {
            ///****I NEED HELP WITH CODING HERE
        }

        // Setting the enabled property changes the look and feel of the cell.
        // Instead, this code removes the event handler from each square.
        // Use it when someone wins or the board is full to prevent clicking a square.
        private void DisableAllSquares()
        {
            for (int row = 0; row < SIZE; row++)
            {
                for (int col = 0; col < SIZE; col++)
                {
                    Label square = GetSquare(row, col);
                    DisableSquare(square);
                }
            }
        }

        // Inside the click event handler you have a reference to the label that was clicked
        // Use this method (and pass that label as a parameter) to disable just that one square
        private void DisableSquare(Label square)
        {
            square.Click -= new System.EventHandler(this.label_Click);
        }

        // You\'ll need this method to allow the user to start a new game
        private void EnableAllSquares()
        {
            for (int row = 0; row < SIZE; row++)
            {
                for (int col = 0; col < SIZE; col++)
                {
                    Label square = GetSquare(row, col);
                    square.Click += new System.EventHandler(this.label_Click);
                }
            }
        }

        //* TODO: finish the event handlers
        private void label_Click(object sender, EventArgs e)
        {
            int winningDimension = NONE;
            int winningValue = NONE;

            Label clickedLabel = (Label)sender;
            clickedLabel.Text = USER_SYMBOL;
            DisableSquare(clickedLabel);
            if (IsWinner(out winningDimension, out winningValue))
            {
                HighlightWinner(\"The User\", winningDimension, winningValue);

            }


        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

100 Error List (X) 7 Errors A 1 Warning OO Messages Entire Solution Search Error List Build IntelliSense Code Description Project File nee S (x CS0128 A local variable named \'row\' is already defined in this scope TicTacToe TTT Form.cs X CS0103 The name \'col\' does not exist in the current context TicTacToe TTT Form.cs (X cs0103 The name \'col\' does not exist in the current context TicTacToe TTT Form.cs X CS0103 The name \'col\' does not exist in the current context TicTacToe TTT Form.cs 113 cso103 The name IsDiagonallwinner\' does not exist in the current context X TicTacToe TTT Form.cs 135 CS0428 Cannot convert method group \'lsDiagonal2winner\' to non-delegate type \'bool\'. Did you TicTacToe TTTForm.cs 139 A intend to invoke the method? CS0103 The name IsDiagonallwinner\' does not exist in the current context X TicTacToe TTT Form.cs 178 A cs0219 The variable \'row\' is assigned but its value is never used TicTacToe TTT Form.cs Error List output Build failed Publish

Solution

Complete logic for Tic Tac toe

  

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace tictacktoe
{
   /// <summary>
   /// Description of MainForm.
   /// </summary>
   public partial class MainForm : Form
   {
       public MainForm()
       {
           //
           // The InitializeComponent() call is required for Windows Forms designer support.
           //
           InitializeComponent();
           reset();
           //
           // TODO: Add constructor code after the InitializeComponent() call.
           //
       }
      
       int[,] pos=new int[3,3];
   int cnt,val,a,b,c=1,d=1,diff=1,vs=1;
   char let;
   String pl1=\"You\",pl2=\"Computer\";
   Random rnd=new Random();
   bool turn=true;
  
   void reset()
   {
   for (int i=0;i<3 ;i++ )
   {
   for (int j=0;j<3 ;j++ ){pos[i,j]=0;}
   }
   foreach(Control ctrl in this.Controls)
           {
               if (ctrl is Label)
               {
                   ctrl.ResetText();
               }
           }
   cnt=0;
   val=1;
   let=\'X\';
   label10.Text=pl1+\" to Play NOW.\";
   }
     
   bool play(int l,int m)
   {
   if(pos[l,m]==0)
   {
   a=c;b=d;c=l;d=m;
   Label ctrl=link(l,m);
   ctrl.Text=let.ToString();
   pos[l,m]=val;
   flip();
   checkwin(l,m,pos[l,m]);
   return true;
   }
   else
   return false;
   }
  
   Label link(int l,int m)
   {
   if(l==0)
   {
   if(m==0)
   return label1;
   if(m==1)
   return label2;
   if(m==2)
   return label3;
   }
   if(l==1)
   {
   if(m==0)
   return label6;
   if(m==1)
   return label5;
   if(m==2)
   return label4;
   }
   if(l==2)
   {
   if(m==0)
   return label9;
   if(m==1)
   return label8;
   if(m==2)
   return label7;
   }
   return null;
   }

   void flip()
   {
   if(let==\'X\')
   {
   let = \'O\';
   val=4;
   cnt++;
   }
   else
   {
   let = \'X\';
   val=1;
   cnt++;
   }
   }
  
   void checkwin(int l,int m,int n)
   {
   if(cnt==1)
   if(vs==1)
   turn=true;
   if(cnt>4)
   {
   if((pos[l,0]+pos[l,1]+pos[l,2]==n*3)||(pos[0,m]+pos[1,m]+pos[2,m]==n*3))
   {
   cnt=n;
   }
   else
   {
   if((pos[0,0]+pos[1,1]+pos[2,2]==n*3)||(pos[2,0]+pos[1,1]+pos[0,2]==n*3))
   {
   cnt=n;
   }
   else
   {
   if(cnt==9)
   {
   cnt=0;
   }
   }
   }
   if(cnt==1||cnt==0)
   {
   if(cnt==1)
   declare(pl1+\" (Playing X) Wins!\");
   if(cnt==0)
   declare(\"The Game is a Draw!\");
   reset();
   if(vs==1)
   if(pl1==\"Computer\")
   {
   turn=false;
   compplay(val);
   }
   else
   turn=false;
     
   }
   else
   if(cnt==4)
   {
   declare(pl2+\" (Playing O) Wins!\");
   String temp=pl1;
   pl1=pl2;
   pl2=temp;
   reset();
   if(vs==1)
   if(pl1==\"Computer\")
   compplay(val);
   else
   turn=false;
   }
   }
   }
  
   void declare(string stmt)
       {
           if(MessageBox.Show(stmt+\" Do you want to continue?\",\"\",MessageBoxButtons.YesNo,MessageBoxIcon.Question)!=DialogResult.Yes)
           {
               Application.Exit();
           }
       }
  
   void compplay(int n)
   {
   bool carry=true;
   if(diff==3)
   carry=winorstop(a,b,n);
   if((diff==2||diff==3) && carry)
   {
   if(n==1)
   carry=winorstop(c,d,4);
   else
   carry=winorstop(c,d,1);
   }
   if(carry)
   doany();
   }
     
   bool winorstop(int l,int m,int n)
   {
   if(pos[l,0]+pos[l,1]+pos[l,2]==n*2)
   {
   for(int i=0;i<3;i++)
   {
   if(play(l,i))
   return false;
   }
   }
   else
   if(pos[0,m]+pos[1,m]+pos[2,m]==n*2)
   {
   for(int i=0;i<3;i++)
   {
   if(play(i,m))
   return false;
   }
   }
   else
   if(pos[0,0]+pos[1,1]+pos[2,2]==n*2)
   {
   for(int i=0;i<3;i++)
   {
   if(play(i,i))
   return false;
   }
   }
   else
   if(pos[2,0]+pos[1,1]+pos[0,2]==n*2)
   {
   for(int i=0,j=2;i<3;i++,j--)
   {
   if(play(i,j))
   return false;
   }
   }
  
   return true;
   }
  
   void doany()
   {
   int l=2,m=0;
   switch(cnt)
   {
   case 0: play(0,0);
   break;
   case 1: if(!(play(1,1)))
   play(0,0);
   break;
   case 2: if(!(play(2,2)))
   play(0,2);
   break;
   case 3: if((pos[0,1]+pos[1,1]+pos[2,1])==val)
   play(0,1);
   else
   if((pos[1,0]+pos[1,1]+pos[1,2])==val)
   play(1,0);
   else
   if(pos[0,1]!=0)
   play(0,2);
   else
   play(2,0);
  
   break;
   default : while(!(play(l,m)))
   {
   l=rnd.Next(3);
   m=rnd.Next(3);
   }
   break;
   }
   }
      
       void Label1Click(object sender, EventArgs e)
       {
           if(play(0,0)&&turn==true)
compplay(val);
       }
      
       void Label2Click(object sender, EventArgs e)
       {
           if(play(0,1)&&turn==true)
compplay(val);
       }
      
       void Label3Click(object sender, EventArgs e)
       {
           if(play(0,2)&&turn==true)
compplay(val);
       }
      
       void Label6Click(object sender, EventArgs e)
       {
           if(play(1,0)&&turn==true)
compplay(val);
       }
      
       void Label5Click(object sender, EventArgs e)
       {
           if(play(1,1)&&turn==true)
compplay(val);
       }
      
       void Label4Click(object sender, EventArgs e)
       {
           if(play(1,2)&&turn==true)
compplay(val);
       }
      
       void Label9Click(object sender, EventArgs e)
       {
           if(play(2,0)&&turn==true)
compplay(val);
       }
      
       void Label8Click(object sender, EventArgs e)
       {
           if(play(2,1)&&turn==true)
compplay(val);
       }
      
       void Label7Click(object sender, EventArgs e)
       {
           if(play(2,2)&&turn==true)
compplay(val);
       }
          
       void EasyToolStripMenuItemClick(object sender, EventArgs e)
       {
           onlyone();
           easyToolStripMenuItem.Checked=true;
           diff=1;
       }
      
       void MediumToolStripMenuItemClick(object sender, EventArgs e)
       {
           onlyone();
           mediumToolStripMenuItem.Checked=true;
           diff=2;
       }
      
       void HardToolStripMenuItemClick(object sender, EventArgs e)
       {
           onlyone();
           hardToolStripMenuItem.Checked=true;
           diff=3;
       }
      
       void onlyone()
       {
           easyToolStripMenuItem.Checked=false;
           mediumToolStripMenuItem.Checked=false;
           hardToolStripMenuItem.Checked=false;
       }
      
       void VsComputerToolStripMenuItemClick(object sender, EventArgs e)
       {
           pl1=\"You\";
   pl2=\"Computer\";
   reset();
   vsComputerToolStripMenuItem.Checked=true;
   vsPlayerToolStripMenuItem.Checked=false;
   vs=1;
       }
      
       void VsPlayerToolStripMenuItemClick(object sender, EventArgs e)
       {
           pl1=\"Player 1\";
   pl2=\"Player 2\";
   reset();
   vsComputerToolStripMenuItem.Checked=false;
   vsPlayerToolStripMenuItem.Checked=true;
   vs=2;
   turn=false;
       }
      
       void NewGameToolStripMenuItemClick(object sender, EventArgs e)
       {
           if(vs==1)
   {
   pl1=\"You\";
   pl2=\"Computer\";
   }
   else
   {
   pl1=\"Player 1\";
   pl2=\"Player 2\";
   }
   reset();
  
   }
}

Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help
Hello I\'m needing help in completing this Tic-Tac-Toe assignment in C# Windows Form Application . I\'m using Visual Studio 2015 Community edition. I need help

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site