Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    10
  • comments
    147
  • views
    2453

c# tic tac toe game

phil67rpg

1289 views

here is my code for my tic tac toe game, I am still working on the computer player.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace wintictactoe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        
        int [,] board_x=new int[3,3];
        int[,] board_o = new int[3, 3];

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if(e.Button == MouseButtons.Left)
            {
                Random rnd = new Random();

                int col = rnd.Next(325, 476);
                int row = rnd.Next(200, 351);

                Graphics g1 = this.CreateGraphics();
                if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 200 && e.Y - 10 <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215));
                    board_x[0, 0] = 1;
                }
                if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 200 && e.Y - 10 <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215));
                    board_x[0, 1] = 1;
                }
                if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 200 && e.Y - 10 <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215));
                    board_x[0, 2] = 1;
                }
                if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 250 && e.Y - 10 <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260));
                    board_x[1, 0] = 1;
                }
                if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 250 && e.Y - 10 <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260));
                    board_x[1, 1] = 1;
                }
                if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 250 && e.Y - 10 <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260));
                    board_x[1, 2] = 1;
                }
                if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 300 && e.Y - 10 <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315));
                    board_x[2, 0] = 1;
                }
                if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 300 && e.Y - 10 <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315));
                    board_x[2, 1] = 1;
                }
                if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 300 && e.Y - 10 <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315));
                    board_x[2, 2] = 1;
                }

                if (col >= 325 && col <= 375 && row >= 200 && row <= 250)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215));
                    board_o[0, 0] = 1;
                }
                if (col >= 375 && col <= 425 && row >= 200 && row <= 250)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215));
                    board_o[0, 1] = 1;
                }
                if (col >= 425 && col <= 475 && row >= 200 && row <= 250)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215));
                    board_o[0, 2] = 1;
                }

                if (col >= 325 && col <= 375 && row >= 250 && row <= 300)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260));
                    board_o[1, 0] = 1;
                }
                if (col >= 375 && col <= 425 && row >= 250 && row <= 300)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260));
                    board_o[1, 1] = 1;
                }
                if (col >= 425 && col <= 475 && row >= 250 && row <= 300)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260));
                    board_o[1, 2] = 1;
                }

                if (col >= 325 && col <= 375 && row >= 300 && row <= 350)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315));
                    board_o[2, 0] = 1;
                }
                if (col >= 375 && col <= 425 && row >= 300 && row <= 350)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315));
                    board_o[2, 1] = 1;
                }
                if (col >= 425 && col <= 475 && row >= 300 && row <= 350)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315));
                    board_o[2, 2] = 1;
                }
                g1.Dispose();
            }
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen redPen = new Pen(Color.Red,3);
            g.DrawLine(redPen, 375, 200, 375, 350);
            g.DrawLine(redPen, 425, 200, 425, 350);
            g.DrawLine(redPen, 325, 250, 475, 250);
            g.DrawLine(redPen, 325, 300, 475, 300);
            g.Dispose();
        }
    }
}

 



13 Comments


Recommended Comments

