Click here to Skip to main content
15,881,882 members
Home / Discussions / C#
   

C#

 
QuestionUsing Deployment Item with Directory.GetFiles Pin
RamboSp31-Mar-16 2:17
RamboSp31-Mar-16 2:17 
AnswerRe: Using Deployment Item with Directory.GetFiles Pin
Eddy Vluggen1-Apr-16 1:33
professionalEddy Vluggen1-Apr-16 1:33 
Questioncurrent state of old issue of Enum boxing when used as Keys in a Dictionary ? Pin
BillWoodruff31-Mar-16 2:15
professionalBillWoodruff31-Mar-16 2:15 
AnswerRe: current state of old issue of Enum boxing when used as Keys in a Dictionary ? Pin
Richard Deeming31-Mar-16 2:52
mveRichard Deeming31-Mar-16 2:52 
QuestionMessage Removed Pin
31-Mar-16 0:25
PomegranateTiger31-Mar-16 0:25 
QuestionSync SQLite with Oracle or Postgre Pin
Potestas30-Mar-16 21:42
Potestas30-Mar-16 21:42 
AnswerRe: Sync SQLite with Oracle or Postgre Pin
Nathan Minier31-Mar-16 1:26
professionalNathan Minier31-Mar-16 1:26 
QuestionC# Tic Tac Toe "Simulator" Pin
Member 1242680830-Mar-16 11:24
Member 1242680830-Mar-16 11:24 
I'm very sorry if I didn't post my code correctly. I am having trouble with this. The code is working to the directions specifications, but, I am not sure about one thing. How do avoid getting....lets say....6 "O's" and 3 "X's" when I run the program. That is not simulation. Thanks.

C#
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 Tic_Tac_Toe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            const int ROWS = 3;
            const int COLS = 3;
            int[,] game = new int[ROWS, COLS];

            Random rand = new Random();

            for (int row = 0; row < ROWS; row++)
            {
                for (int col = 0; col < COLS; col++)
                {
                    game[row, col] = rand.Next(2);
                }
                if (game[0, 0] == 0)
                {
                    label2.Text = "O";
                }
                else
                {
                    label2.Text = "X";
                }
                if (game[0, 1] == 0)
                {
                    label3.Text = "O";
                }
                else
                {
                    label3.Text = "X";
                }
                if (game[0, 2] == 0)
                {
                    label4.Text = "O";
                }
                else
                {
                    label4.Text = "X";
                }
                if (game[1, 0] == 0)
                {
                    label5.Text = "O";
                }
                else
                {
                    label5.Text = "X";
                }
                if (game[1, 1] == 0)
                {
                    label6.Text = "O";
                }
                else
                {
                    label6.Text = "X";
                }
                if (game[1, 2] == 0)
                {
                    label7.Text = "O";
                }
                else
                {
                    label7.Text = "X";
                }
                if (game[2, 0] == 0)
                {
                    label8.Text = "O";
                }
                else
                {
                    label8.Text = "X";
                }
                if (game[2, 1] == 0)
                {
                    label9.Text = "O";
                }
                else
                {
                    label9.Text = "X";
                }
                if (game[2, 2] == 0)
                {
                    label10.Text = "O";
                }
                else
                {
                    label10.Text = "X";
                }

                if (game[0, 0] == 0 && game[0, 1] == 0 && game[0, 2] == 0)
                {
                    label11.Text = "O Wins";
                }
                 else if (game[0, 0] == 1 && game[0, 1] == 1 && game[0, 2] == 1)
                    {
                        label11.Text = "X Wins";
                    }
                else if (game[1, 0] == 0 && game[1, 1] == 0 && game[1, 2] == 0)
                {
                    label11.Text = "O Wins";
                }
                else if (game[1, 0] == 1 && game[1, 1] == 1 && game[1, 2] == 1)
                {
                    label11.Text = "X Wins";
                }
                else if (game[2, 0] == 0 && game[2, 1] == 0 && game[2, 2] == 0)
                {
                    label11.Text = "O Wins";
                }
                else if (game[2, 0] == 1 && game[2, 1] == 1 && game[2, 2] == 1)
                {
                    label11.Text = "X Wins";
                }
                else if (game[0, 0] == 0 && game[1, 0] == 0 && game[2, 0] == 0)
                {
                    label11.Text = "O Wins";
                }
                else if (game[0, 0] == 1 && game[1, 0] == 1 && game[2, 0] == 1)
                {
                    label11.Text = "X Wins";
                }
                else if (game[0, 1] == 0 && game[1, 1] == 0 && game[2, 1] == 0)
                {
                    label11.Text = "O Wins";
                }
                else if (game[0, 1] == 1 && game[1, 1] == 1 && game[2, 1] == 1)
                {
                    label11.Text = "X Wins";
                }
                else if (game[0, 2] == 0 && game[1, 2] == 0 && game[2, 2] == 0)
                {
                    label11.Text = "O Wins";
                }
                else if (game[0, 2] == 1 && game[1, 2] == 1 && game[2, 2] == 1)
                {
                    label11.Text = "X Wins";
                }
                else if (game[0, 0] == 0 && game[1, 1] == 0 && game[2, 2] == 0)
                {
                    label11.Text = "O Wins";
                }
                else if (game[0, 0] == 1 && game[1, 1] == 1 && game[2, 2] == 1)
                {
                    label11.Text = "X Wins";
                }
                else if (game[0, 2] == 0 && game[1, 1] == 0 && game[2, 0] == 0)
                {
                    label11.Text = "O Wins";
                }
                else if (game[0, 2] == 1 && game[1, 1] == 1 && game[2, 0] == 1)
                {
                    label11.Text = "X Wins";
                }
                else
                {
                    label11.Text = "DRAW";
                }


                


                }

            }
        }
    }

