Skip to content

Commit

Permalink
corrected errors, added screenshot and English titles
Browse files Browse the repository at this point in the history
  • Loading branch information
matiduda committed Jun 2, 2022
1 parent 0ea52f6 commit f1ac6c6
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<br />
<div align="center">
<h1>🕹️<br><br>❌ Ultimate <b>Tic Tac Toe</b>⭕<br><br>
<img src="images/visuals.png" width="90%"/>
<img src="images/screenshot.png" width="90%"/>
</h1>
</div>

Expand Down
Binary file removed images/screenshot.jpg
Binary file not shown.
Binary file added images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/visuals.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module com.example.ultimatetictactoe {
requires javafx.controls;
requires transitive javafx.controls;
requires javafx.fxml;
requires javafx.web;

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/tictactoe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Objects;

import javafx.fxml.FXMLLoader;
import tictactoe.logic.Logic;

public class Main extends Application {

Expand All @@ -37,6 +36,7 @@ public void start(Stage primaryStage) throws IOException {
primaryStage.show();

GameInfo info = new GameInfo(scene);
if(info != null) {};
}

public Parent sceneBuilder() throws IOException {
Expand Down Expand Up @@ -69,7 +69,6 @@ private void addResetButton(Pane backgroundPane){
timebox.add(resetButton, 1, 0);

resetButton.setOnAction(event ->{
System.out.println("Reset");

Pane bg = (Pane)backgroundPane.lookup("#GameArenaContainer");
bg.getChildren().removeIf(node -> node instanceof BigBoard);
Expand All @@ -89,7 +88,6 @@ private void addExitButton(Pane backgroundPane){
timebox.add(exitButton, 0, 0);

exitButton.setOnAction(event ->{
System.out.println("Exit");
Platform.exit();
});
}
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/tictactoe/arena/components/BigBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,31 @@
import tictactoe.logic.Logic;
import javafx.scene.layout.GridPane;

import java.util.ArrayList;

public class BigBoard extends GridPane {

private static final int[][] coords = new int[9][2];
private final Logic bigLogic;
private static Logic bigLogic;

public BigBoard() {
getStyleClass().add("BigBoard");
bigLogic = new Logic();
generateSmallBoards();
}

public int checkForWin() {
public static int checkForWin() {
return bigLogic.checkForWin();
}

private void generateSmallBoards() {
int ids = 1;

for (int i = 0; i < 3; i++) {
int idx = 0;
for (int j = 0; j < 3; j++) {
SmallBoard smallBoard = new SmallBoard(ids, this);
coords[ids - 1][0] = i;
coords[ids - 1][1] = j;
ids++;
add(smallBoard, i, j);
idx++;
}
}
}
Expand All @@ -59,21 +55,17 @@ public void updateLogic(int boardID, int won) {
}
}

// TODO: check if game is finished
public void setPlayerWon(int won) {
switch (won) {
case 1 -> {
System.out.println("-------- X WON WHOLE GAME --------");
GameInfo.showFinal("X Won");
GameInfo.stopTimer();
}
case 2 -> {
System.out.println("-------- O WON WHOLE GAME --------");
GameInfo.showFinal("O Won");
GameInfo.stopTimer();
}
case 3 -> {
System.out.println("------ DRAW OMG WHAT A MATCH -----");
GameInfo.showFinal("Draw");
GameInfo.stopTimer();
}
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/tictactoe/arena/components/SmallBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import javafx.geometry.VPos;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import tictactoe.arena.components.SmallBoardButton;

import java.util.ArrayList;

public class SmallBoard extends GridPane {
public static int boardState = 0;
Expand All @@ -32,11 +29,9 @@ public SmallBoard(int id, BigBoard bb) {
getStyleClass().add("SmallBoard");

for (int i = 0; i < 3; i++) {
int idx = 0;
for (int j = 0; j < 3; j++) {
SmallBoardButton button = new SmallBoardButton(i, j, this, bb);
SmallBoardButton button = new SmallBoardButton(i, j, this);
add(button, i, j);
idx++;
}
}
}
Expand All @@ -51,18 +46,15 @@ public void setPlayerWon(int whoWon) {

switch (boardState) {
case 1 -> {
System.out.println("X WON");
getStyleClass().add("WonX");
setBoardFull("X");
}
case 2 -> {
System.out.println("O WON");
getStyleClass().add("WonO");
setBoardFull("O");
}

case 3 -> {
System.out.println("DRAW");
getStyleClass().add("Draw");
setBoardFull("X/O");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

public class SmallBoardButton extends Button {

private BigBoard bigBoard;
private SmallBoard gameBoard;

public SmallBoardButton(int x, int y, SmallBoard board, BigBoard bigBoard) {
this.bigBoard = bigBoard;
public SmallBoardButton(int x, int y, SmallBoard board) {
this.gameBoard = board;
setFocused(false);

// CO SIE DZIEJE PO KLIKNIECIU
setOnAction(e -> {

// Check for bigBoard win
if (bigBoard.checkForWin() != 0) {
if (BigBoard.checkForWin() != 0) {
return;
}

Expand All @@ -39,8 +37,7 @@ public SmallBoardButton(int x, int y, SmallBoard board, BigBoard bigBoard) {
});
}

public void resetValue(){
public void resetValue() {
this.setText("");
}

}
2 changes: 1 addition & 1 deletion src/main/java/tictactoe/arena/controllers/GameInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void update(char player) {
setO();
}

showFinal("Teraz rusza się");
showFinal("Now moves player");
}

private static void disableXO() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fxml/GameWindow/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ImageView>
<VBox layoutX="473.0" layoutY="529.0" prefHeight="196.0" prefWidth="380.0">
<children>
<Label id="moveLabel" prefHeight="27.0" prefWidth="380.0" style="-fx-alignment: center; -fx-effect: dropshadow(three-pass-box, rgba(100,100, 100, 1), 0, 2, -3, 3);" text="Teraz rusza się" textAlignment="CENTER" textFill="#ffffffe5">
<Label id="moveLabel" prefHeight="27.0" prefWidth="380.0" style="-fx-alignment: center; -fx-effect: dropshadow(three-pass-box, rgba(100,100, 100, 1), 0, 2, -3, 3);" text="Now moves player" textAlignment="CENTER" textFill="#ffffffe5">
<font>
<Font size="27.0" />
</font>
Expand Down Expand Up @@ -52,7 +52,7 @@
</VBox>
<VBox id="timevbox" fx:id="timevbox" layoutX="471.0" layoutY="328.0" prefHeight="161.0" prefWidth="383.0">
<children>
<Label prefHeight="39.0" prefWidth="383.0" style="-fx-alignment: center; -fx-effect: dropshadow(three-pass-box, rgba(100,100, 100, 1), 0, 2, -3, 3);" text="Czas Rozgrywki:" textAlignment="CENTER" textFill="#ffffffe5">
<Label prefHeight="39.0" prefWidth="383.0" style="-fx-alignment: center; -fx-effect: dropshadow(three-pass-box, rgba(100,100, 100, 1), 0, 2, -3, 3);" text="Playtime:" textAlignment="CENTER" textFill="#ffffffe5">
<font>
<Font size="27.0" />
</font>
Expand Down

0 comments on commit f1ac6c6

Please sign in to comment.