-
Notifications
You must be signed in to change notification settings - Fork 0
Test #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ilkivoo
wants to merge
3
commits into
master
Choose a base branch
from
TEST
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test #4
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| language: java | ||
| jdk: | ||
| - oraclejdk8 | ||
| os: | ||
| - linux | ||
| script: | ||
| - chmod +x buildscript.sh && ./buildscript.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>02</groupId> | ||
| <artifactId>TicTacToe</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>1.8</source> | ||
| <target>1.8</target> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.12</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.12</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
|
|
||
| </project> | ||
201 changes: 201 additions & 0 deletions
201
02.TicTacToe/src/main/java/ru/spbau/mit/alyokhina/TicTacToe/CreateElements.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| package ru.spbau.mit.alyokhina.TicTacToe; | ||
|
|
||
|
|
||
| import javafx.application.Platform; | ||
| import javafx.geometry.Insets; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.TextArea; | ||
| import javafx.scene.layout.GridPane; | ||
| import javafx.scene.layout.HBox; | ||
| import javafx.scene.layout.Pane; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
|
||
| /** Create UI elements */ | ||
| public class CreateElements { | ||
|
|
||
| /** | ||
| * Create button | ||
| * | ||
| * @param x abscissa coordinate | ||
| * @param y ordinate coordinate | ||
| * @param text this text will be on the button | ||
| * @return new button | ||
| */ | ||
| public static Button createButton(GridPane gridPane, double height, double width, int x, int y, String text) { | ||
| Button button = new Button(); | ||
| gridPane.add(button, x, y); | ||
| button.setText(text); | ||
| button.setPrefHeight(height); | ||
| button.setPrefWidth(width); | ||
| button.setLayoutX(x); | ||
| button.setLayoutY(y); | ||
| return button; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Create board for TicTacToe. Every cell is button | ||
| * | ||
| * @return array of buttons | ||
| */ | ||
| public static Button[] createTableView(GridPane gridPane) { | ||
| Button[] buttons = new Button[9]; | ||
| for (int i = 0; i < 9; i++) { | ||
| buttons[i] = createButton(gridPane, 60, 60, 210 + 60 * (i % 3), 110 + 60 * (i / 3), ""); | ||
| } | ||
| return buttons; | ||
| } | ||
|
|
||
| /**Create Menu for Main Activity */ | ||
| public static void createMainActivity(GridPane gridPane) { | ||
| Button buttonPlayWithComp = CreateElements.createButton(gridPane, 50, 200, 0, 0, "Играть с компьютером"); | ||
| Button buttonPlayWithFriend = CreateElements.createButton(gridPane, 50, 200, 0, 1, "Играть с другом"); | ||
| Button buttonExit = CreateElements.createButton(gridPane, 50, 200, 0, 2, "Выход"); | ||
| buttonPlayWithComp.setOnAction(actionEvent -> { | ||
| GameWithComp gameWithComp = new GameWithComp(gridPane, new Statistics()); | ||
| gameWithComp.menu(); | ||
| }); | ||
|
|
||
| buttonPlayWithFriend.setOnAction(actionEvent -> { | ||
| GameWithFriend gameWithFriend = new GameWithFriend(gridPane, new Statistics()); | ||
| gameWithFriend.menu(); | ||
| }); | ||
| buttonExit.setOnAction(value -> Platform.exit()); | ||
| } | ||
|
|
||
| /** | ||
| * Create button for new game | ||
| * | ||
| * @param statistics is parameter for consumer | ||
| * @param consumer will be accepted after clicking on the button | ||
| */ | ||
| public static void createButtonReplay(GridPane gridPane, Statistics statistics, Consumer<Statistics> consumer) { | ||
| Button rePlay = CreateElements.createButton(gridPane, 50, 200, 400, 20, "Начать новую партию"); | ||
| rePlay.setOnAction(actionEvent -> { | ||
| gridPane.getChildren().clear(); | ||
| consumer.accept(statistics); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| /** Create button to go to the main activity */ | ||
| public static void createButtonToMainActivity(GridPane gridPane) { | ||
| Button buttonToMainActivity = CreateElements.createButton(gridPane, 50, 200, 400, 350, "В главное меню"); | ||
| buttonToMainActivity.setOnAction(actionEvent -> { | ||
| gridPane.getChildren().clear(); | ||
| createMainActivity(gridPane); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Create button to go to statistics for hot seat. After clicking go to new activity | ||
| * | ||
| * @param go will be accepted after clicking button back | ||
| */ | ||
| public static void createButtonGetStatisticsForOnePlayers(GridPane gridPane, Statistics statistics, Consumer<Statistics> go) { | ||
| Button getStatistics = CreateElements.createButton(gridPane, 50, 200, 200, 270, "Статистика"); | ||
| getStatistics.setOnAction(actionEvent -> { | ||
| gridPane.getChildren().clear(); | ||
| CreateElements.createButtonToMainActivity(gridPane); | ||
| Button buttonBack = CreateElements.createButton(gridPane, 50, 200, 400, 20, "Назад"); | ||
| buttonBack.setOnAction(actionEvent1 -> { | ||
| gridPane.getChildren().clear(); | ||
| go.accept(statistics); | ||
| }); | ||
| TextArea textArea = new TextArea(); | ||
| textArea.setLayoutY(0); | ||
| textArea.setLayoutX(0); | ||
| textArea.setPrefHeight(600); | ||
| textArea.setPrefWidth(200); | ||
| gridPane.getChildren().add(textArea); | ||
| textArea.setText("количество побед: " + statistics.getCountWins().toString() | ||
| + "\nколичество поражений: " + statistics.getCountLose().toString() | ||
| + "\nколичество ничьих: " + statistics.getCountDraw().toString()); | ||
|
|
||
| }); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Create button to go to statistics for two players. After clicking go to new activity | ||
| * | ||
| * @param go will be accepted after clicking button back | ||
| */ | ||
| public static void createButtonGetStatisticsForTwoPlayers(GridPane gridPane, Statistics statistics, Consumer<Statistics> go) { | ||
| Button getStatistics = CreateElements.createButton(gridPane, 50, 200, 200, 240, "Статистика"); | ||
| getStatistics.setOnAction(actionEvent -> { | ||
| gridPane.getChildren().clear(); | ||
| CreateElements.createButtonToMainActivity(gridPane); | ||
| Button button = CreateElements.createButton(gridPane, 50, 200, 400, 20, "Назад"); | ||
| button.setOnAction(actionEvent1 -> { | ||
| gridPane.getChildren().clear(); | ||
| go.accept(statistics); | ||
| }); | ||
| TextArea textAreaForFirst = new TextArea(); | ||
| //textAreaForFirst.setLayoutY(0); | ||
| //textAreaForFirst.setLayoutX(0); | ||
| textAreaForFirst.setPrefHeight(600); | ||
| textAreaForFirst.setPrefWidth(200); | ||
| gridPane.add(textAreaForFirst, 0, 0); | ||
| textAreaForFirst.setText("Х \nколичество побед: " + statistics.getCountLose().toString() | ||
| + "\nколичество поражений: " + statistics.getCountWins().toString() | ||
| + "\nколичество ничьих: " + statistics.getCountDraw().toString()); | ||
|
|
||
|
|
||
| TextArea textAreaForSecond = new TextArea(); | ||
| textAreaForSecond.setLayoutY(0); | ||
| textAreaForSecond.setLayoutX(200); | ||
| textAreaForSecond.setPrefHeight(600); | ||
| textAreaForSecond.setPrefWidth(200); | ||
| gridPane.add(textAreaForSecond, 5, 0); | ||
| textAreaForSecond.setText("О \nколичество побед: " + statistics.getCountWins().toString() | ||
| + "\nколичество поражений: " + statistics.getCountLose().toString() | ||
| + "\nколичество ничьих: " + statistics.getCountDraw().toString()); | ||
| }); | ||
| } | ||
|
|
||
| /** Print result on screen and update statistics */ | ||
| public static void setResult(GridPane gridPane, Statistics statistics, String win) { | ||
| gridPane.getChildren().clear(); | ||
| CreateElements.createButtonToMainActivity(gridPane); | ||
| switch (win) { | ||
| case "draw": { | ||
| TextArea textArea = new TextArea(); | ||
| textArea.setLayoutY(150); | ||
| textArea.setLayoutX(250); | ||
| textArea.setPrefHeight(50); | ||
| textArea.setPrefWidth(100); | ||
| textArea.setText("draw"); | ||
| gridPane.getChildren().add(textArea); | ||
| statistics.incDraw(); | ||
| break; | ||
| } | ||
| case "X": { | ||
| TextArea textArea = new TextArea(); | ||
| textArea.setLayoutY(150); | ||
| textArea.setLayoutX(250); | ||
| textArea.setPrefHeight(50); | ||
| textArea.setPrefWidth(100); | ||
| textArea.setText("X wins"); | ||
| gridPane.getChildren().add(textArea); | ||
| statistics.incLose(); | ||
| break; | ||
| } | ||
| default: { | ||
| TextArea textArea = new TextArea(); | ||
| textArea.setLayoutY(150); | ||
| textArea.setLayoutX(250); | ||
| textArea.setPrefHeight(50); | ||
| textArea.setPrefWidth(100); | ||
| gridPane.getChildren().add(textArea); | ||
| textArea.setText("O wins"); | ||
| statistics.incWins(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
138 changes: 138 additions & 0 deletions
138
02.TicTacToe/src/main/java/ru/spbau/mit/alyokhina/TicTacToe/Game.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| package ru.spbau.mit.alyokhina.TicTacToe; | ||
|
|
||
| import javafx.scene.control.Button; | ||
| import javafx.scene.layout.GridPane; | ||
|
|
||
| /** | ||
| * Class for key actions of game | ||
| */ | ||
| public class Game { | ||
| /** | ||
| * GridPane for current game | ||
| */ | ||
| protected GridPane gridPane; | ||
| /** | ||
| * Number playing | ||
| */ | ||
| protected int numberGames = 0; | ||
| /** | ||
| * Statistics for current game | ||
| */ | ||
| protected Statistics statistics; | ||
|
|
||
| /** | ||
| * Constructor | ||
| */ | ||
| public Game(GridPane gridPane, Statistics statistics) { | ||
| this.gridPane = gridPane; | ||
| this.statistics = statistics; | ||
| gridPane.getChildren().clear(); | ||
| CreateElements.createButtonToMainActivity(gridPane); | ||
| } | ||
|
|
||
| /** | ||
| * Translated text from buttons array in string array | ||
| */ | ||
| protected String[] toStringArray(Button[] table) { | ||
| String[] tableString = new String[table.length]; | ||
| for (int i = 0; i < table.length; i++) { | ||
| tableString[i] = table[i].getText(); | ||
| } | ||
| return tableString; | ||
| } | ||
|
|
||
| /** | ||
| * Check the state of the game | ||
| * | ||
| * @param tableString state board, "" - if cell is empty | ||
| * @return "X" - if X wins , "O" - if O wins, "" - if state is unknown, else - draw | ||
| */ | ||
| public static String check(String[] tableString) { | ||
|
|
||
| boolean existEmpty = false; | ||
| for (int i = 0; i < tableString.length; i++) { | ||
| if (tableString[i].equals("")) { | ||
| existEmpty = true; | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < 9; i += 3) { | ||
| if (!tableString[i].equals("") && tableString[i].equals(tableString[i + 1]) && tableString[i + 1].equals(tableString[i + 2])) { | ||
| return tableString[i]; | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < 3; i++) { | ||
| if (!tableString[i].equals("") && tableString[i].equals(tableString[i + 3]) && tableString[i + 3].equals(tableString[i + 6])) { | ||
| return tableString[i]; | ||
| } | ||
| } | ||
|
|
||
| if (!tableString[0].equals("") && tableString[0].equals(tableString[4]) && tableString[4].equals(tableString[8])) { | ||
| return tableString[0]; | ||
| } | ||
|
|
||
| if (!tableString[2].equals("") && tableString[2].equals(tableString[4]) && tableString[4].equals(tableString[6])) { | ||
|
|
||
| return tableString[2]; | ||
| } | ||
| if (existEmpty) { | ||
| return ""; | ||
| } else { | ||
| return "draw"; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * /** | ||
| * Check the state of the game | ||
| * | ||
| * @param tableString state board, "" - if cell is empty | ||
| * @param isPreliminaryCheck, true - if real state, false - if we want check move | ||
| * @return "X" - if X wins , "O" - if O wins, "" - if state is unknown, else - draw | ||
| */ | ||
| protected String check(String[] tableString, boolean isPreliminaryCheck) { | ||
| String result = check(tableString); | ||
| if (!isPreliminaryCheck && !result.equals("")) { | ||
| setResult(result); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Print result games | ||
| */ | ||
| private void setResult(String win) { | ||
| numberGames++; | ||
| CreateElements.setResult(gridPane, statistics, win); | ||
| CreateElements.createButtonReplay(gridPane, statistics, this::goBack); | ||
| } | ||
|
|
||
| /** | ||
| * For return in this activity | ||
| */ | ||
| protected void goBack(Statistics statistics) { | ||
| this.statistics = statistics; | ||
| gridPane.getChildren().clear(); | ||
| CreateElements.createButtonToMainActivity(gridPane); | ||
| menu(); | ||
| } | ||
|
|
||
| /** | ||
| * Symbol to which the player move | ||
| */ | ||
|
|
||
| public String getCompSymb(int player) { | ||
| return (numberGames % 2 == player) ? "X" : "O"; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Before games we should choose characteristics game | ||
| */ | ||
| public void menu() { | ||
| CreateElements.createButton(gridPane, 50, 200, 200, 70, "Легкий"); | ||
| CreateElements.createButton(gridPane, 50, 200, 200, 170, "Сложный"); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
эх, не от той ветки контрольная растёт