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
Drozdov_Nikita #38
Open
pepya4ka
wants to merge
58
commits into
master
Choose a base branch
from
feature/DrozdovNikita
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
Drozdov_Nikita #38
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
14ecb8d
add homework_1
c36f3b8
refactor README.md
caa0d07
update homework_1
0939a72
del serr, add "\033[0;31m" in sout
5321ff5
homework_2, 1st task done
b1fda1f
homework_2, 2nd task done
95f480c
homework_2, 1st task refactor
7ce3d3c
homework_2, 3rd task done
f5158ab
update README.md
342868e
update README.md
e39ae9a
refactor TrafficLight
9bfa59f
refactor PyramidPrinter
248fc44
refactor RandomCharsTable
a24124e
add ImmutableClass
3f69a84
Merge branch 'master' into feature/DrozdovNikita
eab5371
update TrafficLight
2eabb92
update PyramidPrinter
49edb40
update RandomCharsTable
34779e9
update README.md
ceff88c
add UnitBaseMode.java
2ba110a
add junit tests for TrafficLight, TrafficLightExtraMode
a3548a9
add junit tests for 1st homework
f6e138f
add junit tests for PyramidPrinter
c6cb722
add junit tests for RandomCharsTable, RandomCharsTableCreator
a1de007
refactor hw2
pepya4ka f56c198
refactor hw3
pepya4ka db966e0
refactor hw3
pepya4ka 88f9283
add hw4 CustomFileReader
pepya4ka 4af3225
add hw4 Singleton
pepya4ka 7796db2
add hw4 CustomAnnotation
pepya4ka e1c78c6
refactor hw4 CustomFileReader
pepya4ka b3ee00f
update README.md
pepya4ka b67f41f
update README.md
pepya4ka 328e0e6
update README.md
pepya4ka b2257ec
refactor HW4
pepya4ka a8816e3
refactor HW4: remove apache and guava
pepya4ka 0621fee
add hw5 CustomRegexMatcher
pepya4ka d4ef445
add hw5 PowerOfNumber
pepya4ka 7e0bf34
add BaseClazz
pepya4ka a546438
refactor hw1
pepya4ka db58272
refactor hw2 PyramidPrinter
pepya4ka 4e9cfe3
refactor hw2 TrafficLight
pepya4ka e6769f7
refactor hw2 RandomCharsTable
pepya4ka 68efb7a
refactor hw3 MyImmutableClass
pepya4ka 804c5ef
refactor hw4 CustomFileReader
pepya4ka 070db1b
refactor hw5 CustomRegexMatcher
pepya4ka 579fac1
refactor hw5 PowerOfNumber
pepya4ka 1df79cb
update README.md
pepya4ka 750a82d
add hw7
pepya4ka aee0d31
add hw6
pepya4ka 4f7d50c
beta 1
pepya4ka d17e937
refactor hw6 MapProblemsGenerator
pepya4ka d8ee91a
refactor hw6 MapProblemsGenerator
pepya4ka f5fa480
beta 2
pepya4ka 07b95a7
refactor hw5 PowerOfNumber
pepya4ka 203ef1d
CP: add some message for players
pepya4ka dd2df0e
update README.md
pepya4ka e34eceb
CP: add autoset marks around sunken ship, mark damage on your field, …
pepya4ka 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* | ||
| ## *Drozdov Nikita* つ ◕_◕ ༽つ | ||
|
|
||
| | 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/DrozdovNikita/src/main/java/homework_1) | The app that reads input arguments and prints them, until "error" argument | | ||
| | HW2 | [Traffic light](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_2/traffic_light) </br> [PyramidPrinter](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_2/pyramid_printer) </br> [RandomCharsTable](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_2/random_chars_table)| The app that reads input args and prints current traffic light </br> The app that reads input integer and prints "x" pyramid </br> The app that reads input arg, generate chars table and prints odd/even letters | | ||
| | HW3 | [ImmutableClass](https://github.com/NikolaevArtem/Java_Core_June_2021/blob/feature/DrozdovNikita/src/main/java/homework_3/MyImmutableClass.java) | | | ||
| | HW4 | [CustomFileReader](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_4/custom_file_reader) <br> [Singleton](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_4/singleton) <br> [CustomAnnotation](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_4/custom_annotation) | The app has 6 implementation file reader: Apache, BufferedReader, FileInputStream, Guava, Scanner and NIO <br> The app-singleton <br> The app use custom annotations to create xml structure for your object: XmlSerializable and XmlElement | | ||
| | HW5 | [PowerOfNumber](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_5/power_of_number) <br> [CustomRegexMatcher](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_5/custom_regex_matcher) | The app that reads two input integers and prints a to the power of b <br> The app that reads input phone number and prints its validity | | ||
| | HW6 | [MapProblemsGenerator](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_6) | The app that generate map problems | ||
| | HW7 | [KittenToCatFunction](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/homework_7) | The app that implementation KittenToCatFunction functional interface | ||
| | CP | [SeaBattle](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/main/java/course_project) | Sea Battle | ||
| | | | | | ||
| | TEST | [Test dir](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/DrozdovNikita/src/test/java) | ||
|
|
||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) </br> | ||
| [Link to сodingBat](https://codingbat.com/done?user=ndrozdov9@gmail.com&tag=8408048475) | ||
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,28 @@ | ||
| package base; | ||
|
|
||
| import java.math.BigInteger; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| public abstract class BaseClazz { | ||
|
|
||
| protected static final String ANSI_RESET = "\033[0m"; | ||
| protected static final String ANSI_RED = "\u001B[31m"; | ||
| protected static final String ANSI_RED_BACKGROUND = "\u001B[41m"; | ||
| protected static final String ANSI_GREEN_BACKGROUND = "\u001B[42m"; | ||
| protected static final String ANSI_YELLOW_BACKGROUND = "\u001B[43m"; | ||
|
|
||
| public abstract void run(); | ||
|
|
||
| protected boolean isValid(String... arg) { | ||
| if (arg[0].split("\\s").length > 1) { | ||
| return false; | ||
| } | ||
| if (!arg[0].chars().allMatch(Character::isDigit)) { | ||
| return false; | ||
| } | ||
|
|
||
| return new BigInteger(arg[0]).compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) <= 0 && | ||
| IntStream.of(Integer.parseInt(arg[0])).allMatch(elem -> elem + 1 > 0); | ||
| } | ||
|
|
||
| } |
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,97 @@ | ||
| package course_project; | ||
|
|
||
| import base.BaseClazz; | ||
| import course_project.services.FieldPrinter; | ||
| import course_project.services.GameService; | ||
| import course_project.services.PlayerController; | ||
| import course_project.ship.abstracts.SinglePartShip; | ||
| import course_project.ship.models.Player; | ||
| import course_project.ship.abstracts.ShipType; | ||
|
|
||
| import java.util.*; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static course_project.services.GameService.*; | ||
|
|
||
| public class Game extends BaseClazz { | ||
|
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. It's quite difficult to put ships manually, especially because the field does not refresh
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. I got it, you refresh after the type of ships was placed. Smart move
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.
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. Also time between turns is quite long, could you please reduce sleep time? |
||
|
|
||
| private static String MISS = "Промах. В следующий раз повезет"; | ||
|
|
||
| private final Player player = new Player("player1"); | ||
| private final Player computer = new Player("player2"); | ||
|
|
||
| public static Scanner scanner = new Scanner(System.in); | ||
|
|
||
| private static final Function<Player, Stream<SinglePartShip>> convert = | ||
| elem -> elem | ||
| .getMapShips() | ||
| .values() | ||
| .stream() | ||
| .flatMap(e -> e | ||
| .stream() | ||
| .flatMap(l -> l.getList().stream())); | ||
|
|
||
| @Override | ||
| public void run() { | ||
| player.getMapShips().putAll(GameService.getNewPlayerWithRandomShips(player.getName()).getMapShips()); | ||
| computer.getMapShips().putAll(GameService.getNewPlayerWithRandomShips(computer.getName()).getMapShips()); | ||
| startGame(); | ||
| } | ||
|
|
||
| private void startGame() { | ||
| Player aim = computer; | ||
| Player attacker = player; | ||
| while (!(player.isEmptyHealthShips() || computer.isEmptyHealthShips())) { | ||
| FieldPrinter.printFiled(convert.apply(attacker), attacker.getHitsMap(), attacker.getDamageList().stream()); | ||
| String result = playersHit(aim, attacker); | ||
| if (!result.equals(MISS)) { | ||
| System.out.println(result); | ||
| } else { | ||
| aim = (aim == computer ? player : computer); | ||
| attacker = (attacker == computer ? player : computer); | ||
| clearConsole(); | ||
| System.out.println(result); | ||
| try { | ||
| Thread.sleep(1500); | ||
| } catch (InterruptedException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| clearConsole(); | ||
| } | ||
| } | ||
| FieldPrinter.printFiled(convert.apply(attacker), attacker.getHitsMap(), attacker.getDamageList().stream()); | ||
| System.out.println("Победил " + attacker.getName()); | ||
| } | ||
|
|
||
| private void initPlayer(Player gamer) { | ||
| FieldPrinter.printFieldForInit(convert.apply(gamer)); | ||
| PlayerController.initShipLists(gamer, ShipType.SINGLE_DECK, 4); | ||
| FieldPrinter.printFieldForInit(convert.apply(gamer)); | ||
| PlayerController.initShipLists(gamer, ShipType.DOUBLE_DECK, 3); | ||
| FieldPrinter.printFieldForInit(convert.apply(gamer)); | ||
| PlayerController.initShipLists(gamer, ShipType.THREE_DECK, 2); | ||
| FieldPrinter.printFieldForInit(convert.apply(gamer)); | ||
| PlayerController.initShipLists(gamer, ShipType.FOUR_DECK, 1); | ||
| } | ||
|
|
||
| private void initPlayer1(Player gamer) { | ||
| PlayerController.addToList(gamer, ShipType.SINGLE_DECK, "A10", "V", 1); | ||
| PlayerController.addToList(gamer, ShipType.SINGLE_DECK, "D9", "V", 1); | ||
| PlayerController.addToList(gamer, ShipType.SINGLE_DECK, "F9", "V", 1); | ||
| PlayerController.addToList(gamer, ShipType.SINGLE_DECK, "G6", "V", 1); | ||
| PlayerController.addToList(gamer, ShipType.DOUBLE_DECK, "A1", "H", 2); | ||
| PlayerController.addToList(gamer, ShipType.DOUBLE_DECK, "J3", "V", 2); | ||
| PlayerController.addToList(gamer, ShipType.DOUBLE_DECK, "I9", "V", 2); | ||
| PlayerController.addToList(gamer, ShipType.THREE_DECK, "D1", "V", 3); | ||
| PlayerController.addToList(gamer, ShipType.THREE_DECK, "B5", "V", 3); | ||
| PlayerController.addToList(gamer, ShipType.FOUR_DECK, "G1", "H", 4); | ||
| } | ||
|
|
||
| private void clearConsole() { | ||
| for (int i = 0; i < 20; i++) { | ||
| System.out.println(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
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; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| new Game().run(); | ||
|
|
||
| } | ||
|
|
||
| } |
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,99 @@ | ||
| package course_project.services; | ||
|
|
||
| import course_project.ship.abstracts.SinglePartShip; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.IntStream; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class FieldPrinter { | ||
|
|
||
| private static final int FIELD_CAPACITY = 10; | ||
| protected static final String ANSI_RESET = "\033[0m"; | ||
| protected static final String ANSI_GREEN = "\u001B[32m"; | ||
| protected static final String ANSI_CYAN = "\u001B[36m"; | ||
|
|
||
| private FieldPrinter() { | ||
| throw new IllegalStateException("Utility class"); | ||
| } | ||
|
|
||
| public static void printFieldForInit(Stream<SinglePartShip> attacker) { | ||
| int[][] attackerField = new int[FIELD_CAPACITY][FIELD_CAPACITY]; | ||
| attacker.forEach(elem -> add(attackerField, elem, 1)); | ||
| printTableHeader(); | ||
| System.out.println(); | ||
| for (int i = 0; i < FIELD_CAPACITY; i++) { | ||
| printLineTable(i, attackerField); | ||
| System.out.println(); | ||
| } | ||
| } | ||
|
|
||
| public static void printFiled(Stream<SinglePartShip> attacker, | ||
| Map<Boolean, List<SinglePartShip>> opponent, | ||
| Stream<SinglePartShip> damageList) { | ||
| int[][] attackerField = new int[FIELD_CAPACITY][FIELD_CAPACITY]; | ||
| int[][] opponentField = new int[FIELD_CAPACITY][FIELD_CAPACITY]; | ||
| attacker.forEach(elem -> add(attackerField, elem, 1)); | ||
| damageList.forEach(elem -> add(attackerField, elem, -1)); | ||
| opponent.entrySet().forEach(elem -> add(opponentField, elem)); | ||
|
|
||
| System.out.printf("%-51s", "your field"); | ||
| System.out.println("opponent field"); | ||
|
|
||
| printTableHeader(); | ||
| System.out.printf("%4s", " | "); | ||
| printTableHeader(); | ||
| System.out.println(); | ||
|
|
||
| for (int i = 0; i < FIELD_CAPACITY; i++) { | ||
| printLineTable(i, attackerField); | ||
| System.out.printf("%4s", " | "); | ||
| printLineOpponentTable(i, opponentField); | ||
| System.out.println(); | ||
| } | ||
| } | ||
|
|
||
| private static void printTableHeader() { | ||
| System.out.printf("%4s", ""); | ||
| IntStream.range(0, FIELD_CAPACITY).forEach(i -> System.out.printf("%4s", (char) (65 + i))); | ||
| } | ||
|
|
||
| private static void printLineTable(int i, int[][] field) { | ||
| System.out.printf("%4s", i + 1); | ||
| for (int j = 0; j < FIELD_CAPACITY; j++) { | ||
| if (field[i][j] == 1) { | ||
| System.out.printf("%13s", ANSI_GREEN + "x" + ANSI_RESET); | ||
| } else if (field[i][j] == -1) { | ||
| System.out.printf("%13s", ANSI_CYAN + "o" + ANSI_RESET); | ||
| } else { | ||
| System.out.printf("%4s", "."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void printLineOpponentTable(int i, int[][] field) { | ||
| System.out.printf("%4s", i + 1); | ||
| for (int j = 0; j < FIELD_CAPACITY; j++) { | ||
| if (field[i][j] == 1) { | ||
| System.out.printf("%13s", ANSI_GREEN + "x" + ANSI_RESET); | ||
| } else if (field[i][j] == -1) { | ||
| System.out.printf("%13s", ANSI_CYAN + "o" + ANSI_RESET); | ||
| } else { | ||
| System.out.printf("%4s", "?"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void add(int[][] field, SinglePartShip partShip, int value) { | ||
| field[partShip.getY() - 1][partShip.getX() - 1] = value; | ||
| } | ||
|
|
||
| private static void add(int[][] field, Map.Entry<Boolean, List<SinglePartShip>> partShip) { | ||
| if (partShip.getKey()) { | ||
| partShip.getValue().forEach(elem -> add(field, elem, 1)); | ||
| } else { | ||
| partShip.getValue().forEach(elem -> add(field, elem, -1)); | ||
| } | ||
| } | ||
| } |
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-looking readme 👍