# Help with placing a shape on grid for tic tac toe. My code is shown below

**URL:** https://discourse.processing.org/t/help-with-placing-a-shape-on-grid-for-tic-tac-toe-my-code-is-shown-below/25846
**Category:** Coding Questions
**Created:** [December 1, 2020, 1:35am UTC](https://discourse.processing.org/t/help-with-placing-a-shape-on-grid-for-tic-tac-toe-my-code-is-shown-below/25846 "2020-12-01T01:35:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![seannyb2000](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@seannyb2000](https://discourse.processing.org/u/seannyb2000)
#### Post date: [December 1, 2020, 1:35am UTC](https://discourse.processing.org/t/help-with-placing-a-shape-on-grid-for-tic-tac-toe-my-code-is-shown-below/25846/1 "2020-12-01T01:35:07Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

char player=‘X’+‘O’; // inputs 2 players

int cols=3;  
int rows=3;

Cell board= new Cell[cols][rows];

void setup() {  
size(600,600);

for(int i=0; i\<cols; i++) {  
for(int j=0; j\<rows; j++) {  
board[i][j]= new Cell(i_150,j_150,150,150);  
}  
}  
}

void draw(){

for(int i=0; i\<cols; i++) {  
for(int j=0; j\<rows; j++) {  
board[i][j].display();  
}  
}

```
if(mousePressed){ 

```

if(mouseButton == RIGHT){  
player=‘X’;  
stroke(0,255,0); // colour of X  
line(mouseX-50,mouseY-50,mouseX+50,mouseY+50);  
line(mouseX+50,mouseY-50,mouseX-50,mouseY+50); //Right click the mouse to spawn an X  
println(“Player O’s turn”); /_Prints when player X took their turn  
to indicate player O’s turn_/  
}  
if(mouseButton == LEFT){  
player=‘O’;  
stroke(255,0,0); //colour of O  
ellipse(mouseX,mouseY,50,50); //Left click the mouse to spawn an O  
println(“Player X’s turn”); /\*Prints when player O took their turn \*/

}  
}  
}

class Cell {  
float x;  
float y;  
float w;  
float h;  
int state;  
Cell (float \_x, float \_y, float \_w, float \_h) {  
x= \_x;  
y= \_y;  
w= \_w;  
h= \_h;  
}  
void display() {  
stroke(0);  
fill(255,255,255);  
tint (rgb,alpha);  
rect(x,y,w,h);  
}  
}

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [December 2, 2020, 12:28am UTC](https://discourse.processing.org/t/help-with-placing-a-shape-on-grid-for-tic-tac-toe-my-code-is-shown-below/25846/2 "2020-12-02T00:28:13Z")

</div>

Hi,

Welcome to the community! 😉

Few things before we start digging into the real issue :

- Nice tip : you can auto format your code by pressing `Ctrl + T` in the Processing IDE. It’s going to correct indentations and spaces.

- On the forum, you need to always format your code inside code blocks by using the `</>` button. You can edit your previous post to change that. Multi line code is between those characters : ```

- When starting a new thread, your issue description shouldn’t be inside the title but rather in the body of the message. Also be descriptive otherwise people are not willing to answer you 😉  
Anyway check the posting guidelines and the FAQ :

---

<div class="post-metadata">

### Author: ![seannyb2000](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@seannyb2000](https://discourse.processing.org/u/seannyb2000)
#### Post date: [December 2, 2020, 12:51am UTC](https://discourse.processing.org/t/help-with-placing-a-shape-on-grid-for-tic-tac-toe-my-code-is-shown-below/25846/3 "2020-12-02T00:51:04Z")

</div>

Oh didn’t know most of this have only joined recently, thank you very much