I have made some progress on my game, here is my code so far.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace wintictactoe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        bool[,] board_x = new bool[3, 3];
        bool[,] board_o = new bool[3, 3];
       
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Random rnd = new Random();

                int col = rnd.Next(325, 476);
                int row = rnd.Next(200, 351);
                
                Graphics g1 = this.CreateGraphics();
                if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 200 && e.Y - 10 <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215));
                    board_x[0, 0] = true;
                }
                if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 200 && e.Y - 10 <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215));
                    board_x[0, 1] = true;
                }
                if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 200 && e.Y - 10 <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215));
                    board_x[0, 2] = true;
                }
                if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 250 && e.Y - 10 <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260));
                    board_x[1, 0] = true;
                }
                if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 250 && e.Y - 10 <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260));
                    board_x[1, 1] = true;
                }
                if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 250 && e.Y - 10 <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260));
                    board_x[1, 2] = true;
                }
                if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 300 && e.Y - 10 <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315));
                    board_x[2, 0] = true;
                }
                if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 300 && e.Y - 10 <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315));
                    board_x[2, 1] = true;
                }
                if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 300 && e.Y - 10 <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315));
                    board_x[2, 2] = true;
                }

                if (col >= 325 && col <= 375 && row >= 200 && row <= 250)
                {
                    board_o[0, 0] = true;
                }
                if (col >= 375 && col <= 425 && row >= 200 && row <= 250)
                {
                    board_o[0, 1] = true;
                }
                if (col >= 425 && col <= 475 && row >= 200 && row <= 250)
                {
                    board_o[0, 2] = true;
                }

                if (col >= 325 && col <= 375 && row >= 250 && row <= 300)
                {
                    board_o[1, 0] = true;
                }
                if (col >= 375 && col <= 425 && row >= 250 && row <= 300)
                {
                    board_o[1, 1] = true;
                }
                if (col >= 425 && col <= 475 && row >= 250 && row <= 300)
                {
                    board_o[1, 2] = true;
                }

                if (col >= 325 && col <= 375 && row >= 300 && row <= 350)
                {
                    board_o[2, 0] = true;
                }
                if (col >= 375 && col <= 425 && row >= 300 && row <= 350)
                {
                    board_o[2, 1] = true;
                }
                if (col >= 425 && col <= 475 && row >= 300 && row <= 350)
                {
                    board_o[2, 2] = true;
                }

                if ((board_x[0,0]&&board_o[0,0])||(board_x[0,1]&&board_o[0,1])||(board_x[0,2]&&board_o[0, 2])||(board_x[1,0]&&board_o[1,0])||(board_x[1,1]&&board_o[1,1])||(board_x[1,2]&&board_o[1,2])||(board_x[2,0]&&board_o[2,0])||(board_x[2, 1]&&board_o[2,1])||(board_x[2,2]&&board_o[2,2])) 
                {
                    Random rand = new Random();
                    col = rand.Next(325, 476);
                    row = rand.Next(200, 351);
                    g1.DrawString(" ", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215));
                }
                                
                if (col >= 325 && col <= 375 && row >= 200 && row <= 250)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215));
                }
                if (col >= 375 && col <= 425 && row >= 200 && row <= 250)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215));
                }
                if (col >= 425 && col <= 475 && row >= 200 && row <= 250)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215));
                }

                if (col >= 325 && col <= 375 && row >= 250 && row <= 300)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260));
                }
                if (col >= 375 && col <= 425 && row >= 250 && row <= 300)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260));
                }
                if (col >= 425 && col <= 475 && row >= 250 && row <= 300)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260));
                }

                if (col >= 325 && col <= 375 && row >= 300 && row <= 350)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315));
                }
                if (col >= 375 && col <= 425 && row >= 300 && row <= 350)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315));
                }
                if (col >= 425 && col <= 475 && row >= 300 && row <= 350)
                {
                    g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315));
                }
        
                g1.Dispose();
            }
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen redPen = new Pen(Color.Red,3);
            g.DrawLine(redPen, 375, 200, 375, 350);
            g.DrawLine(redPen, 425, 200, 425, 350);
            g.DrawLine(redPen, 325, 250, 475, 250);
            g.DrawLine(redPen, 325, 300, 475, 300);
            g.Dispose();
        }
    }
}

my only problem is that my O's draw over my X's sometimes.

Share this comment


Link to comment

Maybe instead of posting raw code, show off the game a bit more by showing screen shots, maybe even a few videos of the game in action.

Share this comment


Link to comment

I am doing some research on recursion, and I think I am going to have to implement recursion.

Share this comment


Link to comment
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace wintictactoe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        bool[,] board_x = new bool[3, 3];
        bool[,] board_o = new bool[3, 3];
       
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Random rnd = new Random();

                int col = rnd.Next(325, 476);
                int row = rnd.Next(200, 351);

