Ask coding questions

← Back to all posts
Dots and boxes game in Java
jose1

Hello guys, Im new to programming and Im currently learning basic Java. For my final project we have to make a dots and boxes game using only what we have learned in class, which is switch, for loop, if, basic methods and functions and do while loops. If youre not familiar with dots and boxes, basically you just connect dots vertically or horizontally and whoever is able to make the line that creates a box with the other dots, can put their initials inside the box. In order to know whose initials can be in the box (player 1 or 2), I used a variable that increased by every turn and then I created an if condition where if the turn variable was an even number it meant it was player 2s turn and he could have his initial in the box if he completed the square, and if it was odd, it was player 1s turn . But with this condition, the initial inside the box changes from player 1 to player 2s initial in every turn, I dont know what else to do or how to fix this. Could you guy help me out?

contadorturnos++;

//placing initials
if (juego[0] == '-'&& juego[1] == '|'&& juego[2] == '-'&& juego[1] == '|') //these array indexes refer to the spaces in between the dots
{
if (contadorturnos%2!=0) {
juego[1]=simb1; //simb1 is the 1st players initial, the array
//index is where the initial is meant to go in
}
else juego[1]=simb2; //simb2 is the 2nd players initial
}

Voters
kivigamex
jose1
Comments
hotnewtop
[deleted]

Could you put this in a repl.it and then link the repl.it?

mwilki7

@barrycarter every time someone fails to link a repl, a kitten is punched
you don't want to know what happens to the kitten if an image of code is posted

[deleted]

@mwilki7 Well, great. I support linking to repl.it but I also hate kittens. Sort of a rock and a hard place here ;)