errr..juz to let u know how my design looks like
(these below are the names given to the buttons in case u are wondering)
btn11 btn12 btn13
btn21 btn22 btn23
btn31 btn32 btn33

btnPlayer1 btnPlayer2

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace tictactoe
{
public partial class TTT : Form
{
public TTT()
{
InitializeComponent();
}
private void btn22_Click(object sender, EventArgs e)
{
playGame(btn22);
}
private void btn11_Click(object sender, EventArgs e)
{
playGame(btn11);
}
private void btn12_Click(object sender, EventArgs e)
{
playGame(btn12);
}
private void btn13_Click(object sender, EventArgs e)
{
playGame(btn13);
}
private void btn21_Click(object sender, EventArgs e)
{
playGame(btn21);
}
private void btn23_Click(object sender, EventArgs e)
{
playGame(btn23);
}
private void btn31_Click(object sender, EventArgs e)
{
playGame(btn31);
}
private void btn32_Click(object sender, EventArgs e)
{
playGame(btn32);
}
private void btn33_Click(object sender, EventArgs e)
{
playGame(btn33);
}
private void btnPlayer1_Click(object sender, EventArgs e)
{
btnPlayer1.Enabled = false;
player1 = true;
player2 = false;
}
private void btnPlayer2_Click(object sender, EventArgs e)
{
btnPlayer2.Enabled = false;
player1 = false;
player2 = true;
}
private void TTT_Load(object sender, EventArgs e)
{
bool player1 = false, player2 = false;
string str11 = "0" , str12 = "0" , str13 "0"
str21 = "0" , str22 = "0" , str23 "0"; // for this case i duno wats wrong wif juz shows there is an error...
str31 = "0" , str32 = "0" , str33 "0";
}
private void playGame
{
if (player1 = false && player2 = false)

MessageBox.Show("select Player1's turn, then click on 1 tic tac toe box",
"select Player no", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
int cellPlace = 0
if (player1) cellUpdate "cell"10+1;
else if (player2) cellUpdate "cell" 10+2;
if ((player1) && (btn.Text == "")
{
btn.Text = "1" ;
btnPlayer1.Enabled = false ;
btnPlayer2.Enabled = true ;

updateCell(cellUpdate);
winGame();
player1 = false ;
player2 = true;
}
else if
{
btn.Text = "2" ;
btnPlayer1.Enabled = true ;
btnPlayer2.Enabled = false ;
updateCell(cellUpdate);
winGame();
player1 = true;
player2 = false;
}


}

private void updateCell (int cell)
{
switch (cell)
{
case 111: str11 = "1" ; break;
case 112: str11 = "2" ; break;
case 121: str12 = "1" ; break;
case 122: str12 = "2" ; break;
case 131: str13 = "1" ; break;
case 132: str13 = "2" ; break;
case 211: str21 = "1" ; break;
case 212: str21 = "2" ; break;
case 221: str22 = "1" ; break;
case 222: str22 = "2" ; break;
case 231: str23 = "1" ; break;
case 232: str23 = "2" ; break;
case 311: str31 = "1" ; break;
case 312: str31 = "2" ; break;
case 321: str32 = "1" ; break;
case 322: str32 = "2" ; break;
case 331: str33 = "1" ; break;
case 332: str33 = "2" ; break;

}
}
private void winGame()
{
if(player1)
{
if(str11 == "1" && str12 == "1" && str13 == "1") //frm me:here i wanna write OR and i know the symbol of Or is "||" but everytime i wanna write it...got some error
(str21 == "1" && str22 == "1" && str23 == "1")
(str31 == "1" && str32 == "1" && str33 == "1")
MessageBox.Show(" You won!!!","winner",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if(player1)
{
if(str11 == "2" && str12 == "2" && str13 == "2")
(str21 == "2" && str22 == "2" && str23 == "2")
(str31 == "2" && str32 == "2" && str33 == "2")
MessageBox.Show(" You won!!!",winner";
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}


some1..pls help me...i know how to do..but the part is tat there is error...and i dunno wat to do...pls help :!:

Dani AI

Generated

There are two kinds of problems in the code you posted: syntax/compile errors (missing semicolons, malformed statements, wrong method signature) and design/scope issues (variables declared inside TTT_Load, using = where you intend comparison, fragile per-cell string state). is correct about using || to join win conditions — that fixes only the win-check expression, not the other compile errors or the variable-scope problems.

Move game state to fields and simplify the board representation. A small, safer pattern is to use a 3x3 int array (0 empty, 1 player1, 2 player2) and store each button's coordinates in its Tag. Example pattern (put these as class members and methods, not inside TTT_Load):

private bool player1, player2;
private int[,] board = new int[3,3]; // 0 empty, 1 player1, 2 player2

private void playGame(System.Windows.Forms.Button btn)
{
    if (!player1 && !player2)
    {
        MessageBox.Show("Select a player first.","Select Player",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
        return;
    }
    if (btn.Text != "") return;

    int current = player1 ? 1 : 2;
    btn.Text = current == 1 ? "1" : "2";

    var rc = btn.Tag.ToString().Split(',');
    int r = int.Parse(rc[0]), c = int.Parse(rc[1]);
    board[r,c] = current;

    if (CheckWin(current)) MessageBox.Show("You won!","Winner",MessageBoxButtons.OK,MessageBoxIcon.Information);

    player1 = !player1; player2 = !player2;
}

private bool CheckWin(int p)
{
    for (int i = 0; i < 3; i++)
    {
        if (board[i,0]==p && board[i,1]==p && board[i,2]==p) return true;
        if (board[0,i]==p && board[1,i]==p && board[2,i]==p) return true;
    }
    if (board[0,0]==p && board[1,1]==p && board[2,2]==p) return true;
    if (board[0,2]==p && board[1,1]==p && board[2,0]==p) return true;
    return false;
}

Practical fixes checklist:

  • Move player1, player2, and the cell state out of TTT_Load into class fields.
  • Change playGame signature to accept the clicked Button (as above).
  • Replace if (player1 = false && player2 = false) with if (!player1 && !player2) (assignment = vs logical check).
  • Fix missing ;, malformed MessageBox.Show(...) calls and incorrect else if(player1) (should be else if(player2)).
  • Consider using btn.Tag for coordinates to compute which board cell to update, rather than hard-coded numeric encodings.

Use the Visual Studio Error List and step the code with breakpoints after these fixes. Once it compiles, test one flow at a time: select player, click an empty cell, verify board[] changes, then verify win detection.

if(player1)
{
if (
(str11 == "1" && str12 == "1" && str13 == "1") ||
(str21 == "1" && str22 == "1" && str23 == "1") ||
(str31 == "1" && str32 == "1" && str33 == "1")
)
MessageBox.Show(" You won!!!","winner",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

Is that what you were going for?
If not, please post error text.

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.