//                MessageBox.Show(col.ToString());
//                MessageBox.Show(row.ToString());

                Graphics g1 = this.CreateGraphics();
                
                if (e.X >= 325 && e.X <= 375 && e.Y >= 200 && e.Y <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215));
                    board_x[0, 0] = true;
                }
                if (e.X >= 375 && e.X  <= 425 && e.Y >= 200 && e.Y <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215));
                    board_x[0, 1] = true;
                }
                if (e.X >= 425 && e.X <= 475 && e.Y >= 200 && e.Y <= 250)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215));
                    board_x[0, 2] = true;
                }
                if (e.X >= 325 && e.X <= 375 && e.Y >= 250 && e.Y <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260));
                    board_x[1, 0] = true;
                }
                if (e.X >= 375 && e.X <= 425 && e.Y >= 250 && e.Y <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260));
                    board_x[1, 1] = true;
                }
                if (e.X >= 425 && e.X <= 475 && e.Y >= 250 && e.Y <= 300)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260));
                    board_x[1, 2] = true;
                }
                if (e.X >= 325 && e.X <= 375 && e.Y >= 300 && e.Y <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315));
                    board_x[2, 0] = true;
                }
                if (e.X >= 375 && e.X <= 425 && e.Y >= 300 && e.Y <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315));
                    board_x[2, 1] = true;
                }
                if (e.X >= 425 && e.X <= 475 && e.Y >= 300 && e.Y <= 350)
                {
                    g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315));
                    board_x[2, 2] = true;
                }

                if (col >= 325 && col <= 375 && row >= 200 && row <= 250)
                {
                    board_o[0, 0] = true;
                }
                if (col >= 375 && col <= 425 && row >= 200 && row <= 250)
                {
                    board_o[0, 1] = true;
                }
                if (col >= 425 && col <= 475 && row >= 200 && row <= 250)
                {
                    board_o[0, 2] = true;
                }

                if (col >= 325 && col <= 375 && row >= 250 && row <= 300)
                {
                    board_o[1, 0] = true;
                }
                if (col >= 375 && col <= 425 && row >= 250 && row <= 300)
                {
                    board_o[1, 1] = true;
                }
                if (col >= 425 && col <= 475 && row >= 250 && row <= 300)
                {
                    board_o[1, 2] = true;
                }

                if (col >= 325 && col <= 375 && row >= 300 && row <= 350)
                {
                    board_o[2, 0] = true;
                }
                if (col >= 375 && col <= 425 && row >= 300 && row <= 350)
                {
                    board_o[2, 1] = true;
                }
                if (col >= 425 && col <= 475 && row >= 300 && row <= 350)
                {
                    board_o[2, 2] = true;
                }

                if ((board_x[0, 0] && board_o[0, 0]) || (board_x[0, 1] && board_o[0, 1]) || (board_x[0, 2] && board_o[0, 2]) || (board_x[1, 0] && board_o[1, 0]) || (board_x[1, 1] && board_o[1, 1]) || (board_x[1, 2] && board_o[1, 2]) || (board_x[2, 0] && board_o[2, 0]) || (board_x[2, 1] && board_o[2, 1]) || (board_x[2, 2] && board_o[2, 2]))
                {
//                    MessageBox.Show(col.ToString());
//                    MessageBox.Show(row.ToString());
                }
                else
                {

                    if (col >= 325 && col <= 375 && row >= 200 && row <= 250)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215));
                    }
                    if (col >= 375 && col <= 425 && row >= 200 && row <= 250)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215));
                    }
                    if (col >= 425 && col <= 475 && row >= 200 && row <= 250)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215));
                    }

                    if (col >= 325 && col <= 375 && row >= 250 && row <= 300)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260));
                    }
                    if (col >= 375 && col <= 425 && row >= 250 && row <= 300)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260));
                    }
                    if (col >= 425 && col <= 475 && row >= 250 && row <= 300)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260));
                    }

                    if (col >= 325 && col <= 375 && row >= 300 && row <= 350)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315));
                    }
                    if (col >= 375 && col <= 425 && row >= 300 && row <= 350)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315));
                    }
                    if (col >= 425 && col <= 475 && row >= 300 && row <= 350)
                    {
                        g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315));
                    }

                    g1.Dispose();
                }
            }
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen redPen = new Pen(Color.Red,3);
            g.DrawLine(redPen, 375, 200, 375, 350);
            g.DrawLine(redPen, 425, 200, 425, 350);
            g.DrawLine(redPen, 325, 250, 475, 250);
            g.DrawLine(redPen, 325, 300, 475, 300);
            g.Dispose();
        }
    }
}

I have made some more progress, unfortunately I cant seem to figure out how to get the computer player to draw more then 3 o's on the grid. I will continue to work on this problem.

Share this comment


Link to comment

