This repository was archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Svetlana_Emelianchik #27
Open
rlrio
wants to merge
82
commits into
master
Choose a base branch
from
feature/SvetlanaEmelianchik
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
Changes from all commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
c81cfc4
new branch
rlrio e3fb801
update gitignore
rlrio f9b91e7
add readme
rlrio d833a1f
add homework_1
rlrio c542dbb
add refactoring to English to homework_1
rlrio fef0824
update readme, homework_1
rlrio 8377630
update gitignore
rlrio 9e2f25f
update homework_1
rlrio 133b5b5
Merge branch 'master' into feature/SvetlanaEmelianchik
rlrio ada747e
update homework_1
rlrio a32e922
Merge remote-tracking branch 'origin/master' into feature/SvetlanaEme…
ArtemNikolaev1 4e2980b
Update
ArtemNikolaev1 9f16a90
update homework_1
rlrio f3c09be
update homework_1
rlrio af2a08f
add homework_2
rlrio ab87918
update readme with hw2
rlrio d1e07fd
update hw2 with Main classes
rlrio 63db402
update hw2 with Main classes
rlrio 4a79147
refactor homework_2
rlrio 2c266b6
add homework_3
rlrio 9f0773b
add homework_3
rlrio af9e990
add homework_3
rlrio 72ec557
Merge branch 'master' into feature/SvetlanaEmelianchik
rlrio 7fe8fa1
refactor homework_2
rlrio 06bb33a
add unit tests for homework_2
rlrio 912f78e
refactor homework_3
rlrio 8d5f228
refactor homework_3
rlrio ba34642
update readme
rlrio e72c2f8
refactor homework_2, homework_3
rlrio e98f980
update readme
rlrio 9be84ae
refactor hw2 and hw3
rlrio 8e72a91
refactor hw2 and hw3
rlrio b714726
refactor hw2 and hw3
rlrio a7c4e40
update ImmutableWorker and ImmutableWorkerTest
rlrio e4e9e11
update RandomCharsTable and RandomCharsTableTest
rlrio 95aa6ce
update hw2 and hw3
rlrio 537f80a
update hw2 and hw3
rlrio 6a93208
update hw2 and hw3
rlrio 1ebba5f
add hw4
rlrio dab661b
add hw4
rlrio 075565a
add hw4
rlrio 7066727
add hw4
rlrio ef2d9e8
add hw4
rlrio 82fd0db
add hw4
rlrio d5acd27
add hw4
rlrio c440a4d
add hw4
rlrio 8f6ffa3
update hw4
rlrio 080c768
update hw4
rlrio 5adc35d
add hw5 math_power
rlrio 38245c2
update README
rlrio dfa2920
update README
rlrio ddd9c88
update hw5
rlrio b4a2189
update hw5
rlrio 5de585e
update readme
rlrio 22cf66f
add hw5 custom_regex_matcher
rlrio 6d6b1e0
update readme
rlrio dd2cc57
refactor hw2 and hw5
rlrio 7a70ee1
refactor hw2 and hw5
rlrio aa15994
refactor hw5
rlrio 2c194d3
add homework_6
rlrio 45bbdbe
add homework_6
rlrio b5cd1be
add homework_7
rlrio be9b160
add raw course_project realization
rlrio 4636cec
add raw course_project realization
rlrio c0c4f6b
add raw course_project realization
rlrio 6fc2987
bug unit test
rlrio c7acea3
refactoring course_project
rlrio e159e8b
refactoring course_project
rlrio 77ddf71
add Mockito dependency
rlrio 7c3c540
refactor course_project
rlrio 860a783
refactor course_project
rlrio a8810e3
refactor course_project
rlrio 223083d
refactor course_project
rlrio b7a6098
refactor course_project
rlrio 068e9fb
update README
rlrio 98c3145
refactor course_project
rlrio 34b0d61
hw5
rlrio 03ea478
update hw6
rlrio 9e732a7
update hw6
rlrio 962a051
update hw3
rlrio 750631e
update hw3
rlrio 9af7017
update hw3
rlrio 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 |
|---|---|---|
| @@ -1,9 +1,24 @@ | ||
| # Java Core June 2021 | ||
|
|
||
| ## *Nikolaev Artem* | ||
| ## *Emelianchik Svetlana* | ||
|
|
||
| | Number | Solution | Short description | ||
| | --- | --- | --- | | ||
| | HW1 | [Console printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/master/src/main/java/homework_1) | The app that reads input arguments and prints them, until "error" argument | | ||
| | HW1 | [ConsolePrinter](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_1) | The app that reads input arguments and prints them, until "error" argument | | ||
| | HW2 | [TrafficLight](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_2/traffic_light) | The app that reads the input time of the day in seconds or in format hh:mm:ss and checks the traffic light to cross the road.| | ||
| | HW2 | [PyramidPrinter](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_2/pyramid_printer) | The app that reads the input number and prints the pyramid of symbol "x" with such a base. | | ||
| | HW2 | [RandomCharsTable](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_2/random_chars_table) | The app that reads two numbers and a string and prints a table with random chars from A to Z and also shows the even or odd chars that was in a table depending on a strategy that was chosen. | | ||
| | HW3 | [TrafficLightTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_2/traffic_light) | Add unit tests for Traffic Light app | | ||
| | HW3 | [PyramidPrinterTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_2/pyramid_printer) | Add unit tests for Print Pyramid app| | ||
| | HW3 | [RandomCharsTableTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_2/random_chars_table) | Add unit tests for Random Chars Table app | | ||
| | HW3 | [ImmutableClass](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_3) <br />[ImmutableClassTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_3) | Add Immutable class | | ||
| | HW4 | [CustomFileReader](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_4/custom_file_reader) [CustomFileReaderTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_4/custom_file_reader) | The app that reads data from the file and prints it to the console without dots and commas | | ||
| | HW4 | [Singleton](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_4/singleton) <br />[SingletonTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_4/singleton) | The class that can have only one instance | | ||
| | HW4 | [CustomAnnotation](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_4/custom_annotation) <br />[CustomAnnotationTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_4/custom_annotation) | The annotation Author is used to get a default value when creating an instance of Book | | ||
| | HW5 | [PowerOfNumber](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_5/math_power) [PowerOfNumberTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_5/math_power) | PowerOfNumber App with method pow implemented via recursion | | ||
| | HW5 | [CustomRegexMatcher](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_5/custom_regex_matcher) [CustomRegexMatcherTest](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/homework_5/custom_regex_matcher) | The App checks whether the arguments match the hardcoded regex | | ||
| | HW6 | [MapProblemsGenerator](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_6/map_problems_generator) | 1)CollidingMapProblemsGeneratorKey is the class that always creates collisions in the HashMap. <br /> 2)MutableMapProblemsGeneratorKey is the class with HashCode method that returns random value. | | ||
| | HW7 | [KittenToCatFunction](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/homework_7) | Custom Functional Interface KittenToCatFunction with abstract method grow(). | | ||
| | Course Project | [BattleShipGame](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/main/java/course_project/battleship_game) <br /> [UnitTests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/SvetlanaEmelianchik/src/test/java/course_project/battleship_game)| BattleShip game with three modes (CVC, PVC, PVP). | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
| [Link to CodingBat profile](https://codingbat.com/done?user=sveta881@mail.ru&tag=8234249112) |
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
Empty file.
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,11 @@ | ||
| package course_project.battleship_game; | ||
|
|
||
| import course_project.battleship_game.controller.GameController; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| GameController controller = new GameController(); | ||
| controller.run(); | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
src/main/java/course_project/battleship_game/controller/GameController.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,40 @@ | ||
| package course_project.battleship_game.controller; | ||
|
|
||
| import course_project.battleship_game.exception.GameException; | ||
| import course_project.battleship_game.model.GameMode; | ||
| import course_project.battleship_game.model.Player; | ||
| import course_project.battleship_game.service.GameService; | ||
|
|
||
| import static course_project.battleship_game.controller.PrintController.printMessage; | ||
| import static course_project.battleship_game.utils.Constants.EXCEPTION_MESSAGE; | ||
| import static course_project.battleship_game.utils.Constants.FLEETS_CREATED_MESSAGE; | ||
| import static course_project.battleship_game.utils.Constants.WELCOME_MESSAGE; | ||
|
|
||
| public class GameController { | ||
| private final GameService service = new GameService(); | ||
| private final InputController inputController = new InputController(); | ||
|
|
||
| public void run() { | ||
| printMessage(WELCOME_MESSAGE); | ||
| GameMode gameMode = inputController.getGameMode(); | ||
| Player[] players = service.createPlayers(gameMode); | ||
| service.rollingDiceToChooseWhoStarts(players); | ||
| try { | ||
| service.createFleet(players); | ||
| } catch (GameException e) { | ||
| printMessage(EXCEPTION_MESSAGE); | ||
| } | ||
| printMessage(FLEETS_CREATED_MESSAGE); | ||
| Player player1 = players[0]; | ||
| Player player2 = players[1]; | ||
| boolean isGameOver = false; | ||
| while (!isGameOver) { | ||
| isGameOver = service.isGameOver(player1, player2, gameMode); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opt: service.isGameOver has really unexpected nature - most of game logic is there, but actually, by name, it should only check isGameOver or not, nothing else. Better separate |
||
| if (!isGameOver) { | ||
| isGameOver = service.isGameOver(player2, player1, gameMode); | ||
| } | ||
| } | ||
| service.determineWinner(players); | ||
| } | ||
|
|
||
| } | ||
86 changes: 86 additions & 0 deletions
86
src/main/java/course_project/battleship_game/controller/InputController.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,86 @@ | ||
| package course_project.battleship_game.controller; | ||
|
|
||
| import course_project.battleship_game.model.Cell; | ||
| import course_project.battleship_game.model.GameMode; | ||
| import course_project.battleship_game.utils.CoordinateValidator; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| import static course_project.battleship_game.controller.PrintController.printMessage; | ||
| import static course_project.battleship_game.utils.Constants.CHOOSE_GAME_MODE_MESSAGE; | ||
| import static course_project.battleship_game.utils.Constants.CHOOSE_MODE_TO_CREATE_FLEET_MESSAGE; | ||
| import static course_project.battleship_game.utils.Constants.CHOOSE_SHIP_DIRECTION_MESSAGE; | ||
| import static course_project.battleship_game.utils.Constants.DEFAULT_PLAYER_NAME; | ||
| import static course_project.battleship_game.utils.Constants.ERROR_INPUT_MESSAGE; | ||
| import static course_project.battleship_game.utils.Constants.GET_CELL_COORDINATE_MESSAGE; | ||
| import static course_project.battleship_game.utils.Constants.GET_PLAYER_NAME_MESSAGE; | ||
|
|
||
| public class InputController { | ||
| private final BufferedReader READER = new BufferedReader(new InputStreamReader(System.in)); | ||
|
|
||
| public String getPlayerName() { | ||
| printMessage(GET_PLAYER_NAME_MESSAGE); | ||
| String line = readLine(); | ||
| return line == null || line.isEmpty() ? DEFAULT_PLAYER_NAME : line; | ||
| } | ||
|
|
||
| public GameMode getGameMode() { | ||
| printMessage(CHOOSE_GAME_MODE_MESSAGE); | ||
| String mode = readLine(); | ||
| while (true) { | ||
| if (mode.equals("0")) { | ||
| return GameMode.CVC; | ||
| } else if (mode.equals("1")) { | ||
| return GameMode.PVC; | ||
| } else if (mode.equals("2")) { | ||
| return GameMode.PVP; | ||
| } else { | ||
| printMessage(ERROR_INPUT_MESSAGE); | ||
| mode = readLine(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public int getModeToCreateFleet() { | ||
| printMessage(CHOOSE_MODE_TO_CREATE_FLEET_MESSAGE); | ||
| return getZeroOrOne(); | ||
| } | ||
|
|
||
| public int getDirection() { | ||
| printMessage(CHOOSE_SHIP_DIRECTION_MESSAGE); | ||
| return getZeroOrOne(); | ||
| } | ||
|
|
||
| public Cell getCell() { | ||
| printMessage(GET_CELL_COORDINATE_MESSAGE); | ||
| String coordinate = readLine(); | ||
| while (!CoordinateValidator.isCoordinate(coordinate)) { | ||
| printMessage(ERROR_INPUT_MESSAGE); | ||
| coordinate = readLine(); | ||
| } | ||
| int x = Integer.parseInt(coordinate.substring(1)) - 1; | ||
| int y = ((int) coordinate.toUpperCase().charAt(0)) - 65; | ||
| return new Cell(x, y); | ||
| } | ||
|
|
||
| private String readLine() { | ||
| try { | ||
| return READER.readLine(); | ||
| } catch (IOException e) { | ||
| return ""; | ||
| } | ||
| } | ||
|
|
||
| private int getZeroOrOne() { | ||
| String mode = readLine(); | ||
| while (true) { | ||
| if (mode.equals("0") || mode.equals("1")) { | ||
| return Integer.parseInt(mode); | ||
| } | ||
| printMessage(ERROR_INPUT_MESSAGE); | ||
| mode = readLine(); | ||
| } | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
src/main/java/course_project/battleship_game/controller/PrintController.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,53 @@ | ||
| package course_project.battleship_game.controller; | ||
|
|
||
| import course_project.battleship_game.model.Cell; | ||
| import course_project.battleship_game.model.CellStatus; | ||
| import course_project.battleship_game.model.GameMode; | ||
| import course_project.battleship_game.model.Player; | ||
|
|
||
| import static course_project.battleship_game.utils.Constants.DEFAULT_COMPUTER_NAME; | ||
| import static course_project.battleship_game.utils.Constants.PLAYER_BOARD_MESSAGE_FORMAT; | ||
| import static java.lang.System.lineSeparator; | ||
|
|
||
| public class PrintController { | ||
|
|
||
| public static void printMessage(String message) { | ||
| System.out.print(message); | ||
| } | ||
|
|
||
| public void printBoards(GameMode mode, Player player1, Player player2) { | ||
| if (mode.equals(GameMode.CVC) || !player1.getName().contains(DEFAULT_COMPUTER_NAME)) { | ||
| printBoardForPlayer(player1, false); | ||
| printBoardForPlayer(player2, true); | ||
| } | ||
| } | ||
|
|
||
| public void printBoardForPlayer(Player player, boolean isEnemy) { | ||
| printMessage(String.format(PLAYER_BOARD_MESSAGE_FORMAT, player.getName())); | ||
| printHeader(); | ||
| Cell[][] boardMatrix = player.getBoard().getBoardMatrix(); | ||
| for (int y = 0; y < boardMatrix.length; y++) { | ||
| printMessage((char) (65 + y) + " "); | ||
| for (int x = 0; x < boardMatrix.length; x++) { | ||
| printCell(isEnemy, boardMatrix[y][x]); | ||
| } | ||
| printMessage(lineSeparator()); | ||
| } | ||
| } | ||
|
|
||
| private void printCell(boolean isEnemy, Cell cell) { | ||
| if (isEnemy && cell.getCellStatus().equals(CellStatus.SHIP)) { | ||
| printMessage(CellStatus.EMPTY.getCharacter()); | ||
| } else { | ||
| printMessage(cell.getCellStatus().getCharacter()); | ||
| } | ||
| } | ||
|
|
||
| private void printHeader() { | ||
| printMessage(" "); | ||
| for (int i = 1; i < 11; i++) { | ||
| printMessage(i + " "); | ||
| } | ||
| printMessage(lineSeparator()); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/course_project/battleship_game/exception/GameException.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,6 @@ | ||
| package course_project.battleship_game.exception; | ||
|
|
||
| public class GameException extends RuntimeException { | ||
| public GameException() { | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/course_project/battleship_game/model/Board.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,35 @@ | ||
| package course_project.battleship_game.model; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static course_project.battleship_game.utils.Constants.BOARD_SIZE; | ||
|
|
||
| public class Board { | ||
| private final Cell[][] boardMatrix; | ||
| private final List<Ship> shipList; | ||
|
|
||
| public Board() { | ||
| this.boardMatrix = createBoard(); | ||
| this.shipList = new ArrayList<>(); | ||
| } | ||
|
|
||
| public Cell[][] getBoardMatrix() { | ||
| return boardMatrix; | ||
| } | ||
|
|
||
| public List<Ship> getShipList() { | ||
| return shipList; | ||
| } | ||
|
|
||
| private Cell[][] createBoard() { | ||
| Cell[][] boardMatrix = new Cell[BOARD_SIZE][BOARD_SIZE]; | ||
| for (int y = 0; y < BOARD_SIZE; y++) { | ||
| for (int x = 0; x < BOARD_SIZE; x++) { | ||
| boardMatrix[y][x] = new Cell(x, y, CellStatus.EMPTY); | ||
| } | ||
| } | ||
| return boardMatrix; | ||
| } | ||
|
|
||
| } |
55 changes: 55 additions & 0 deletions
55
src/main/java/course_project/battleship_game/model/Cell.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,55 @@ | ||
| package course_project.battleship_game.model; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Cell { | ||
| private final int x; | ||
| private final int y; | ||
| private CellStatus status; | ||
|
|
||
| public Cell(int x, int y, CellStatus status) { //change in controller | ||
| this.x = x; | ||
| this.y = y; | ||
| this.status = status; | ||
| } | ||
|
|
||
| public Cell(int x, int y) { | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
|
|
||
| public int getX() { | ||
| return x; | ||
| } | ||
|
|
||
| public int getY() { | ||
| return y; | ||
| } | ||
|
|
||
| public CellStatus getCellStatus() { | ||
| return status; | ||
| } | ||
|
|
||
| public void setCellStatus(CellStatus status) { | ||
| this.status = status; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Cell cell = (Cell) o; | ||
| return getX() == cell.getX() && | ||
| getY() == cell.getY(); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(getX(), getY()); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.valueOf((char) (y + 65)) + (x + 1); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/course_project/battleship_game/model/CellStatus.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,19 @@ | ||
| package course_project.battleship_game.model; | ||
|
|
||
| public enum CellStatus { | ||
| EMPTY("\uD83C\uDF0A"), | ||
| SHIP("\uD83D\uDEA2"), | ||
| HIT("\u274C"), | ||
| SHIP_BORDER("\uD83C\uDF0A"), | ||
| MISSED("\uD83D\uDD18"); | ||
|
|
||
| private final String character; | ||
|
|
||
| CellStatus(String character) { | ||
| this.character = character; | ||
| } | ||
|
|
||
| public String getCharacter() { | ||
| return character; | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/course_project/battleship_game/model/GameMode.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,7 @@ | ||
| package course_project.battleship_game.model; | ||
|
|
||
| public enum GameMode { | ||
| CVC, | ||
| PVC, | ||
| PVP | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/course_project/battleship_game/model/Player.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,35 @@ | ||
| package course_project.battleship_game.model; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Player { | ||
| private final String name; | ||
| private final Board board; | ||
| private final int modeToCreateFleet; | ||
| private final List<Cell> logOfMoves; | ||
|
|
||
| public Player(String name, int modeToCreateFleet) { | ||
| this.name = name; | ||
| this.modeToCreateFleet = modeToCreateFleet; | ||
| this.board = new Board(); | ||
| this.logOfMoves = new ArrayList<>(); | ||
| } | ||
|
|
||
| public Board getBoard() { | ||
| return board; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public List<Cell> getLogOfMoves() { | ||
| return logOfMoves; | ||
| } | ||
|
|
||
| public int getModeToCreateFleet() { | ||
| return modeToCreateFleet; | ||
| } | ||
|
|
||
| } |
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.
Opt: it seems indentation is a little bit shifted

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.
it looks like this on my computer
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.
Really nice game, well-done! Excellent architecture, model/service separation, easy to read code, pretty interface and a lot of options how to play. Also, you're showing good knowledge of Java Core and Java libraries, as well as following Code Conventions and creating proper application architecture. Special thanks for automatic ship placement :) Testing is also fine, as I understand testing of console application can be tough.
Good job, approved!