package com.codegym.games.ticktacktoe;
import com.codegym.engine.cell.*;
public class TicTacToeGame extends Game {
private boolean isGameStopped;
private int[][] model = new int[3][3];
private int currentPlayer;
public void initialize(){
setScreenSize(3, 3);
startGame();
updateView();
}
public void startGame(){
isGameStopped = false;
currentPlayer = 1;
for(int i = 0; i < model.length; i++){
for(int j = 0; j < model[i].length; j++){
model[i][j] = 0;
updateCellView(i, j, 0);
}
}
}
public void updateCellView(int x, int y, int value){
String text = "";
Color cellColor = Color.WHITE;
Color textColor = Color.WHITE;
switch(value){
case 0: text = " ";
textColor = Color.WHITE;
break;
case 1: text = "X";
textColor = Color.RED;
break;
case 2: text = "O";
textColor = Color.BLUE;
break;
default:
break;
}
//setCellValue(x, y, text);
setCellValueEx(x, y, cellColor, text, textColor);
}
public void updateView(){
for (int i = 0; i < model.length; i++){
for (int j = 0; j < model[i].length; j++){
updateCellView(i, j, model[i][j]);
}
}
}
public void onMouseLeftClick(int x, int y){
if (isGameStopped){
return;
}
if (model[x][y] != 0){
return;
}
model[x][y] = currentPlayer;
updateView();
currentPlayer = currentPlayer==1? 2 : 1;
}
}
According to the code check, my code didn't assign false to isGameStopped, but in line 17 it does!
Neu
Kommentare
- Beliebt
- Neu
- Alt
Sie müssen angemeldet sein um einen Kommentar zu hinterlassen
Auf dieser Seite gibt es noch keine Kommentare