This is my first time here on Stackoverflow, this question might have been asked before, but I had little trouble finding those threads. I'm currently working on a Tic Tac Toe Android Game, as my first project to make an app.
The case is I'm working on my PlayState-class where the main-part of the game is to take place. PlayState is to be a instance that appears when you've selected it in the Menu. This is how I've done it in PlayState:
As I have PlayState as an instance, not wanting to have any static methods. I also made an EndMechanism-class, that is created as an instance within PlayState. That class checks for Wins/Lose/Draw. The way I want to do this is to make each Tile (3x3) get a Character (X or O) tagged by a variable in a loop.
boardTileMark[row][col] = 'x';
As I've managed to do that by using the Character class:
boardTiles = new BoardTile[3][3]; // To make the Tiles 3 by 3
boardTileMark = new Character[boardTiles.length][boardTiles[0].length];
I've used the size of the real BoardTile to make the size numbers of marks. So everything so far works now.
And then it's the EndMechanism-class as an instance:
endMech = new EndMechanism();
Not to go into to much details everything works so far when I press a square, it gets a X or O (graphic) boardTile and also a char 'x' or 'o' is given parallell on boardTileMark.
This is the problem now:
As I want to check if it's a Win, draw or lose on EndMechanism, I'm realy not sure how to pick up those marks into EndMechanism, without copy over the values and then make the same code in EndMechanism.
This is how I set boardTileMark's to x or o.
public void markBoardTiles(){
for(int row = 0;row < boardTiles.length;row++){
for(int col = 0;col < boardTiles[0].length;col++){
if(boardTiles[row][col].selected() && boardTiles[row][col].cross()){
boardTileMark[row][col] = 'x';
}
else if(boardTiles[row][col].selected() && boardTiles[row][col].circle()){
boardTileMark[row][col] = 'o';
}
}
}
}
If there is something that is confusing please tell, and I'll describe it better. Thank you for your time :)
PS: I'm trying to make this game as solid as possible, so I can use it for another project. So keeping the game itself and the check for wins in same class is not what I intend to do.