import java.awt.*; public class TwoPlayersGame extends Game{ int[][] gameStatus;//0 - unset, 1 - player1, 2 - player2 int size; int userScore; Window window; int movesCounter; User player1; User player2; private static int whoseTurn = 0; TwoPlayersGame(int size, Window w) { this.size = size; window = w; player1 = new User(window); player2 = new User(window); gameStatus = new int[size][size]; window = w; userScore = 0; movesCounter = 0; } public void playTheGame() { player1.start(); player2.start(); while(isGameNotEnded()) { synchronized(window) { while(whoseTurn%2 == 0) { try { player1.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } player1Turn();//tutaj tak naprawdę ruch był już wykonany, teraz tylko zapisujemy gdzie się ruszono player1.run();//moveDone = false // stary poczekaj while(whoseTurn%2 != 0) if(isGameNotEnded()) {//tu trzeba analogicznie pozwolić spać jeszcze nie wiem komu, bo najpierw sobie pozwolę. Dobranoc. Lordzik zamknij japę. try { player2.wait(); player2Turn(); } catch (InterruptedException e) { e.printStackTrace(); } } } } endGame(); } void player1Turn() { Point p; p = window.currentButton; //do score Usera dodaje punkty z tury gameStatus[p.x][p.y] = 1; movesCounter += 1; System.out.println("Teraz gra gracz1"); } void player2Turn() { Point p; p = window.currentButton; // p = ai.play(gameStatus); gameStatus[p.x][p.y] = 2; //wpisz p do GUI movesCounter += 1; System.out.println("Teraz gra gracz2"); } public boolean checkIfScored() { boolean scored = false; for(int i = 0; i < size; i++) { for(int j = 0; j < size; j++) { // window.buttons//coś się wymyśli } } return scored; } private void endGame() { //wyświetl punkty i zwycięzcę } private boolean isGameNotEnded() { return movesCounter < size * size; } public static void setWhoseTurn(int whoseTurn) { TwoPlayersGame.whoseTurn = whoseTurn; } public static void addTurn() { TwoPlayersGame.whoseTurn += 1; } }