shsh_shah
asked on
Draw Functionality Halts in TicTac Toe
In TicTacToe When the draw occurs form became halts and stop down
Below is the code that all related to draw functionality
public void Draw()
{
lblDraw.Visible = true;
lblDraw.Enabled = true;
sta.compdraws++;
}
public void checkAll()
{
else if (box1.Image != null &&Â box2.Image != null &&Â box3.Image != null &&Â box4.Image != null &&Â box5.Image != null
&&Â box6.Image != null &&Â box7.Image != null &&Â box8.Image != null &&Â box9.Image != null)
{
// DRAW occurs
Draw();
}
private void resetBtn_Click(object sender, EventArgs e)
{
reset();
}
public void reset()
{
lblDraw.Visible = false;
lblDraw.Enabled = false;
box1.Image = null;
box2.Image = null;
box3.Image = null;
box4.Image = null;
box5.Image = null;
box6.Image = null;
box7.Image = null;
box8.Image = null;
box9.Image = null;
displayAgain();
}
public void displayAgain()
{
box1.Enabled = true;
box2.Enabled = true;
box3.Enabled = true;
box4.Enabled = true;
box5.Enabled = true;
box6.Enabled = true;
box7.Enabled = true;
box8.Enabled = true;
box9.Enabled = true;
}
It stops when the game is done few times i mean when their is some winning occurs then it halts at when the draw label appears. And reset button is no more clickable.
There is no exception occurs at any point.
Below is the code that all related to draw functionality
public void Draw()
{
lblDraw.Visible = true;
lblDraw.Enabled = true;
sta.compdraws++;
}
public void checkAll()
{
else if (box1.Image != null &&Â box2.Image != null &&Â box3.Image != null &&Â box4.Image != null &&Â box5.Image != null
&&Â box6.Image != null &&Â box7.Image != null &&Â box8.Image != null &&Â box9.Image != null)
{
// DRAW occurs
Draw();
}
private void resetBtn_Click(object sender, EventArgs e)
{
reset();
}
public void reset()
{
lblDraw.Visible = false;
lblDraw.Enabled = false;
box1.Image = null;
box2.Image = null;
box3.Image = null;
box4.Image = null;
box5.Image = null;
box6.Image = null;
box7.Image = null;
box8.Image = null;
box9.Image = null;
displayAgain();
}
public void displayAgain()
{
box1.Enabled = true;
box2.Enabled = true;
box3.Enabled = true;
box4.Enabled = true;
box5.Enabled = true;
box6.Enabled = true;
box7.Enabled = true;
box8.Enabled = true;
box9.Enabled = true;
}
It stops when the game is done few times i mean when their is some winning occurs then it halts at when the draw label appears. And reset button is no more clickable.
There is no exception occurs at any point.
ASKER
there are many if statements to check to see who is winner thats why i didnt included anyway here is the following checkall() function look like
public void checkAll()
    {
      if (CompareImages(box1.Image, box2.Image, box3.Image))
      {
        DisplayWinner();
      }
      else if (CompareImages(box4.Image, box5.Image, box6.Image))
      {
        DisplayWinner();
      }
      else if (CompareImages(box7.Image, box8.Image, box9.Image))
      {
        DisplayWinner();
      }
      else if (CompareImages(box1.Image, box5.Image, box9.Image))
      {
        DisplayWinner();
      }
      else if (CompareImages(box3.Image, box5.Image, box7.Image))
      {
        DisplayWinner();
      }
      else if (CompareImages(box1.Image, box4.Image, box7.Image))
      {
        DisplayWinner();
      }
      else if (CompareImages(box2.Image, box5.Image, box8.Image))
      {
        DisplayWinner();
      }
      else if (CompareImages(box3.Image, box6.Image, box9.Image))
      {
        DisplayWinner();
      }
      else if (box1.Image != null && box2.Image != null && box3.Image != null && box4.Image != null && box5.Image != null
      && box6.Image != null && box7.Image != null && box8.Image != null && box9.Image != null)
      {
        Draw();
       Â
      }
    }
public void checkAll()
    {
      if (CompareImages(box1.Image,
      {
        DisplayWinner();
      }
      else if (CompareImages(box4.Image,
      {
        DisplayWinner();
      }
      else if (CompareImages(box7.Image,
      {
        DisplayWinner();
      }
      else if (CompareImages(box1.Image,
      {
        DisplayWinner();
      }
      else if (CompareImages(box3.Image,
      {
        DisplayWinner();
      }
      else if (CompareImages(box1.Image,
      {
        DisplayWinner();
      }
      else if (CompareImages(box2.Image,
      {
        DisplayWinner();
      }
      else if (CompareImages(box3.Image,
      {
        DisplayWinner();
      }
      else if (box1.Image != null && box2.Image != null && box3.Image != null && box4.Image != null && box5.Image != null
      && box6.Image != null && box7.Image != null && box8.Image != null && box9.Image != null)
      {
        Draw();
       Â
      }
    }
ASKER
I have full TicTacToe game working apart from Draw so would be hard now to look at the program u asked me to look Mikal.
I have done on network,2 players and with computer but the draw functionality is some how not working not sure why?
Please help by looking at my code.
I have done on network,2 players and with computer but the draw functionality is some how not working not sure why?
Please help by looking at my code.
what variable is this?
sta.compdraws++;
sta.compdraws++;
ASKER
This variable is from another class even if i remove this sta.compdraws still it halts. Remaining whole functionality works. And one thing i found which is wierd which is when ist time draw occurs i click reset button and it reset the pictureboxes when draw happend for 2nd time it halts then and no exception is thrown as i added few try catch as well.
But i would tell you abt this variable
Statistics.cs
public partial class Statistics : Form
  {
    public int userwin;
    public int computerwins;
    public int compdraws;
    public int comptotal;
    public int usertotal;
   Â
    public Statistics()
    {
      InitializeComponent();
    }
    private void resetButton_Click(object sender, EventArgs e)
    {
      compdraws = 0;
      comptotal = 0;
      userwin = 0;
      computerwins = 0;
      usertotal = 0;
      Map();  Â
    }
public void Map()
    {
      this.computerWinsLabel.Tex t = this.computerwins.ToString ();
      this.userWinsLabel.Text = this.userwin.ToString();
      this.vsComputerDrawsLabel. Text = this.compdraws.ToString();
      this.computerTotalScoreLab el.Text = this.comptotal.ToString();
      this.userTotalScoreLabel.T ext = this.usertotal.ToString();
      this.Refresh();
    }
tictactoe.cs
public void checkAll()
    {
      try
      {
        if (CompareImages(box1.Image, box2.Image, box3.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box4.Image, box5.Image, box6.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box7.Image, box8.Image, box9.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box1.Image, box5.Image, box9.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box3.Image, box5.Image, box7.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box1.Image, box4.Image, box7.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box2.Image, box5.Image, box8.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box3.Image, box6.Image, box9.Image))
        {
          DisplayWinner();
        }
        else if (box1.Image != null && box2.Image != null && box3.Image != null && box4.Image != null && box5.Image != null
        && box6.Image != null && box7.Image != null && box8.Image != null && box9.Image != null)
        {
          Draw();
        }
      }
      catch (Exception e3)
      {
        MessageBox.Show(e3.ToStrin g());
      }
    }
public void Draw()
    {
      try
      {
        lblDraw.Visible = true;
        lblDraw.Enabled = true;
        //sta.compdraws++;
      }
      catch (Exception e)
      {
        MessageBox.Show(e.ToString ());
      }
    }
 private void resetBtn_Click(object sender, EventArgs e)
    {
      reset();
      // displayAgain();
    }
 public void displayAgain()
    {
      box1.Enabled = true;
      box2.Enabled = true;
      box3.Enabled = true;
      box4.Enabled = true;
      box5.Enabled = true;
      box6.Enabled = true;
      box7.Enabled = true;
      box8.Enabled = true;
      box9.Enabled = true;
    }
    private void switchPlayers()
    {
      checkAll();
      if (player == 1)
      {
        player = 2;
      }
      else
      {
        player = 1;
      }
    }
public void reset()
    {
      try
      {
        lblDraw.Visible = false;
        lblDraw.Enabled = false;
        box1.Image = null;
        box2.Image = null;
        box3.Image = null;
        box4.Image = null;
        box5.Image = null;
        box6.Image = null;
        box7.Image = null;
        box8.Image = null;
        box9.Image = null;
        displayAgain();
      }
      catch (Exception e1)
      {
        MessageBox.Show(e1.ToStrin g());
      }
    }
But i would tell you abt this variable
Statistics.cs
public partial class Statistics : Form
  {
    public int userwin;
    public int computerwins;
    public int compdraws;
    public int comptotal;
    public int usertotal;
   Â
    public Statistics()
    {
      InitializeComponent();
    }
    private void resetButton_Click(object sender, EventArgs e)
    {
      compdraws = 0;
      comptotal = 0;
      userwin = 0;
      computerwins = 0;
      usertotal = 0;
      Map();  Â
    }
public void Map()
    {
      this.computerWinsLabel.Tex
      this.userWinsLabel.Text = this.userwin.ToString();
      this.vsComputerDrawsLabel.
      this.computerTotalScoreLab
      this.userTotalScoreLabel.T
      this.Refresh();
    }
tictactoe.cs
public void checkAll()
    {
      try
      {
        if (CompareImages(box1.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box4.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box7.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box1.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box3.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box1.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box2.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box3.Image,
        {
          DisplayWinner();
        }
        else if (box1.Image != null && box2.Image != null && box3.Image != null && box4.Image != null && box5.Image != null
        && box6.Image != null && box7.Image != null && box8.Image != null && box9.Image != null)
        {
          Draw();
        }
      }
      catch (Exception e3)
      {
        MessageBox.Show(e3.ToStrin
      }
    }
public void Draw()
    {
      try
      {
        lblDraw.Visible = true;
        lblDraw.Enabled = true;
        //sta.compdraws++;
      }
      catch (Exception e)
      {
        MessageBox.Show(e.ToString
      }
    }
 private void resetBtn_Click(object sender, EventArgs e)
    {
      reset();
      // displayAgain();
    }
 public void displayAgain()
    {
      box1.Enabled = true;
      box2.Enabled = true;
      box3.Enabled = true;
      box4.Enabled = true;
      box5.Enabled = true;
      box6.Enabled = true;
      box7.Enabled = true;
      box8.Enabled = true;
      box9.Enabled = true;
    }
    private void switchPlayers()
    {
      checkAll();
      if (player == 1)
      {
        player = 2;
      }
      else
      {
        player = 1;
      }
    }
public void reset()
    {
      try
      {
        lblDraw.Visible = false;
        lblDraw.Enabled = false;
        box1.Image = null;
        box2.Image = null;
        box3.Image = null;
        box4.Image = null;
        box5.Image = null;
        box6.Image = null;
        box7.Image = null;
        box8.Image = null;
        box9.Image = null;
        displayAgain();
      }
      catch (Exception e1)
      {
        MessageBox.Show(e1.ToStrin
      }
    }
Try adding a lblDraw.Refresh();
public void Draw()
{
lblDraw.Visible = true;
lblDraw.Enabled = true;
lblDraw.Refresh();
sta.compdraws++;
}
public void Draw()
{
lblDraw.Visible = true;
lblDraw.Enabled = true;
lblDraw.Refresh();
sta.compdraws++;
}
ASKER
It doesnt work.
How about enabling them first .
lblDraw.Enabled = true;
lblDraw.Visible = true;
lblDraw.Refresh();
lblDraw.Enabled = true;
lblDraw.Visible = true;
lblDraw.Refresh();
ASKER
No its not working. Mikal i have found when the draw function is se is finished it goes in SwitchPlayer function I am not sure why?
Have you seen my code above as a whole? Did you found any issue you think?
Have you seen my code above as a whole? Did you found any issue you think?
there must be an event that is triggering.
Is there one triggering when you click the Image?
Is there one triggering when you click the Image?
ASKER
i dont think so can i send here my whole code. I can remove some if conditions which i made for winning or checking different moves.
You are not using any events?
ASKER
I am using Picturebox_Click events
    public int player = 1;
    static Random rnd = new Random();
    public PictureBox pressedPicBox;
    Statistics sta = new Statistics();
   Â
    public void DisplayWinner()
    {
      if (player == 1)
      {
        // add a bunch of stats to the list
        sta.userwin++;
        sta.usertotal++;
        MessageBox.Show("Player 1 win");
        reset1();
      }
      else if(player==2)
      {
        MessageBox.Show("Player 2 win");
        sta.computerwins++;
        sta.comptotal++;
        reset1();
      }
      sta.Map();
     Â
    }
   Â
    public void reset1()
    {
      try
      {
        lblDraw.Visible = false;
        lblDraw.Enabled = false;
        box1.Image = null;
        box2.Image = null;
        box3.Image = null;
        box4.Image = null;
        box5.Image = null;
        box6.Image = null;
        box7.Image = null;
        box8.Image = null;
        box9.Image = null;
        displayAgain();
      }
      catch (Exception e1)
      {
        MessageBox.Show(e1.ToStrin g());
      }
    }
    public void displayAgain()
    {
      box1.Enabled = true;
      box2.Enabled = true;
      box3.Enabled = true;
      box4.Enabled = true;
      box5.Enabled = true;
      box6.Enabled = true;
      box7.Enabled = true;
      box8.Enabled = true;
      box9.Enabled = true;
    }
    private void switchPlayers()
    {
      checkAll();
      if (player == 1)
      {
        player = 2;
      }
      else
      {
        player = 1;
      }
    }
    private void TicTacToe_Load(object sender, EventArgs e)
    {
      pictureBox1.Image = Image.FromFile("C:\\Docume nts and Settings\\hahmed\\My Documents\\family pics\\Atif.JPG");
      pictureBox2.Image = Image.FromFile("c:\\WINDOW S\\system3 2\\setup.b mp");
      pictureBox1.SizeMode = PictureBoxSizeMode.Stretch Image;
      pictureBox2.SizeMode = PictureBoxSizeMode.Stretch Image;
    }
    private void resetBtn_Click(object sender, EventArgs e)
    {
      reset1();
    }
    public void Draw()
    {
      try
      {
        lblDraw.Enabled = true;
        lblDraw.Visible = true;
       Â
        lblDraw.Refresh();
        sta.compdraws++;
      }
      catch (Exception e)
      {
        MessageBox.Show(e.ToString ());
      }
    }
    // Random Functionality
    public string comPlaceRand()
    {
      const string result = "123456789";
      return result[rnd.Next(result.Len gth)].ToSt ring();
    }
    private void box_Click(object sender, EventArgs e)
    {
      try
      {
        PictureBox pressedPicBox = (PictureBox)sender;
        pressedPicBox.SizeMode = PictureBoxSizeMode.Stretch Image;
        pressedPicBox.Image = pictureBox1.Image;
        pressedPicBox.Enabled = false;
        switchPlayers();
        // Alot of if conditions .. skipped
        else
        {
          int c = 1;
          while (c > 0)
          {
            PictureBox pb = (PictureBox)this.Controls[ "box" + comPlaceRand()];
            if (pb.Image == null)
            {
              pb.SizeMode = PictureBoxSizeMode.Stretch Image;
              pb.Image = pictureBox2.Image;
              pb.Enabled = false;
              c = 0;
            }
          }
        }
        switchPlayers();
      }
      catch (Exception e2)
      {
        MessageBox.Show(e2.ToStrin g());
      }
}
    public bool CompareImages(Image image1, Image image2, Image image3)
    {
      if (!Object.Equals(image1, image2))
      {
        return false;
      }
      if (!Object.Equals(image2, image3))
      {
        return false;
      }
      if ((image1 == null) || (image2 == null) || (image3 == null))
      {
        return false;
      }
      return true;
    }
    public void checkAll()
    {
      try
      {
        if (CompareImages(box1.Image, box2.Image, box3.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box4.Image, box5.Image, box6.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box7.Image, box8.Image, box9.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box1.Image, box5.Image, box9.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box3.Image, box5.Image, box7.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box1.Image, box4.Image, box7.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box2.Image, box5.Image, box8.Image))
        {
          DisplayWinner();
        }
        else if (CompareImages(box3.Image, box6.Image, box9.Image))
        {
          DisplayWinner();
        }
        else if (box1.Image != null && box2.Image != null && box3.Image != null && box4.Image != null && box5.Image != null
        && box6.Image != null && box7.Image != null && box8.Image != null && box9.Image != null)
        {
        //   Draw();
          MessageBox.Show("DRAW");
          sta.compdraws++;
          sta.Map();
          reset1();
       Â
        }
      }
      catch (Exception e3)
      {
        MessageBox.Show(e3.ToStrin g());
      }
    }
   Â
  }
}
    public int player = 1;
    static Random rnd = new Random();
    public PictureBox pressedPicBox;
    Statistics sta = new Statistics();
   Â
    public void DisplayWinner()
    {
      if (player == 1)
      {
        // add a bunch of stats to the list
        sta.userwin++;
        sta.usertotal++;
        MessageBox.Show("Player 1 win");
        reset1();
      }
      else if(player==2)
      {
        MessageBox.Show("Player 2 win");
        sta.computerwins++;
        sta.comptotal++;
        reset1();
      }
      sta.Map();
     Â
    }
   Â
    public void reset1()
    {
      try
      {
        lblDraw.Visible = false;
        lblDraw.Enabled = false;
        box1.Image = null;
        box2.Image = null;
        box3.Image = null;
        box4.Image = null;
        box5.Image = null;
        box6.Image = null;
        box7.Image = null;
        box8.Image = null;
        box9.Image = null;
        displayAgain();
      }
      catch (Exception e1)
      {
        MessageBox.Show(e1.ToStrin
      }
    }
    public void displayAgain()
    {
      box1.Enabled = true;
      box2.Enabled = true;
      box3.Enabled = true;
      box4.Enabled = true;
      box5.Enabled = true;
      box6.Enabled = true;
      box7.Enabled = true;
      box8.Enabled = true;
      box9.Enabled = true;
    }
    private void switchPlayers()
    {
      checkAll();
      if (player == 1)
      {
        player = 2;
      }
      else
      {
        player = 1;
      }
    }
    private void TicTacToe_Load(object sender, EventArgs e)
    {
      pictureBox1.Image = Image.FromFile("C:\\Docume
      pictureBox2.Image = Image.FromFile("c:\\WINDOW
      pictureBox1.SizeMode = PictureBoxSizeMode.Stretch
      pictureBox2.SizeMode = PictureBoxSizeMode.Stretch
    }
    private void resetBtn_Click(object sender, EventArgs e)
    {
      reset1();
    }
    public void Draw()
    {
      try
      {
        lblDraw.Enabled = true;
        lblDraw.Visible = true;
       Â
        lblDraw.Refresh();
        sta.compdraws++;
      }
      catch (Exception e)
      {
        MessageBox.Show(e.ToString
      }
    }
    // Random Functionality
    public string comPlaceRand()
    {
      const string result = "123456789";
      return result[rnd.Next(result.Len
    }
    private void box_Click(object sender, EventArgs e)
    {
      try
      {
        PictureBox pressedPicBox = (PictureBox)sender;
        pressedPicBox.SizeMode = PictureBoxSizeMode.Stretch
        pressedPicBox.Image = pictureBox1.Image;
        pressedPicBox.Enabled = false;
        switchPlayers();
        // Alot of if conditions .. skipped
        else
        {
          int c = 1;
          while (c > 0)
          {
            PictureBox pb = (PictureBox)this.Controls[
            if (pb.Image == null)
            {
              pb.SizeMode = PictureBoxSizeMode.Stretch
              pb.Image = pictureBox2.Image;
              pb.Enabled = false;
              c = 0;
            }
          }
        }
        switchPlayers();
      }
      catch (Exception e2)
      {
        MessageBox.Show(e2.ToStrin
      }
}
    public bool CompareImages(Image image1, Image image2, Image image3)
    {
      if (!Object.Equals(image1, image2))
      {
        return false;
      }
      if (!Object.Equals(image2, image3))
      {
        return false;
      }
      if ((image1 == null) || (image2 == null) || (image3 == null))
      {
        return false;
      }
      return true;
    }
    public void checkAll()
    {
      try
      {
        if (CompareImages(box1.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box4.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box7.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box1.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box3.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box1.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box2.Image,
        {
          DisplayWinner();
        }
        else if (CompareImages(box3.Image,
        {
          DisplayWinner();
        }
        else if (box1.Image != null && box2.Image != null && box3.Image != null && box4.Image != null && box5.Image != null
        && box6.Image != null && box7.Image != null && box8.Image != null && box9.Image != null)
        {
        //   Draw();
          MessageBox.Show("DRAW");
          sta.compdraws++;
          sta.Map();
          reset1();
       Â
        }
      }
      catch (Exception e3)
      {
        MessageBox.Show(e3.ToStrin
      }
    }
   Â
  }
}
bool ignoreEvent  = false;
public void Draw()
    {
       ignoreEvent  = true;
      try
      {
        lblDraw.Enabled = true;
        lblDraw.Visible = true;
       Â
        lblDraw.Refresh();
        sta.compdraws++;
      }
      catch (Exception e)
      {
        MessageBox.Show(e.ToString ());
      }
      finally
      {
         ignoreEvent  = false;
       }
    }
private void box_Click(object sender, EventArgs e)
    {
      if(ignoreEvent == false)
     {
      try
      {
        PictureBox pressedPicBox = (PictureBox)sender;
        pressedPicBox.SizeMode = PictureBoxSizeMode.Stretch Image;
        pressedPicBox.Image = pictureBox1.Image;
        pressedPicBox.Enabled = false;
        switchPlayers();
        // Alot of if conditions .. skipped
        else
        {
          int c = 1;
          while (c > 0)
          {
            PictureBox pb = (PictureBox)this.Controls[ "box" + comPlaceRand()];
            if (pb.Image == null)
            {
              pb.SizeMode = PictureBoxSizeMode.Stretch Image;
              pb.Image = pictureBox2.Image;
              pb.Enabled = false;
              c = 0;
            }
          }
        }
        switchPlayers();
      }
      catch (Exception e2)
      {
        MessageBox.Show(e2.ToStrin g());
      }
   }
}
public void Draw()
    {
       ignoreEvent  = true;
      try
      {
        lblDraw.Enabled = true;
        lblDraw.Visible = true;
       Â
        lblDraw.Refresh();
        sta.compdraws++;
      }
      catch (Exception e)
      {
        MessageBox.Show(e.ToString
      }
      finally
      {
         ignoreEvent  = false;
       }
    }
private void box_Click(object sender, EventArgs e)
    {
      if(ignoreEvent == false)
     {
      try
      {
        PictureBox pressedPicBox = (PictureBox)sender;
        pressedPicBox.SizeMode = PictureBoxSizeMode.Stretch
        pressedPicBox.Image = pictureBox1.Image;
        pressedPicBox.Enabled = false;
        switchPlayers();
        // Alot of if conditions .. skipped
        else
        {
          int c = 1;
          while (c > 0)
          {
            PictureBox pb = (PictureBox)this.Controls[
            if (pb.Image == null)
            {
              pb.SizeMode = PictureBoxSizeMode.Stretch
              pb.Image = pictureBox2.Image;
              pb.Enabled = false;
              c = 0;
            }
          }
        }
        switchPlayers();
      }
      catch (Exception e2)
      {
        MessageBox.Show(e2.ToStrin
      }
   }
}
ASKER
Still the same. It halts
im so stuck . Can you step through it?
ASKER
What you mean step through it?
ASKER
I did and as i said after draw it goes in switchplayer() and then in random functionality and goes through
following code continously and doesnt come out.
 while (c > 0)
          {
            PictureBox pb = (PictureBox)this.Controls[ "box" + comPlaceRand()];
            if (pb.Image == null)
            {
              pb.SizeMode = PictureBoxSizeMode.Stretch Image;
              pb.Image = pictureBox2.Image;
              pb.Enabled = false;
              c = 0;
            }
following code continously and doesnt come out.
 while (c > 0)
          {
            PictureBox pb = (PictureBox)this.Controls[
            if (pb.Image == null)
            {
              pb.SizeMode = PictureBoxSizeMode.Stretch
              pb.Image = pictureBox2.Image;
              pb.Enabled = false;
              c = 0;
            }
If there all checked then it will never come out. Your only setting it to 0 if one of the boxes are null.
ASKER
so what could be the solution?
only execute the loop if there  not all checked.
ASKER
I am now confused. I think I have workaround which is not very good but atleast i just want to make it working thats all which will be
else if (box1.Image != null &&Â box2.Image != null &&Â box3.Image != null &&Â box4.Image != null &&Â box5.Image != null
        && box6.Image != null && box7.Image != null && box8.Image != null && box9.Image != null)
        {
          MessageBox.Show("DRAW");
          sta.compdraws++;
          sta.Map();
          reset1();
       Â
        }
Adding reset option here and without clicking any reset button it will reset itself.
else if (box1.Image != null &&Â box2.Image != null &&Â box3.Image != null &&Â box4.Image != null &&Â box5.Image != null
        && box6.Image != null && box7.Image != null && box8.Image != null && box9.Image != null)
        {
          MessageBox.Show("DRAW");
          sta.compdraws++;
          sta.Map();
          reset1();
       Â
        }
Adding reset option here and without clicking any reset button it will reset itself.
Your loop is looking for the unclicked box. If there are non then it will be an infinite loop.
ASKER
when the draw happens all boxes are clicked that what was meant to do.
 "if there are none then it will be an infinite loop"??
 "if there are none then it will be an infinite loop"??
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Mikal Thanks anyway as i cant do any more changes i did the work around and it works. But thanks a million anyway.
No problem.
{
// Where is the originating If statement?
else if (box1.Image != null &&Â box2.Image != null &&Â box3.Image != null &&Â box4.Image != null &&Â box5.Image != null
&&Â box6.Image != null &&Â box7.Image != null &&Â box8.Image != null &&Â box9.Image != null)
{