Skip to content
This repository was archived by the owner on Oct 25, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
a914887
add homework_1
Kollega1984 Jul 6, 2021
5eaca7d
homework_1
Kollega1984 Jul 6, 2021
3b052bc
homework_1
Kollega1984 Jul 6, 2021
6631c49
homework_1
Kollega1984 Jul 7, 2021
96dee71
Merge remote-tracking branch 'origin/Feature/DmitriyPrihodko1' into F…
Kollega1984 Jul 7, 2021
290b2c1
homework_1.1
Kollega1984 Jul 7, 2021
3f5fd3f
homework_1.4
Kollega1984 Jul 7, 2021
6cb762c
homework_1
Kollega1984 Jul 10, 2021
272252c
Create README.md
Kollega1984 Jul 10, 2021
1feb7cd
fixed it
Kollega1984 Jul 11, 2021
b3e488c
Merge branch 'master' into Feature/DmitriyPrihodko
Kollega1984 Jul 11, 2021
938a501
fixed it
Kollega1984 Jul 11, 2021
0c9b710
changed README
Kollega1984 Jul 11, 2021
709d3d3
fix bugs
Kollega1984 Jul 14, 2021
37be372
Traffic_light v2
Kollega1984 Jul 14, 2021
b651323
add Pyramid_Printer v1
Kollega1984 Jul 15, 2021
d2b63c8
Random_Chars_Table v1
Kollega1984 Jul 15, 2021
4565ca0
Random_Chars_Table v1
Kollega1984 Jul 18, 2021
41c4c3b
readMe add homeWork2
Kollega1984 Jul 18, 2021
c35ddb5
Piramid v1
Kollega1984 Jul 21, 2021
62f6913
Merge branch 'master' into feature/Dmitriy_Prihodko
Kollega1984 Jul 21, 2021
e092683
RandomChar v2
Kollega1984 Jul 21, 2021
127880a
RandomChar v3
Kollega1984 Jul 21, 2021
d4c12ed
readme add HW2
Kollega1984 Jul 24, 2021
2acfbd5
up HW2
Kollega1984 Jul 24, 2021
35c4e10
add tests
Kollega1984 Jul 24, 2021
4c72932
changes tests and readme
Kollega1984 Jul 24, 2021
72a3928
changes tests and readme
Kollega1984 Jul 24, 2021
c0423d0
add test
Kollega1984 Jul 24, 2021
c66149f
add tests
Kollega1984 Jul 25, 2021
0cf0418
ImmutableClass
Kollega1984 Jul 25, 2021
ef29a97
readme change
Kollega1984 Jul 25, 2021
dacf138
hw1 change
Kollega1984 Jul 25, 2021
79fbb5d
fix apps names
Kollega1984 Jul 25, 2021
a55d597
RandomCharsTable fix 1 error
Kollega1984 Jul 26, 2021
945224c
main/resources/custom_file_reader
Kollega1984 Aug 4, 2021
14cc3d0
run 1 completed
Kollega1984 Aug 11, 2021
4a8a041
run 1 completed
Kollega1984 Aug 11, 2021
9d4f397
run 1 completed
Kollega1984 Aug 11, 2021
429eb93
run 1 completed
Kollega1984 Aug 11, 2021
f748716
run 1 completed
Kollega1984 Aug 11, 2021
907b55d
Singleton v1
Kollega1984 Aug 11, 2021
311b50e
Singleton test
Kollega1984 Aug 12, 2021
e7ab552
homework4
Kollega1984 Aug 15, 2021
8c56e8d
change readme
Kollega1984 Aug 15, 2021
4417ecc
fix
Kollega1984 Aug 15, 2021
98d014c
hw5
Kollega1984 Aug 21, 2021
88f6458
hw5
Kollega1984 Aug 23, 2021
d3c5b80
м6
Kollega1984 Aug 29, 2021
8c9e151
v6.2
Kollega1984 Aug 29, 2021
90da94e
v6.3
Kollega1984 Aug 30, 2021
0faa0dd
v6.3
Kollega1984 Aug 30, 2021
757527b
README.md changev1
Kollega1984 Aug 31, 2021
00a33ef
README.md changev2
Kollega1984 Aug 31, 2021
b1ed477
README.md changev3
Kollega1984 Aug 31, 2021
94ef46f
README.md changev4
Kollega1984 Aug 31, 2021
9254b73
README.md changev5
Kollega1984 Aug 31, 2021
65ae690
README.md changev6
Kollega1984 Aug 31, 2021
e8be92a
README.md changev6
Kollega1984 Aug 31, 2021
eda5372
README.md changev6
Kollega1984 Aug 31, 2021
e61d330
README.md changev6
Kollega1984 Aug 31, 2021
3c0c5d0
README.md changev7
Kollega1984 Aug 31, 2021
c4cde6a
README.md changev8
Kollega1984 Aug 31, 2021
87a20cb
README.md changev9
Kollega1984 Aug 31, 2021
53a28c1
Course Project generated
Kollega1984 Sep 1, 2021
2bcf251
Course Project fields and add ship complete
Kollega1984 Sep 2, 2021
361dce8
piramid fix whitespace
Kollega1984 Sep 2, 2021
ebd192f
piramid fix whitespace
Kollega1984 Sep 2, 2021
4935b41
random fix whitespace
Kollega1984 Sep 2, 2021
d33165f
random fix whitespace
Kollega1984 Sep 2, 2021
07e267c
random fix whitespace1
Kollega1984 Sep 2, 2021
6fbb5da
random fix whitespace1
Kollega1984 Sep 2, 2021
ef6378a
fix
Kollega1984 Sep 2, 2021
3c55f6a
fix RandomCharsTable
Kollega1984 Sep 7, 2021
337e316
fix RandomCharsTable del else
Kollega1984 Sep 7, 2021
3e96d07
add reader class
Kollega1984 Sep 7, 2021
a35e390
7lesson and curse
Kollega1984 Sep 15, 2021
3cb6643
readme change
Kollega1984 Sep 15, 2021
a216509
v 3.0
Kollega1984 Sep 16, 2021
e21e470
add tests and fix some bags
Kollega1984 Sep 16, 2021
904825a
add README.md test SeaBattle
Kollega1984 Sep 16, 2021
a27403b
add test Speaker
Kollega1984 Sep 18, 2021
907452c
Add Animation
Kollega1984 Sep 19, 2021
3892138
Add package animated
Kollega1984 Sep 19, 2021
339bda2
field test add
Kollega1984 Sep 19, 2021
6a6d458
readme fix
Kollega1984 Sep 21, 2021
488dbd9
fix bag
Kollega1984 Sep 21, 2021
31acc66
fix
Kollega1984 Sep 21, 2021
e9d3154
fix hw3
Kollega1984 Sep 21, 2021
6a06522
fix hw4
Kollega1984 Sep 21, 2021
c0a1ecc
fix hw5
Kollega1984 Sep 21, 2021
db9f58f
fix hw6
Kollega1984 Sep 21, 2021
9a0f100
hw3 add main
Kollega1984 Sep 22, 2021
36feaf6
hw6 add main end change class MutableGenerator
Kollega1984 Sep 23, 2021
94b3579
hw3 add ane getter ImmutableClass
Kollega1984 Sep 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.md
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. |
Copy link
Owner

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?

| 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)
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repositories {
}

dependencies {

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/course_project/sea_battle/Main.java
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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange...
image

Copy link
Owner

Choose a reason for hiding this comment

The 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

Copy link
Owner

Choose a reason for hiding this comment

The 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*****************************");
}
}
83 changes: 83 additions & 0 deletions src/main/java/course_project/sea_battle/conroller/Dialog.java
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");
}
}

}
73 changes: 73 additions & 0 deletions src/main/java/course_project/sea_battle/conroller/SeaBattle.java
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);
}
}
Loading