hi guys...
I am having a hard time figuring out how i could determine the winner of the game and how I can determine if a game is a draw. Any suggestions or code that i should input in my porject? Please help me. Im new in C#.
jude1693 0 Newbie Poster
im using microsoft visual studio 2008.
Momerath 1,327 Nearly a Senior Poster Featured Poster
How are you storing the playing board? What indicates that a player has occupied a spot on the board?
jude1693 0 Newbie Poster
This is my program.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace game.casestudy
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void objectiveToolStripMenuItem_Click(object sender, EventArgs e)
{
Form Ronald = new Form3();
Ronald.Show();
}
private void closeGameToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
{
Form Ronald = new Form2();
Ronald.Show();
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button1.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button1.Enabled = false;
}
else
{
button1.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button1.Enabled = false;
}
{
if (label1.Enabled == true)
{
button1.Text = "X";
button2.Text = "X";
button3.Text = "X";
MessageBox.Show("Player1 wins!");
}
else
{
MessageBox.Show("Player2 wins!");
}
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button2.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button2.Enabled = false;
}
else
{
button2.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button2.Enabled = false;
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button3.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button3.Enabled = false;
}
else
{
button3.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button3.Enabled = false;
}
}
private void button4_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button4.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button4.Enabled = false;
}
else
{
button4.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button4.Enabled = false;
}
}
private void button5_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button5.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button5.Enabled = false;
}
else
{
button5.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button5.Enabled = false;
}
}
private void button6_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button6.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button6.Enabled = false;
}
else
{
button6.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button6.Enabled = false;
}
}
private void button7_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button7.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button7.Enabled = false;
}
else
{
button7.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button7.Enabled = false;
}
}
private void button8_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button8.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button8.Enabled = false;
}
else
{
button8.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button8.Enabled = false;
}
}
private void button9_Click(object sender, EventArgs e)
{
if (label1.Enabled == true)
{
button9.Text = "X";
label1.Enabled = false;
label2.Enabled = true;
button9.Enabled = false;
}
else
{
button9.Text = "O";
label1.Enabled = true;
label2.Enabled = false;
button9.Enabled = false;
}
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}
Edited by Dani because: Formatting fixed
moteutsch 0 Newbie Poster
You're going about this all wrong. You should have a 3x3 array that is updated as the game goes along with the placement of the pieces. Then you can use a loop to see if there are 3 pieces in a row or to see if the array is full.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.