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
Ilia_Prokofev #15
Open
blowushka
wants to merge
72
commits into
master
Choose a base branch
from
feature/IliaProkofev
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
Ilia_Prokofev #15
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
f44f031
Change "Hello World" to "Hello Russia"
blowushka c82e811
Change "Hello, Russia" to "Hello, Epam"
blowushka 67e53ab
.gitignore update
blowushka 58734b1
Add new folder called homework_1 and complete homework
blowushka 0fcb854
Edit args output a bit
blowushka e4d75d5
Change russian words to english
blowushka 56a06cf
Update .gitignore
blowushka f5f49ac
Add if(args.length == 0) validation
blowushka 8201f13
Update .gitignore
blowushka 3b14785
Delete unnecessary files
blowushka c6cc772
Merge remote-tracking branch 'origin/master' into feature/IliaProkofev
blowushka 7e09d62
Add README.md and update .gitignore
blowushka 6898d5c
Update README.md
blowushka 5d50400
Delete build.gradle
blowushka 5477b92
Delete Main.java from wrong folder
blowushka 6af1c99
Ignore .gitignore for push
blowushka ee5f09c
Delete .gitignore from remote repo
blowushka 3f56714
Restore .gitignore to remote repo
blowushka 795a130
Merge remote-tracking branch 'origin/feature/IliaProkofev' into featu…
blowushka 13ff790
Restore .gitignore to remote repo
blowushka c998ab1
Fix indentation and RED-text output
blowushka 265a86f
Restore deleted files
blowushka 121d8e2
Fix indentation
blowushka 0421d59
Refactoring
blowushka d1f46cb
Refactoring
blowushka 2fc8a83
Final refactoring
blowushka 03eb76f
Complete Homework_2
blowushka e29f38b
Edit README.md
blowushka 73b485c
Delete unnecessary import
blowushka 0d89e98
Change output for PyramidPrinter
blowushka 7d43fbc
Change program exit style
blowushka 94cb687
Fix minor problems, close Scanner in RandomCharsTable.java, fix Engli…
blowushka a2d4b50
Changed the entry point to applications, major refactoring
blowushka b6b380a
Merge branch 'master' into feature/IliaProkofev
blowushka a6ebdae
Global refactoring:
blowushka cc1ee4a
Complete all tests for homework, create Immutable Class, minor improv…
blowushka 86d5f3c
Update Readme.md
blowushka 26f642c
Edit ImmutableClass and add test
blowushka 5ccef57
--Changed the class names as specified in the condition
blowushka a2b062f
Fixed typo in README.md
blowushka 3750150
Change the type of abstraction
blowushka 3575493
Changed the names of the tests, added some blank lines, deleted tests…
blowushka e81d405
Refactoring + README edit
blowushka 61b1bfa
README edit
blowushka 7da109c
Change .txt input
blowushka f850b76
Refactoring
blowushka 795027a
Add CustomAnnotation, edit README.md
blowushka 7f805ed
Added test for CustomAnnotation
blowushka 6e7d1e5
Edit README.md
blowushka f0833d6
Add couple of tests for CustomAnnotation
blowushka d2a9b33
Complete homework 5
blowushka 631db28
HW5 refactoring and add tests
blowushka 69e5170
Refactoring
blowushka e7a84a0
Edit README.md
blowushka 80ad1a2
Add one case for unit-test
blowushka 1d4b053
Major refactoring, add tests, complete CustomRegexMatcher
blowushka 6a354d9
Edit README.md
blowushka f15163d
Complete Homework 6
blowushka bc43c5b
Edit README.md
blowushka 1eac62d
Major refactoring
blowushka 86ff890
Edited method names
blowushka 759f5ea
Complete homework_7
blowushka fb8ef30
Edit README.md
blowushka f15468d
Fix wrong naming
blowushka 01fb814
Edit README.md
blowushka 641ed85
Course project complete
blowushka 655d904
Edit README.md
blowushka 3d5a14d
Edit README.md
blowushka 0b4857b
Edit MapProblemsMutableGenerator
blowushka 0d77640
Minor refactoring
blowushka 775070c
Delete seriesUp method
blowushka 77a16b2
FIX HW_3
blowushka 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,21 @@ | ||
| # Java Core June 2021 | ||
|
|
||
| ## *Nikolaev Artem* | ||
| ## *Prokofev Ilia* | ||
|
|
||
| | 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 | | ||
| | Index | Solution | Short description| | ||
| | :---: | --- | --- | | ||
| |**Course Project**|[Sea Battle](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/course_project)|Console version of the classic Sea Battle game with graphical representation| | ||
| | HW1 | [Console printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_1) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_1/char_count) | The app that reads input arguments and prints them, until "error" argument | | ||
| |-----| [Traffic Light](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_2/traffic_light) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_2/traffic_light) | The app that reads console and calculate current traffic light's color | | ||
| | HW2 | [Pyramid Printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_2/pyramid_printer) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_2/pyramid_printer) | The app that reads console and prints a pyramid based on this | | ||
| |-----| [Random Chars Table](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_2/random_chars_table) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_2/random_chars_table) | The app that reads console for length, width and strategy and prints table based on this| | ||
| | HW3 | [Immutable Class](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_3) | The class that give opportunity for create Immutable object| | ||
| |-----| [Custom Annotation](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_4/custom_annotation) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_4/custom_annotation) | A form of syntactic metadata that can be added to Java source code| | ||
| | HW4 | [Custom File Reader](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_4/custom_file_reader) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_4/custom_file_reader) | The app that provides 3 ways to read and edit a file| | ||
| |-----| [Singleton](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_4/singleton) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_4/singleton) | Creational design pattern, which ensures that only one object of its kind exists | | ||
| | HW5 | [PowerOfNumber](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_5/power_of_number) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_5/power_of_number) | The app that raises a number to a power | | ||
| |-----| [CustomRegexMatcher](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_5/custom_regex_matcher) <br> [Test](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/test/java/homework_5/custom_regex_matcher) | The app that check input string by hardcoded regex and return boolean answer | | ||
| | HW6 | [MapProblemsGenerator](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_6/map_problems_generator)|Two classes that allow you to check the work of the collision and create a situation where it is impossible to get the object just put| | ||
| | HW7 | [KittenToCatFunction](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/IliaProkofev/src/main/java/homework_7)|Functional interface that allows you to transform a Kitten into a Cat| | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
| [CodingBat link](https://codingbat.com/done?user=slowly@live.ru&tag=8165639202) |
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,8 @@ | ||
| package course_project; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| SeaBattle.initializeGame(); | ||
| } | ||
| } | ||
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,12 @@ | ||
| package course_project; | ||
|
|
||
| import course_project.dialogue.Menu; | ||
|
|
||
| final class SeaBattle { | ||
|
|
||
| public static void initializeGame() { | ||
| Menu.showLogo(); | ||
| Menu.showGreetings(); | ||
| Menu.showMainMenu(); | ||
| } | ||
| } |
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,207 @@ | ||
| package course_project.board; | ||
|
|
||
| import course_project.player.Player; | ||
| import course_project.ships.*; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import static course_project.dialogue.Menu.*; | ||
| import static course_project.utils.RandomPositionGenerator.generateRandomForCell; | ||
| import static course_project.utils.RandomDirectionGenerator.generateRandomDirection; | ||
|
|
||
| public class Battlefield extends Board { | ||
|
|
||
| private final List<Ship> availableShips = new ArrayList<>(); | ||
|
|
||
| public Battlefield() { | ||
| super.cells = new Cell[FIELD_SIZE][FIELD_SIZE]; | ||
| fillCells(); | ||
| addShipsToList(); | ||
| } | ||
|
|
||
| public List<Ship> getAvailableShips() { | ||
| return this.availableShips; | ||
| } | ||
|
|
||
| public void addShipsToList() { | ||
| availableShips.add(new Battleship()); | ||
| availableShips.add(new Destroyer()); | ||
| availableShips.add(new Destroyer()); | ||
| availableShips.add(new Cruiser()); | ||
| availableShips.add(new Cruiser()); | ||
| availableShips.add(new Cruiser()); | ||
| availableShips.add(new PatrolBoat()); | ||
| availableShips.add(new PatrolBoat()); | ||
| availableShips.add(new PatrolBoat()); | ||
| availableShips.add(new PatrolBoat()); | ||
| } | ||
|
|
||
| public boolean addShipOnBattlefield(Ship ship, Cell cell, boolean isHorizontal) { | ||
| if (checkSpaceForPlaceShip(cell, ship.getSize(), isHorizontal)) { | ||
| if (isHorizontal) { | ||
| return !addRowOfCells(cell, ship); | ||
| } else { | ||
| return !addColumnOfCells(cell, ship); | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public void availableShipsDecrease(Ship ship) { | ||
| this.availableShips.remove(ship); | ||
| } | ||
|
|
||
| private boolean addColumnOfCells(Cell entryCell, Ship ship) { | ||
| if (checkPossibilityForAddColumn(entryCell, ship.getSize())) { | ||
| int y = entryCell.getY(); | ||
| for (int i = entryCell.getX(); i < entryCell.getX() + ship.getSize(); i++) { | ||
| getCellByPosition(i, y).setShipAtCell(ship); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private boolean addRowOfCells(Cell entryCell, Ship ship) { | ||
| if (checkPossibilityForAddRow(entryCell, ship.getSize())) { | ||
| int x = entryCell.getX(); | ||
| for (int j = entryCell.getY(); j < entryCell.getY() + ship.getSize(); j++) { | ||
| getCellByPosition(x, j).setShipAtCell(ship); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private boolean checkPossibilityForAddColumn(Cell entryCell, int shipSize) { | ||
| if (!(checkCellAbove(entryCell) && | ||
| checkCellAboveLeftDiagonal(entryCell) && | ||
| checkCellAboveRightDiagonal(entryCell))) { | ||
| return false; | ||
| } | ||
| int y = entryCell.getY(); | ||
| for (int i = entryCell.getX(); i < entryCell.getX() + shipSize; i++) { | ||
| Cell currentCell = cells[i][y]; | ||
| if (!(isCellEmpty(currentCell) && | ||
| checkCellBelow(currentCell) && | ||
| checkCellOnTheLeft(currentCell) && | ||
| checkCellOnTheRight(currentCell))) { | ||
| return false; | ||
| } | ||
| if (i == entryCell.getX() + shipSize - 1 && | ||
| !(checkCellBelowLeftDiagonal(currentCell) && | ||
| checkCellBelowRightDiagonal(currentCell)) | ||
| ) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private boolean checkPossibilityForAddRow(Cell entryCell, int shipSize) { | ||
| if (!(checkCellOnTheLeft(entryCell) && | ||
| checkCellAboveLeftDiagonal(entryCell) && | ||
| checkCellBelowLeftDiagonal(entryCell) && | ||
| checkCellAboveRightDiagonal(entryCell)) | ||
| ) { | ||
| return false; | ||
| } | ||
| int x = entryCell.getX(); | ||
| for (int j = entryCell.getY(); j < entryCell.getY() + shipSize; j++) { | ||
| Cell currentCell = cells[x][j]; | ||
| if (!(isCellEmpty(currentCell) && | ||
| checkCellOnTheRight(currentCell) && | ||
| checkCellAbove(currentCell) && | ||
| checkCellBelow(currentCell)) | ||
| ) { | ||
| System.out.println("Cannot set the ship to coordinates " + Character.toUpperCase((char) (entryCell.getY() + 97)) + "" + (entryCell.getX() + 1) + ", check if the ship is in contact with another.\n"); | ||
| return false; | ||
| } | ||
| if (j == entryCell.getY() + shipSize - 1 && | ||
| !(checkCellAboveRightDiagonal(currentCell) && | ||
| checkCellBelowRightDiagonal(currentCell)) | ||
| ) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private boolean checkSpaceForPlaceShip(Cell fromCell, int shipSize, boolean isHorizontal) { | ||
| return isHorizontal ? | ||
| fromCell.getY() >= 0 && fromCell.getY() + shipSize <= FIELD_SIZE : | ||
| fromCell.getX() >= 0 && fromCell.getX() + shipSize <= FIELD_SIZE; | ||
| } | ||
|
|
||
| private boolean checkCellAbove(Cell currentCell) { | ||
| return currentCell.getX() == 0 || isCellEmpty(cells[currentCell.getX() - 1][currentCell.getY()]); | ||
| } | ||
|
|
||
| private boolean checkCellBelow(Cell currentCell) { | ||
| return currentCell.getX() == 9 || isCellEmpty(cells[currentCell.getX() + 1][currentCell.getY()]); | ||
| } | ||
|
|
||
| private boolean checkCellOnTheRight(Cell currentCell) { | ||
| return currentCell.getY() == 9 || isCellEmpty(cells[currentCell.getX()][currentCell.getY() + 1]); | ||
| } | ||
|
|
||
| private boolean checkCellOnTheLeft(Cell currentCell) { | ||
| return currentCell.getY() == 0 || isCellEmpty(cells[currentCell.getX()][currentCell.getY() - 1]); | ||
| } | ||
|
|
||
| private boolean checkCellAboveLeftDiagonal(Cell currentCell) { | ||
| return currentCell.getX() == 0 || currentCell.getY() == 0 || | ||
| isCellEmpty(cells[currentCell.getX() - 1][currentCell.getY() - 1]); | ||
| } | ||
|
|
||
| private boolean checkCellBelowLeftDiagonal(Cell currentCell) { | ||
| return currentCell.getX() == 9 || currentCell.getY() == 0 || | ||
| isCellEmpty(cells[currentCell.getX() + 1][currentCell.getY() - 1]); | ||
| } | ||
|
|
||
| private boolean checkCellAboveRightDiagonal(Cell currentCell) { | ||
| return currentCell.getX() == 0 || currentCell.getY() == 9 || | ||
| isCellEmpty(cells[currentCell.getX() - 1][currentCell.getY() + 1]); | ||
| } | ||
|
|
||
| private boolean checkCellBelowRightDiagonal(Cell currentCell) { | ||
| return currentCell.getX() == 9 || currentCell.getY() == 9 || | ||
| isCellEmpty(cells[currentCell.getX() + 1][currentCell.getY() + 1]); | ||
| } | ||
|
|
||
|
|
||
| public boolean hasAvailableShips() { | ||
| return !this.availableShips.isEmpty(); | ||
| } | ||
|
|
||
| public static void addShipsOneByOne(Player currentPlayer) { | ||
| showHelp(); | ||
| for (Ship ship : currentPlayer.getField().getAvailableShips()) { | ||
| currentPlayer.getField().printField(); | ||
| Cell position; | ||
| boolean isHorizontal = true; | ||
| do { | ||
| System.out.print("Ship's type: " + ship.getName() + ". Size: " + ship.getSize() + ". Specify coordinates: "); | ||
| String[] cellPossition = getInputPosition().split(" "); | ||
| int x = Integer.parseInt(cellPossition[0].substring(1)) - 1; | ||
| int y = Integer.parseInt(String.valueOf(cellPossition[0].charAt(0) - 97)); | ||
| position = currentPlayer.getField().getCellByPosition(x, y); | ||
| if (cellPossition.length == 2) { | ||
| isHorizontal = !"v".equals(cellPossition[1]); | ||
| } | ||
| } while (currentPlayer.getField().addShipOnBattlefield(ship, position, isHorizontal)); | ||
| } | ||
| } | ||
|
|
||
| public static void generateRandomPlacesForShips(Player currentPlayer) { | ||
| for (Ship ship : currentPlayer.getField().getAvailableShips()) { | ||
| Cell toPos; | ||
| boolean isHorizontal; | ||
| do { | ||
| toPos = currentPlayer.getField().getCellByPosition(generateRandomForCell(), | ||
| generateRandomForCell()); | ||
| isHorizontal = generateRandomDirection(); | ||
| } while (currentPlayer.getField().addShipOnBattlefield(ship, toPos, isHorizontal)); | ||
| } | ||
| } | ||
| } |
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,113 @@ | ||
| package course_project.board; | ||
|
|
||
| import course_project.player.Player; | ||
|
|
||
| import static course_project.utils.Colors.*; | ||
|
|
||
| public class Board { | ||
|
|
||
| public static final int FIELD_SIZE = 10; | ||
| private static final String SHIP = ANSI_GREEN + "■" + ANSI_RESET; | ||
| private static final String WATER = "~"; | ||
| private static final String MISS = ANSI_MAGENTA + "▓" + ANSI_RESET; | ||
| private static final String HIT = ANSI_YELLOW + "×" + ANSI_RESET; | ||
| private static final String DESTROY = ANSI_RED + "*" + ANSI_RESET; | ||
|
|
||
| Cell[][] cells; | ||
|
|
||
| protected Board() { | ||
| this.cells = new Cell[FIELD_SIZE][FIELD_SIZE]; | ||
| fillCells(); | ||
| } | ||
|
|
||
| public void fillCells() { | ||
| for (int i = 0; i < FIELD_SIZE; i++) { | ||
| for (int j = 0; j < FIELD_SIZE; j++) { | ||
| cells[i][j] = new Cell(i, j); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void printField() { | ||
| StringBuilder field = new StringBuilder(); | ||
| field.append("\t" + "A B C D E F G H I J").append("\n"); | ||
|
|
||
| for (int i = 0; i < FIELD_SIZE; i++) { | ||
| field.append(String.format("|%-2d|", i + 1)); | ||
| for (int j = 0; j < FIELD_SIZE; j++) { | ||
| Cell currentCell = getCellByPosition(i, j); | ||
| String symbol = WATER; | ||
| if (!isCellEmpty(currentCell)) { | ||
| symbol = SHIP; | ||
| } | ||
| field.append(String.format("%s ", symbol)); | ||
| } | ||
| field.append("\n"); | ||
| } | ||
| System.out.println(field); | ||
| } | ||
|
|
||
| public void showTwoFields(Player currentPlayer, Player enemy) { | ||
|
|
||
| StringBuilder twoFields = new StringBuilder(); | ||
|
|
||
| twoFields.append("\t" + "A B C D E F G H I J").append("\t\t\t " + "A B C D E F G H I J").append("\n"); | ||
|
|
||
| for (int i = 0; i < FIELD_SIZE; i++) { | ||
| twoFields.append(String.format("|%-2d|", i + 1)); | ||
| for (int j = 0; j < FIELD_SIZE; j++) { | ||
| if (currentPlayer.getField().getCellByPosition(i, j).isHit()) { | ||
| checkCellStateAndMarkIt(currentPlayer, twoFields, i, j); | ||
| } else { | ||
| if (currentPlayer.getField().isCellEmpty(currentPlayer.getField().getCellByPosition(i, j))) { | ||
| twoFields.append(String.format("%s ", WATER)); | ||
| } else { | ||
| twoFields.append(String.format("%s ", SHIP)); | ||
| } | ||
| } | ||
| } | ||
| twoFields.append("\t\t").append(String.format("|%-2d|", i + 1)); | ||
| for (int j = 0; j < FIELD_SIZE; j++) { | ||
| if (enemy.getField().getCellByPosition(i, j).isHit()) { | ||
| checkCellStateAndMarkIt(enemy, twoFields, i, j); | ||
| } else { | ||
| twoFields.append(String.format("%s ", WATER)); | ||
| } | ||
| } | ||
| twoFields.append("\n"); | ||
| } | ||
| System.out.println(twoFields); | ||
| } | ||
|
|
||
| private void checkCellStateAndMarkIt(Player currentPlayer, StringBuilder bothFields, int i, int j) { | ||
| if (currentPlayer.getField().isHit(currentPlayer.getField().getCellByPosition(i, j))) { | ||
| if (currentPlayer.getField().getCellByPosition(i, j).getReference().isDestroyed()) { | ||
| bothFields.append(String.format("%s ", DESTROY)); | ||
| } else { | ||
| bothFields.append(String.format("%s ", HIT)); | ||
| } | ||
| } else { | ||
| bothFields.append(String.format("%s ", MISS)); | ||
| } | ||
| } | ||
|
|
||
| public Cell getCellByPosition(int x, int y) { | ||
| for (Cell[] cellRow : this.cells) { | ||
| for (Cell cellColumn : cellRow) { | ||
| if (cellColumn.getX() == x && cellColumn.getY() == y) { | ||
| return cellColumn; | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public boolean isCellEmpty(Cell currentCell) { | ||
| return currentCell.getShipReference() == null; | ||
| } | ||
|
|
||
| public boolean isHit(Cell toCell) { | ||
| return !isCellEmpty(cells[toCell.getX()][toCell.getY()]); | ||
| } | ||
|
|
||
| } |
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.
Good job! Nice interface, a lot of features (such as automatic ship placement, different game modes), comfortable to play, informative messages. I like the architecture, the code is readable and understandable. You show good knowledge of Java Core (missing Java 8 and some concepts of OOP).
To make it better: add automatic miss marks placement around a destroyed ship. Also, your code has a lot of static. It seems logical that if you don't care about having multiple objects of a class in your app (like Ship), then mark it static, but actually in this case it should be a singleton, and still dynamic. Static is rarely used in Java, mostly for constants and utils. And mostly your methods are void, which is also rare.
Approved!