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
Filipchik_Kirill #30
Open
filipchikkirill
wants to merge
84
commits into
master
Choose a base branch
from
feature/KirillFilipchik
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
Filipchik_Kirill #30
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
5d3db82
test from kirill
filipchikkirill cda7765
Gitignore update
ArtemNikolaev1 986bf6e
Initial commit v5
ArtemNikolaev1 1d0a10b
Moving and gitignore update
ArtemNikolaev1 a4c3c7b
add homework_lesson_2
filipchikkirill b7db6c6
add homework_lesson_2
filipchikkirill dbfe254
homework_lesson_2
filipchikkirill 52ae014
rename Homework_lesson_2 -> homework
filipchikkirill 59d2dd8
refactor README.md
filipchikkirill 42cd073
Delete src/main/java/lesson_2 directory
filipchikkirill aed8cb2
fix bugs
filipchikkirill 1d4356c
Merge remote-tracking branch 'origin/master' into feature/KirillFilip…
filipchikkirill ce8002f
fix bugs
filipchikkirill 0775258
fix bugs
filipchikkirill c0cc291
fix style
filipchikkirill a57fb6d
homework 2 start
filipchikkirill a7344a0
homework 2 PyramidPrinter
filipchikkirill 3dff0e8
homework 2 change README.md
filipchikkirill c1b7933
homework 2 add TrafficLight.
filipchikkirill 4947867
homework 2 add RandomCharsTable.
filipchikkirill 7c4b7a7
homework 2 ready for check.
filipchikkirill b21edbb
homework 2 ready for check.
filipchikkirill accdbb2
homework 2 ready for check.
filipchikkirill 5fa1a3b
homework 2 refactoring the project structure
filipchikkirill 0db5d6d
homework 2 RandomCharsTable refactor
filipchikkirill 4ad9d12
homework 2 refactor TrafficLight
filipchikkirill eb09bf6
homework 2 refactor utils
filipchikkirill 781e1e5
modify README.md
filipchikkirill 76fa0ec
homework_3
filipchikkirill ce3ca96
homework_2 small refactor
filipchikkirill f333990
homework_2 small refactor
filipchikkirill 97ee39c
homework_2 I don't know what result is needed, so now output the raw …
filipchikkirill bc6a30f
homework_2 method start() -> run()
filipchikkirill 1bda9c7
Merge remote-tracking branch 'origin/master' into feature/KirillFilip…
filipchikkirill 6a9110a
homework_3 add PyramidPrinterTest
filipchikkirill 2355efd
homework_3 add TrafficLightTest
filipchikkirill 92d5491
homework_3 add RandomCharsTableTest not full
filipchikkirill e44be42
homework_2 fix RandomCharsTable
filipchikkirill f9af1a8
homework_3 ready for check
filipchikkirill 18b9a0e
homework_3 ready for check
filipchikkirill b003a8c
homework_3 ready for check
filipchikkirill ba88fc3
homework_3 ready for check
filipchikkirill 1ce9200
homework_3 ready for check
filipchikkirill d210ece
homework_3 ready for check
filipchikkirill 6478f77
homework_3 ready for check
filipchikkirill 838ce8d
homework_2 fix Main.java
filipchikkirill 95c50dc
homework_2 fix Main.java
filipchikkirill 514a8c1
homework_4 start
filipchikkirill 0cb7be3
homework_4 change README.md
filipchikkirill f0c4bda
homework_4 add annotation
filipchikkirill 0a1c1b6
homework_4 add annotation
filipchikkirill 5870a57
homework_4 add CustomFileReader
filipchikkirill f1cded3
homework_4 add fix README.md
filipchikkirill c603925
homework_4 add fix
filipchikkirill 311e359
homework_5 add
filipchikkirill 13b2021
homework_4 fix
filipchikkirill 6117c71
homework_4 add test for CustomAnnotation
filipchikkirill 4d24b63
homework_5 add
filipchikkirill c940b66
homework_5 README.md change
filipchikkirill 3049b13
homework_6
filipchikkirill 4ce308e
homework_6
filipchikkirill 663d28a
homework_7
filipchikkirill 9dcbbe4
homework_4
filipchikkirill 35fb91b
course_project first iteration
filipchikkirill 0b28c70
course_project fix 1
filipchikkirill 9e2d0b2
course_project fix 2
filipchikkirill e71d04a
course_project fix 3
filipchikkirill 628b0c3
course_project fix 4
filipchikkirill 1c931dd
course_project fix 5
filipchikkirill 72b5a3b
course_project fix 6
filipchikkirill 8a66fec
course_project add Tests (not all)
filipchikkirill 24408c3
Homework3 fix immutableclass
filipchikkirill d579c63
Homework3 fix immutableclass
filipchikkirill acb9a49
Homework 6 add mutable
filipchikkirill 7a97598
Homework 3 add mutable
filipchikkirill 71662a4
Homework fix SingletonTest
filipchikkirill 193cfd9
course_project fix and add random fill field
filipchikkirill 5d67208
course_project fix
filipchikkirill 2be5bc1
course_project fix
filipchikkirill a2464ce
course_project test
filipchikkirill d56c17e
course_project test
filipchikkirill 71f99ca
course_project test
filipchikkirill d6cb9f7
course_project test
filipchikkirill a7c5231
hw_3 fix
filipchikkirill 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,27 @@ | ||
| # Java Core June 2021 | ||
|
|
||
| ## *Nikolaev Artem* | ||
| ## *Filipchik Kirill* | ||
|
|
||
| | 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 | [Console printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_1) | The app that reads input arguments and prints them, until "ошибка" argument | | ||
| | HW2 | [PyramidPrinter](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_2/pyramid_printer) | The app that reads input argument and builds pyramid base on input value | | ||
| | HW2 | [RandomCharsTable](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_2/random_chars_table) | App reads from the console width and length of the chart, strategy keyword (even or odd). Prints to the console the chart of random chars from A to Z | | ||
| | HW2 | [TrafficLight](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_2/traffic_light) | App reads current time in seconds from the console and prints the traffic light| | ||
| | HW3 | [ImmutableClass](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_3) | ImmutableClass | | ||
| | HW3 | [Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/test/java/homework_2/) | HW_2 Tests | | ||
| | HW4 | [Singleton](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_4/singleton) | Singleton| | ||
| | HW4 | [CustomAnnotation](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_4/сustom_annotation) | CustomAnnotation| | ||
| | HW4 | [CustomFileReader](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_4/custom_file_reader) | CustomFileReader| | ||
| | HW4 | [Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/test/java/homework_4) | HW_4 Tests| | ||
| | HW5 | [HW_5](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_5) | HW_5| | ||
| | HW5 | [PowerOfNumber](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_5/power_of_number) | PowerOfNumber| | ||
| | HW5 | [CustomRegexMatcher](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_5/custom_regex_matcher) | CustomRegexMatcher| | ||
| | HW5 | [Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/test/java/homework_5) | HW_5 Tests| | ||
| | HW6 | [MapProblemsGenerator](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_6/map_problems_generator) | MapProblemsGenerator| | ||
| | HW7 | [KittenToCatFunction](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/KirillFilipchik/src/main/java/homework_7/kitten_to_cat_function) | KittenToCatFunction| | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
|
|
||
| [Link to CodingBat](https://codingbat.com/done?user=parallaksik@gmail.com&tag=9517187513) | ||
|
|
||
| [Link to markdown guide](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) |
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
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,16 @@ | ||
| package course_project.sea_battle; | ||
|
|
||
| import course_project.sea_battle.controller.impl.GameControllerImpl; | ||
| import course_project.sea_battle.controller.impl.IOControllerImpl; | ||
|
|
||
| public class SeaBattleApp { | ||
| public static void main(String[] args) { | ||
| try { | ||
| GameControllerImpl.getInstance().start(); | ||
| } catch (Exception ex) { | ||
| ex.printStackTrace(); | ||
| } finally { | ||
| IOControllerImpl.getInstance().close(); | ||
| } | ||
| } | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
src/main/java/course_project/sea_battle/controller/FieldController.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,8 @@ | ||
| package course_project.sea_battle.controller; | ||
|
|
||
| import course_project.sea_battle.model.Field; | ||
|
|
||
| public interface FieldController { | ||
| Field instance(); | ||
| void drawFields(Field... fields); | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/course_project/sea_battle/controller/FieldFillController.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,8 @@ | ||
| package course_project.sea_battle.controller; | ||
|
|
||
| import course_project.sea_battle.model.Field; | ||
|
|
||
| public interface FieldFillController { | ||
| void setShips(Field field); | ||
| FieldFillController setGameSetupHolder(GameSetupHolder gameSetupHolder); | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/course_project/sea_battle/controller/FireController.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,9 @@ | ||
| package course_project.sea_battle.controller; | ||
|
|
||
| import course_project.sea_battle.model.CellStatus; | ||
| import course_project.sea_battle.model.Field; | ||
|
|
||
| public interface FireController { | ||
| CellStatus fire(Field targetField, Field enemyField, String coordinate); | ||
| boolean checkFire(Field field, String coordinate); | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/course_project/sea_battle/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,7 @@ | ||
| package course_project.sea_battle.controller; | ||
|
|
||
| import course_project.sea_battle.model.Game; | ||
|
|
||
| public interface GameController { | ||
| Game start(); | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/course_project/sea_battle/controller/GameSetupHolder.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.sea_battle.controller; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public interface GameSetupHolder { | ||
| Map<Integer, Integer> getMapShips(); | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/course_project/sea_battle/controller/IOController.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,8 @@ | ||
| package course_project.sea_battle.controller; | ||
|
|
||
| public interface IOController { | ||
| void clr(); | ||
| void close(); | ||
| String dialog(String msg); | ||
| void print(String msg); | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/course_project/sea_battle/controller/ParseController.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.sea_battle.controller; | ||
|
|
||
| public interface ParseController { | ||
| int[] parseCoordinate(String coordinate); | ||
| boolean isVerticalVector(String vector); | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/course_project/sea_battle/controller/PlayerController.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.sea_battle.controller; | ||
|
|
||
| import course_project.sea_battle.model.GamePlayer; | ||
|
|
||
| public interface PlayerController { | ||
| GamePlayer instance(String name); | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/course_project/sea_battle/controller/ShipController.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,9 @@ | ||
| package course_project.sea_battle.controller; | ||
|
|
||
| import course_project.sea_battle.model.Field; | ||
|
|
||
| public interface ShipController { | ||
| boolean placeShip(Field field, String coordinate, String vector, int size); | ||
| boolean placeShipByCoordinate(Field field, int x, int y, boolean isVertical, int size); | ||
| boolean isAnyShipAlive(Field field); | ||
| } |
74 changes: 74 additions & 0 deletions
74
src/main/java/course_project/sea_battle/controller/impl/FieldControllerImpl.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,74 @@ | ||
| package course_project.sea_battle.controller.impl; | ||
|
|
||
| import course_project.sea_battle.controller.FieldController; | ||
| import course_project.sea_battle.controller.IOController; | ||
| import course_project.sea_battle.model.CellStatus; | ||
| import course_project.sea_battle.model.Field; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Optional; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| public final class FieldControllerImpl implements FieldController { | ||
| private static final String TOP = " ╔══════════╗"; | ||
| private static final String HUD = " ║ABCDEFGHIG║"; | ||
| private static final String SPLIT_TOP_LINE = "╔══╬══════════╣"; | ||
| private static final String SPLIT_BOT_LINE = "╚══╩══════════╝"; | ||
| private static final String SPLIT_COL_LINE = "║"; | ||
|
|
||
| private final IOController ioController = IOControllerImpl.getInstance(); | ||
|
|
||
| private FieldControllerImpl() {} | ||
|
|
||
| @Override | ||
| public Field instance() { | ||
| Field field = new Field(); | ||
| this.fillWater(field); | ||
| return field; | ||
| } | ||
|
|
||
| private void fillWater(Field field) { | ||
| if (field == null) return; | ||
| CellStatus[][] cells = field.getCells(); | ||
| for (CellStatus[] row : | ||
| cells) { | ||
| Arrays.fill(row, CellStatus.WATER); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void drawFields(Field... fields) { | ||
| Arrays.stream(fields) | ||
| .map(this::prepareForPrint) | ||
| .reduce((arr1, arr2) -> { | ||
| Arrays.setAll(arr1, i -> arr1[i] + "\t" + arr2[i]); | ||
| return arr1; | ||
| }).ifPresent(x -> Arrays.stream(x).forEach(ioController::print)); | ||
| } | ||
|
|
||
| private String[] prepareForPrint(Field field) { | ||
| String[] arr = new String[field.getCells().length + 4]; | ||
| arr[0] = TOP; | ||
| arr[1] = HUD; | ||
| arr[2] = SPLIT_TOP_LINE; | ||
| arr[arr.length - 1] = SPLIT_BOT_LINE; | ||
| StringBuilder sb = new StringBuilder(); | ||
| int bound = Field.FIELD_SIZE; | ||
| IntStream.range(0, bound).forEachOrdered(i -> { | ||
| sb.append(String.format(SPLIT_COL_LINE + "%2s" + SPLIT_COL_LINE, i + 1)); | ||
| Arrays.stream(field.getCells()[i]).forEachOrdered(sb::append); | ||
| sb.append(SPLIT_COL_LINE); | ||
| arr[i + 3] = sb.toString(); | ||
| sb.setLength(0); | ||
| }); | ||
| return arr; | ||
| } | ||
|
|
||
| public static FieldControllerImpl getInstance() { | ||
| return FieldControllerImpl.Holder.INSTANCE; | ||
| } | ||
|
|
||
| private static class Holder { | ||
| static final FieldControllerImpl INSTANCE = new FieldControllerImpl(); | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
src/main/java/course_project/sea_battle/controller/impl/FireControllerImpl.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,50 @@ | ||
| package course_project.sea_battle.controller.impl; | ||
|
|
||
| import course_project.sea_battle.controller.FireController; | ||
| import course_project.sea_battle.model.CellStatus; | ||
| import course_project.sea_battle.model.Field; | ||
|
|
||
| public final class FireControllerImpl implements FireController { | ||
| private final ValidateControllerImpl validateController = ValidateControllerImpl.getInstance(); | ||
| private final ParserControllerImpl parserController = ParserControllerImpl.getInstance(); | ||
|
|
||
| private FireControllerImpl() {} | ||
|
|
||
| @Override | ||
| public CellStatus fire(Field opponentField, Field radar, String coordinate) { | ||
| if (radar == null || opponentField == null) throw new RuntimeException("Поле не может быть null"); | ||
|
|
||
| int[] cordXY = parserController.parseCoordinate(coordinate); | ||
| int x = cordXY[0], y = cordXY[1]; | ||
|
|
||
| CellStatus cellBefore = opponentField.getCell(x, y); | ||
| CellStatus cellAfter; | ||
| if (cellBefore == CellStatus.SHIP || cellBefore == CellStatus.HIT) { | ||
| cellAfter = CellStatus.HIT; | ||
| } | ||
| else { | ||
| cellAfter = CellStatus.SHOT; | ||
| } | ||
| opponentField.setCell(x, y, cellAfter); | ||
| radar.setCell(x, y, cellAfter); | ||
| return cellAfter; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkFire(Field field, String coordinate) { | ||
| if (field == null) return false; | ||
| if (!validateController.coordinate(coordinate)) return false; | ||
| int[] cordXY = parserController.parseCoordinate(coordinate); | ||
|
|
||
| return field.getCell(cordXY[0], cordXY[1]) != CellStatus.HIT | ||
| && field.getCell(cordXY[0], cordXY[1]) != CellStatus.SHOT; | ||
| } | ||
|
|
||
| public static FireControllerImpl getInstance() { | ||
| return FireControllerImpl.Holder.INSTANCE; | ||
| } | ||
|
|
||
| private static class Holder { | ||
| static final FireControllerImpl INSTANCE = new FireControllerImpl(); | ||
| } | ||
| } |
121 changes: 121 additions & 0 deletions
121
src/main/java/course_project/sea_battle/controller/impl/GameControllerImpl.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,121 @@ | ||
| package course_project.sea_battle.controller.impl; | ||
|
|
||
| import course_project.sea_battle.controller.*; | ||
| import course_project.sea_battle.model.CellStatus; | ||
| import course_project.sea_battle.model.Game; | ||
| import course_project.sea_battle.model.GamePlayer; | ||
|
|
||
| public final class GameControllerImpl implements GameController{ | ||
| private final PlayerController playerController = PlayerControllerImpl.getInstance(); | ||
| private final IOController ioController = IOControllerImpl.getInstance(); | ||
| private final FieldFillController manualFieldFillService = ManualFieldFillController.getInstance(); | ||
| private final FieldFillController randomFieldFillController = RandomFieldFillController.getInstance(); | ||
| private final FieldController fieldController = FieldControllerImpl.getInstance(); | ||
| private final FireController fireController = FireControllerImpl.getInstance(); | ||
| private final ShipController shipController = ShipControllerImpl.getInstance(); | ||
|
|
||
| private GameControllerImpl() {} | ||
|
|
||
| public Game start() { | ||
| Game game = new Game(); | ||
| addPlayers(game); | ||
| setShips(game.getPlayer1()); | ||
| ioController.dialog("Позовите Следующего"); | ||
| ioController.clr(); | ||
| setShips(game.getPlayer2()); | ||
| ioController.dialog("Да начнется битва"); | ||
| ioController.clr(); | ||
|
|
||
| doGame(game); | ||
| ioController.close(); | ||
| return game; | ||
| } | ||
|
|
||
| private void addPlayers(Game game) { | ||
| String name1; | ||
| String name2; | ||
| do { | ||
| name1 = ioController.dialog("Введите имя первого игрока:"); | ||
| } while (name1.isEmpty()); | ||
| game.setPlayer1(playerController.instance(name1)); | ||
| do { | ||
| name2 = ioController.dialog("Введите имя второго игрока:"); | ||
| } while (name2.isEmpty()); | ||
| game.setPlayer2(playerController.instance(name2)); | ||
| } | ||
|
|
||
| private void setShips(GamePlayer player) { | ||
| ioController.print(player.getName() + ", установите корабли!"); | ||
| boolean nextStep = false; | ||
| while (!nextStep) { | ||
| String answerP1 = ioController.dialog("Заполнить рандомно?(y/n):"); | ||
| if (answerP1.trim().toLowerCase().matches("y")) { | ||
| randomFieldFillController.setShips(player.getFieldPlayer()); | ||
| nextStep = true; | ||
| } else if (answerP1.trim().toLowerCase().matches("n")) { | ||
| manualFieldFillService.setShips(player.getFieldPlayer()); | ||
| nextStep = true; | ||
| } else { | ||
| ioController.print("Попробуйте еще раз"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void doGame(Game game){ | ||
| boolean isPlayer1Move = true; | ||
| boolean isGameOver = false; | ||
|
|
||
| GamePlayer playerAtk = game.getPlayer1(); | ||
| GamePlayer playerDef = game.getPlayer2(); | ||
|
|
||
| while (!isGameOver) { | ||
|
|
||
| if (isPlayer1Move) { | ||
| playerAtk = game.getPlayer1(); | ||
| playerDef = game.getPlayer2(); | ||
| } else { | ||
| playerAtk = game.getPlayer2(); | ||
| playerDef = game.getPlayer1(); | ||
| } | ||
|
|
||
| ioController.clr(); | ||
| if (!turnResult(playerAtk, playerDef)) { | ||
| isPlayer1Move = !isPlayer1Move; | ||
| } | ||
| isGameOver = !shipController.isAnyShipAlive(playerDef.getFieldPlayer()); | ||
| } | ||
| ioController.print(playerAtk.getName() + " Выйграл!"); | ||
| ioController.print(playerDef.getName() + " Проиграл!"); | ||
| fieldController.drawFields(playerAtk.getFieldPlayer(), playerAtk.getRadarPlayer(), | ||
| playerDef.getFieldPlayer(), playerDef.getRadarPlayer()); | ||
| game.setPlayerWin(playerAtk); | ||
| } | ||
|
|
||
| private boolean turnResult(GamePlayer playerAtk, GamePlayer playerDef) { | ||
| ioController.dialog(playerAtk.getName() + ", Ваш ход!"); | ||
| fieldController.drawFields(playerAtk.getFieldPlayer(), playerAtk.getRadarPlayer()); | ||
| String coordinate; | ||
| do coordinate = ioController.dialog("Координаты:"); | ||
| while (!fireController.checkFire(playerAtk.getRadarPlayer(), coordinate)); | ||
| CellStatus cellStatus = fireController.fire(playerDef.getFieldPlayer(), | ||
| playerAtk.getRadarPlayer(), | ||
| coordinate); | ||
| fieldController.drawFields(playerAtk.getFieldPlayer(), playerAtk.getRadarPlayer()); | ||
| if (cellStatus != CellStatus.HIT) { | ||
| ioController.dialog("Мимо!"); | ||
| ioController.clr(); | ||
| return false; | ||
| } else { | ||
| ioController.dialog("Попали!"); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| public static GameControllerImpl getInstance() { | ||
| return GameControllerImpl.Holder.INSTANCE; | ||
| } | ||
|
|
||
| private static class Holder { | ||
| static final GameControllerImpl INSTANCE = new GameControllerImpl(); | ||
| } | ||
| } |
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: The field is quite narrow, i think it would look better with more space between cells by width

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.
The game seems not working. I see you implemented PvP, but I play only for 1 Player. I don't see field for 2nd, don't see his name anywhere. Don't know how to shoot for 2nd.
And please introduce automatic ship placement, testing will be much easier
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.
Good! Nice architecture, SOLID is followed. Code is pretty readable. Good Java Core and Java libraries usage.
To make better: interface could be refactored. Also check correct working of the game.
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.
Also nice approach to testing, test cases are readable
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.
Good, automatic ship placement! I found some minor issues with the interface:
The app now works correctly, I didn't find any bugs. And from the code perspective, the app looks great!
To make better: improve interface:)
The homework is approved