-
Notifications
You must be signed in to change notification settings - Fork 2
Gamzat_Asadulaev #16
base: master
Are you sure you want to change the base?
Gamzat_Asadulaev #16
Changes from all commits
4a301c4
e415e29
a10dd3a
9c504e1
bfb5444
ba3855b
05f80cc
41cc0af
a070d28
abaa02f
a3c38f4
1a4c1fe
fe7492b
33b8843
1600ec2
26bcf10
3cadaf8
ebb46c1
a6e2803
9798739
a8e54e2
0362a55
bbcf762
ab8c985
ebf65a5
7dc71cc
72a8095
dbeb65e
e70afe3
62cffc2
2f7a81e
9715ccd
8d55a6b
cda54b2
29d37c2
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* | ||
| ## *Asadulaev Gamzat* | ||
|
|
||
| | 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/GamzatAsadulaev/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/GamzatAsadulaev/src/main/java/homework_2/traffic_light) | The app that reads the time from the console (seconds/hh:mm:ss) and calculates the output color of the traffic light | | ||
| | | [Pyramid printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_2/pyramid_printer) | The app that prints a pyramid based on user input | | ||
| | | [Random Chars Table](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_2/random_chars_table) | The app that reads length, width, strategy from the console generates the table and prints even/odd letters | | ||
| | HW3 | [ImmutableClass](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_3) | Immutable Class "Book" | | ||
| | HW4 | [CustomFileReader](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_4/custom_file_reader) |The app that reads the file in different ways and prints the text without(, .) | | ||
| | | [CustomSingleton](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_4/singleton) | Custom Singleton | | ||
| | | [CustomAnnotation](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_4/custom_annotation) | Custom Annotation | | ||
| | HW5 | [PowerOfNumber](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_5/power_of_number) | The app that reads the number from the console and raises it to the power | | ||
| | | [CustomRegexMatcher](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_5/custom_regex_matcher) | The app that reads the number from the console and checks it for validity | | ||
| | HW6 | [MapProblemsGenerator](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_6/map_problems_generator) | | | ||
| | HW7 | [KittenToCatFunction](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_7) | Custom functional interface that transform Kitten to Cat | | ||
| | CP | [Battleship](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/GamzatAsadulaev/src/main/java/homework_7/course_project_battleship) | Course project "Battleship" | | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
| [Link to markdown guide](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
|
|
||
| [CodingBat](https://codingbat.com/done?user=asadulaevgamzat@gmail.com&tag=2887423202) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package course_project.battleship; | ||
|
|
||
|
|
||
| import course_project.battleship.game.Game; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| new Game().run(); | ||
|
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. Input is not quite simple... Automatic ship placement is nice!
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. Opt: Your utils folder is oversized, some classes should be moved to other places
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. Quite good! You show good knowledge of Java Core and Java libraries, code is mostly clean and easy to read. Abstractions are chosen correctly, also good architecture. I didn't see any bugs in the game, but it would look better if you refactor the interface. Approved! |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package course_project.battleship.controller; | ||
|
|
||
|
|
||
| import course_project.battleship.player.Player; | ||
|
|
||
| public class AIController implements PlayerController { | ||
|
|
||
| @Override | ||
| public void placeShips(Player player) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void makeTurns(Player player1, Player player2) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package course_project.battleship.controller; | ||
|
|
||
| import course_project.battleship.game.GameRule; | ||
| import course_project.battleship.player.Player; | ||
| import course_project.battleship.utils.*; | ||
|
|
||
|
|
||
| public class HumanController implements PlayerController { | ||
|
|
||
| @Override | ||
| public void placeShips(Player player) { | ||
| System.out.println(player.getName() + " choose the ship placement mode:\n1.Manually\n2.Randomly"); | ||
| int setupMode = Menu.getInt(2); | ||
| if (setupMode == 1) { | ||
| new ManualShipPlacement().placeShips(player); | ||
| } else { | ||
| new RandomShipPlacement().placeShips(player); | ||
| } | ||
|
|
||
| System.out.println("Ships are placed!\n"); | ||
| } | ||
|
|
||
| public void makeTurns(Player player1, Player player2) { | ||
| System.out.println("Your field: "); | ||
| Display.drawField(player1.getBattlefield()); | ||
|
|
||
| while (true) { | ||
| System.out.println(); | ||
| System.out.println("" + player1.getName() + ", please, make your turn."); | ||
| Display.drawField(player1.getMonitorField()); | ||
|
|
||
| Coordinate coordinate = Menu.createCoordinate(); | ||
|
|
||
| if (coordinate == null || !Validator.isValidCoordinate(coordinate)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (!player1.makeTurn(player2, | ||
| coordinate)) { | ||
| System.out.println("\nMiss! Your opponents turn!\n"); | ||
| break; | ||
| } | ||
|
|
||
| if (GameRule.isWinCondition(player1)) { | ||
| break; | ||
| } | ||
| // display.clearConsole(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package course_project.battleship.controller; | ||
|
|
||
| import course_project.battleship.player.Player; | ||
|
|
||
| public interface PlayerController { | ||
|
|
||
| void placeShips(Player player); | ||
|
|
||
| void makeTurns(Player player1, Player player2); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package course_project.battleship.game; | ||
|
|
||
|
|
||
| import course_project.battleship.controller.HumanController; | ||
| import course_project.battleship.controller.PlayerController; | ||
| import course_project.battleship.player.Human; | ||
| import course_project.battleship.player.Player; | ||
| import course_project.battleship.utils.Menu; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Game { | ||
| private final GameMode gameMode = new GameMode(); | ||
| private static final Scanner scanner = new Scanner(System.in); | ||
|
|
||
| public void run() { | ||
| System.out.println("----------SeaBattle---------"); | ||
| System.out.println("Choose Mode\n1. PvP\n2. PvE"); | ||
|
|
||
| int mode = Menu.getInt(2); | ||
| if (mode == 1) { | ||
| gameMode.setMode(GameMode.Mode.PVP); | ||
| } else { | ||
| gameMode.setMode(GameMode.Mode.PVE); | ||
| } | ||
| startGame(); | ||
| } | ||
|
|
||
| public void startGame() { | ||
| if (gameMode.getMode() == GameMode.Mode.PVP) { | ||
| playVsHuman(); | ||
| } else { | ||
| playVsComputer(); | ||
| } | ||
| } | ||
|
|
||
| private void playVsHuman() { | ||
| System.out.println("Player 1, please, enter your name:"); | ||
| String playerName1 = scanner.nextLine(); | ||
| Player player1 = new Human(playerName1); | ||
| System.out.println("Player 2, please, enter your name:"); | ||
| String playerName2 = scanner.nextLine(); | ||
| Player player2 = new Human(playerName2); | ||
|
|
||
| System.out.println("-----------------------------"); | ||
|
|
||
| PlayerController playerController = new HumanController(); | ||
| playerController.placeShips(player1); | ||
| playerController.placeShips(player2); | ||
|
|
||
| String winner; | ||
|
|
||
| while (true) { | ||
| playerController.makeTurns(player1, player2); | ||
| if (GameRule.isWinCondition(player1)) { | ||
| winner = player1.getName(); | ||
| break; | ||
| } | ||
| playerController.makeTurns(player2, player1); | ||
| if (GameRule.isWinCondition(player2)) { | ||
| winner = player1.getName(); | ||
| break; | ||
| } | ||
| } | ||
| System.out.println(winner + " win this game!"); | ||
| } | ||
|
|
||
| public void playVsComputer() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package course_project.battleship.game; | ||
|
|
||
| public class GameMode { | ||
| private Mode mode; | ||
|
|
||
| public GameMode() { | ||
| } | ||
|
|
||
| public enum Mode { | ||
| PVP, | ||
| PVE | ||
| } | ||
|
|
||
| public Mode getMode() { | ||
| return mode; | ||
| } | ||
|
|
||
| public void setMode(Mode mode) { | ||
| this.mode = mode; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package course_project.battleship.game; | ||
|
|
||
|
|
||
| import course_project.battleship.player.Player; | ||
| import course_project.battleship.utils.Position; | ||
|
|
||
| public class GameRule { | ||
| private final static int WIN_STREAK = 20; | ||
|
|
||
| public static boolean isWinCondition(Player player) { | ||
| int counter = 0; | ||
| for (int i = 0; i < player.getMonitorField().getField().length; i++) { | ||
| for (int j = 0; j < player.getMonitorField().getField().length; j++) { | ||
| if (player.getMonitorField().getField()[i][j].getState() == Position.State.HIT) { | ||
| counter++; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+11
to
+18
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. Opt: that's not really efficient... you iterate through all field each turn. There are much easier ways to achieve the same result |
||
| return counter >= WIN_STREAK; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package course_project.battleship.model; | ||
|
|
||
| import course_project.battleship.utils.Position; | ||
|
|
||
| public class Field { | ||
| public static final int FILED_SIZE = 10; | ||
| private Position[][] field; | ||
|
|
||
| public Field() { | ||
| this.field = new Position[FILED_SIZE][FILED_SIZE]; | ||
| initTable(); | ||
| } | ||
|
|
||
| private void initTable() { | ||
| for (int i = 0; i < field.length; i++) { | ||
| for (int j = 0; j < field[i].length; j++) { | ||
| field[i][j] = new Position(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public Position[][] getField() { | ||
| return field; | ||
| } | ||
|
|
||
| public void setField(Position[][] field) { | ||
| this.field = field; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package course_project.battleship.model; | ||
|
|
||
| public class Ship { | ||
| private int deck; | ||
| private boolean isAlive; | ||
|
|
||
| private int countHits = 1; | ||
|
|
||
| public Ship(int deck) { | ||
| this.isAlive = true; | ||
| this.deck = deck; | ||
| } | ||
|
|
||
| public boolean getDamage() { | ||
| if (countHits != deck) { | ||
| countHits++; | ||
| return true; | ||
| } | ||
| isAlive = false; | ||
| return false; | ||
| } | ||
|
|
||
| public int getDeck() { | ||
| return deck; | ||
| } | ||
|
|
||
| public void setDeck(int deck) { | ||
| this.deck = deck; | ||
| } | ||
|
|
||
| public boolean isAlive() { | ||
| return isAlive; | ||
| } | ||
|
|
||
| public void setAlive(boolean alive) { | ||
| isAlive = alive; | ||
| } | ||
|
|
||
| public int getCountHits() { | ||
| return countHits; | ||
| } | ||
|
|
||
| public void setCountHits(int countHits) { | ||
| this.countHits = countHits; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package course_project.battleship.player; | ||
|
|
||
|
|
||
| import course_project.battleship.model.Ship; | ||
| import course_project.battleship.utils.Coordinate; | ||
|
|
||
| public class Computer extends Player { | ||
|
|
||
| public Computer() { | ||
| super("Computer"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean makeTurn(Player enemy, Coordinate coordinate) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void placeShip(Coordinate coordinate, Ship ship, int direction) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } |

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.
Hamcrest matchers are nice!