Simple Tic Tac Toe game.

I am trying to develop the simple Tic Tac Toe game.
can any one tell me how should I assign the player at the start of the game I mean.which player starts first player 1 or player 2.

you could use an array to set whats placed on the grid and a for loop to create the grid. Then simply have a bool for which players go it is, or as i somtimes have 1 or 2 that loops. (i only usually do this for GUI as bools can be weird).

so if its 1 then its player ones go and if its two then its player twos. Then when a box is clicked it would place a players mark in the array. so arr.push(clicked space:int);

sorry but did not understood.

ok, ill try to explain a little clearer, i did ramble a tad :smile:. ill also write some pseudo.
Heres a more simple idea:

var Player1 = true;
var player1Count = 0;
var Player1Texture : Texture;

var Player2 = false;
var Player2Count = 0;
var Player1Texture : Texture;

var B1Clicked = false;
var B1T : Texture;

function OnGUI () {
if(GUI.Button(Rect(x,y,x1,x2),B1T  Player1  B1Clicked == false); {
      Player1Count++;
      B1T = Player1Texture;
      }
if(GUI.Button(Rect(x,y,x1,x2),B1T  Player2  B1Clicked == false); {
      Player2Count++;
      B1T =  Player2Texture;
      }

and so on, this is a very long winded way and would take a while to set up all of the boxes and the code would be unessential long, so you should look into for loops for creating the buttons and arrays for holding which buttons have been clicked ect so you can tell when 3 have been matched.

I know there’s a video on vimeo…

which video and where

wow, you seem really good at coding :confused: im supprised you havn’t been able to acheive this :confused: can’t you just use a bool that holds individual data for every box?

I was not able to achieve this.I am not a programmer.And dont have much idea about programming.I take help of forums n google and try to do.

can u plzz tell me how should I do.I understood that I should set a bool for each of them.

Here is my modify code.still not able to figure it out.when i click a button it displays “X” and again when i click the same button it displays “O”. i m using the vairable turn.when turn = -1 it displays “X” and when turn = 1 it displays “O”.help me out.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class tictactoe_ : MonoBehaviour
{

public string stringToEdit_player1 = " Enter Your Name";
public string stringToEdit_player2 = " Enter Your Name ";

public bool m_show = true;
public bool m_click = false;

public int score = 0;
public int round = 1;

public int turn = -1;
public int player_1;
public int player_2;

public bool _isX = false;

public float starttime = 0.0f;
public float timelimit = 30.0f;

public string tempLabel;
public List m_tictacoptionList;
// Use this for initializatio
void Start()
{
m_tictacoptionList = new List();
m_tictacoptionList.Add(new tictacoptionClass(“”, 50.0f, 50.0f, false)); // make this all false to true.
m_tictacoptionList.Add(new tictacoptionClass(“”, 50.0f, 100.0f, false));
m_tictacoptionList.Add(new tictacoptionClass(“”, 50.0f, 150.0f, false));
m_tictacoptionList.Add(new tictacoptionClass(“”, 100.0f, 50.0f, false));
m_tictacoptionList.Add(new tictacoptionClass(“”, 100.0f, 100.0f, false));
m_tictacoptionList.Add(new tictacoptionClass(“”, 100.0f, 150.0f, false));
m_tictacoptionList.Add(new tictacoptionClass(“”, 150.0f, 50.0f, false));
m_tictacoptionList.Add(new tictacoptionClass(“”, 150.0f, 100.0f, false));
m_tictacoptionList.Add(new tictacoptionClass(“”, 150.0f, 150.0f, false));
}

// Update is called once per frame
void Update()
{

}

void OnGUI()
{
if (m_show)
{
GUI.Box(new Rect(40, 20, 500, 450), “Tic Tac Toe”);
GUI.Label(new Rect(70, 50, 50, 30), “Player 1”);
GUI.Label(new Rect(380, 50, 50, 30), “Player 2”);
GUI.Label(new Rect(70, 70, 50, 30), “Name :”);
GUI.Label(new Rect(380, 70, 50, 30), “Name :”);

stringToEdit_player1 = GUI.TextField(new Rect(70, 90, 100, 20), stringToEdit_player1, 10);
stringToEdit_player2 = GUI.TextField(new Rect(380, 90, 100, 20), stringToEdit_player2, 10);

if (GUI.Button(new Rect(250, 170, 50, 30), “Start”))
{
// if (stringToEdit_player1.Length > 0 stringToEdit_player2.Length > 0 )
{
m_show = !m_show;
m_click = !m_click;
}
}
}

if (m_click)
{
GUI.Box(new Rect(40, 20, 500, 450), " Welcome");

GUI.Label(new Rect(250, 50, 50, 30), “Round :”);
GUI.Button(new Rect(300, 50, 30, 25), round.ToString());

GUI.Label(new Rect(70, 70, 50, 30), “Player 1”);
GUI.Label(new Rect(70, 90, 50, 30), stringToEdit_player1);
GUI.Label(new Rect(70, 110, 50, 30), “Score :”);
GUI.Button(new Rect(115, 110, 30, 25), score.ToString());
GUI.Button(new Rect(70, 130, 30, 25), “X”);

GUI.Label(new Rect(380, 70, 50, 30), “Player 2”);
GUI.Label(new Rect(380, 90, 50, 30), stringToEdit_player2);
GUI.Label(new Rect(380, 110, 50, 30), “Score :”);
GUI.Button(new Rect(425, 110, 30, 25), score.ToString());
GUI.Button(new Rect(380, 130, 30, 25), “O”);

GUI.Label(new Rect(250, 420, 50, 30), “Timer :”);

for (int a = 0; a < 9; a++)
{

if (GUI.Button(new Rect(150 + (m_tictacoptionList[a].m_Xoffset), 150 + (m_tictacoptionList[a].m_Yoffset), 50, 50), m_tictacoptionList[a].m_stringTODisplay))
{
m_tictacoptionList[a].m_bool = !m_tictacoptionList[a].m_bool; //omit this line.

}
if (m_tictacoptionList[a].m_bool) // put this if loop in the above if loop and it works.
{
if (turn == -1)
{
Debug.Log(“a :” + a);

m_tictacoptionList[a].m_stringTODisplay = “X”;
m_tictacoptionList[a].m_bool = false;
Debug.Log(" m_tictacoptionList m_bool :" + m_tictacoptionList[a].m_bool);
turn = 1;
}
else if (turn == 1)
{
Debug.Log(“a :” + a);
Debug.Log(" m_tictacoptionList m_bool :" + m_tictacoptionList[a].m_bool);

m_tictacoptionList[a].m_stringTODisplay = “O”;
m_tictacoptionList[a].m_bool = false;
turn = -1;
}

}
}

}
}

public class tictacoptionClass
{
public string m_stringTODisplay;
public float m_Xoffset = 0.0f;
public float m_Yoffset = 0.0f;
public bool m_bool;
public tictacoptionClass(string a_stringTODisplay, float a_xoffset, float a_yoffset, bool _bool)
{
m_stringTODisplay = a_stringTODisplay;
m_Xoffset = a_xoffset;
m_Yoffset = a_yoffset;
m_bool = _bool;
}
}
}

THIS WORKS NOW WELL

finally figured it out.was setting my bool to false first and every time i clicked the button I used to make it true.So it used to display both the string on the same button.