AnswerRe: C# Tic Tac Toe "Simulator" Pin
Sascha Lefèvre30-Mar-16 17:15
professionalSascha Lefèvre30-Mar-16 17:15 
AnswerRe: C# Tic Tac Toe "Simulator" Pin
Rob Philpott30-Mar-16 23:41
Rob Philpott30-Mar-16 23:41 
AnswerRe: C# Tic Tac Toe "Simulator" Pin
Patrice T31-Mar-16 0:55
mvePatrice T31-Mar-16 0:55 
RantREPOST Pin
Richard Deeming31-Mar-16 1:42
mveRichard Deeming31-Mar-16 1:42 
QuestionDynamically close DB2 CLP window using C# Pin
Tej_dev30-Mar-16 6:44
Tej_dev30-Mar-16 6:44 
AnswerMessage Closed Pin
30-Mar-16 7:19
mveGerry Schmitz30-Mar-16 7:19 
GeneralRe: Dynamically close DB2 CLP window using C# Pin
Tej_dev30-Mar-16 8:14
Tej_dev30-Mar-16 8:14 
SuggestionRe: Dynamically close DB2 CLP window using C# Pin
Richard Deeming30-Mar-16 8:44
mveRichard Deeming30-Mar-16 8:44 
GeneralMessage Closed Pin
30-Mar-16 8:52
mveGerry Schmitz30-Mar-16 8:52 
GeneralRe: Dynamically close DB2 CLP window using C# Pin
Richard Deeming30-Mar-16 8:54
mveRichard Deeming30-Mar-16 8:54 
AnswerRe: Dynamically close DB2 CLP window using C# Pin
Richard Deeming30-Mar-16 8:52
mveRichard Deeming30-Mar-16 8:52 
GeneralRe: Dynamically close DB2 CLP window using C# Pin
Tej_dev30-Mar-16 9:03
Tej_dev30-Mar-16 9:03 
QuestionBitmap to BitmapImage Conversion Not Working - WPF Pin
AmbiguousName30-Mar-16 4:36
AmbiguousName30-Mar-16 4:36 
AnswerRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
Rob Philpott30-Mar-16 5:46
Rob Philpott30-Mar-16 5:46 
GeneralRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
AmbiguousName30-Mar-16 6:04
AmbiguousName30-Mar-16 6:04 
AnswerRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
Matt T Heffron30-Mar-16 6:54
professionalMatt T Heffron30-Mar-16 6:54 
AnswerRe: Bitmap to BitmapImage Conversion Not Working - WPF Pin
Gerry Schmitz30-Mar-16 7:06
mveGerry Schmitz30-Mar-16 7:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.