I have decided to work on a console based c# tic tac toe game hopefully it will be little easier.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 1;
            Console.WriteLine(" 1 | 2 | 3 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 4 | 5 | 6 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 7 | 8 | 9 ");

            char[,] board = new char[3, 3];
            
            while (count <= 9)
            {
                Console.Write("Enter X spot (1-9): ");
                int num = Convert.ToInt32(Console.ReadLine());

                switch (num)
                {
                    case 1:
                        board[0, 0] = 'X';
                        break;
                    case 2:
                        board[1, 0] = 'X';
                        break;
                    case 3:
                        board[2, 0] = 'X';
                        break;
                    case 4:
                        board[0, 1] = 'X';
                        break;
                    case 5:
                        board[1, 1] = 'X';
                        break;
                    case 6:
                        board[2, 1] = 'X';
                        break;
                    case 7:
                        board[0, 2] = 'X';
                        break;
                    case 8:
                        board[1, 2] = 'X';
                        break;
                    case 9:
                        board[2, 2] = 'X';
                        break;
                }
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 0], board[1, 0], board[2, 0]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 1], board[1, 1], board[2, 1]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 2], board[1, 2], board[2, 2]);
                count++;
            }
        }
    }
}

 

Share this comment


Link to comment

here is my updated game code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 1;
            int player_x=0,player_o=0;
            Console.WriteLine(" 1 | 2 | 3 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 4 | 5 | 6 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 7 | 8 | 9 ");

            char[,] board = new char[3, 3];
            
            while (count <= 9)
            {
                Console.Write("Enter X spot (1-9): ");
                int num = Convert.ToInt32(Console.ReadLine());
                
                Random rnd = new Random();
                int num_one = rnd.Next(1, 10);

                switch (num)
                {
                    case 1:
                        board[0, 0] = 'X';
                        player_x = 1;
                        break;
                    case 2:
                        board[1, 0] = 'X';
                        player_x = 2;
                        break;
                    case 3:
                        board[2, 0] = 'X';
                        player_x = 3;
                        break;
                    case 4:
                        board[0, 1] = 'X';
                        player_x = 4;
                        break;
                    case 5:
                        board[1, 1] = 'X';
                        player_x = 5;
                        break;
                    case 6:
                        board[2, 1] = 'X';
                        player_x = 6;
                        break;
                    case 7:
                        board[0, 2] = 'X';
                        player_x = 7;
                        break;
                    case 8:
                        board[1, 2] = 'X';
                        player_x = 8;
                        break;
                    case 9:
                        board[2, 2] = 'X';
                        player_x = 9;
                        break;
                }

                switch (num_one)
                {
                    case 1:
                        board[0, 0] = 'O';
                        player_o = 1;
                        break;
                    case 2:
                        board[1, 0] = 'O';
                        player_o = 2;
                        break;
                    case 3:
                        board[2, 0] = 'O';
                        player_o = 3;
                        break;
                    case 4:
                        board[0, 1] = 'O';
                        player_o = 4;
                        break;
                    case 5:
                        board[1, 1] = 'O';
                        player_o = 5;
                        break;
                    case 6:
                        board[2, 1] = 'O';
                        player_o = 6;
                        break;
                    case 7:
                        board[0, 2] = 'O';
                        player_o = 7;
                        break;
                    case 8:
                        board[1, 2] = 'O';
                        player_o = 8;
                        break;
                    case 9:
                        board[2, 2] = 'O';
                        player_o = 9;
                        break;
                }

                Console.WriteLine(" {0} | {1} | {2} ", board[0, 0], board[1, 0], board[2, 0]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 1], board[1, 1], board[2, 1]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 2], board[1, 2], board[2, 2]);
                count++;
            }
        }
    }
}

 

Share this comment


Link to comment

I have almost done my tic tac toe game, I just need to make it bulletproof.

