Skip to content
Snippets Groups Projects
Commit b088c5a2 authored by Ricardo Müller's avatar Ricardo Müller
Browse files

Merge branch 'dev-endbildschirm' into 'main'

end bildschirm ist fertit aber muss noch mal wincheck methode verarbeiten

See merge request !8
parents e645a3c0 ca040aa0
No related branches found
No related tags found
2 merge requests!9Cleaned up and re-added GameBoard,!8end bildschirm ist fertit aber muss noch mal wincheck methode verarbeiten
......@@ -8,7 +8,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
......@@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/tictactoeswtha2" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -10,6 +10,7 @@ import java.io.IOException;
* Main class
*/
public class Application extends javafx.application.Application {
Stage window;
/**
* starts the program
* @param stage
......@@ -17,12 +18,12 @@ public class Application extends javafx.application.Application {
*/
@Override
public void start(Stage stage) throws IOException {
window = stage;
FXMLLoader fxmlLoader = new FXMLLoader(Application.class.getResource("game-view.fxml"));
Scene scene = new Scene(fxmlLoader.load());
stage.setTitle("TicTacToe!");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
window.setTitle("TicTacToe!");
window.setScene(scene);
window.show();
}
/**
......
package com.example.tictactoeswtha2;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.IOException;
/**
* Controller for the game-view
......@@ -24,7 +34,7 @@ public class Controller {
* the buttons on the field
*/
@FXML
private Button b00, b01, b02, b10, b11, b12, b20, b21, b22;
private Button b00, b01, b02, b10, b11, b12, b20, b21, b22, restartBtn;
/**
* the labels beneath the buttons that display the character
*/
......@@ -36,21 +46,55 @@ public class Controller {
*/
@FXML
private Label turnLabel;
/**
* to start new window
*/
private Stage stage;
/**
* gameBoard access
*/
private GameBoard gameBoard = new GameBoard();
/**
* turns the player sign and checks the game state
* @param row the row of the tile
* @param column the column of the tile
*/
private void click(int row, int column) {
private void click(int row, int column) throws IOException {
// Todo: Check for win
if (turnSign == 'X') {
turnSign = 'O';
turnLabel.setText("O's turn");
} else {
turnSign = 'X';
turnLabel.setText("X's turn");
if(gameBoard.winCheck() ==1 || gameBoard.winCheck() == 2)
{
stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.setTitle("neu spiel");
stage.setMinWidth(250);
Label label = new Label();
label.setText("willst du neu Spiel starten?");
Button yesBtn = new Button("Ja");
Button noBtn = new Button("Nein");
yesBtn.setOnAction(e->{
restart();
stage.close();
});
noBtn.setOnAction(e->{
stage.close();
});
VBox layout = new VBox(10);
layout.getChildren().addAll(label, yesBtn, noBtn);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout);
stage.setScene(scene);
stage.showAndWait();
}else
{
if (turnSign == 'X') {
turnSign = 'O';
turnLabel.setText("O's turn");
} else {
turnSign = 'X';
turnLabel.setText("X's turn");
}
}
}
......@@ -59,7 +103,7 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB00(ActionEvent e) {
public void clickB00(ActionEvent e) throws IOException {
int row = 0, column = 0;
l00.setText("" + turnSign);
b00.setVisible(false);
......@@ -70,7 +114,7 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB01(ActionEvent e) {
public void clickB01(ActionEvent e) throws IOException {
int row = 0, column = 1;
l01.setText("" + turnSign);
b01.setVisible(false);
......@@ -81,7 +125,7 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB02(ActionEvent e) {
public void clickB02(ActionEvent e) throws IOException {
int row = 0, column = 2;
l02.setText("" + turnSign);
b02.setVisible(false);
......@@ -92,7 +136,7 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB10(ActionEvent e) {
public void clickB10(ActionEvent e) throws IOException {
int row = 1, column = 0;
l10.setText("" + turnSign);
b10.setVisible(false);
......@@ -103,7 +147,7 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB11(ActionEvent e) {
public void clickB11(ActionEvent e) throws IOException {
int row = 1, column = 1;
l11.setText("" + turnSign);
b11.setVisible(false);
......@@ -114,7 +158,7 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB12(ActionEvent e) {
public void clickB12(ActionEvent e) throws IOException {
int row = 1, column = 2;
l12.setText("" + turnSign);
b12.setVisible(false);
......@@ -125,7 +169,7 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB20(ActionEvent e) {
public void clickB20(ActionEvent e) throws IOException {
int row = 2, column = 0;
l20.setText("" + turnSign);
b20.setVisible(false);
......@@ -136,7 +180,7 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB21(ActionEvent e) {
public void clickB21(ActionEvent e) throws IOException {
int row = 2, column = 1;
l21.setText("" + turnSign);
b21.setVisible(false);
......@@ -147,10 +191,39 @@ public class Controller {
* show the label
* @param e obligatory ActionEvent
*/
public void clickB22(ActionEvent e) {
public void clickB22(ActionEvent e) throws IOException {
int row = 2, column = 2;
l22.setText("" + turnSign);
b22.setVisible(false);
click(row, column);
}
/**
* start new Game
*/
public void restart(){
b00.setVisible(true);
b01.setVisible(true);
b02.setVisible(true);
b10.setVisible(true);
b11.setVisible(true);
b12.setVisible(true);
b20.setVisible(true);
b21.setVisible(true);
b22.setVisible(true);
l00.setText("");
l01.setText("");
l02.setText("");
l10.setText("");
l11.setText("");
l12.setText("");
l20.setText("");
l21.setText("");
l22.setText("");
turnSign = 'X';
turnLabel.setText("X's turn");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment