Skip to content

Commit

Permalink
Segregate interface GameManager
Browse files Browse the repository at this point in the history
- Add maven javafx version property
  • Loading branch information
germandilio committed Jul 1, 2022
1 parent 052317e commit 282fc46
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<javafx.version>17.0.1</javafx.version>
<derby.version>10.15.2.0</derby.version>
<junit.version>5.8.1</junit.version>
</properties>
Expand All @@ -20,12 +21,12 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.1</version>
<version>${javafx.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void run() {

// handling input
handlingInput();

} catch (Exception e) {
System.out.println("Can't close socket");
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/ru/hse/germandilio/tetris/server/game/GameFlow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.hse.germandilio.tetris.server.game;

import ru.hse.germandilio.tetris.server.clienthandling.Connection;

public interface GameFlow {
boolean readyToStartGame();

void startGame(Connection client);

boolean readyToEndGame();

void endGame(Connection client);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package ru.hse.germandilio.tetris.server.game;

import ru.hse.germandilio.tetris.server.clienthandling.CommandSender;
import ru.hse.germandilio.tetris.server.clienthandling.Connection;

public interface GameManager {
Connection playerConnected(CommandSender clientHandler);

void disconnectPlayer(Connection client);

public interface GameManager extends GameFlow, GameSessions, PlayerConnection {
void setName(Connection client, String name);

void sendWaitingStartGame(Connection client);
Expand All @@ -16,17 +11,6 @@ public interface GameManager {

void sendNextBrick(Connection client, int indexInSequence);

boolean readyToStartGame();

void startGame(Connection client);

boolean readyToEndGame();

void endGame(Connection client);

void sendEndGameWithoutResults(Connection client);

void saveGameSessionResults(Connection client);

void getTopSessions(Connection client, int topNumber);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.hse.germandilio.tetris.server.game;

import ru.hse.germandilio.tetris.server.clienthandling.Connection;

public interface GameSessions {
void saveGameSessionResults(Connection client);

void getTopSessions(Connection client, int topNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.hse.germandilio.tetris.server.game;

import ru.hse.germandilio.tetris.server.clienthandling.CommandSender;
import ru.hse.germandilio.tetris.server.clienthandling.Connection;

public interface PlayerConnection {
Connection playerConnected(CommandSender clientHandler);

void disconnectPlayer(Connection client);
}
Original file line number Diff line number Diff line change
@@ -1,84 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="452.0" prefWidth="712.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.hse.germandilio.tetris.client.controllers.TetrisViewController">
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="452.0"
prefWidth="712.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.hse.germandilio.tetris.client.controllers.TetrisViewController">
<center>
<BorderPane prefHeight="657.0" prefWidth="453.0" style="-fx-border-color: #000000; -fx-border-width: 1;">
<center>
<GridPane fx:id="gridPanel" hgap="1" onDragDropped="#handleBrickDropped" onDragOver="#handleDragOver" prefHeight="450.0" prefWidth="503.0" style="lor: #000000; -fx-background-image: url(GameFieldBackground.png) " vgap="1">
<GridPane fx:id="gridPanel" hgap="1" onDragDropped="#handleBrickDropped" onDragOver="#handleDragOver"
prefHeight="450.0" prefWidth="503.0"
style="lor: #000000; -fx-background-image: url(GameFieldBackground.png) " vgap="1">
<opaqueInsets>
<Insets />
<Insets/>
</opaqueInsets>
<BorderPane.margin>
<Insets />
<Insets/>
</BorderPane.margin>
</GridPane>
</center>
</BorderPane>
</center>
<left>
<VBox prefHeight="501.0" prefWidth="270.0" style="-fx-spacing: 10; -fx-padding: 10;" BorderPane.alignment="CENTER">
<VBox prefHeight="501.0" prefWidth="270.0" style="-fx-spacing: 10; -fx-padding: 10;"
BorderPane.alignment="CENTER">
<HBox prefHeight="4.0" prefWidth="292.0" style="-fx-padding: 20;">
<Text fx:id="status" fill="#ff0101" text="Ожидание партнера" textAlignment="CENTER" wrappingWidth="251.87939453125" />
<Text fx:id="status" fill="#ff0101" text="Ожидание партнера" textAlignment="CENTER"
wrappingWidth="251.87939453125"/>
</HBox>
<HBox prefHeight="11.0" prefWidth="292.0" style="-fx-padding: 0;">
<children>
<Text text="Ваше имя: " textAlignment="CENTER" wrappingWidth="141.07421875" />
<Text fx:id="userName" text="" textAlignment="CENTER" wrappingWidth="89.8359375" />
<Text text="Ваше имя: " textAlignment="CENTER" wrappingWidth="141.07421875"/>
<Text fx:id="userName" text="" textAlignment="CENTER" wrappingWidth="89.8359375"/>
</children>
</HBox>
<HBox prefHeight="2.0" prefWidth="292.0" style="-fx-padding: 0;">
<children>
<Text text="Имя партнера: " textAlignment="CENTER" wrappingWidth="141.07421875" />
<Text fx:id="partnerName" text="" textAlignment="CENTER" wrappingWidth="89.8359375" />
<Text text="Имя партнера: " textAlignment="CENTER" wrappingWidth="141.07421875"/>
<Text fx:id="partnerName" text="" textAlignment="CENTER" wrappingWidth="89.8359375"/>
</children>
</HBox>
<HBox prefHeight="3.0" prefWidth="292.0" style="-fx-padding: 0;">
<children>
<Text text="Макс. время сеанса: " textAlignment="CENTER" wrappingWidth="141.07421875" />
<Text fx:id="timeout" text="00:00:00" textAlignment="CENTER" wrappingWidth="89.8359375" />
<Text text="Макс. время сеанса: " textAlignment="CENTER" wrappingWidth="141.07421875"/>
<Text fx:id="timeout" text="00:00:00" textAlignment="CENTER" wrappingWidth="89.8359375"/>
</children>
</HBox>
<HBox prefHeight="0.0" prefWidth="292.0" style="-fx-padding: 0;">
<children>
<Text text="Текущая сессия: " textAlignment="CENTER" wrappingWidth="141.07421875" />
<Text fx:id="currentSessionStopwatch" text="00:00:00" textAlignment="CENTER" wrappingWidth="89.8359375" />
<Text text="Текущая сессия: " textAlignment="CENTER" wrappingWidth="141.07421875"/>
<Text fx:id="currentSessionStopwatch" text="00:00:00" textAlignment="CENTER"
wrappingWidth="89.8359375"/>
</children>
</HBox>
<HBox prefHeight="46.0" prefWidth="292.0" style="-fx-padding: 20;">
<children>
<Button fx:id="startStopButton" alignment="CENTER" onMouseClicked="#onGameStartStopClick" prefHeight="24.0" prefWidth="123.0" text="Начать игру">
<Button fx:id="startStopButton" alignment="CENTER" onMouseClicked="#onGameStartStopClick"
prefHeight="24.0" prefWidth="123.0" text="Начать игру">
<opaqueInsets>
<Insets />
<Insets/>
</opaqueInsets>
<font>
<Font name="Arial" size="13.0" />
<Font name="Arial" size="13.0"/>
</font>
</Button>
</children>
<children>
<Button fx:id="top10Button" alignment="CENTER" onMouseClicked="#onTop10ResultClick" prefHeight="24.0" prefWidth="123.0" text="ТОП 10">
<Button fx:id="top10Button" alignment="CENTER" onMouseClicked="#onTop10ResultClick"
prefHeight="24.0" prefWidth="123.0" text="ТОП 10">
<opaqueInsets>
<Insets />
<Insets/>
</opaqueInsets>
<font>
<Font name="Arial" size="13.0" />
<Font name="Arial" size="13.0"/>
</font>
</Button>
</children>
</HBox>
<Text text="Следующая фигура:" textAlignment="CENTER" wrappingWidth="251.87939453125" />
<Text text="Следующая фигура:" textAlignment="CENTER" wrappingWidth="251.87939453125"/>
<BorderPane prefHeight="106.0" prefWidth="261.0" style="-fx-border-color: #000000; -fx-border-width: 1;">
<center>
<GridPane fx:id="brickToDrag" alignment="CENTER" hgap="1" onDragDetected="#handleDragOnNextBrick" prefHeight="121.0" prefWidth="267.0" vgap="1" />
<GridPane fx:id="brickToDrag" alignment="CENTER" hgap="1" onDragDetected="#handleDragOnNextBrick"
prefHeight="121.0" prefWidth="267.0" vgap="1"/>
</center>
</BorderPane>
<opaqueInsets>
<Insets />
<Insets/>
</opaqueInsets>
</VBox>
</left>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>


<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>


<AnchorPane prefHeight="400.0" prefWidth="650.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.hse.germandilio.tetris.client.controllers.TopResultsController">
<children>
<TableView fx:id="gameResults" layoutX="200.0" layoutY="84.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0">
<columns>
<TableColumn fx:id="login" prefWidth="170.0" text="Имя игрока" />
<TableColumn fx:id="endSessionTime" prefWidth="200.0" text="Время окончания игры" />
<TableColumn fx:id="movesCount" prefWidth="109.0" text="Кол-во фигур" />
<TableColumn fx:id="sessionDuration" prefWidth="153.0" text="Игровое время" />
</columns>
</TableView>
</children>
<AnchorPane prefHeight="400.0" prefWidth="650.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.hse.germandilio.tetris.client.controllers.TopResultsController">
<children>
<TableView fx:id="gameResults" layoutX="200.0" layoutY="84.0" prefHeight="200.0" prefWidth="200.0"
AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0"
AnchorPane.topAnchor="10.0">
<columns>
<TableColumn fx:id="login" prefWidth="170.0" text="Имя игрока"/>
<TableColumn fx:id="endSessionTime" prefWidth="200.0" text="Время окончания игры"/>
<TableColumn fx:id="movesCount" prefWidth="109.0" text="Кол-во фигур"/>
<TableColumn fx:id="sessionDuration" prefWidth="153.0" text="Игровое время"/>
</columns>
</TableView>
</children>
</AnchorPane>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.junit.jupiter.api.Test;
import ru.hse.germandilio.tetris.shared.commands.CommandBuilder;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

class CommandBuilderTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void getClientsNumber_RepeatedInput() {
}



@Test
void getTimeout() {
Scanner scanner = new Scanner("100");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;

import static org.junit.jupiter.api.Assertions.*;

class JdbcDataProviderTest {
private final String databaseUrl = "jdbc:derby:memory:game-session-results;create=true";

Expand Down

0 comments on commit 282fc46

Please sign in to comment.