here is my code so far.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 1;
            int player_x=0,player_o=0;
            Console.WriteLine(" 1 | 2 | 3 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 4 | 5 | 6 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 7 | 8 | 9 ");

            char[,] board = new char[3, 3];
            
            while (count <= 9)
            {
                Console.Write("Enter X spot (1-9): ");
                int num = Convert.ToInt32(Console.ReadLine());
                
                Random rnd = new Random();
                int num_one = rnd.Next(1, 10);

                switch (num)
                {
                    case 1:
                        board[0, 0] = 'X';
                        player_x = 1;
                        break;
                    case 2:
                        board[1, 0] = 'X';
                        player_x = 2;
                        break;
                    case 3:
                        board[2, 0] = 'X';
                        player_x = 3;
                        break;
                    case 4:
                        board[0, 1] = 'X';
                        player_x = 4;
                        break;
                    case 5:
                        board[1, 1] = 'X';
                        player_x = 5;
                        break;
                    case 6:
                        board[2, 1] = 'X';
                        player_x = 6;
                        break;
                    case 7:
                        board[0, 2] = 'X';
                        player_x = 7;
                        break;
                    case 8:
                        board[1, 2] = 'X';
                        player_x = 8;
                        break;
                    case 9:
                        board[2, 2] = 'X';
                        player_x = 9;
                        break;
                }

                switch (num_one)
                {
                    case 1:
                        board[0, 0] = 'O';
                        player_o = 1;
                        break;
                    case 2:
                        board[1, 0] = 'O';
                        player_o = 2;
                        break;
                    case 3:
                        board[2, 0] = 'O';
                        player_o = 3;
                        break;
                    case 4:
                        board[0, 1] = 'O';
                        player_o = 4;
                        break;
                    case 5:
                        board[1, 1] = 'O';
                        player_o = 5;
                        break;
                    case 6:
                        board[2, 1] = 'O';
                        player_o = 6;
                        break;
                    case 7:
                        board[0, 2] = 'O';
                        player_o = 7;
                        break;
                    case 8:
                        board[1, 2] = 'O';
                        player_o = 8;
                        break;
                    case 9:
                        board[2, 2] = 'O';
                        player_o = 9;
                        break;
                }
                if (player_x == 1 && player_o == 1) 
                {
                    board[0, 0] = 'X';
                }
                if (player_x == 2 && player_o == 2)
                {
                    board[1, 0] = 'X';
                }
                if (player_x == 3 && player_o == 3)
                {
                    board[2, 0] = 'X';
                }
                if (player_x == 4 && player_o == 4)
                {
                    board[0, 1] = 'X';
                }
                if (player_x == 5 && player_o == 5)
                {
                    board[1, 1] = 'X';
                }
                if (player_x == 6 && player_o == 6)
                {
                    board[2, 1] = 'X';
                }
                if (player_x == 7 && player_o == 7)
                {
                    board[0, 2] = 'X';
                }
                if (player_x == 8 && player_o == 8)
                {
                    board[1, 2] = 'X';
                }
                if (player_x == 9 && player_o == 9)
                {
                    board[2, 2] = 'X';
                }
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 0], board[1, 0], board[2, 0]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 1], board[1, 1], board[2, 1]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 2], board[1, 2], board[2, 2]);

                if (board[0, 0] == 'X' && board[1, 0] == 'X' && board[2, 0] == 'X') 
                {
                    Console.WriteLine("Player X Wins");
                    Environment.Exit(0);
                }
                if (board[0, 1] == 'X' && board[1, 1] == 'X' && board[2, 1] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    Environment.Exit(0);
                }
                if (board[0, 2] == 'X' && board[1, 2] == 'X' && board[2, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    Environment.Exit(0);
                }

                if (board[0, 0] == 'X' && board[0, 1] == 'X' && board[0, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    Environment.Exit(0);
                }
                if (board[1, 0] == 'X' && board[1, 1] == 'X' && board[1, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    Environment.Exit(0);
                }
                if (board[2, 0] == 'X' && board[2, 1] == 'X' && board[2, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    Environment.Exit(0);
                }
                
                if (board[0, 0] == 'O' && board[1, 1] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    Environment.Exit(0);
                }
                if (board[0, 2] == 'O' && board[1, 1] == 'O' && board[2, 0] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    Environment.Exit(0);
                }
                if (board[0, 0] == 'O' && board[1, 0] == 'O' && board[2, 0] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    Environment.Exit(0);
                }
                if (board[0, 1] == 'O' && board[1, 1] == 'O' && board[2, 1] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    Environment.Exit(0);
                }
                if (board[0, 2] == 'O' && board[1, 2] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    Environment.Exit(0);
                }

                if (board[0, 0] == 'O' && board[0, 1] == 'O' && board[0, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    Environment.Exit(0);
                }
                if (board[1, 0] == 'O' && board[1, 1] == 'O' && board[1, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    Environment.Exit(0);
                }
                if (board[2, 0] == 'O' && board[2, 1] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    Environment.Exit(0);
                }

                if (board[0, 0] == 'X' && board[1, 1] == 'X' && board[2, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    Environment.Exit(0);
                }
                if (board[0, 2] == 'X' && board[1, 1] == 'X' && board[2, 0] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    Environment.Exit(0);
                }
                count++;
            }
        }
    }
}

 

Share this comment


Link to comment

1. There is no point checking for a winner until one player has played at least three moves.

2. Your if statements should be if/else if since they are all mutually exclusive.

3. This is a console game which means you should never trust then input of the player do not assume the user will enter an integer value.

4. Don't use Envrionment.Exit, use a boolean to say gameOver = true at the very least, and have your while loop check against that, do not hardcode with integers if you can avoid it, it makes for maintenance and expansion of the game difficult.

5. Namespace can be named something a bit better

6. I dont see any comments here, there should be comments to explain things that you are doing. You should also think about what parts of the code can be turned into methods, since this is in your main and you have zero objects created you can have static methods.

7. Your using statements, if there are some usings that are not being used you should clean that up

8. Include a license at the top of your file(s) with your name and your open source license of choice, its a good idea to open source all your learning experiences so that others can benefit from it.

Edited by Daniel Ricci

Share this comment


Link to comment
41 minutes ago, Daniel Ricci said:

1. There is no point checking for a winner until one player has played at least three moves.

2. Your if statements should be if/else if since they are all mutually exclusive.

3. This is a console game which means you should never trust then input of the player do not assume the user will enter an integer value.

4. Don't use Envrionment.Exit, use a boolean to say gameOver = true at the very least, and have your while loop check against that, do not hardcode with integers if you can avoid it, it makes for maintenance and expansion of the game difficult.

5. Namespace can be named something a bit better

6. I dont see any comments here, there should be comments to explain things that you are doing. You should also think about what parts of the code can be turned into methods, since this is in your main and you have zero objects created you can have static methods.

7. Your using statements, if there are some usings that are not being used you should clean that up

8. Include a license at the top of your file(s) with your name and your open source license of choice, its a good idea to open source all your learning experiences so that others can benefit from it.

He's been working on one game or another for well over a decade.  I think this is the furthest he has ever gotten with any game and he has been given pretty much all the advice you've provided many times over.  He never takes it or listens.  Quite a few of us are convinced he is a troll to be honest.  Just a heads up :)

Share this comment


Link to comment

well Daniel I have made some progress on my game I have made some of the changes you suggested. I am still working on the AI for this game. do you have any suggestions on how  to implement the computer player.

here is the code

using System;

namespace tictactoe
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 1;
            int player_x=0,player_o=0;
            Console.WriteLine(" 1 | 2 | 3 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 4 | 5 | 6 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 7 | 8 | 9 ");
            
            bool gameOver = false;

            char[,] board = new char[3, 3];
            
            while (gameOver==false)
            {
                Console.Write("Enter X spot (1-9): ");
                int num = Convert.ToInt32(Console.ReadLine());
                
                Random rnd = new Random();
                int num_one = rnd.Next(1, 10);

                switch (num)
                {
                    case 1:
                        board[0, 0] = 'X';
                        player_x = 1;
                        break;
                    case 2:
                        board[1, 0] = 'X';
                        player_x = 2;
                        break;
                    case 3:
                        board[2, 0] = 'X';
                        player_x = 3;
                        break;
                    case 4:
                        board[0, 1] = 'X';
                        player_x = 4;
                        break;
                    case 5:
                        board[1, 1] = 'X';
                        player_x = 5;
                        break;
                    case 6:
                        board[2, 1] = 'X';
                        player_x = 6;
                        break;
                    case 7:
                        board[0, 2] = 'X';
                        player_x = 7;
                        break;
                    case 8:
                        board[1, 2] = 'X';
                        player_x = 8;
                        break;
                    case 9:
                        board[2, 2] = 'X';
                        player_x = 9;
                        break;
                }

                switch (num_one)
                {
                    case 1:
                        board[0, 0] = 'O';
                        player_o = 1;
                        break;
                    case 2:
                        board[1, 0] = 'O';
                        player_o = 2;
                        break;
                    case 3:
                        board[2, 0] = 'O';
                        player_o = 3;
                        break;
                    case 4:
                        board[0, 1] = 'O';
                        player_o = 4;
                        break;
                    case 5:
                        board[1, 1] = 'O';
                        player_o = 5;
                        break;
                    case 6:
                        board[2, 1] = 'O';
                        player_o = 6;
                        break;
                    case 7:
                        board[0, 2] = 'O';
                        player_o = 7;
                        break;
                    case 8:
                        board[1, 2] = 'O';
                        player_o = 8;
                        break;
                    case 9:
                        board[2, 2] = 'O';
                        player_o = 9;
                        break;
                }
                if (player_x == 1 && player_o == 1) 
                {
                    board[0, 0] = 'X';
                }
                else if (player_x == 2 && player_o == 2)
                {
                    board[1, 0] = 'X';
                }
                else if (player_x == 3 && player_o == 3)
                {
                    board[2, 0] = 'X';
                }
                else if (player_x == 4 && player_o == 4)
                {
                    board[0, 1] = 'X';
                }
                else if (player_x == 5 && player_o == 5)
                {
                    board[1, 1] = 'X';
                }
                else if (player_x == 6 && player_o == 6)
                {
                    board[2, 1] = 'X';
                }
                else if (player_x == 7 && player_o == 7)
                {
                    board[0, 2] = 'X';
                }
                else if (player_x == 8 && player_o == 8)
                {
                    board[1, 2] = 'X';
                }
                else if (player_x == 9 && player_o == 9)
                {
                    board[2, 2] = 'X';
                }
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 0], board[1, 0], board[2, 0]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 1], board[1, 1], board[2, 1]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 2], board[1, 2], board[2, 2]);

                if (board[0, 0] == 'X' && board[1, 0] == 'X' && board[2, 0] == 'X') 
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                else if (board[0, 1] == 'X' && board[1, 1] == 'X' && board[2, 1] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                else if (board[0, 2] == 'X' && board[1, 2] == 'X' && board[2, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }

                else if (board[0, 0] == 'X' && board[0, 1] == 'X' && board[0, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                else if (board[1, 0] == 'X' && board[1, 1] == 'X' && board[1, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                else  if (board[2, 0] == 'X' && board[2, 1] == 'X' && board[2, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                
                else if (board[0, 0] == 'O' && board[1, 1] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 2] == 'O' && board[1, 1] == 'O' && board[2, 0] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 0] == 'O' && board[1, 0] == 'O' && board[2, 0] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 1] == 'O' && board[1, 1] == 'O' && board[2, 1] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 2] == 'O' && board[1, 2] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }

                else if (board[0, 0] == 'O' && board[0, 1] == 'O' && board[0, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[1, 0] == 'O' && board[1, 1] == 'O' && board[1, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[2, 0] == 'O' && board[2, 1] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }

                else if (board[0, 0] == 'O' && board[1, 1] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 2] == 'O' && board[1, 1] == 'O' && board[2, 0] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
            }
        }
    }
}

 

Share this comment


Link to comment
2 hours ago, Daniel Ricci said:

8. Include a license at the top of your file(s) with your name and your open source license of choice

Please don't. If you need that info put it in a separate file.

Share this comment


Link to comment

here is my latest code

using System;
using System.Collections.Generic;

namespace tictactoe
{
    class Program
    {
        static void Main(string[] args)
        {
            int player_x = 0, player_o = 0, count = 9;
            Console.WriteLine(" 1 | 2 | 3 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 4 | 5 | 6 ");
            Console.WriteLine("---|---|---");
            Console.WriteLine(" 7 | 8 | 9 ");
            
            bool gameOver = false;

            char[,] board = new char[3, 3];

            while (gameOver==false)
            {
                Console.Write("Enter X spot (1-9): ");
                int num = Convert.ToInt32(Console.ReadLine());

                Random rnd = new Random();

                List<int> boardmove = new List<int>();
                boardmove.Add(1);
                boardmove.Add(2);
                boardmove.Add(3);
                boardmove.Add(4);
                boardmove.Add(5);
                boardmove.Add(6);
                boardmove.Add(7);
                boardmove.Add(8);
                boardmove.Add(9);

                int rand = rnd.Next(1, count);

                int num_one = boardmove[rand];

                boardmove.RemoveAt(rand);

                count--;

                switch (num)
                {
                    case 1:
                        board[0, 0] = 'X';
                        player_x = 1;
                        break;
                    case 2:
                        board[1, 0] = 'X';
                        player_x = 2;
                        break;
                    case 3:
                        board[2, 0] = 'X';
                        player_x = 3;
                        break;
                    case 4:
                        board[0, 1] = 'X';
                        player_x = 4;
                        break;
                    case 5:
                        board[1, 1] = 'X';
                        player_x = 5;
                        break;
                    case 6:
                        board[2, 1] = 'X';
                        player_x = 6;
                        break;
                    case 7:
                        board[0, 2] = 'X';
                        player_x = 7;
                        break;
                    case 8:
                        board[1, 2] = 'X';
                        player_x = 8;
                        break;
                    case 9:
                        board[2, 2] = 'X';
                        player_x = 9;
                        break;
                }

                switch (num_one)
                {
                    case 1:
                        board[0, 0] = 'O';
                        player_o = 1;
                        break;
                    case 2:
                        board[1, 0] = 'O';
                        player_o = 2;
                        break;
                    case 3:
                        board[2, 0] = 'O';
                        player_o = 3;
                        break;
                    case 4:
                        board[0, 1] = 'O';
                        player_o = 4;
                        break;
                    case 5:
                        board[1, 1] = 'O';
                        player_o = 5;
                        break;
                    case 6:
                        board[2, 1] = 'O';
                        player_o = 6;
                        break;
                    case 7:
                        board[0, 2] = 'O';
                        player_o = 7;
                        break;
                    case 8:
                        board[1, 2] = 'O';
                        player_o = 8;
                        break;
                    case 9:
                        board[2, 2] = 'O';
                        player_o = 9;
                        break;
                }
                if (player_x == 1 && player_o == 1) 
                {
                    board[0, 0] = 'X';
                }
                else if (player_x == 2 && player_o == 2)
                {
                    board[1, 0] = 'X';
                }
                else if (player_x == 3 && player_o == 3)
                {
                    board[2, 0] = 'X';
                }
                else if (player_x == 4 && player_o == 4)
                {
                    board[0, 1] = 'X';
                }
                else if (player_x == 5 && player_o == 5)
                {
                    board[1, 1] = 'X';
                }
                else if (player_x == 6 && player_o == 6)
                {
                    board[2, 1] = 'X';
                }
                else if (player_x == 7 && player_o == 7)
                {
                    board[0, 2] = 'X';
                }
                else if (player_x == 8 && player_o == 8)
                {
                    board[1, 2] = 'X';
                }
                else if (player_x == 9 && player_o == 9)
                {
                    board[2, 2] = 'X';
                }
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 0], board[1, 0], board[2, 0]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 1], board[1, 1], board[2, 1]);
                Console.WriteLine("---|---|---");
                Console.WriteLine(" {0} | {1} | {2} ", board[0, 2], board[1, 2], board[2, 2]);

                if (board[0, 0] == 'X' && board[1, 0] == 'X' && board[2, 0] == 'X') 
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                else if (board[0, 1] == 'X' && board[1, 1] == 'X' && board[2, 1] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                else if (board[0, 2] == 'X' && board[1, 2] == 'X' && board[2, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }

                else if (board[0, 0] == 'X' && board[0, 1] == 'X' && board[0, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                else if (board[1, 0] == 'X' && board[1, 1] == 'X' && board[1, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                else  if (board[2, 0] == 'X' && board[2, 1] == 'X' && board[2, 2] == 'X')
                {
                    Console.WriteLine("Player X Wins");
                    gameOver = true;
                }
                
                else if (board[0, 0] == 'O' && board[1, 1] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 2] == 'O' && board[1, 1] == 'O' && board[2, 0] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 0] == 'O' && board[1, 0] == 'O' && board[2, 0] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 1] == 'O' && board[1, 1] == 'O' && board[2, 1] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 2] == 'O' && board[1, 2] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }

                else if (board[0, 0] == 'O' && board[0, 1] == 'O' && board[0, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[1, 0] == 'O' && board[1, 1] == 'O' && board[1, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[2, 0] == 'O' && board[2, 1] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }

                else if (board[0, 0] == 'O' && board[1, 1] == 'O' && board[2, 2] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
                else if (board[0, 2] == 'O' && board[1, 1] == 'O' && board[2, 0] == 'O')
                {
                    Console.WriteLine("Player O Wins");
                    gameOver = true;
                }
            }
        }
    }
}

I am still stuck on how to get the computer player  to work.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!