-
Notifications
You must be signed in to change notification settings - Fork 2
Dmitriy_Prihodko #49
base: master
Are you sure you want to change the base?
Dmitriy_Prihodko #49
Changes from all commits
a914887
5eaca7d
3b052bc
6631c49
96dee71
290b2c1
3f5fd3f
6cb762c
272252c
1feb7cd
b3e488c
938a501
0c9b710
709d3d3
37be372
b651323
d2b63c8
4565ca0
41c4c3b
c35ddb5
62f6913
e092683
127880a
d4c12ed
2acfbd5
35c4e10
4c72932
72a3928
c0423d0
c66149f
0cf0418
ef29a97
dacf138
79fbb5d
a55d597
945224c
14cc3d0
4a8a041
9d4f397
429eb93
f748716
907b55d
311b50e
e7ab552
8c56e8d
4417ecc
98d014c
88f6458
d3c5b80
8c9e151
90da94e
0faa0dd
757527b
00a33ef
b1ed477
94ef46f
9254b73
65ae690
e8be92a
eda5372
e61d330
3c0c5d0
c4cde6a
87a20cb
53a28c1
2bcf251
361dce8
ebd192f
4935b41
d33165f
07e267c
6fbb5da
ef6378a
3c55f6a
337e316
3e96d07
a35e390
3cb6643
a216509
e21e470
904825a
a27403b
907452c
3892138
339bda2
6a6d458
488dbd9
31acc66
e9d3154
6a06522
c0a1ecc
db9f58f
9a0f100
36feaf6
94b3579
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,23 @@ | ||
| # Java Core June 2021 | ||
|
|
||
| ## *Nikolaev Artem* | ||
| ## *Dmitriy Prihodko* | ||
|
|
||
| | 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](./src/main/java/homework_1) | The app that reads input arguments and prints them, until "error" argument | | ||
| | HW2 | [TrafficLight](./src/main/java/homework_2/traffic_light) <br/> :wrench:[TrafficLightTest](./src/test/java/homework_2/traffic_light) | App reads one time the number of seconds since the beginning of the day and prints the traffic light| | ||
| | HW2 | [PyramidPrinter](./src/main/java/homework_2/pyramid_printer) <br/> :wrench:[PyramidPrinterTest](./src/test/java/homework_2/pyramid_printer)| App reads the number one time from the command line, and prints a pyramid of "x". | | ||
| | HW2 | [RandomCharsTable](./src/main/java/homework_2/random_chars_table) <br/> :wrench:[RandomCharsTableTest](./src/test/java/homework_2/random_chars_table)| App reads width and length of the table array, and strategy keyword (even or odd). App adds random chars from A to Z in table. Prints a table and all even or odd letters. | | ||
| | HW3 | [ImmutableClass](./src/main/java/homework_3)| ImmutableClass| | ||
| | HW4 | [CustomFileReader](./src/main/java/homework_4/custom_file_reader) <br/> :wrench:[CustomFileReaderTest](./src/test/java/homework_4/custom_file_reader)| This application reads the text from the file, removes commas and periods and them outputs the text to the console. | | ||
| | HW4 | [CustomAnnotation](./src/main/java/homework_4/custom_annotation) <br/> :wrench:[CustomAnnotationTest](./src/test/java/homework_4/custom_annotation)| Create custom annotation| | ||
| | HW4 | [Singleton](./src/main/java/homework_4/singleton) <br/> :wrench:[SingletonTest](./src/test/java/homework_4/singleton)| This is a singleton app. you can create only 1 instance of this class.| | ||
| | HW5 | [CustomRegexMatcher](./src/main/java/homework_5/custom_regex_matcher) <br/> :wrench:[CustomRegexMatcherTest](./src/test/java/homework_5/custom_regex_matcher)| This app that accepts 2 numbers from the command line, and raises 1 number to the power of 2 numbers.| | ||
| | HW5 | [PowerOfNumber](./src/main/java/homework_4/power_of_number) <br/> :wrench:[PowerOfNumberTest](./src/test/java/homework_4/power_of_number)| This app checks whether the email is entered correctly.| | ||
| | HW6 | [MapProblemsCollisionGenerator](./src/main/java/homework_6/map_problems_generator) | This app creates collisions in HashMap.| | ||
| | HW6 | [MapProblemsMutableGenerator](./src/main/java/homework_6/map_problems_generator) | A mutable class is declared, this object in HashMap we will not be able to get this object by the key. | | ||
| | HW7 | [KittenToCatFunction](./src/main/java/homework_7/) | the KittenToCatFunction functional interface, with the abstract grow () method, accepts Kitten and return only Cat.. | | ||
| | CourseProject |[SeaBattle](./src/main/java/course_project/sea_battle) <br/> :wrench:[SeaBattleTest](./src/test/java/course_project/sea_battle)| the game follows the standard rules of sea battle | | ||
|
|
||
| [Link to CodingBat](https://codingbat.com/done?user=bomba_25@mail.ru&tag=8601275236) | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package course_project.sea_battle; | ||
|
|
||
| import course_project.sea_battle.conroller.SeaBattle; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) throws IOException { | ||
|
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. The names of variables/methods/classes are not always chosen correctly and follow Code Conventions
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. Well-done! The game is quite comfortable to play, it has a nice interface. Also, you show good knowledge of Java Core and Java libraries, mostly abstractions are chosen correctly, and the structure of the project is quite cool. Here and there are some minor Code Conventions violations, but in general the code is easy to read. Cool implementations of Speaker and Threads! Approved |
||
| SeaBattle game = new SeaBattle(); | ||
| game.start(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package course_project.sea_battle.animated; | ||
|
|
||
| public class AnimateStartGame extends Thread { | ||
| @Override | ||
| public void run() { | ||
| System.out.println("*****************************"); | ||
| String str = "\u001B[31m" + " WELCOME TO BATTLESHIPS GAME" + "\u001B[0m"; | ||
|
|
||
| try { | ||
| Thread.sleep(2000); | ||
| for (Character character : str.toCharArray()) { | ||
| System.out.print(character); | ||
| Thread.sleep(100); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| System.out.println("\n*****************************"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package course_project.sea_battle.conroller; | ||
|
|
||
| import course_project.sea_battle.model.CoordinateTranslator; | ||
| import course_project.sea_battle.model.ModelPlayer; | ||
| import course_project.sea_battle.model.Ship; | ||
| import course_project.sea_battle.view.PaintFieldPlayer; | ||
| import course_project.sea_battle.view.Speaker; | ||
|
|
||
| import java.util.Locale; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Dialog { | ||
|
|
||
| private final Scanner reader; | ||
|
|
||
| public Dialog(final Scanner reader) { | ||
| this.reader = reader; | ||
| } | ||
|
|
||
| public void generateShips(ModelPlayer player) { | ||
| PaintFieldPlayer paint = new PaintFieldPlayer(player); | ||
| Speaker.voice("inputInstruction"); | ||
| while (!player.readyToGame()) { | ||
| paint.paintField(); | ||
| String dateShip = reader.nextLine(); | ||
| tryAddShipInField(dateShip, player); | ||
| } | ||
| } | ||
|
|
||
| public String namePlayerGet() { | ||
| try { | ||
| String name = reader.nextLine(); | ||
| return name; | ||
| } catch (Exception e) { | ||
|
|
||
| } | ||
| return "Empty"; | ||
| } | ||
|
|
||
| public String shotPlayer(ModelPlayer player) { | ||
| while (true) { | ||
| String shot = reader.nextLine(); | ||
| if (shot.matches("(([1-9])|([1][0])) [a-jA-J]")) { | ||
| return player.shot(shot); | ||
| } else { | ||
| Speaker.voice("notCorrect"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public boolean autoGenerate() { | ||
| while (true) { | ||
| String choice = reader.nextLine().toLowerCase(Locale.ROOT); | ||
| if (choice.matches("y|n")) { | ||
| if (choice.equals("y")) { | ||
| return true; | ||
| } | ||
| if (choice.equals("n")) { | ||
| return false; | ||
| } | ||
| } else { | ||
| Speaker.voice("notCorrect"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void tryAddShipInField(String dateShip, ModelPlayer player){ | ||
| if (dateShip.matches("[1-2] (([1-9])|([1][0])) [a-jA-J] [1-4]")) { | ||
|
|
||
| String[] dateShipSplit = dateShip.split(" "); | ||
| boolean orient = dateShipSplit[0].equals("2"); | ||
| int start = Integer.parseInt(dateShipSplit[1]) - 1; | ||
| int end = CoordinateTranslator.coordinate(dateShipSplit[2].toLowerCase(Locale.ROOT)); | ||
| int size = Integer.parseInt(dateShipSplit[3]); | ||
|
|
||
| String message = player.addShip(new Ship(orient, start, end, size)); | ||
| Speaker.voice(message); | ||
| } else { | ||
| Speaker.voice("notCorrect"); | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package course_project.sea_battle.conroller; | ||
|
|
||
| import course_project.sea_battle.model.Field; | ||
| import course_project.sea_battle.model.ModelPlayer; | ||
| import course_project.sea_battle.animated.AnimateStartGame; | ||
| import course_project.sea_battle.view.PaintFieldInPlay; | ||
| import course_project.sea_battle.view.Speaker; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class SeaBattle extends Thread { | ||
|
|
||
| public void run() { | ||
| try (Scanner scanner = new Scanner(System.in)) { | ||
| Dialog dialog = new Dialog(scanner); | ||
| Thread anim = new AnimateStartGame(); | ||
| anim.start(); | ||
| anim.join(); | ||
| Speaker.voice("dialogName"); | ||
|
|
||
| String PlayerName = dialog.namePlayerGet(); | ||
|
|
||
| ModelPlayer player = new ModelPlayer(PlayerName, new Field(10, 10)); | ||
| ModelPlayer IIPlayer = new ModelPlayer("BOT2", new Field(10, 10)); | ||
| Speaker.voice("autoGenerate"); | ||
| boolean choiceGenerate = dialog.autoGenerate(); | ||
|
|
||
| if (choiceGenerate) { | ||
| player.autoGenerateShips(); | ||
| } else { | ||
| dialog.generateShips(player); | ||
| } | ||
| IIPlayer.autoGenerateShips(); | ||
|
|
||
| PaintFieldInPlay play = new PaintFieldInPlay(player, IIPlayer); | ||
| boolean whoCanGo = true; | ||
| play.paintFields(); | ||
| do { | ||
| if (whoCanGo) { | ||
| Speaker.voice("queuePlayer"); | ||
| String shot1 = dialog.shotPlayer(IIPlayer); | ||
| Speaker.voice("shot", shot1); | ||
|
|
||
| if ("Hit! And Kill!".equals(shot1)||"Hit!".equals(shot1)) { | ||
| whoCanGo = true; | ||
| } else { | ||
| whoCanGo = false; | ||
| } | ||
| } else { | ||
| Thread.sleep(1000); | ||
| String shot2 = player.autoShot(); | ||
| Speaker.voice("queueII", shot2); | ||
|
|
||
| if ("Hit! And Kill!".equals(shot2)||"Hit!".equals(shot2)) { | ||
| whoCanGo = false; | ||
| } else { | ||
| whoCanGo = true; | ||
| } | ||
| Thread.sleep(1000); | ||
| } | ||
| Thread.sleep(1000); | ||
| play.paintFields(); | ||
| } while (!player.lose() && !IIPlayer.lose()); | ||
|
|
||
| if (player.lose()) { | ||
| Speaker.voice("lose1", player.getName()); | ||
| } else Speaker.voice("lose1", IIPlayer.getName()); | ||
|
|
||
| } catch (Exception e) { | ||
| System.out.println(e + " FAIL"); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package course_project.sea_battle.model; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class CoordinateTranslator { | ||
| private static final Map<String, Integer> coordinateTranslatorMap; | ||
| static { | ||
| coordinateTranslatorMap = new HashMap<>(); | ||
| coordinateTranslatorMap.put("a", 0); | ||
| coordinateTranslatorMap.put("b", 1); | ||
| coordinateTranslatorMap.put("c", 2); | ||
| coordinateTranslatorMap.put("d", 3); | ||
| coordinateTranslatorMap.put("e", 4); | ||
| coordinateTranslatorMap.put("f", 5); | ||
| coordinateTranslatorMap.put("g", 6); | ||
| coordinateTranslatorMap.put("h", 7); | ||
| coordinateTranslatorMap.put("i", 8); | ||
| coordinateTranslatorMap.put("j", 9); | ||
| } | ||
| public static int coordinate(String key){ | ||
| if(key == null) return 10; | ||
| return coordinateTranslatorMap.get(key); | ||
| } | ||
| } |

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: are these still in progress?