diff --git a/.idea/.gitignore b/.idea/.gitignore
index 3f6be49..4ebaf35 100644
--- a/.idea/.gitignore
+++ b/.idea/.gitignore
@@ -2,7 +2,7 @@
/shelf/
/workspace.xml
# Datasource local storage ignored files
-/../../../../../../../:\# Personal Data\University\Advanced Programming\Project\Phase 1\.idea/dataSources/
+/../../../../:\project team 13\graphical\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index f060d48..217af47 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,14 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
-
\ No newline at end of file
+
+
diff --git a/.idea/description.html b/.idea/description.html
new file mode 100644
index 0000000..cc10d56
--- /dev/null
+++ b/.idea/description.html
@@ -0,0 +1,2 @@
+Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..3e3960b
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1.xml b/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1.xml
new file mode 100644
index 0000000..ea70fe1
--- /dev/null
+++ b/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__junit_junit_4_13_1.xml b/.idea/libraries/Maven__junit_junit_4_13_1.xml
new file mode 100644
index 0000000..9fa24fc
--- /dev/null
+++ b/.idea/libraries/Maven__junit_junit_4_13_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_0.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_0.xml
new file mode 100644
index 0000000..f854ab0
--- /dev/null
+++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
new file mode 100644
index 0000000..f58bbc1
--- /dev/null
+++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_7_0.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_7_0.xml
new file mode 100644
index 0000000..f7cf4fe
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_7_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_7_0.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_7_0.xml
new file mode 100644
index 0000000..cc01e3f
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_7_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_7_0.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_7_0.xml
new file mode 100644
index 0000000..f198e4b
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_7_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_7_0.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_7_0.xml
new file mode 100644
index 0000000..a53686b
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_7_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_7_0.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_7_0.xml
new file mode 100644
index 0000000..cde8a48
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_7_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_7_0.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_7_0.xml
new file mode 100644
index 0000000..3391deb
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_7_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml
new file mode 100644
index 0000000..fbc1b16
--- /dev/null
+++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/javafx11.xml b/.idea/libraries/javafx11.xml
new file mode 100644
index 0000000..0a4cde9
--- /dev/null
+++ b/.idea/libraries/javafx11.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/json_simple_1_1_1.xml b/.idea/libraries/json_simple_1_1_1.xml
new file mode 100644
index 0000000..9fa52eb
--- /dev/null
+++ b/.idea/libraries/json_simple_1_1_1.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/json_simple_3_1_1.xml b/.idea/libraries/json_simple_3_1_1.xml
new file mode 100644
index 0000000..50bf4b0
--- /dev/null
+++ b/.idea/libraries/json_simple_3_1_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 48b4b95..95ae90c 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,17 +1,9 @@
-
-
-
+
+
-
-
-
-
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..42fbad4
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
index e96534f..3b00020 100644
--- a/.idea/uiDesigner.xml
+++ b/.idea/uiDesigner.xml
@@ -121,4 +121,5 @@
-
\ No newline at end of file
+
+
diff --git a/Plato.iml b/Plato.iml
new file mode 100644
index 0000000..a3bb54c
--- /dev/null
+++ b/Plato.iml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/admins.json b/admins.json
new file mode 100644
index 0000000..b456185
--- /dev/null
+++ b/admins.json
@@ -0,0 +1 @@
+[{"firstname":"likmhjngf","lastname":"lk,mhnbgf","username":"hasan","userID":1,"password":"123","email":"iujynbgvds","phoneNumber":"olikujyh","isMainAdminJoinnt":true,"messages":[]}]
\ No newline at end of file
diff --git a/events.json b/events.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/events.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/games.json b/games.json
new file mode 100644
index 0000000..7084eef
--- /dev/null
+++ b/games.json
@@ -0,0 +1 @@
+[{"name":"reversi","gameID":1},{"name":"battleSea","gameID":2},{"name":"reversi","gameID":1},{"name":"battleSea","gameID":2}]
\ No newline at end of file
diff --git a/graphical.iml b/graphical.iml
new file mode 100644
index 0000000..285926b
--- /dev/null
+++ b/graphical.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/logs.json b/logs.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/logs.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/out/production/graphical/BattleSea/Controller/BattleSea.class b/out/production/graphical/BattleSea/Controller/BattleSea.class
new file mode 100644
index 0000000..e5d0f19
Binary files /dev/null and b/out/production/graphical/BattleSea/Controller/BattleSea.class differ
diff --git a/out/production/graphical/BattleSea/Controller/GameManager.class b/out/production/graphical/BattleSea/Controller/GameManager.class
new file mode 100644
index 0000000..2b50e9e
Binary files /dev/null and b/out/production/graphical/BattleSea/Controller/GameManager.class differ
diff --git a/out/production/graphical/BattleSea/Controller/GridManager.class b/out/production/graphical/BattleSea/Controller/GridManager.class
new file mode 100644
index 0000000..a4e1b88
Binary files /dev/null and b/out/production/graphical/BattleSea/Controller/GridManager.class differ
diff --git a/out/production/graphical/BattleSea/Controller/ShipManager.class b/out/production/graphical/BattleSea/Controller/ShipManager.class
new file mode 100644
index 0000000..a72e34c
Binary files /dev/null and b/out/production/graphical/BattleSea/Controller/ShipManager.class differ
diff --git a/out/production/graphical/BattleSea/Model/Coordination.class b/out/production/graphical/BattleSea/Model/Coordination.class
new file mode 100644
index 0000000..a135e93
Binary files /dev/null and b/out/production/graphical/BattleSea/Model/Coordination.class differ
diff --git a/out/production/graphical/BattleSea/Model/Grid.class b/out/production/graphical/BattleSea/Model/Grid.class
new file mode 100644
index 0000000..0dcddad
Binary files /dev/null and b/out/production/graphical/BattleSea/Model/Grid.class differ
diff --git a/out/production/graphical/BattleSea/Model/Ship.class b/out/production/graphical/BattleSea/Model/Ship.class
new file mode 100644
index 0000000..d34ebea
Binary files /dev/null and b/out/production/graphical/BattleSea/Model/Ship.class differ
diff --git a/out/production/graphical/BattleSea/View/InGameMenu.class b/out/production/graphical/BattleSea/View/InGameMenu.class
new file mode 100644
index 0000000..ad61df9
Binary files /dev/null and b/out/production/graphical/BattleSea/View/InGameMenu.class differ
diff --git a/out/production/graphical/BattleSea/View/StartingPage.class b/out/production/graphical/BattleSea/View/StartingPage.class
new file mode 100644
index 0000000..d630261
Binary files /dev/null and b/out/production/graphical/BattleSea/View/StartingPage.class differ
diff --git a/out/production/graphical/Plato/Controller/FriendsMenuController.class b/out/production/graphical/Plato/Controller/FriendsMenuController.class
new file mode 100644
index 0000000..37fa0d8
Binary files /dev/null and b/out/production/graphical/Plato/Controller/FriendsMenuController.class differ
diff --git a/out/production/graphical/Plato/Controller/LoginPageController.class b/out/production/graphical/Plato/Controller/LoginPageController.class
new file mode 100644
index 0000000..ba9eca1
Binary files /dev/null and b/out/production/graphical/Plato/Controller/LoginPageController.class differ
diff --git a/out/production/graphical/Plato/Controller/MainPageAdminController.class b/out/production/graphical/Plato/Controller/MainPageAdminController.class
new file mode 100644
index 0000000..603af73
Binary files /dev/null and b/out/production/graphical/Plato/Controller/MainPageAdminController.class differ
diff --git a/out/production/graphical/Plato/Controller/MainPagePlayerController.class b/out/production/graphical/Plato/Controller/MainPagePlayerController.class
new file mode 100644
index 0000000..0503d9e
Binary files /dev/null and b/out/production/graphical/Plato/Controller/MainPagePlayerController.class differ
diff --git a/out/production/graphical/Plato/Model/Admin.class b/out/production/graphical/Plato/Model/Admin.class
new file mode 100644
index 0000000..c0dad18
Binary files /dev/null and b/out/production/graphical/Plato/Model/Admin.class differ
diff --git a/out/production/graphical/Plato/Model/Event.class b/out/production/graphical/Plato/Model/Event.class
new file mode 100644
index 0000000..b8c554e
Binary files /dev/null and b/out/production/graphical/Plato/Model/Event.class differ
diff --git a/out/production/graphical/Plato/Model/Game.class b/out/production/graphical/Plato/Model/Game.class
new file mode 100644
index 0000000..55e89da
Binary files /dev/null and b/out/production/graphical/Plato/Model/Game.class differ
diff --git a/out/production/graphical/Plato/Model/Log.class b/out/production/graphical/Plato/Model/Log.class
new file mode 100644
index 0000000..ff82042
Binary files /dev/null and b/out/production/graphical/Plato/Model/Log.class differ
diff --git a/out/production/graphical/Plato/Model/Player.class b/out/production/graphical/Plato/Model/Player.class
new file mode 100644
index 0000000..d54052a
Binary files /dev/null and b/out/production/graphical/Plato/Model/Player.class differ
diff --git a/out/production/graphical/Plato/Model/User.class b/out/production/graphical/Plato/Model/User.class
new file mode 100644
index 0000000..ce91b84
Binary files /dev/null and b/out/production/graphical/Plato/Model/User.class differ
diff --git a/out/production/graphical/Plato/View/BattleSeaMenu.class b/out/production/graphical/Plato/View/BattleSeaMenu.class
new file mode 100644
index 0000000..ee81ea7
Binary files /dev/null and b/out/production/graphical/Plato/View/BattleSeaMenu.class differ
diff --git a/out/production/graphical/Plato/View/Commands.class b/out/production/graphical/Plato/View/Commands.class
new file mode 100644
index 0000000..a469e8c
Binary files /dev/null and b/out/production/graphical/Plato/View/Commands.class differ
diff --git a/out/production/graphical/Plato/View/FriendsMenu.class b/out/production/graphical/Plato/View/FriendsMenu.class
new file mode 100644
index 0000000..2980a79
Binary files /dev/null and b/out/production/graphical/Plato/View/FriendsMenu.class differ
diff --git a/out/production/graphical/Plato/View/GamesMenu.class b/out/production/graphical/Plato/View/GamesMenu.class
new file mode 100644
index 0000000..e9a165d
Binary files /dev/null and b/out/production/graphical/Plato/View/GamesMenu.class differ
diff --git a/out/production/graphical/Plato/View/LoginPage.class b/out/production/graphical/Plato/View/LoginPage.class
new file mode 100644
index 0000000..6fcfd54
Binary files /dev/null and b/out/production/graphical/Plato/View/LoginPage.class differ
diff --git a/out/production/graphical/Plato/View/MainPageAdmin.class b/out/production/graphical/Plato/View/MainPageAdmin.class
new file mode 100644
index 0000000..e95c646
Binary files /dev/null and b/out/production/graphical/Plato/View/MainPageAdmin.class differ
diff --git a/out/production/graphical/Plato/View/MainPagePlayer.class b/out/production/graphical/Plato/View/MainPagePlayer.class
new file mode 100644
index 0000000..fccc78d
Binary files /dev/null and b/out/production/graphical/Plato/View/MainPagePlayer.class differ
diff --git a/out/production/graphical/Plato/View/Page.class b/out/production/graphical/Plato/View/Page.class
new file mode 100644
index 0000000..1f1480d
Binary files /dev/null and b/out/production/graphical/Plato/View/Page.class differ
diff --git a/out/production/graphical/Plato/View/ReversiMenu.class b/out/production/graphical/Plato/View/ReversiMenu.class
new file mode 100644
index 0000000..c23489d
Binary files /dev/null and b/out/production/graphical/Plato/View/ReversiMenu.class differ
diff --git a/out/production/graphical/Plato/View/UserPage.class b/out/production/graphical/Plato/View/UserPage.class
new file mode 100644
index 0000000..0af3b69
Binary files /dev/null and b/out/production/graphical/Plato/View/UserPage.class differ
diff --git a/out/production/graphical/Reversi/Reversi.class b/out/production/graphical/Reversi/Reversi.class
new file mode 100644
index 0000000..b6e61d3
Binary files /dev/null and b/out/production/graphical/Reversi/Reversi.class differ
diff --git a/out/production/graphical/Reversi/ReversiController.class b/out/production/graphical/Reversi/ReversiController.class
new file mode 100644
index 0000000..3b8b0a9
Binary files /dev/null and b/out/production/graphical/Reversi/ReversiController.class differ
diff --git a/out/production/graphical/Reversi/ReversiView.class b/out/production/graphical/Reversi/ReversiView.class
new file mode 100644
index 0000000..1f570db
Binary files /dev/null and b/out/production/graphical/Reversi/ReversiView.class differ
diff --git a/out/production/graphical/Reversi/Table.class b/out/production/graphical/Reversi/Table.class
new file mode 100644
index 0000000..baa48a7
Binary files /dev/null and b/out/production/graphical/Reversi/Table.class differ
diff --git a/out/production/graphical/graphic/LoginRegister.class b/out/production/graphical/graphic/LoginRegister.class
new file mode 100644
index 0000000..27bc095
Binary files /dev/null and b/out/production/graphical/graphic/LoginRegister.class differ
diff --git a/out/production/graphical/graphic/LoginRegister.fxml b/out/production/graphical/graphic/LoginRegister.fxml
new file mode 100644
index 0000000..b2f5e2e
--- /dev/null
+++ b/out/production/graphical/graphic/LoginRegister.fxml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/out/production/graphical/graphic/MainGraphic.class b/out/production/graphical/graphic/MainGraphic.class
new file mode 100644
index 0000000..d7b95ce
Binary files /dev/null and b/out/production/graphical/graphic/MainGraphic.class differ
diff --git a/out/production/graphical/module-info.class b/out/production/graphical/module-info.class
new file mode 100644
index 0000000..e07bb3b
Binary files /dev/null and b/out/production/graphical/module-info.class differ
diff --git a/out/production/graphical/sample/AdminGraphicalMainPageController.class b/out/production/graphical/sample/AdminGraphicalMainPageController.class
new file mode 100644
index 0000000..c1f6943
Binary files /dev/null and b/out/production/graphical/sample/AdminGraphicalMainPageController.class differ
diff --git a/out/production/graphical/sample/AdminMainPage.fxml b/out/production/graphical/sample/AdminMainPage.fxml
new file mode 100644
index 0000000..bd6be13
--- /dev/null
+++ b/out/production/graphical/sample/AdminMainPage.fxml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/out/production/graphical/sample/Controller.class b/out/production/graphical/sample/Controller.class
new file mode 100644
index 0000000..d3242b0
Binary files /dev/null and b/out/production/graphical/sample/Controller.class differ
diff --git a/out/production/graphical/sample/Main.class b/out/production/graphical/sample/Main.class
new file mode 100644
index 0000000..6c33af2
Binary files /dev/null and b/out/production/graphical/sample/Main.class differ
diff --git a/out/production/graphical/sample/PlayerGraphicalMainPageController.class b/out/production/graphical/sample/PlayerGraphicalMainPageController.class
new file mode 100644
index 0000000..8d10308
Binary files /dev/null and b/out/production/graphical/sample/PlayerGraphicalMainPageController.class differ
diff --git a/out/production/graphical/sample/PlayerMainPage.fxml b/out/production/graphical/sample/PlayerMainPage.fxml
new file mode 100644
index 0000000..99b11c7
--- /dev/null
+++ b/out/production/graphical/sample/PlayerMainPage.fxml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/out/production/graphical/sample/sample.fxml b/out/production/graphical/sample/sample.fxml
new file mode 100644
index 0000000..c72db1a
--- /dev/null
+++ b/out/production/graphical/sample/sample.fxml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/players.json b/players.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/players.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 6d28849..0b9298b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,11 +62,20 @@
RELEASE
compile
+
com.googlecode.json-simple
json-simple
- 1.1
+ 1.1.1
+
+
+ org.openjfx
+ javafx
+ 11
+ pom
+
+
diff --git a/src/main/java/BattleSea/Controller/BattleSea.java b/src/BattleSea/Controller/BattleSea.java
similarity index 53%
rename from src/main/java/BattleSea/Controller/BattleSea.java
rename to src/BattleSea/Controller/BattleSea.java
index 77ac40f..094556e 100644
--- a/src/main/java/BattleSea/Controller/BattleSea.java
+++ b/src/BattleSea/Controller/BattleSea.java
@@ -1,5 +1,6 @@
package BattleSea.Controller;
+import BattleSea.View.StartingPage;
import Plato.Model.Game;
import Plato.Model.Player;
@@ -8,15 +9,24 @@ public class BattleSea extends Game {
private Player firstPlayer;
private Player secondPlayer;
+ /*public static void main(String[] args) {
+ Player player1=new Player();
+ Player player2=new Player();
+ player1.setUsername("dehghani");
+ player2.setUsername("sheykh");
+ new BattleSea(player1,player2).run();
+ }*/
+
public BattleSea(Player firstPlayer, Player secondPlayer) {
this.firstPlayer = firstPlayer;
this.secondPlayer = secondPlayer;
-
}
public BattleSea() {
}
-
+ public void run(){
+ new StartingPage(firstPlayer,secondPlayer).run();
+ }
}
diff --git a/src/main/java/BattleSea/Controller/GameManager.java b/src/BattleSea/Controller/GameManager.java
similarity index 72%
rename from src/main/java/BattleSea/Controller/GameManager.java
rename to src/BattleSea/Controller/GameManager.java
index 7b1d82a..76dc6ed 100644
--- a/src/main/java/BattleSea/Controller/GameManager.java
+++ b/src/BattleSea/Controller/GameManager.java
@@ -48,7 +48,7 @@ private void createShips(int boardDimension, int numberOfShips) {
putTheShipsOnBoardRandomly(secondPlayerGridManager, secondPlayerShipManager, boardDimension);
}
- public byte bombLocation(int xAxis, int yAxis) {
+ public int bombLocation(int xAxis, int yAxis) {
if (turn.equals(firstPlayer)) {
return bombLocationByPlayer(xAxis, yAxis, firstPlayerGridManager, firstPlayerShipManager, secondPlayerGridManager, secondPlayerShipManager);
} else {
@@ -56,98 +56,103 @@ public byte bombLocation(int xAxis, int yAxis) {
}
}
- public byte changeLocationOfShip(int shipCode, int xAxis, int yAxis) {
+ public int changeLocationOfShip(int shipCode, int xAxis, int yAxis) {
if (turn.equals(firstPlayer)) {
if (firstPlayerShipManager.getShipByShipCode(shipCode).isDestroyed() || !firstPlayerShipManager.getShipByShipCode(shipCode).isMovable())
- return 0; //"This Ship Cannot Move Because It Is Partially or Completely destroyed"
+ return 0;
} else if (secondPlayerShipManager.getShipByShipCode(shipCode).isDestroyed() || !secondPlayerShipManager.getShipByShipCode(shipCode).isMovable())
- return 0; //"This Ship Cannot Move Because It Is Partially or Completely destroyed"
+ return 0;
try {
if (turn.equals(firstPlayer)) {
if (firstPlayerGridManager.changeLocationOfShip(firstPlayerShipManager.getShipByShipCode(shipCode), xAxis, yAxis)) {
- return 1; //"The Ship " + shipCode + " Has Been Moved To The New Location Successfully"
- } else return 2; //"Cannot Move The Ship To The Requested Location! Try A New Location"
+ return 1;
+ } else return 2;
} else {
if (secondPlayerGridManager.changeLocationOfShip(secondPlayerShipManager.getShipByShipCode(shipCode), xAxis, yAxis)) {
- return 1; //"The Ship " + shipCode + " Has Been Moved To The New Location Successfully"
- } else return 2; //"Cannot Move The Ship To The Requested Location! Try A New Location"
+ return 1;
+ } else return 2;
}
} catch (IndexOutOfBoundsException e) {
firstPlayerGridManager.fixTheGrid();
secondPlayerGridManager.fixTheGrid();
- return 3; //"You Cannot Move The Ship To This Location! Because Part Of Ship Will Be Out Of The Board. Try A New Location";
+ return 3;
}
}
- public byte changeDirectionOfShip(int shipCode, char newDirection) {
+ public int changeDirectionOfShip(int shipCode, char newDirection) {
if (turn.equals(firstPlayer)) {
if (firstPlayerShipManager.getShipByShipCode(shipCode).isDestroyed() || !firstPlayerShipManager.getShipByShipCode(shipCode).isMovable())
- return 0; //"This Ship Cannot Rotate Because It Is Partially or Completely destroyed";
+ return 0;
} else if (secondPlayerShipManager.getShipByShipCode(shipCode).isDestroyed() || !secondPlayerShipManager.getShipByShipCode(shipCode).isMovable())
- return 0; //"This Ship Cannot Rotate Because It Is Partially or Completely destroyed";
+ return 0;
try {
if (turn.equals(firstPlayer)) {
if (firstPlayerGridManager.changeDirectionOfShip(firstPlayerShipManager.getShipByShipCode(shipCode), newDirection)) {
- return 1; //"The Ship " + shipCode + " Has Been Rotated To The New Direction Successfully";
- } else return 2; //"Cannot Rotate The Ship To The Requested Direction! Try A New One";
+ return 1;
+ } else return 2;
} else {
if (secondPlayerGridManager.changeDirectionOfShip(secondPlayerShipManager.getShipByShipCode(shipCode), newDirection)) {
- return 1; //"The Ship " + shipCode + " Has Been Rotated To The New Direction Successfully";
- } else return 2; //"Cannot Rotate The Ship To The Requested Direction! Try A New One";
+ return 1;
+ } else return 2;
}
} catch (IndexOutOfBoundsException e) {
firstPlayerGridManager.fixTheGrid();
secondPlayerGridManager.fixTheGrid();
- return 3; //"You Cannot Move The Ship To This Location! Because Part Of Ship Will Be Out Of The Board. Try Another Direction";
+ return 3;
}
}
- private byte bombLocationByPlayer(int xAxis, int yAxis, GridManager playerGridManager, ShipManager playerShipManager, GridManager opponentGridManager, ShipManager opponentShipManager) {
+ private int bombLocationByPlayer(int xAxis, int yAxis, GridManager playerGridManager, ShipManager playerShipManager, GridManager opponentGridManager, ShipManager opponentShipManager) {
if (playerGridManager.bombLocation(xAxis, yAxis, turn, playerShipManager)) {
if (opponentGridManager.bombLocation(xAxis, yAxis, turn, opponentShipManager)) {
addScore(1, turn);
playerGridManager.wasBombingLocationSuccessful(true, xAxis, yAxis);
- if (!(opponentShipManager.isAnyShipDestroyed(opponentGridManager) == -1)) {
+ int destroyedShipCode = opponentShipManager.isAnyShipDestroyed(opponentGridManager);
+ if (!(destroyedShipCode == -1)) {
addScore(5, turn);
- playerGridManager.destroyShip(opponentShipManager.isAnyShipDestroyed(opponentGridManager),turn);
- opponentGridManager.destroyShip(opponentShipManager.isAnyShipDestroyed(opponentGridManager),turn);
+ playerGridManager.destroyShip(opponentShipManager.getShipByShipCode(destroyedShipCode), turn);
+ opponentGridManager.destroyShip(opponentShipManager.getShipByShipCode(destroyedShipCode), turn);
if (opponentShipManager.areAllShipsDestroyed()) InGameMenu.gameHasEnded();
- return 2; //"You Destroyed Your Opponent's Ship";
+ return 2;
}
- return 1; //"Your Bomb Hit The Opponent's Ship";
+ return 1;
} else {
playerGridManager.wasBombingLocationSuccessful(false, xAxis, yAxis);
changeTurn();
- return 0; //"You Missed Your Shot";
+ return 0;
}
} else {
if (playerGridManager.isTheGridFullyBombed() && opponentGridManager.isTheGridFullyBombed())
InGameMenu.gameHasEnded();
- return 3; //"You Have Already Bombed This Location! Choose Another Location";
+ return 3;
}
}
- private void changeTurn() {
+ public void changeTurn() {
if (turn.equals(firstPlayer)) turn = secondPlayer;
else turn = firstPlayer;
}
public void putTheShipsOnBoardRandomly(GridManager gridManager, ShipManager shipManager, int boardDimension) {
for (Ship ship : shipManager.getAllShips()) {
- ship.setStartPoint(new Coordination(randomNumber(boardDimension), randomNumber(boardDimension)));
+ ship.setStartPoint(new Coordination(randomNumber(boardDimension) + 1, randomNumber(boardDimension) + 1));
int temp = randomNumber(4);
if (temp == 0) ship.setDirection('n');
else if (temp == 1) ship.setDirection('e');
else if (temp == 2) ship.setDirection('s');
else ship.setDirection('w');
putThisShipOnBoard(ship, gridManager, boardDimension);
+
}
}
private void putThisShipOnBoard(Ship ship, GridManager gridManager, int boardDimension) {
try {
- gridManager.changeLocationOfShip(ship, randomNumber(boardDimension), randomNumber(boardDimension));
+ while (!gridManager.changeLocationOfShip(ship, randomNumber(boardDimension) + 1, randomNumber(boardDimension) + 1)) {
+ gridManager.fixTheGrid();
+ }
} catch (IndexOutOfBoundsException e) {
+ gridManager.fixTheGrid();
putThisShipOnBoard(ship, gridManager, boardDimension);
}
}
@@ -177,12 +182,12 @@ public ShipManager getSecondPlayerShipManager() {
return secondPlayerShipManager;
}
- public Grid getTurnsOwnBoard(){
+ public Grid getTurnsOwnBoard() {
if (turn.equals(firstPlayer)) return firstPlayerGridManager.getPlayerGrid();
else return secondPlayerGridManager.getPlayerGrid();
}
- public Grid getTurnsOpponentBoard(){
+ public Grid getTurnsOpponentBoard() {
if (turn.equals(firstPlayer)) return firstPlayerGridManager.getOpponentGrid();
else return secondPlayerGridManager.getOpponentGrid();
}
@@ -203,13 +208,37 @@ public int getSecondPlayerScore() {
return secondPlayerScore;
}
- public void withdraw(){
- if (turn.equals(firstPlayer)) firstPlayerScore=-10;
- else secondPlayerScore=-10;
+ public void withdraw() {
+ if (turn.equals(firstPlayer)) firstPlayerScore = -10;
+ else secondPlayerScore = -10;
InGameMenu.gameHasEnded();
}
public void clearScreen() throws IOException, InterruptedException {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
+
+ public ArrayList getShips(int option) {
+ if (turn.equals(firstPlayer)) {
+ return getShipsOfPlayer(option, firstPlayerShipManager);
+ } else {
+ return getShipsOfPlayer(option, secondPlayerShipManager);
+ }
+ }
+
+ private ArrayList getShipsOfPlayer(int option, ShipManager playerShipManager) {
+ ArrayList ships = new ArrayList<>();
+ for (Ship ship : playerShipManager.getAllShips()) {
+ if (option == 1) {
+ ships.add("ship " + ship.getCode());
+ } else if (option == 2 && ship.isMovable()) {
+ ships.add("ship " + ship.getCode());
+ } else if (option == 3 && !ship.isMovable() && !ship.isDestroyed()) {
+ ships.add("ship " + ship.getCode());
+ } else if (option == 4 && ship.isDestroyed()) {
+ ships.add("ship " + ship.getCode());
+ }
+ }
+ return ships;
+ }
}
diff --git a/src/main/java/BattleSea/Controller/GridManager.java b/src/BattleSea/Controller/GridManager.java
similarity index 74%
rename from src/main/java/BattleSea/Controller/GridManager.java
rename to src/BattleSea/Controller/GridManager.java
index f09f49b..1c60df7 100644
--- a/src/main/java/BattleSea/Controller/GridManager.java
+++ b/src/BattleSea/Controller/GridManager.java
@@ -9,7 +9,6 @@ public class GridManager {
private final Player owner;
private Grid playerGrid;
private Grid opponentGrid;
- private boolean bombingFlag;
public GridManager(Player owner, int gridDimension) {
this.owner = owner;
@@ -20,15 +19,13 @@ public GridManager(Player owner, int gridDimension) {
public boolean bombLocation(int xAxis, int yAxis, Player bomber, ShipManager playerShipManager) {
if (bomber.equals(owner)) {
- if(opponentGrid.getLocation(xAxis, yAxis).Bomb()){
- return true;
- } else return false;
+ return opponentGrid.getLocation(xAxis, yAxis).Bomb();
} else {
playerGrid.getLocation(xAxis, yAxis).Bomb();
if (playerGrid.getLocation(xAxis, yAxis).isOccupied()) {
- playerGrid.getLocation(xAxis, yAxis).setContent("+");
- int shipCode = Integer.parseInt(playerGrid.getLocation(xAxis, yAxis).getContent().split(" ")[1]);
+ int shipCode = Integer.parseInt(playerGrid.getLocation(xAxis, yAxis).getContent());
playerShipManager.getShipByShipCode(shipCode).makeItImmovable();
+ playerGrid.getLocation(xAxis, yAxis).setContent("+");
return true;
} else {
playerGrid.getLocation(xAxis, yAxis).setContent("-");
@@ -38,10 +35,10 @@ public boolean bombLocation(int xAxis, int yAxis, Player bomber, ShipManager pla
}
}
- public void wasBombingLocationSuccessful(boolean answer,int xAxis, int yAxis){
- if (answer){
- opponentGrid.getLocation(xAxis,yAxis).setContent("+");
- } else opponentGrid.getLocation(xAxis,yAxis).setContent("-");
+ public void wasBombingLocationSuccessful(boolean answer, int xAxis, int yAxis) {
+ if (answer) {
+ opponentGrid.getLocation(xAxis, yAxis).setContent("+");
+ } else opponentGrid.getLocation(xAxis, yAxis).setContent("-");
}
public boolean changeLocationOfShip(Ship ship, int newStartPointXAxis, int newStartPointYAxis) throws IndexOutOfBoundsException {
@@ -113,12 +110,12 @@ public boolean changeDirectionOfShip(Ship ship, char newDirection) throws IndexO
private boolean reserveLocation(Ship ship, int xAxis, int yAxis) {
if (playerGrid.getLocation(ship.getStartPoint().getXAxis() + xAxis, ship.getStartPoint().getYAxis() + yAxis).isOccupied()) {
- if (playerGrid.getLocation(ship.getStartPoint().getXAxis() + xAxis, ship.getStartPoint().getYAxis() + yAxis).getContent().equalsIgnoreCase("ship " + ship.getCode())) {
- playerGrid.getLocation(ship.getStartPoint().getXAxis() + xAxis, ship.getStartPoint().getYAxis() + yAxis).setContent("reserve");
+ if (playerGrid.getLocation(ship.getStartPoint().getXAxis() + xAxis, ship.getStartPoint().getYAxis() + yAxis).getContent().equals("" + ship.getCode())) {
+ playerGrid.getLocation(ship.getStartPoint().getXAxis() + xAxis, ship.getStartPoint().getYAxis() + yAxis).setContent("r");
return true;
} else return false;
} else {
- playerGrid.getLocation(ship.getStartPoint().getXAxis() + xAxis, ship.getStartPoint().getYAxis() + yAxis).setContent("reserve");
+ playerGrid.getLocation(ship.getStartPoint().getXAxis() + xAxis, ship.getStartPoint().getYAxis() + yAxis).setContent("r");
return true;
}
@@ -127,7 +124,7 @@ private boolean reserveLocation(Ship ship, int xAxis, int yAxis) {
public void fixTheGrid() {
for (Coordination[] coordinations : playerGrid.getTheGrid()) {
for (Coordination coordination : coordinations) {
- if (coordination.getContent().equalsIgnoreCase("reserve")) coordination.rollbackContentChange();
+ if (coordination.getContent().equalsIgnoreCase("r")) coordination.rollbackContentChange();
}
}
}
@@ -135,12 +132,12 @@ public void fixTheGrid() {
private void moveShipToReservedLocation(Ship ship) {
for (Coordination[] coordinations : playerGrid.getTheGrid()) {
for (Coordination coordination : coordinations) {
- if (coordination.getContent().equalsIgnoreCase("ship " + ship.getCode())) {
+ if (coordination.getContent().equalsIgnoreCase("" + ship.getCode())) {
coordination.setContent("");
coordination.unoccupy();
}
- if (coordination.getContent().equalsIgnoreCase("reserve")) {
- coordination.setContent("ship " + ship.getCode());
+ if (coordination.getContent().equalsIgnoreCase("r")) {
+ coordination.setContent("" + ship.getCode());
coordination.occupy();
}
@@ -149,18 +146,14 @@ private void moveShipToReservedLocation(Ship ship) {
}
public Grid getPlayerGrid() {
- return playerGrid.getClone();
+ return playerGrid;
}
public Grid getOpponentGrid() {
- return opponentGrid.getClone();
- }
-
- public Player getOwner() {
- return owner;
+ return opponentGrid;
}
- public boolean isTheGridFullyBombed(){
+ public boolean isTheGridFullyBombed() {
for (Coordination[] coordinations : opponentGrid.getTheGrid()) {
for (Coordination coordination : coordinations) {
if (!coordination.isBombed()) return false;
@@ -169,18 +162,33 @@ public boolean isTheGridFullyBombed(){
return true;
}
- public void destroyShip(int shipCode,Player destroyer){
- if (destroyer.equals(owner)){
- for (Coordination[] coordinations : opponentGrid.getTheGrid()) {
- for (Coordination coordination : coordinations) {
- if (coordination.getContent().equalsIgnoreCase("ship "+shipCode))
- coordination.setContent("*");
+ public void destroyShip(Ship ship, Player destroyer) {
+ if (destroyer.equals(owner)) {
+ if (ship.getDirection() == 'n' || ship.getDirection() == 's') {
+ for (int i = 0; i < ship.getLength(); i++) {
+ for (int j = 0; j < ship.getWidth(); j++) {
+ if (ship.getDirection() == 'n') {
+ opponentGrid.getLocation(ship.getStartPoint().getXAxis() - i, ship.getStartPoint().getYAxis() + j).setContent("*");
+ } else {
+ opponentGrid.getLocation(ship.getStartPoint().getXAxis() + i, ship.getStartPoint().getYAxis() + j).setContent("*");
+ }
+ }
+ }
+ } else if (ship.getDirection() == 'w' || ship.getDirection() == 'e') {
+ for (int i = 0; i < ship.getWidth(); i++) {
+ for (int j = 0; j < ship.getLength(); j++) {
+ if (ship.getDirection() == 'w') {
+ opponentGrid.getLocation(ship.getStartPoint().getXAxis() + i, ship.getStartPoint().getYAxis() - j).setContent("*");
+ } else {
+ opponentGrid.getLocation(ship.getStartPoint().getXAxis() + i, ship.getStartPoint().getYAxis() + j).setContent("*");
+ }
+ }
}
}
- }else{
+ } else {
for (Coordination[] coordinations : playerGrid.getTheGrid()) {
for (Coordination coordination : coordinations) {
- if (coordination.getContent().equalsIgnoreCase("ship "+shipCode))
+ if (coordination.getPreviousContent().equalsIgnoreCase("" + ship.getCode()))
coordination.setContent("*");
}
}
diff --git a/src/main/java/BattleSea/Controller/ShipManager.java b/src/BattleSea/Controller/ShipManager.java
similarity index 98%
rename from src/main/java/BattleSea/Controller/ShipManager.java
rename to src/BattleSea/Controller/ShipManager.java
index 43eefd1..8d681e6 100644
--- a/src/main/java/BattleSea/Controller/ShipManager.java
+++ b/src/BattleSea/Controller/ShipManager.java
@@ -1,7 +1,6 @@
package BattleSea.Controller;
import BattleSea.Model.Coordination;
-import BattleSea.Model.Grid;
import BattleSea.Model.Ship;
import Plato.Model.Player;
@@ -13,7 +12,7 @@ public class ShipManager {
public ShipManager(Player owner, int gridDimension, int numberOfShips) {
this.owner = owner;
- allShips = new ArrayList();
+ allShips = new ArrayList<>();
createShips(gridDimension, numberOfShips);
}
diff --git a/src/main/java/BattleSea/Model/Coordination.java b/src/BattleSea/Model/Coordination.java
similarity index 58%
rename from src/main/java/BattleSea/Model/Coordination.java
rename to src/BattleSea/Model/Coordination.java
index a71d7c7..abd0e30 100644
--- a/src/main/java/BattleSea/Model/Coordination.java
+++ b/src/BattleSea/Model/Coordination.java
@@ -1,6 +1,6 @@
package BattleSea.Model;
-public class Coordination implements Comparable {
+public class Coordination {
private final int xAxis;
private final int yAxis;
private String content;
@@ -11,12 +11,12 @@ public class Coordination implements Comparable {
public Coordination(int xAxis, int yAxis) {
this.xAxis = xAxis;
this.yAxis = yAxis;
- content="";
- previousContent="";
+ content = "";
+ previousContent = "";
}
public void setContent(String content) {
- this.previousContent=this.content;
+ this.previousContent = this.content;
this.content = content;
}
@@ -24,8 +24,10 @@ public String getPreviousContent() {
return previousContent;
}
- public void rollbackContentChange(){
- this.content=this.previousContent;
+ public void rollbackContentChange() {
+ String temp = this.content;
+ this.content = this.previousContent;
+ this.previousContent = temp;
}
public boolean Bomb() {
@@ -36,16 +38,12 @@ public boolean Bomb() {
}
}
- public boolean occupy() {
- if (this.isOccupied) return false;
- else {
- this.isOccupied = true;
- return true;
- }
+ public void occupy() {
+ this.isOccupied = true;
}
- public void unoccupy(){
- this.isOccupied=false;
+ public void unoccupy() {
+ this.isOccupied = false;
}
public int getXAxis() {
@@ -68,11 +66,4 @@ public boolean isOccupied() {
return isOccupied;
}
- public int compareTo(Coordination o) {
- return (this.xAxis - o.getXAxis()) + (this.yAxis - o.getYAxis());
- }
-
- public Coordination getClone(){
- return new Coordination(this.getXAxis(),this.getYAxis());
- }
}
diff --git a/src/main/java/BattleSea/Model/Grid.java b/src/BattleSea/Model/Grid.java
similarity index 63%
rename from src/main/java/BattleSea/Model/Grid.java
rename to src/BattleSea/Model/Grid.java
index abbb62c..f7dde77 100644
--- a/src/main/java/BattleSea/Model/Grid.java
+++ b/src/BattleSea/Model/Grid.java
@@ -22,26 +22,12 @@ public int getDimension() {
return dimension;
}
- public Player getOwner() {
- return owner;
- }
-
public Coordination[][] getTheGrid() {
return theGrid;
}
public Coordination getLocation(int xAxis, int yAxis) {
- return theGrid[xAxis - 1][yAxis - 1].getClone();
- }
-
- public Grid getClone() {
- Grid clone = new Grid(this.dimension, this.owner);
- for (int i = 0; i < dimension; i++) {
- for (int j = 0; j < dimension; j++) {
- clone.getTheGrid()[i][j] = theGrid[i][j].getClone();
- }
- }
- return clone;
+ return theGrid[xAxis - 1][yAxis - 1];
}
}
diff --git a/src/main/java/BattleSea/Model/Ship.java b/src/BattleSea/Model/Ship.java
similarity index 100%
rename from src/main/java/BattleSea/Model/Ship.java
rename to src/BattleSea/Model/Ship.java
diff --git a/src/BattleSea/View/InGameMenu.java b/src/BattleSea/View/InGameMenu.java
new file mode 100644
index 0000000..d8ea0af
--- /dev/null
+++ b/src/BattleSea/View/InGameMenu.java
@@ -0,0 +1,275 @@
+package BattleSea.View;
+
+import BattleSea.Controller.GameManager;
+import Plato.Model.Log;
+import Plato.Model.Player;
+
+import java.util.Scanner;
+
+
+public class InGameMenu {
+ private final GameManager gameManager;
+ private static boolean isGameEnded;
+ private final Scanner scanner;
+
+
+ public InGameMenu(GameManager gameManager, Scanner scanner) {
+ this.gameManager = gameManager;
+ this.scanner = scanner;
+ isGameEnded = false;
+ }
+
+ public static void gameHasEnded() {
+ InGameMenu.isGameEnded = true;
+ }
+
+ public void run() {
+ while (!isGameEnded) {
+ try {
+ System.out.print("enter the number of one of these inputs to continue\n" +
+ "0- show turn\n" +
+ "1- change location of a ship\n" +
+ "2- change direction of a ship\n" +
+ "3- bomb a location\n" +
+ "4- see your ships \n" +
+ "5- see locations you bombed\n" +
+ "6- see your board\n" +
+ "7- see opponents board\n" +
+ "8- see scores\n" +
+ "9- clear screen\n" +
+ "10- withdraw and quit the game\n" +
+ "choose an option:");
+ int input = Integer.parseInt(scanner.nextLine().trim().toLowerCase());
+ if (input == 0) {
+ showTurn();
+ } else if (input == 1) {
+ System.out.print("enter the ship's number:");
+ int shipCode = Integer.parseInt(scanner.nextLine().trim());
+ if (shipCode < 1 || shipCode > gameManager.getShips(1).size())
+ System.out.println("invalid ship number");
+ else {
+ System.out.print("enter x axis of destination:");
+ int xDestination = Integer.parseInt(scanner.nextLine().trim());
+ System.out.print("enter y axis of destination:");
+ int yDestination = Integer.parseInt(scanner.nextLine().trim());
+ changeLocation(shipCode, xDestination, yDestination);
+ }
+ } else if (input == 2) {
+ System.out.print("enter the ship's number:");
+ int shipCode = Integer.parseInt(scanner.nextLine().trim());
+ if (shipCode < 1 || shipCode > gameManager.getShips(1).size())
+ System.out.println("invalid ship number");
+ else {
+ System.out.print("1-north \n2-east \n3-south \n4-west \nenter the direction:");
+ int direction = Integer.parseInt(scanner.nextLine().trim().toLowerCase());
+ if (direction == 1) {
+ changeDirection(shipCode, 'n');
+ } else if (direction == 2) {
+ changeDirection(shipCode, 'e');
+ } else if (direction == 3) {
+ changeDirection(shipCode, 's');
+ } else if (direction == 4) {
+ changeDirection(shipCode, 'w');
+ } else System.out.println("you entered an invalid number");
+ }
+ } else if (input == 3) {
+ System.out.print("enter x axis of bombing location:");
+ int xAxis = Integer.parseInt(scanner.nextLine().trim());
+ System.out.print("enter y axis of bombing location:");
+ int yAxis = Integer.parseInt(scanner.nextLine().trim());
+ if (gameManager.getTurnsOwnBoard().getDimension() < xAxis ||
+ gameManager.getTurnsOwnBoard().getDimension() < yAxis ||
+ xAxis < 1 || yAxis < 1)
+ System.out.println("Please Choose a Location Inside The Game Board");
+ else {
+ bombLocation(xAxis, yAxis);
+ }
+ } else if (input == 4) {
+ System.out.print("1-all ships " +
+ "\n2-functional ships (ships that are not damaged) " +
+ "\n3-damaged ships " +
+ "\n4-destroyed ships" +
+ "\nchoose an option:");
+ int option = Integer.parseInt(scanner.nextLine().trim());
+ if (option < 0 || option > 5) System.out.println("you entered an invalid number");
+ else showShips(option);
+ } else if (input == 5) {
+ System.out.print("1-all bombs " +
+ "\n2-missed bombs" +
+ "\n3-hit bombs " +
+ "\nchoose an option:");
+ int option = Integer.parseInt(scanner.nextLine().trim());
+ if (option < 0 || option > 3) System.out.println("you entered an invalid number");
+ else showBombardLocations(option);
+ } else if (input == 6) {
+ showPlayerGameBoard();
+ } else if (input == 7) {
+ showOpponentGameBoard();
+ } else if (input == 8) {
+ showScores();
+ } else if (input == 9) {
+ clearScreen();
+ } else if (input == 10) {
+ withdraw();
+ } else System.out.println("invalid input.\n to see the input options enter \"help\"");
+ } catch (NumberFormatException e) {
+ System.out.println("you must enter the number for that option");
+ }
+ }
+ finalizingTheGame();
+ }
+
+ private void finalizingTheGame() {
+ Player firstPlayer = gameManager.getFirstPlayer();
+ Player secondPlayer = gameManager.getSecondPlayer();
+ int firstPlayerScore = gameManager.getFirstPlayerScore();
+ int secondPlayerScore = gameManager.getSecondPlayerScore();
+ firstPlayer.addBattleSeaPlayedCount();
+ secondPlayer.addBattleSeaPlayedCount();
+ firstPlayer.addBattleSeaPoints(firstPlayerScore);
+ secondPlayer.addBattleSeaPoints(secondPlayerScore);
+ if (firstPlayerScore == secondPlayerScore) {
+ firstPlayer.addBattleSeaDraws();
+ secondPlayer.addBattleSeaDraws();
+ Log.addLog(2, firstPlayer, secondPlayer, secondPlayer);
+ } else if (firstPlayerScore > secondPlayerScore) {
+ firstPlayer.addBattleSeaWins();
+ secondPlayer.addBattleSeaLosses();
+ Log.addLog(2, firstPlayer, secondPlayer, firstPlayer);
+ } else {
+ firstPlayer.addBattleSeaLosses();
+ secondPlayer.addBattleSeaWins();
+ Log.addLog(2, firstPlayer, secondPlayer, secondPlayer);
+ }
+ }
+
+ private void withdraw() {
+ gameManager.withdraw();
+ }
+
+ public void clearScreen() {
+ /*try {
+ new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
+ } catch (InterruptedException | IOException e) {
+ e.printStackTrace();
+ }*/
+ }
+
+ private void showTurn() {
+ System.out.println("It's " + gameManager.getTurn().getUsername() + "'s turn");
+ }
+
+ private void changeDirection(int shipCode, char direction) {
+ int result = gameManager.changeDirectionOfShip(shipCode, direction);
+ if (result == 0) {
+ System.out.println("This Ship Cannot Rotate Because It Is Partially Damaged or Completely destroyed");
+ } else if (result == 1) {
+ System.out.println("The Ship " + shipCode + " Has Been Rotated To The New Direction Successfully");
+ } else if (result == 2) {
+ System.out.println("Cannot Rotate The Ship To The Requested Direction!");
+ } else
+ System.out.println("You Cannot Move The Ship To This Location! Because Part Of Ship Will Be Out Of The Board!");
+
+ }
+
+ private void changeLocation(int shipCode, int xDestination, int yDestination) {
+ int result = gameManager.changeLocationOfShip(shipCode, xDestination, yDestination);
+ if (result == 0) {
+ System.out.println("This Ship Cannot Move Because It Is Partially Damaged or Completely destroyed");
+ } else if (result == 1) {
+ System.out.println("The Ship " + shipCode + " Has Been Moved To The New Location Successfully");
+ } else if (result == 2) {
+ System.out.println("Cannot Move The Ship To The Requested Location!");
+ } else
+ System.out.println("You Cannot Move The Ship To This Location Because Part Of Ship Will Be Out Of The Board!");
+
+ }
+
+ private void bombLocation(int xAxis, int yAxis) {
+ int result = gameManager.bombLocation(xAxis, yAxis);
+ if (result == 0) {
+ System.out.println("You Missed Your Shot");
+ changeTurn();
+ } else if (result == 1) {
+ System.out.println("Your Bomb Hit The Opponent's Ship");
+ } else if (result == 2) {
+ System.out.println("You Destroyed Your Opponent's Ship");
+ } else if (result == 3) {
+ System.out.println("You Have Already Bombed This Location!");
+ }
+ }
+
+ public void showPlayerGameBoard() {
+ for (int i = 1; i < gameManager.getTurnsOwnBoard().getDimension() + 1; i++) {
+ System.out.print("|");
+ for (int j = 1; j < gameManager.getTurnsOwnBoard().getDimension() + 1; j++) {
+ if (gameManager.getTurnsOwnBoard().getLocation(i, j).getContent().equalsIgnoreCase(""))
+ System.out.print(" " + "|");
+ else System.out.print(gameManager.getTurnsOwnBoard().getLocation(i, j).getContent() + "|");
+ }
+ System.out.println();
+ }
+ }
+
+ public void showOpponentGameBoard() {
+ for (int i = 1; i < gameManager.getTurnsOpponentBoard().getDimension() + 1; i++) {
+ System.out.print("|");
+ for (int j = 1; j < gameManager.getTurnsOpponentBoard().getDimension() + 1; j++) {
+ if (gameManager.getTurnsOpponentBoard().getLocation(i, j).getContent().equalsIgnoreCase(""))
+ System.out.print(" " + "|");
+ else System.out.print(gameManager.getTurnsOpponentBoard().getLocation(i, j).getContent() + "|");
+ }
+ System.out.println();
+ }
+ }
+
+ public void showShips(int option) {
+ for (String ship : gameManager.getShips(option)) {
+ System.out.println(ship);
+ }
+ }
+
+ public void showBombardLocations(int option) {
+ for (int i = 1; i < gameManager.getTurnsOpponentBoard().getDimension() + 1; i++) {
+ for (int j = 1; j < gameManager.getTurnsOpponentBoard().getDimension() + 1; j++) {
+ if (option == 1 && !gameManager.getTurnsOpponentBoard().getLocation(i, j).getContent().equals("")) {
+ System.out.println("X:" + gameManager.getTurnsOpponentBoard().getLocation(i, j).getXAxis() +
+ "\t" + "Y:" + gameManager.getTurnsOpponentBoard().getLocation(i, j).getYAxis());
+ }
+ if (option == 2 && gameManager.getTurnsOpponentBoard().getLocation(i, j).getContent().equals("-")) {
+ System.out.println("X:" + gameManager.getTurnsOpponentBoard().getLocation(i, j).getXAxis() +
+ "\t" + "Y:" + gameManager.getTurnsOpponentBoard().getLocation(i, j).getYAxis());
+ }
+ if (option == 3) {
+ if (gameManager.getTurnsOpponentBoard().getLocation(i, j).getContent().equals("+") ||
+ gameManager.getTurnsOpponentBoard().getLocation(i, j).getContent().equals("*")) {
+ System.out.println("X:" + gameManager.getTurnsOpponentBoard().getLocation(i, j).getXAxis() +
+ "\t" + "Y:" + gameManager.getTurnsOpponentBoard().getLocation(i, j).getYAxis());
+ }
+ }
+ }
+ }
+ }
+
+ public void showScores() {
+ System.out.println(gameManager.getFirstPlayer().getUsername() + " : " + gameManager.getFirstPlayerScore() +
+ "\t" + gameManager.getSecondPlayer().getUsername() + " : " + gameManager.getSecondPlayerScore());
+ }
+
+ public void showWinner() {
+ if (gameManager.getFirstPlayerScore() > gameManager.getSecondPlayerScore()) {
+ System.out.println(gameManager.getFirstPlayer().getUsername() + " won");
+ } else if (gameManager.getFirstPlayerScore() < gameManager.getSecondPlayerScore()) {
+ System.out.println(gameManager.getSecondPlayer().getUsername() + " won");
+ } else System.out.println("it was a draw!");
+ }
+
+ public void changeTurn() {
+ System.out.println("Next Player's Turn!");
+ }
+
+ public void changeTurn(boolean t) {
+ if (t) gameManager.changeTurn();
+ }
+
+}
diff --git a/src/BattleSea/View/StartingPage.java b/src/BattleSea/View/StartingPage.java
new file mode 100644
index 0000000..9859990
--- /dev/null
+++ b/src/BattleSea/View/StartingPage.java
@@ -0,0 +1,162 @@
+package BattleSea.View;
+
+import BattleSea.Controller.GameManager;
+import Plato.Model.*;
+import Plato.View.BattleSeaMenu;
+import Plato.View.GamesMenu;
+import Plato.View.Page;
+import Plato.View.UserPage;
+
+import java.io.FileNotFoundException;
+
+public class StartingPage extends Page {
+ Player firstPlayer;
+ Player secondPlayer;
+ GameManager gameManager;
+ InGameMenu inGameMenu;
+
+ public StartingPage(Player firstPlayer, Player secondPlayer) {
+ this.firstPlayer = firstPlayer;
+ this.secondPlayer = secondPlayer;
+ }
+
+ public Page run() {
+ while (true) {
+ System.out.print("1-run the game\n" +
+ "2-View account menu\n" +
+ "3-Back\n" +
+ "choose an option:");
+ try {
+ int option = Integer.parseInt(scanner.nextLine().trim());
+ if (option == 1) {
+ runInPrivate();
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
+ } else if (option == 2) {
+ return UserPage.userPage;
+ } else if (option == 3) {
+ return BattleSeaMenu.battleSeaMenu;
+ }
+
+ } catch (NumberFormatException | FileNotFoundException e) {
+ System.out.println("you must enter the number for that option");
+ }
+ }
+
+ }
+
+ private void runInPrivate() {
+ System.out.println("Welcome to battle sea\n" +
+ "now one of the players will choose the dimensions of the board\n" +
+ "and the other on the number of ships");
+ boolean isBoardOptionDecided = false;
+ while (!isBoardOptionDecided) {
+ try {
+ System.out.print("1-10*10\n" +
+ "2-15*15\n" +
+ "3-20*20\n" +
+ "choose an options:");
+ int boardOption = Integer.parseInt(scanner.nextLine().trim());
+ if (boardOption < 1 || boardOption > 3) System.out.println("invalid input");
+ else {
+ isBoardOptionDecided = true;
+ boolean isNumberOfShipsDecided = false;
+ int numberOfShips;
+ while (!isNumberOfShipsDecided) {
+ try {
+ if (boardOption == 1) {
+ System.out.print("1- 4 ships\n" +
+ "2- 5 ships\n" +
+ "3- 6 ships\n" +
+ "chose an option:");
+ numberOfShips = Integer.parseInt(scanner.nextLine().trim());
+ if (numberOfShips < 1 || numberOfShips > 3) System.out.println("invalid input");
+ else {
+ isNumberOfShipsDecided = true;
+ if (numberOfShips == 1)
+ gameManager = new GameManager(firstPlayer, secondPlayer, 10, 4);
+ else if (numberOfShips == 2)
+ gameManager = new GameManager(firstPlayer, secondPlayer, 10, 5);
+ else gameManager = new GameManager(firstPlayer, secondPlayer, 10, 6);
+ }
+ } else if (boardOption == 2) {
+ System.out.print("1- 6 ships\n" +
+ "2- 7 ships\n" +
+ "3- 8 ships\n" +
+ "chose an option:");
+ numberOfShips = Integer.parseInt(scanner.nextLine().trim());
+ if (numberOfShips < 1 || numberOfShips > 3) System.out.println("invalid input");
+ else {
+ isNumberOfShipsDecided = true;
+ if (numberOfShips == 1)
+ gameManager = new GameManager(firstPlayer, secondPlayer, 15, 6);
+ else if (numberOfShips == 2)
+ gameManager = new GameManager(firstPlayer, secondPlayer, 15, 7);
+ else gameManager = new GameManager(firstPlayer, secondPlayer, 15, 8);
+ }
+ } else {
+ System.out.print("1- 7 ships\n" +
+ "2- 8 ships\n" +
+ "3- 9 ships\n" +
+ "chose an option:");
+ numberOfShips = Integer.parseInt(scanner.nextLine().trim());
+ if (numberOfShips < 1 || numberOfShips > 3) System.out.println("invalid input");
+ else {
+ isNumberOfShipsDecided = true;
+ if (numberOfShips == 1)
+ gameManager = new GameManager(firstPlayer, secondPlayer, 20, 7);
+ else if (numberOfShips == 2)
+ gameManager = new GameManager(firstPlayer, secondPlayer, 20, 8);
+ else gameManager = new GameManager(firstPlayer, secondPlayer, 20, 9);
+ }
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("you must enter the number for that option");
+ }
+ }
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("you must enter the number for that option");
+ }
+ }
+ inGameMenu = new InGameMenu(gameManager, scanner);
+ System.out.println("let's see first player's game board!");
+ inGameMenu.showPlayerGameBoard();
+ System.out.println("if you want another random board enter \"next\" \n" +
+ "but if you want to continue enter anything else");
+ while (scanner.nextLine().trim().equalsIgnoreCase("next")) {
+ inGameMenu.clearScreen();
+ gameManager.putTheShipsOnBoardRandomly(gameManager.getFirstPlayerGridManager(),
+ gameManager.getFirstPlayerShipManager(),
+ gameManager.getTurnsOwnBoard().getDimension());
+ inGameMenu.showPlayerGameBoard();
+ }
+ inGameMenu.clearScreen();
+ inGameMenu.changeTurn(true);
+ inGameMenu.changeTurn();
+ System.out.println("now its second player's turn to see their board");
+ inGameMenu.showPlayerGameBoard();
+ System.out.println("if you want another random board enter \"next\" \n" +
+ "but if you want to continue enter anything else");
+ while (scanner.nextLine().trim().equalsIgnoreCase("next")) {
+ inGameMenu.clearScreen();
+ gameManager.putTheShipsOnBoardRandomly(gameManager.getSecondPlayerGridManager(),
+ gameManager.getSecondPlayerShipManager(),
+ gameManager.getTurnsOwnBoard().getDimension());
+ inGameMenu.showPlayerGameBoard();
+ System.out.println("if you want another random board enter \"next\" \n" +
+ "but if you want to continue enter anything else");
+ }
+ inGameMenu.clearScreen();
+ inGameMenu.changeTurn(true);
+ System.out.println("now it's time to play the game");
+ inGameMenu.run();
+ System.out.println("the game has ended\n");
+ inGameMenu.showScores();
+ inGameMenu.showWinner();
+ System.out.println("//////////////////////////////////////////////////////////////////////");
+ }
+}
diff --git a/src/main/java/Plato/Controller/FriendsMenuController.java b/src/Plato/Controller/FriendsMenuController.java
similarity index 100%
rename from src/main/java/Plato/Controller/FriendsMenuController.java
rename to src/Plato/Controller/FriendsMenuController.java
diff --git a/src/main/java/Plato/Controller/LoginPageController.java b/src/Plato/Controller/LoginPageController.java
similarity index 97%
rename from src/main/java/Plato/Controller/LoginPageController.java
rename to src/Plato/Controller/LoginPageController.java
index 4fd621f..4c6c9c7 100644
--- a/src/main/java/Plato/Controller/LoginPageController.java
+++ b/src/Plato/Controller/LoginPageController.java
@@ -10,7 +10,7 @@
import java.util.Date;
public class LoginPageController {
- private static LoginPageController loginPageController = new LoginPageController();
+ public static LoginPageController loginPageController = new LoginPageController();
public static User user;
static boolean isMainAdminRegistered;
diff --git a/src/main/java/Plato/Controller/MainPageAdminController.java b/src/Plato/Controller/MainPageAdminController.java
similarity index 100%
rename from src/main/java/Plato/Controller/MainPageAdminController.java
rename to src/Plato/Controller/MainPageAdminController.java
diff --git a/src/main/java/Plato/Controller/MainPagePlayerController.java b/src/Plato/Controller/MainPagePlayerController.java
similarity index 100%
rename from src/main/java/Plato/Controller/MainPagePlayerController.java
rename to src/Plato/Controller/MainPagePlayerController.java
diff --git a/src/main/java/Plato/Controller/UserPageController.java b/src/Plato/Controller/UserPageController.java
similarity index 100%
rename from src/main/java/Plato/Controller/UserPageController.java
rename to src/Plato/Controller/UserPageController.java
diff --git a/src/Plato/Model/Admin.java b/src/Plato/Model/Admin.java
new file mode 100644
index 0000000..ac78a4c
--- /dev/null
+++ b/src/Plato/Model/Admin.java
@@ -0,0 +1,69 @@
+package Plato.Model;
+
+
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class Admin extends User{
+ private static ArrayList admins =new ArrayList();
+ private static ArrayList messages = new ArrayList();
+ public static ArrayList getAdmins() {
+ return admins;
+ }
+
+ public static void addNewAdmin(String username, String password, String email, String firstname, String lastname, String phoneNumber) throws Exception {
+ for (User allUser : User.getAllUsers()) {
+ if ((allUser.getUsername().equals(username))||(allUser.getEmail().equals(email)))
+ {
+ Exception exception = new Exception();
+ throw exception;
+ }
+ }
+ Admin admin = new Admin();
+ admin.setAdmin(true);
+ admin.setEmail(email);
+ admin.setFirstname(firstname);
+ admin.setLastname(lastname);
+ admin.setPassword(password);
+ admin.setPhoneNumber(phoneNumber);
+ admin.setUsername(username);
+ User.getAllUsers().add(admin);
+ admins.add(admin);
+
+ }
+
+ public Admin() {
+ }
+
+ public static ArrayList getMessages() {
+ return messages;
+ }
+
+ public static void setMessages(ArrayList messages) {
+ Admin.messages = messages;
+ }
+
+ //update the admins that has been saved in file
+ public static void updateAdmins() throws FileNotFoundException {
+ int n = admins.size();
+ for (int i = 0; i < n; i++) {
+ Map m = new LinkedHashMap(9);
+ m.put("firstname", admins.get(i).getFirstname());
+ m.put("lastname", admins.get(i).getLastname());
+ m.put("username", admins.get(i).getUsername());
+ m.put("userID", admins.get(i).getUserID());
+ m.put("password", admins.get(i).getPassword());
+ m.put("email", admins.get(i).getEmail());
+ m.put("phoneNumber", admins.get(i).getPhoneNumber());
+ m.put("isMainAdminJoinnt", isIsMainAdminJoinnt());
+ m.put("messages", getMessages());
+ }
+ PrintWriter pw = new PrintWriter("admins.json");
+
+ pw.flush();
+ pw.close();
+ }
+}
diff --git a/src/main/java/Plato/Model/Event.java b/src/Plato/Model/Event.java
similarity index 60%
rename from src/main/java/Plato/Model/Event.java
rename to src/Plato/Model/Event.java
index efc5861..496bb38 100644
--- a/src/main/java/Plato/Model/Event.java
+++ b/src/Plato/Model/Event.java
@@ -1,8 +1,10 @@
package Plato.Model;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.GregorianCalendar;
+
+
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.util.*;
public class Event {
private static ArrayList events = new ArrayList();
@@ -25,7 +27,9 @@ public Event( Game game, GregorianCalendar startDate, GregorianCalendar endDate,
this.hasEnded = false;
}
-
+ public static void addEvent(Event event){
+ events.add(event);
+ }
public static ArrayList getEvents() {
return events;
@@ -39,16 +43,17 @@ public ArrayList getPlayersOfThisEvent() {
return playersOfThisEvent;
}
- public void setPlayersOfThisEvent(ArrayList playersOfThisEvent) {
- this.playersOfThisEvent = playersOfThisEvent;
+ public void setPlayersOfThisEvent(ArrayList playersOfThisEvent) {
+ int n = playersOfThisEvent.size();
+ for (int i = 0; i < n; i++) {
+ this.playersOfThisEvent.add(Player.getPlayerByID(playersOfThisEvent.get(i)));
+ }
}
public Game getGame() {
return game;
}
-
-
public int getEventScore() {
return eventScore;
}
@@ -81,26 +86,6 @@ public void setHasEnded(boolean hasEnded) {
this.hasEnded = hasEnded;
}
- public void startEvent(int eventId){
-
- }
- public void endEvent(int eventId){
-
- }
- public static void removeEvent(int eventId){
-
- }
- public static Event getEvent(int eventId){
- return null;
- }
-
- public void joinEvent(Player player){
-
- }
- public void quitEvent(Player player){
-
- }
-
public void setGame(Game game) {
this.game = game;
}
@@ -120,4 +105,29 @@ public GregorianCalendar getEndDate() {
public void setEndDate(GregorianCalendar endDate) {
this.endDate = endDate;
}
+
+ //update the admins that has been saved in file
+ public static void updateEvents() throws FileNotFoundException {
+
+ int n = events.size();
+ for (int i = 0; i < n; i++) {
+ Map m = new LinkedHashMap(6);
+ m.put("game", events.get(i).getGame().getGameID());
+ m.put("eventScore", events.get(i).getEventScore());
+ m.put("eventID", events.get(i).getEventId());
+ m.put("hasStarted", events.get(i).isHasStarted());
+ m.put("hasEnded", events.get(i).isHasEnded());
+ int t = events.get(i).getPlayersOfThisEvent().size();
+ ArrayList players = new ArrayList<>();
+ for (int j = 0; j < t; j++) {
+ players.add(events.get(i).getPlayersOfThisEvent().get(j).getUserID());
+ }
+ m.put("playersOfThisEvent", players);
+
+ }
+ PrintWriter pw = new PrintWriter("events.json");
+
+ pw.flush();
+ pw.close();
+ }
}
diff --git a/src/Plato/Model/Game.java b/src/Plato/Model/Game.java
new file mode 100644
index 0000000..59d644d
--- /dev/null
+++ b/src/Plato/Model/Game.java
@@ -0,0 +1,56 @@
+package Plato.Model;
+
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class Game {
+ private static ArrayList games = new ArrayList();
+ private String name;
+ private int gameID;
+
+
+ public static ArrayList getGames() {
+ return games;
+ }
+
+ public static void addGame(String name, int gameID){
+ Game game = new Game();
+ game.setName(name);
+ game.setGameID(gameID);
+ games.add(game);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getGameID() {
+ return gameID;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setGameID(int gameID) {
+ this.gameID = gameID;
+ }
+
+ //update the games that has been saved in file
+ public static void updateGames() throws FileNotFoundException {
+ int n = games.size();
+ for (int i = 0; i < n; i++) {
+ Map m = new LinkedHashMap(2);
+ m.put("name", games.get(i).getName());
+ m.put("gameID", games.get(i).getGameID());
+
+ }
+ PrintWriter pw = new PrintWriter("games.json");
+
+ pw.flush();
+ pw.close();
+ }
+}
diff --git a/src/main/java/Plato/Model/Log.java b/src/Plato/Model/Log.java
similarity index 64%
rename from src/main/java/Plato/Model/Log.java
rename to src/Plato/Model/Log.java
index bca4502..74e0beb 100644
--- a/src/main/java/Plato/Model/Log.java
+++ b/src/Plato/Model/Log.java
@@ -1,7 +1,12 @@
package Plato.Model;
+
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
public class Log {
//fields
@@ -47,6 +52,11 @@ public static void addLog(int gameID, Player player1, Player player2, Player win
logs.add(log);
}
+ //setter
+ public void setFinishTime(LocalDate finishTime) {
+ this.finishTime = finishTime;
+ }
+
//overriding toString method
@Override
public String toString() {
@@ -59,4 +69,19 @@ public String toString() {
;
}
+ //update the logs that has been saved in file
+ public static void updateLogs() throws FileNotFoundException {
+ int n = logs.size();
+ for (int i = 0; i < n; i++) {
+ Map m = new LinkedHashMap(4);
+ m.put("gameID", logs.get(i).getGameID());
+ m.put("player1", logs.get(i).getPlayer1().getUserID());
+ m.put("player2", logs.get(i).getPlayer2().getUserID());
+ m.put("winner", logs.get(i).getWinner().getUserID());
+ }
+ PrintWriter pw = new PrintWriter("logs.json");
+
+ pw.flush();
+ pw.close();
+ }
}
diff --git a/src/main/java/Plato/Model/Player.java b/src/Plato/Model/Player.java
similarity index 59%
rename from src/main/java/Plato/Model/Player.java
rename to src/Plato/Model/Player.java
index c5767b1..ef5475c 100644
--- a/src/main/java/Plato/Model/Player.java
+++ b/src/Plato/Model/Player.java
@@ -1,9 +1,15 @@
package Plato.Model;
+import BattleSea.Controller.BattleSea;
+import Reversi.ReversiController;
+
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.ArrayList;
-import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.Map;
public class Player extends User{
//fields
@@ -46,6 +52,20 @@ public Player() {
this.registerTime = java.time.LocalDate.now();
}
+ public static void addNewPlayer(String username, String password, String email, String firstname, String lastname, String phoneNumber) throws Exception {
+ Player player = new Player();
+ player.setAdmin(false);
+ player.setEmail(email);
+ player.setFirstname(firstname);
+ player.setLastname(lastname);
+ player.setPassword(password);
+ player.setPhoneNumber(phoneNumber);
+ player.setUsername(username);
+ User.getAllUsers().add(player);
+ players.add(player);
+
+ }
+
//remove the player from the list of players
public static void deletePlayerAccount(int ID){
for (Player player : players) {
@@ -278,4 +298,144 @@ public int getReversiLevel(){
public void editInformation(String type, String newValue) {
super.editInformation(type, newValue);
}
+
+ //update the players that has been saved in file
+ public static void updatePlayers() throws FileNotFoundException {
+ int n = players.size();
+ for (int i = 0; i < n; i++) {
+ Map m = new LinkedHashMap(26);
+ m.put("firstname", players.get(i).getFirstname());
+ m.put("lastname", players.get(i).getLastname());
+ m.put("username", players.get(i).getUsername());
+ m.put("userID", players.get(i).getUserID());
+ m.put("password", players.get(i).getPassword());
+ m.put("email", players.get(i).getEmail());
+ m.put("phoneNumber", players.get(i).getPhoneNumber());
+ m.put("money", players.get(i).getMoney());
+ m.put("score", players.get(i).getScore());
+ m.put("reversiWins", players.get(i).getReversiWins());
+ m.put("reversiDraws", players.get(i).getReversiDraws());
+ m.put("reversiLosses", players.get(i).getReversiLosses());
+ m.put("reversiPlayedCount", players.get(i).getReversiPlayedCount());
+ m.put("reversiPoints", players.get(i).getReversiPoints());
+ m.put("battleSeaWins", players.get(i).getBattleSeaWins());
+ m.put("battleSeaDraws", players.get(i).getBattleSeaDraws());
+ m.put("battleSeaLosses", players.get(i).getBattleSeaLosses());
+ m.put("battleSeaPlayedCount", players.get(i).getBattleSeaPlayedCount());
+ m.put("battleSeaPoints", players.get(i).getBattleSeaPoints());
+ int t = players.get(i).getFriends().size();
+ ArrayList friends = new ArrayList<>();
+ for (int j = 0; j < t; j++) {
+ friends.add(players.get(i).getFriends().get(j).getUserID());
+ }
+ m.put("friends", friends);
+ t = players.get(i).getFriendRequests().size();
+ ArrayList friendRequests = new ArrayList<>();
+ for (int j = 0; j < t; j++) {
+ friendRequests.add(players.get(i).getFriendRequests().get(j).getUserID());
+ }
+ m.put("friendRequests", friendRequests);
+ t = players.get(i).getSuggestedGames().size();
+ ArrayList suggestedGames = new ArrayList<>();
+ for (int j = 0; j < t; j++) {
+ suggestedGames.add(players.get(i).getSuggestedGames().get(j).getGameID());
+ }
+ m.put("suggestedGames", suggestedGames);
+ m.put("suggestionID", Player.getPlayers().get(i).getSuggestionID());
+ t = players.get(i).getFavorites().size();
+ ArrayList favorites = new ArrayList<>();
+ for (int j = 0; j < t; j++) {
+ suggestedGames.add(players.get(i).getFavorites().get(j).getGameID());
+ }
+ m.put("favorites", favorites);
+ m.put("messages", Player.getPlayers().get(i).getMessages());
+ m.put("messagesShown", Player.getPlayers().get(i).getMessagesShown());
+
+ }
+ PrintWriter pw = new PrintWriter("players.json");
+
+ pw.flush();
+ pw.close();
+ }
+
+ //setter
+ public void setRegisterTime(LocalDate registerTime) {
+ this.registerTime = registerTime;
+ }
+ public void setMoney(int money) {
+ this.money = money;
+ }
+ public void setScore(int score) {
+ this.score = score;
+ }
+ public void setReversiWins(int reversiWins) {
+ this.reversiWins = reversiWins;
+ }
+ public void setReversiDraws(int reversiDraws) {
+ this.reversiDraws = reversiDraws;
+ }
+ public void setReversiLosses(int reversiLosses) {
+ this.reversiLosses = reversiLosses;
+ }
+ public void setReversiPoints(int reversiPoints) {
+ this.reversiPoints = reversiPoints;
+ }
+ public void setReversiPlayedCount(int reversiPlayedCount) {
+ this.reversiPlayedCount = reversiPlayedCount;
+ }
+ public void setBattleSeaWins(int battleSeaWins) {
+ this.battleSeaWins = battleSeaWins;
+ }
+ public void setBattleSeaDraws(int battleSeaDraws) {
+ this.battleSeaDraws = battleSeaDraws;
+ }
+ public void setBattleSeaLosses(int battleSeaLosses) {
+ this.battleSeaLosses = battleSeaLosses;
+ }
+ public void setBattleSeaPoints(int battleSeaPoints) {
+ this.battleSeaPoints = battleSeaPoints;
+ }
+ public void setBattleSeaPlayedCount(int battleSeaPlayedCount) {
+ this.battleSeaPlayedCount = battleSeaPlayedCount;
+ }
+ public void setFriends(ArrayList friends) {
+ int n = friends.size();
+ for (int i = 0; i < n; i++) {
+ this.friends.add(getPlayerByID(friends.get(i)));
+ }
+ }
+ public void setFriendRequests(ArrayList friendRequests) {
+ int n = friendRequests.size();
+ for (int i = 0; i < n; i++) {
+ this.friendRequests.add(getPlayerByID(friendRequests.get(i)));
+ }
+ }
+ public void setMessages(ArrayList messages) {
+ this.messages = messages;
+ }
+ public void setSuggestedGames(ArrayList suggestedGames){
+ int n = suggestedGames.size();
+ for (int i = 0; i < n; i++) {
+ if(suggestedGames.get(i).intValue() == 1)
+ this.suggestedGames.add(ReversiController.reversiController);
+ else if(suggestedGames.get(i).intValue() == 2)
+ this.suggestedGames.add(BattleSea.battleSea);
+ }
+ }
+ public void setSuggestionID(ArrayList suggestionID) {
+ this.suggestionID = suggestionID;
+ }
+ public void setMessagesShown(ArrayList messagesShown) {
+ this.messagesShown = messagesShown;
+ }
+ public void setFavorites(ArrayList favorites){
+ int n = favorites.size();
+ for (int i = 0; i < n; i++) {
+ if(favorites.get(i).intValue() == 1)
+ this.favorites.add(ReversiController.reversiController);
+ else if(favorites.get(i).intValue() == 2)
+ this.favorites.add(BattleSea.battleSea);
+ }
+ }
+
}
diff --git a/src/main/java/Plato/Model/User.java b/src/Plato/Model/User.java
similarity index 96%
rename from src/main/java/Plato/Model/User.java
rename to src/Plato/Model/User.java
index 853bbc3..6368ba6 100644
--- a/src/main/java/Plato/Model/User.java
+++ b/src/Plato/Model/User.java
@@ -115,8 +115,8 @@ public static boolean isIsMainAdminJoinnt() {
return isMainAdminJoinnt;
}
- public static void setIsMainAdminJoinnt(boolean isMainAdminJoinnt) {
- User.isMainAdminJoinnt = isMainAdminJoinnt;
+ public static void setIsMainAdminJoinnt(Boolean isMainAdminJoinnt) {
+ User.isMainAdminJoinnt = isMainAdminJoinnt;
}
public static void deleteUserAccount(int ID){
diff --git a/src/main/java/Plato/View/BattleSeaMenu.java b/src/Plato/View/BattleSeaMenu.java
similarity index 83%
rename from src/main/java/Plato/View/BattleSeaMenu.java
rename to src/Plato/View/BattleSeaMenu.java
index 9ff3f0f..42dfd6a 100644
--- a/src/main/java/Plato/View/BattleSeaMenu.java
+++ b/src/Plato/View/BattleSeaMenu.java
@@ -2,21 +2,26 @@
import BattleSea.Controller.BattleSea;
import Plato.Controller.LoginPageController;
-import Plato.Model.Log;
-import Plato.Model.Player;
-import Reversi.ReversiController;
+import Plato.Model.*;
+import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class BattleSeaMenu extends Page{
public static BattleSeaMenu battleSeaMenu = new BattleSeaMenu();
private static final int gameID = 2;
- public Page run() {
+ public Page run() throws FileNotFoundException {
String input;
Scanner scanner = new Scanner(System.in);
Page.seenPages.add(BattleSeaMenu.battleSeaMenu);
+ System.out.println("Battle sea menu :");
while(true){
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input = scanner.nextLine();
if(input.trim().equalsIgnoreCase("Show scoreboard")){
ArrayList playersThatHasPlayedBattleSea = new ArrayList();
@@ -84,9 +89,27 @@ else if( input.trim().equalsIgnoreCase("Run game")){
String password = scanner.nextLine();
try {
Player secondPlayer = LoginPageController.loginSecond(username,password);
- //event score
-
- } catch (Exception e) {
+ for (Event event : Event.getEvents()) {
+ if (event.isHasStarted())
+ {
+ if (!event.isHasEnded())
+ {
+ for (Player player : event.getPlayersOfThisEvent()) {
+ if (player.equals(((Player)LoginPageController.user)))
+ {
+ player.addScore();
+ }
+ if (player.equals(secondPlayer))
+ {
+ secondPlayer.addScore();
+ }
+ }
+ }
+ }
+ }
+ new BattleSea((Player)LoginPageController.user,secondPlayer).run();
+ }
+ catch (Exception e) {
}
}
diff --git a/src/main/java/Plato/View/Commands.java b/src/Plato/View/Commands.java
similarity index 98%
rename from src/main/java/Plato/View/Commands.java
rename to src/Plato/View/Commands.java
index b13670b..45dc297 100644
--- a/src/main/java/Plato/View/Commands.java
+++ b/src/Plato/View/Commands.java
@@ -27,7 +27,7 @@ public enum Commands {
ADD_FRIEND("(?i)add\\s+friend\\s+(\\S+)"),
DATER("(?i)(\\d+)\\s+(\\d+)\\s+(\\d+)"),
SHOW_FRIENDS("(?i)show\\s+friends"),
- REMOVE_FRIENDS("(?i)remove\\s+(\\d+)"),
+ REMOVE_FRIENDS("(?i)remove\\s+(\\S+)"),
VIEW_USER_PROFILE_FRIEND_MENU("(?i)view\\s+user\\s+profile\\s+(\\S+)"),
ADD_USER("(?i)add\\s+(\\S+)"),
SHOW_FRIEND_REQUESTS("(?i)show\\s+friend\\s+requests"),
diff --git a/src/main/java/Plato/View/FriendsMenu.java b/src/Plato/View/FriendsMenu.java
similarity index 72%
rename from src/main/java/Plato/View/FriendsMenu.java
rename to src/Plato/View/FriendsMenu.java
index a4fa87e..31a1de4 100644
--- a/src/main/java/Plato/View/FriendsMenu.java
+++ b/src/Plato/View/FriendsMenu.java
@@ -1,64 +1,60 @@
package Plato.View;
import Plato.Controller.FriendsMenuController;
+import Plato.Model.*;
+import java.io.FileNotFoundException;
import java.util.regex.Matcher;
public class FriendsMenu extends Page{
public static FriendsMenu friendsMenu = new FriendsMenu();
private FriendsMenuController friendsMenuController = FriendsMenuController.getInstance();
- public Page run() {
+ public Page run() throws FileNotFoundException {
Matcher matcher;
String input;
Page.seenPages.add(FriendsMenu.friendsMenu);
System.out.println("Friends Menu :");
- while (true)
- {
+ while (true) {
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input=scanner.nextLine();
friendsMenu.showUnShownMessages();
- if ((matcher = Commands.SHOW_FRIENDS.getMatcher(input)).matches())
- {
+ if ((matcher = Commands.SHOW_FRIENDS.getMatcher(input)).matches()) {
friendsMenu.showFriends();
}
- else if ((matcher = Commands.REMOVE_FRIENDS.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.REMOVE_FRIENDS.getMatcher(input)).matches()) {
friendsMenu.removeFriend(matcher.group(1));
}
- else if ((matcher = Commands.VIEW_USER_PROFILE_FRIEND_MENU.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_USER_PROFILE_FRIEND_MENU.getMatcher(input)).matches()) {
friendsMenu.showPerson(matcher.group(1));
}
- else if ((matcher = Commands.ADD_FRIEND.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.ADD_FRIEND.getMatcher(input)).matches()) {
friendsMenu.addFriend(matcher.group(1));
}
- else if ((matcher = Commands.SHOW_FRIEND_REQUESTS.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.SHOW_FRIEND_REQUESTS.getMatcher(input)).matches()) {
friendsMenu.showFriendRequests();
}
- else if ((matcher = Commands.ACCEPT_FRIEND_REQUEST.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.ACCEPT_FRIEND_REQUEST.getMatcher(input)).matches()) {
friendsMenu.acceptFriend(matcher.group(1));
}
- else if ((matcher = Commands.DECLNE_FRIEND_REQUEST.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.DECLNE_FRIEND_REQUEST.getMatcher(input)).matches()) {
friendsMenu.declineFriend(matcher.group(1));
}
- else if ((matcher = Commands.HELP.getMatcher(input)).matches())
- {
- System.out.println("Show friends"+"\n"+"Remove\n"+"View user profile\n"+"Add\n"+"Show friend requests\n"+"Accept\n"
- +"Decline\n");
+ else if ((matcher = Commands.HELP.getMatcher(input)).matches()) {
+ System.out.println("show friends"+"\n"+"remove (username)\n"+"view user profile\n"+"Add (username)\n"+"Show friend requests\n"+"Accept (username)\n"
+ +"decline (username)\n"+"help\n"+"back\n"+"view account menu");
}
- else if (Commands.BACK.getMatcher(input).matches())
- {
+ else if (Commands.BACK.getMatcher(input).matches()) {
return seenPages.get(seenPages.size()-2);
}
- else if ((matcher = Commands.VIEW_ACCOUNT_MENU.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_ACCOUNT_MENU.getMatcher(input)).matches()) {
return UserPage.userPage;
}
else {
- System.out.println("invalid command");
+ System.out.println("invalid command!");
}
}
}
@@ -82,6 +78,7 @@ private void addFriend(String username){
}
private void showFriendRequests(){
String requests = friendsMenuController.showFriendRequests();
+ System.out.println(requests);
}
private void acceptFriend(String username){
friendsMenuController.acceptFrend(username);
@@ -89,9 +86,9 @@ private void acceptFriend(String username){
private void declineFriend(String username){
friendsMenuController.declineFriend(username);
}
- private void showUnShownMessages()
- {
+ private void showUnShownMessages() {
String messages = friendsMenuController.showUnShownMessages();
+ System.out.println(messages);
}
}
diff --git a/src/main/java/Plato/View/GamesMenu.java b/src/Plato/View/GamesMenu.java
similarity index 59%
rename from src/main/java/Plato/View/GamesMenu.java
rename to src/Plato/View/GamesMenu.java
index e67c0c0..77a75fd 100644
--- a/src/main/java/Plato/View/GamesMenu.java
+++ b/src/Plato/View/GamesMenu.java
@@ -2,28 +2,27 @@
import Plato.Controller.LoginPageController;
import Plato.Controller.MainPagePlayerController;
-import Plato.Model.Player;
+import Plato.Model.*;
+import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
public class GamesMenu extends Page{
public static GamesMenu gamesMenu = new GamesMenu();
private Player player;
- public Page run() {
- Page.seenPages.add(GamesMenu.gamesMenu);
- System.out.println("choose one:\n" +
- "1.\n");
- System.out.println(MainPagePlayerController.getInstance().reversiName());
- System.out.println("2.");
- System.out.println(MainPagePlayerController.getInstance().battleSeaName());
- System.out.println("\nback"+
- "\nview account menu"+
- "\n help");
+ public Page run() throws FileNotFoundException {
+ Page.seenPages.add(GamesMenu.gamesMenu);
Scanner scanner = new Scanner(System.in);
String input;
Matcher matcher;
+ System.out.println("Games menu :");
while (true) {
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input = scanner.nextLine();
if (input.equals("1")) {
return ReversiMenu.reversiMenu;
@@ -31,27 +30,24 @@ public Page run() {
else if (input.equals("2")) {
return BattleSeaMenu.battleSeaMenu;
}
- else if ((matcher = Commands.BACK.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.BACK.getMatcher(input)).matches()) {
return seenPages.get(seenPages.size()-2);
}
- else if ((matcher = Commands.VIEW_ACCOUNT_MENU.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_ACCOUNT_MENU.getMatcher(input)).matches()) {
return UserPage.userPage;
}
- else if ((matcher = Commands.HELP.getMatcher(input)).matches())
- {
- System.out.println("choose one:\n" +
- "1.\n");
+ else if ((matcher = Commands.HELP.getMatcher(input)).matches()) {
+ System.out.print("choose one:\n" +
+ "1. ");
System.out.println(MainPagePlayerController.getInstance().reversiName());
- System.out.println("2.");
+ System.out.print("2. ");
System.out.println(MainPagePlayerController.getInstance().battleSeaName());
- System.out.println("\nback"+
+ System.out.println("back"+
"\nview account menu"+
- "\n help");
+ "\nhelp");
}
else {
- System.out.println("You should select 1(for reversi) or 2(for battle sea)!");
+ System.out.println("invalid command!");
}
}
}
diff --git a/src/main/java/Plato/View/LoginPage.java b/src/Plato/View/LoginPage.java
similarity index 64%
rename from src/main/java/Plato/View/LoginPage.java
rename to src/Plato/View/LoginPage.java
index f6180ca..e755066 100644
--- a/src/main/java/Plato/View/LoginPage.java
+++ b/src/Plato/View/LoginPage.java
@@ -1,7 +1,9 @@
package Plato.View;
import Plato.Controller.LoginPageController;
+import Plato.Model.*;
+import java.io.FileNotFoundException;
import java.util.regex.Matcher;
public class LoginPage extends Page{
@@ -11,16 +13,22 @@ public static Page getInstance() {
return loginPage;
}
- public Page run() {
+ public Page run() throws FileNotFoundException {
Matcher matcher;
String input;
seenPages.add(LoginPage.loginPage);
-
+ if(seenPages.size() == 1)
+ System.out.println("hello, welcome to plato!");
+ System.out.println("Login page :");
while (true)
{
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input=scanner.nextLine();
- if ((matcher = Commands.REGISTER.getMatcher(input)).matches())
- {
+ if ((matcher = Commands.REGISTER.getMatcher(input)).matches()) {
System.out.println("enter email");
String email = scanner.nextLine();
System.out.println("enter firstname");
@@ -32,16 +40,17 @@ public Page run() {
loginPage.register(matcher.group(1),matcher.group(2),email,firstname,lastname,phoneNumber);
}
- else if ((matcher = Commands.LOGIN.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.LOGIN.getMatcher(input)).matches()) {
System.out.println("enter password");
String password = scanner.nextLine();
Page page =loginPage.login(matcher.group(1),password);
return page;
}
- else if ((matcher = Commands.HELP.getMatcher(input)).matches())
- {
- System.out.println("login\nregister\nhelp");
+ else if ((matcher = Commands.HELP.getMatcher(input)).matches()) {
+ System.out.println("login (username)\nregister (username) (password)\nhelp");
+ }
+ else{
+ System.out.println("invalid command!");
}
}
@@ -49,28 +58,26 @@ else if ((matcher = Commands.HELP.getMatcher(input)).matches())
private Page login(String username,String password){
String found=loginPageController.loginController(username,password);
- if (found.equals("found player"))
- {
+ if (found.equals("found player")) {
+ System.out.println("successfully logged in!");
return MainPagePlayer.mainPagePlayer;
}
- else if (found.equals("found admin"))
- {
+ else if (found.equals("found admin")) {
+ System.out.println("successfully logged in!");
return MainPageAdmin.mainPageAdmin;
}
else {
- System.out.println("invalid informations");
+ System.out.println("your username or password is wrong!");
return LoginPage.loginPage;
}
}
- private void register(String username,String password,String email,String firstanme,String lastname,String phoneNumber)
- {
+ private void register(String username,String password,String email,String firstanme,String lastname,String phoneNumber) {
boolean validInformation = loginPageController.register(username,password,email,firstanme,lastname,phoneNumber);
- if (validInformation)
- {
- System.out.println("account created succesfully");
+ if (validInformation) {
+ System.out.println("account created successfully");
}
else {
- System.out.println("invalid information");
+ System.out.println("something went wrong!");
}
}
diff --git a/src/main/java/Plato/View/MainPageAdmin.java b/src/Plato/View/MainPageAdmin.java
similarity index 84%
rename from src/main/java/Plato/View/MainPageAdmin.java
rename to src/Plato/View/MainPageAdmin.java
index d1c6079..0d3b41b 100644
--- a/src/main/java/Plato/View/MainPageAdmin.java
+++ b/src/Plato/View/MainPageAdmin.java
@@ -1,21 +1,27 @@
package Plato.View;
import Plato.Controller.MainPageAdminController;
+import Plato.Model.*;
+import java.io.FileNotFoundException;
import java.util.regex.Matcher;
public class MainPageAdmin extends Page {
public static MainPageAdmin mainPageAdmin = new MainPageAdmin();
private MainPageAdminController mainPageAdminController = MainPageAdminController.getInstance();
- public Page run() {
+ public Page run() throws FileNotFoundException {
seenPages.add(mainPageAdmin);
String input;
Matcher matcher;
System.out.println("Main Page Admin :");
while(true){
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input=scanner.nextLine();
- if ((matcher = Commands.ADD_EVENT.getMatcher(input)).matches())
- {
+ if ((matcher = Commands.ADD_EVENT.getMatcher(input)).matches()) {
try {
System.out.println("enter game name");
String gameName = scanner.nextLine();
@@ -31,61 +37,48 @@ public Page run() {
}
}
- else if ((matcher = Commands.VIEW_EVENTS.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_EVENTS.getMatcher(input)).matches()) {
mainPageAdmin.viewEvents();
}
- else if ((matcher = Commands.EDIT_EVENT.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.EDIT_EVENT.getMatcher(input)).matches()) {
mainPageAdmin.editEvent(Integer.parseInt(matcher.group(1)),matcher.group(2),matcher.group(3));
}
- else if ((matcher = Commands.REMOVE_EVENT.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.REMOVE_EVENT.getMatcher(input)).matches()) {
mainPageAdmin.removeEvent(Integer.parseInt(matcher.group(1)));
}
- else if ((matcher = Commands.ADD_SUGGESTION.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.ADD_SUGGESTION.getMatcher(input)).matches()) {
mainPageAdmin.addSuggestion(matcher.group(1),matcher.group(2));
}
- else if ((matcher = Commands.VIEW_SUGGESTIONS.getMatcher(input)).matches())
- {
- mainPageAdmin.viewSuugestions();
+ else if ((matcher = Commands.VIEW_SUGGESTIONS.getMatcher(input)).matches()) {
+ mainPageAdmin.viewSuggestions();
}
- else if ((matcher = Commands.REMOVE_SUGGESTION.getMatcher(input)).matches())
- {
- mainPageAdmin.removeSeggestion(Integer.parseInt(matcher.group(1)));
+ else if ((matcher = Commands.REMOVE_SUGGESTION.getMatcher(input)).matches()) {
+ mainPageAdmin.removeSuggestion(Integer.parseInt(matcher.group(1)));
}
- else if ((matcher = Commands.VIEW_USERS.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_USERS.getMatcher(input)).matches()) {
mainPageAdmin.viewUsers();
}
- else if ((matcher = Commands.VIEW_USER_PROFILE.getMatcher(input)).matches())
- {
- mainPageAdmin.viewuser(Integer.parseInt(matcher.group(1)));
+ else if ((matcher = Commands.VIEW_USER_PROFILE.getMatcher(input)).matches()) {
+ mainPageAdmin.viewUser(Integer.parseInt(matcher.group(1)));
}
- else if ((matcher = Commands.BACK.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.BACK.getMatcher(input)).matches()) {
return seenPages.get(seenPages.size()-2);
}
- else if ((matcher = Commands.VIEW_ACCOUNT_MENU.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_ACCOUNT_MENU.getMatcher(input)).matches()) {
return UserPage.userPage;
}
- else if ((matcher = Commands.ADD_BOT_MESSAGE.getMatcher(input)).matches())
- {
- mainPageAdmin.addplatobotMessage(matcher.group(1));
+ else if ((matcher = Commands.ADD_BOT_MESSAGE.getMatcher(input)).matches()) {
+ mainPageAdmin.addPlatoBotMessage(matcher.group(1));
}
- else if ((matcher = Commands.HELP.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.HELP.getMatcher(input)).matches()) {
System.out.println("Add event"+"\n"+"View events\n"+"Edit event\n"+"Remove event\n"+"Add suggestion\n"+"View suggestions\n"
- +"Remove suggestion\n"+"View users\n"+"View user profile\n"+"change game name\n");
+ +"Remove suggestion\n"+"View users\n"+"View user profile\n"+"change game name\n"+"back\n"+"view account menu\n"+
+ "add bot message\n"+"help");
}
- else if ((matcher = Commands.CHANGE_GAME_NAME.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.CHANGE_GAME_NAME.getMatcher(input)).matches()) {
MainPageAdmin.mainPageAdmin.mainPageAdminController.changeGameName(Integer.parseInt(matcher.group(1)),matcher.group(2));
}
- else if ((matcher = Commands.ADD_NEW_ADMIN.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.ADD_NEW_ADMIN.getMatcher(input)).matches()) {
System.out.println("enter email");
String email = scanner.nextLine();
System.out.println("enter firstname");
@@ -108,19 +101,19 @@ private void viewUsers(){
users=mainPageAdminController.viewUsers();
System.out.println(users);
}
- private void viewuser(int id){
+ private void viewUser(int id){
String userInfo ;
userInfo = mainPageAdminController.getUser(id);
System.out.println(userInfo);
}
- private void viewSuugestions(){
+ private void viewSuggestions(){
String suggestion = mainPageAdminController.viewSuggestions();
System.out.println(suggestion);
}
private void addSuggestion(String username,String gamename){
mainPageAdminController.addSuggestion(username,gamename);
}
- private void removeSeggestion(int id){
+ private void removeSuggestion(int id){
mainPageAdminController.removeSuggestion(id);
}
public void viewEvents(){
@@ -145,13 +138,13 @@ public void editEvent(int id,String field,String newValue){
private void removeEvent(int id){
mainPageAdminController.removeEvent(id);
}
- private void addplatobotMessage(String message){
+ private void addPlatoBotMessage(String message){
mainPageAdminController.addbotMessage(message);
}
private void startEvent(int id){
mainPageAdminController.startEvent(id);
}
- private void endtEvent(int id){
+ private void EndEvent(int id){
mainPageAdminController.endEvent(id);
}
private void changeGameName(int id,String newName)
diff --git a/src/main/java/Plato/View/MainPagePlayer.java b/src/Plato/View/MainPagePlayer.java
similarity index 80%
rename from src/main/java/Plato/View/MainPagePlayer.java
rename to src/Plato/View/MainPagePlayer.java
index 7183b58..3b1d1f1 100644
--- a/src/main/java/Plato/View/MainPagePlayer.java
+++ b/src/Plato/View/MainPagePlayer.java
@@ -1,52 +1,50 @@
package Plato.View;
import Plato.Controller.MainPagePlayerController;
-import Plato.Model.Player;
+import Plato.Model.*;
+import java.io.FileNotFoundException;
import java.util.regex.Matcher;
public class MainPagePlayer extends Page{
public static MainPagePlayer mainPagePlayer = new MainPagePlayer();
private MainPagePlayerController mainPagePlayerController = MainPagePlayerController.getInstance();
- public Page run() {
+ public Page run() throws FileNotFoundException {
Matcher matcher;
String input;
seenPages.add(MainPagePlayer.mainPagePlayer);
System.out.println("Main Page Player :");
- while (true)
- {
+ while (true) {
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input=scanner.nextLine();
- if ((matcher = Commands.HELP.getMatcher(input)).matches())
- {
+ if ((matcher = Commands.HELP.getMatcher(input)).matches()) {
System.out.println("Show Points"+"\n"+"View favorite games\n"+"View platoBot’s messages\n"+"View last played\n"+"View admin’s suggestions\n"+"Choose suggested game\n"
- +"Add friend\n"+"go to friends menu\n"+"go to games menu\n"+"view events\n"+"join event\n");
+ +"choose favorite (1,2)"+"Add friend\n"+"go to friends menu\n"+"go to games menu\n"+"view events\n"+"join event\n"
+ +"back");
}
- else if ((matcher = Commands.SHOW_POINT.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.SHOW_POINT.getMatcher(input)).matches()) {
mainPagePlayer.showPoints();
}
- else if ((matcher = Commands.VIEW_FAVORITE_GAMES.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_FAVORITE_GAMES.getMatcher(input)).matches()) {
mainPagePlayer.viewFavoriteGames();
}
- else if ((matcher = Commands.VIEW_PLATOBOT_MESSAGES.getMatcher(input)).matches())
- {
- mainPagePlayer.platobotMessages();
+ else if ((matcher = Commands.VIEW_PLATOBOT_MESSAGES.getMatcher(input)).matches()) {
+ mainPagePlayer.platoBotMessages();
}
- else if ((matcher = Commands.VIEW_LAST_PLAYED.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_LAST_PLAYED.getMatcher(input)).matches()) {
mainPagePlayer.viewLastPlayed();
}
- else if ((matcher = Commands.VIEW_ADMINS_SUGGESTIONS.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_ADMINS_SUGGESTIONS.getMatcher(input)).matches()) {
mainPagePlayer.adminSuggestions();
}
- else if ((matcher = Commands.ADD_FRIEND.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.ADD_FRIEND.getMatcher(input)).matches()) {
mainPagePlayer.addFriend(matcher.group(1));
}
- else if ((matcher = Commands.CHOOSE_SUGGESTED_GAME.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.CHOOSE_SUGGESTED_GAME.getMatcher(input)).matches()) {
if (Integer.parseInt(matcher.group(1))==1)
{
@@ -62,12 +60,10 @@ else if (Integer.parseInt(matcher.group(1))==2)
System.out.println("invalid gameID");
}
}
- else if ((matcher = Commands.BACK.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.BACK.getMatcher(input)).matches()) {
return seenPages.get(seenPages.size()-2);
}
- else if ((matcher = Commands.CHOOSE_FAVORITE_GAME.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.CHOOSE_FAVORITE_GAME.getMatcher(input)).matches()) {
if (Integer.parseInt(matcher.group(1))==1)
{
@@ -78,22 +74,21 @@ else if (Integer.parseInt(matcher.group(1))==2)
return BattleSeaMenu.battleSeaMenu;
}
}
- else if ((matcher = Commands.VIEW_EVENTS.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.VIEW_EVENTS.getMatcher(input)).matches()) {
MainPageAdmin.mainPageAdmin.viewEvents();
}
- else if ((matcher = Commands.JOIN_EVENT.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.JOIN_EVENT.getMatcher(input)).matches()) {
MainPagePlayer.mainPagePlayer.joinEvent(Integer.parseInt(matcher.group(1)));
}
- else if ((matcher = Commands.GO_TO_FRIENDS_MENU.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.GO_TO_FRIENDS_MENU.getMatcher(input)).matches()) {
return FriendsMenu.friendsMenu;
}
- else if ((matcher = Commands.GO_TO_GAMES_MENU.getMatcher(input)).matches())
- {
+ else if ((matcher = Commands.GO_TO_GAMES_MENU.getMatcher(input)).matches()) {
return GamesMenu.gamesMenu;
}
+ else if(input.trim().equals("logout")){
+ return LoginPage.loginPage;
+ }
else {
System.out.println("invalid command");
}
@@ -111,7 +106,7 @@ private void viewFavoriteGames(){
favorites=mainPagePlayerController.viewFavoriteGames();
System.out.println(favorites);
}
- private void platobotMessages(){
+ private void platoBotMessages(){
String messages;
messages=mainPagePlayerController.platobotMessages();
System.out.println(messages);
@@ -125,7 +120,7 @@ private void viewLastPlayed(){
lastPlayed=mainPagePlayerController.viewLastPlayed();
System.out.println(lastPlayed);
}
- private boolean isGAmeVAlid(int id){
+ private boolean isGameValid(int id){
boolean valid = mainPagePlayerController.isSuggestedGameValid(id);
return valid;
}
diff --git a/src/main/java/Plato/View/Page.java b/src/Plato/View/Page.java
similarity index 71%
rename from src/main/java/Plato/View/Page.java
rename to src/Plato/View/Page.java
index 4d093f8..b3db407 100644
--- a/src/main/java/Plato/View/Page.java
+++ b/src/Plato/View/Page.java
@@ -1,11 +1,12 @@
package Plato.View;
+import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public abstract class Page {
protected static Scanner scanner = new Scanner(System.in);
protected static ArrayList seenPages = new ArrayList() ;
- public abstract Page run();
+ public abstract Page run() throws FileNotFoundException;
}
diff --git a/src/main/java/Plato/View/ReversiMenu.java b/src/Plato/View/ReversiMenu.java
similarity index 86%
rename from src/main/java/Plato/View/ReversiMenu.java
rename to src/Plato/View/ReversiMenu.java
index c87e4b4..b918e89 100644
--- a/src/main/java/Plato/View/ReversiMenu.java
+++ b/src/Plato/View/ReversiMenu.java
@@ -1,9 +1,10 @@
package Plato.View;
import Plato.Controller.LoginPageController;
-import Plato.Model.Log;
-import Plato.Model.Player;
+import Plato.Model.*;
import Reversi.ReversiController;
+
+import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
@@ -11,12 +12,18 @@
public class ReversiMenu extends Page{
public static ReversiMenu reversiMenu = new ReversiMenu();
private static final int gameID = 1;
- public Page run() {
+ public Page run() throws FileNotFoundException {
String input;
Matcher matcher;
Scanner scanner = new Scanner(System.in);
Page.seenPages.add(ReversiMenu.reversiMenu);
+ System.out.println("Reversi menu :");
while(true){
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input = scanner.nextLine();
if(input.trim().equalsIgnoreCase("Show scoreboard")){
ArrayList playersThatHasPlayedReversi = new ArrayList();
@@ -84,7 +91,24 @@ else if(input.trim().equalsIgnoreCase("Run game")){
String password = scanner.nextLine();
try {
Player secondPlayer = LoginPageController.loginSecond(username,password);
- //event score
+ for (Event event : Event.getEvents()) {
+ if (event.isHasStarted())
+ {
+ if (!event.isHasEnded())
+ {
+ for (Player player : event.getPlayersOfThisEvent()) {
+ if (player.equals(((Player)LoginPageController.user)))
+ {
+ player.addScore();
+ }
+ if (player.equals(secondPlayer))
+ {
+ secondPlayer.addScore();
+ }
+ }
+ }
+ }
+ }
ReversiController.run(((Player)LoginPageController.user), secondPlayer);
} catch (Exception e) {
System.out.println("invalid information for second player");
diff --git a/src/main/java/Plato/View/UserPage.java b/src/Plato/View/UserPage.java
similarity index 94%
rename from src/main/java/Plato/View/UserPage.java
rename to src/Plato/View/UserPage.java
index d41e90f..96c0351 100644
--- a/src/main/java/Plato/View/UserPage.java
+++ b/src/Plato/View/UserPage.java
@@ -1,24 +1,29 @@
package Plato.View;
import Plato.Controller.LoginPageController;
-import Plato.Model.Log;
-import Plato.Model.Player;
-import Plato.Model.User;
+import Plato.Model.*;
+
+import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Pattern;
public class UserPage extends Page{
public static UserPage userPage = new UserPage();
-// private UserPageController userPageController = UserPageController.getInstance();
public static User user ;
public static UserPage getInstance(){
return userPage;
}
- public Page run() {
+ public Page run() throws FileNotFoundException {
String input;
Scanner scanner = new Scanner(System.in);
seenPages.add(UserPage.userPage);
+ System.out.println("User page :");
while(true){
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input = scanner.nextLine();
if(input.trim().equals("View personal info")){
System.out.println("firstname: " + LoginPageController.user.getFirstname() +
diff --git a/src/main/java/Reversi/Reversi.java b/src/Reversi/Reversi.java
similarity index 100%
rename from src/main/java/Reversi/Reversi.java
rename to src/Reversi/Reversi.java
diff --git a/src/main/java/Reversi/ReversiController.java b/src/Reversi/ReversiController.java
similarity index 93%
rename from src/main/java/Reversi/ReversiController.java
rename to src/Reversi/ReversiController.java
index 89490b7..9b1bac4 100644
--- a/src/main/java/Reversi/ReversiController.java
+++ b/src/Reversi/ReversiController.java
@@ -1,9 +1,9 @@
package Reversi;
-import Plato.Model.Game;
-import Plato.Model.Log;
-import Plato.Model.Player;
+import Plato.Model.*;
import Plato.View.*;
+
+import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Pattern;
@@ -66,7 +66,7 @@ public void showAvailableCoordinates() {
}
//runs the game
- public static Page run(Player black, Player white) {
+ public static Page run(Player black, Player white) throws FileNotFoundException {
//build a new game
ReversiController game = new ReversiController(black, white);
@@ -75,8 +75,16 @@ public static Page run(Player black, Player white) {
Scanner scanner = new Scanner(System.in);
String input;
+ //title
+ System.out.println("Reversi game :");
+
//the menu while playing
while (!game.getModel().isTableFull() && game.getModel().canAnyoneMove() || !game.getModel().doAllOfTheDisksHaveSameColor()) {
+ Admin.updateAdmins();
+ Player.updatePlayers();
+ Game.updateGames();
+ Log.updateLogs();
+ Event.updateEvents();
input = scanner.nextLine();
if (input.trim().equals("end of my turn")) {
game.changeTurn();
diff --git a/src/main/java/Reversi/ReversiView.java b/src/Reversi/ReversiView.java
similarity index 100%
rename from src/main/java/Reversi/ReversiView.java
rename to src/Reversi/ReversiView.java
diff --git a/src/graphic/LoginRegister.fxml b/src/graphic/LoginRegister.fxml
new file mode 100644
index 0000000..b2f5e2e
--- /dev/null
+++ b/src/graphic/LoginRegister.fxml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/graphic/LoginRegister.java b/src/graphic/LoginRegister.java
new file mode 100644
index 0000000..3cd1795
--- /dev/null
+++ b/src/graphic/LoginRegister.java
@@ -0,0 +1,4 @@
+package graphic;
+
+public class LoginRegister {
+}
diff --git a/src/graphic/MainGraphic.java b/src/graphic/MainGraphic.java
new file mode 100644
index 0000000..f7bc565
--- /dev/null
+++ b/src/graphic/MainGraphic.java
@@ -0,0 +1,4 @@
+package graphic;
+
+public class MainGraphic {
+}
diff --git a/src/main/java/BattleSea/View/InGameMenu.java b/src/main/java/BattleSea/View/InGameMenu.java
deleted file mode 100644
index ee99c25..0000000
--- a/src/main/java/BattleSea/View/InGameMenu.java
+++ /dev/null
@@ -1,196 +0,0 @@
-package BattleSea.View;
-
-import BattleSea.Controller.GameManager;
-import Plato.Model.Player;
-import Plato.View.Page;
-
-import java.io.IOException;
-import java.util.Scanner;
-
-
-public class InGameMenu {
- private GameManager gameManager;
- private static boolean isGameEnded;
- private Scanner scanner;
-
-
- public InGameMenu(GameManager gameManager, Scanner scanner) {
- this.gameManager = gameManager;
- this.scanner = scanner;
- isGameEnded = false;
- }
-
- public static void gameHasEnded() {
- InGameMenu.isGameEnded = true;
- }
-
- public void run() {
- System.out.println("to see the input options enter \"help\"");
- while (!isGameEnded) {
- System.out.println("you are in game menu");
- String input = scanner.nextLine().trim().toLowerCase();
- if (input.equals("help")) {
- System.out.println("enter the number of one of these inputs to continue\n" +
- "0- show turn\n" +
- "1- change location of a ship\n" +
- "2- change direction of a ship\n" +
- "3- bomb a location\n" +
- "4- see your ships \n" +
- "5- see locations you bombed\n" +
- "6- see your board\n" +
- "7- see opponents board\n" +
- "8- see scores\n" +
- "9- clear screen\n" +
- "10- withdraw and quit the game");
-
- } else if (input.equalsIgnoreCase("0")) {
- showTurn();
- } else if (input.equalsIgnoreCase("1")) {
- System.out.print("enter the ship's number:");
- int shipCode = Integer.parseInt(scanner.nextLine().trim());
- System.out.print("\n enter x axis of destination:");
- int xDestination = Integer.parseInt(scanner.nextLine().trim());
- System.out.print("\n enter y axis of destination:");
- int yDestination = Integer.parseInt(scanner.nextLine().trim());
- changeLocation(shipCode, xDestination, yDestination);
- } else if (input.equalsIgnoreCase("2")) {
- System.out.print("enter the ship's number:");
- int shipCode = Integer.parseInt(scanner.nextLine().trim());
- System.out.print("\n1-north \n2-east \n3-south \n4-west \nenter the direction:");
- int direction = Integer.parseInt(scanner.nextLine().trim());
- if (direction == 1) {
- changeDirection(shipCode, 'n');
- } else if (direction == 2) {
- changeDirection(shipCode, 'e');
- } else if (direction == 3) {
- changeDirection(shipCode, 's');
- } else if (direction == 4) {
- changeDirection(shipCode, 'w');
- } else System.out.println("you entered an invalid number");
- } else if (input.equalsIgnoreCase("3")) {
- System.out.print("enter x axis of bombing location:");
- int xAxis = Integer.parseInt(scanner.nextLine().trim());
- System.out.print("\n enter y axis of bombing location:");
- int yAxis = Integer.parseInt(scanner.nextLine().trim());
- bombLocation(xAxis, yAxis);
- } else if (input.equalsIgnoreCase("4")) {
-
- } else if (input.equalsIgnoreCase("5")) {
-
- } else if (input.equalsIgnoreCase("6")) {
- showPlayerGameBoard();
- } else if (input.equalsIgnoreCase("7")) {
- showOpponentGameBoard();
- } else if (input.equalsIgnoreCase("8")) {
- showScores();
- } else if (input.equalsIgnoreCase("9")) {
- clearScreen();
- } else if (input.equalsIgnoreCase("10")) {
- withdraw();
- } else System.err.println("invalid input.\n to see the input options enter \"help\"");
- }
- finalizingTheGame();
- }
-
- private void finalizingTheGame(){
-
- }
-
- private void withdraw(){
- gameManager.withdraw();
- }
-
- private void clearScreen(){
- try{
- gameManager.clearScreen();
- } catch (InterruptedException | IOException ignored) {
-
- }
- }
-
- private void showTurn() {
- System.out.println("It's " + gameManager.getTurn().getFirstname() + " " + gameManager.getTurn().getLastname() + "'s turn");
- }
-
- private void changeDirection(int shipCode, char direction) {
- if (gameManager.changeDirectionOfShip(shipCode, direction) == 0) {
- System.out.println("This Ship Cannot Rotate Because It Is Partially or Completely destroyed");
- } else if (gameManager.changeDirectionOfShip(shipCode, direction) == 1) {
- System.out.println("The Ship " + shipCode + " Has Been Rotated To The New Direction Successfully");
- } else if (gameManager.changeDirectionOfShip(shipCode, direction) == 2) {
- System.out.println("Cannot Rotate The Ship To The Requested Direction!");
- } else
- System.out.println("You Cannot Move The Ship To This Location! Because Part Of Ship Will Be Out Of The Board!");
- }
-
- private void changeLocation(int shipCode, int xDestination, int yDestination) {
- if (gameManager.changeLocationOfShip(shipCode, xDestination, yDestination) == 0) {
- System.out.println("This Ship Cannot Move Because It Is Partially or Completely destroyed");
- } else if (gameManager.changeLocationOfShip(shipCode, xDestination, yDestination) == 1) {
- System.out.println("The Ship " + shipCode + " Has Been Moved To The New Location Successfully");
- } else if (gameManager.changeLocationOfShip(shipCode, xDestination, yDestination) == 2) {
- System.out.println("Cannot Move The Ship To The Requested Location!");
- } else
- System.out.println("You Cannot Move The Ship To This Location Because Part Of Ship Will Be Out Of The Board!");
-
- }
-
- private void bombLocation(int xAxis, int yAxis) {
- if (gameManager.getTurnsOwnBoard().getDimension() < xAxis ||
- gameManager.getTurnsOwnBoard().getDimension() < yAxis ||
- xAxis < 1 || yAxis < 1)
- System.out.println("Please Choose a Location Inside The Game Board");
- else {
- if (gameManager.bombLocation(xAxis, yAxis) == 0) {
- System.out.println("You Missed Your Shot");
- changeTurn();
- } else if (gameManager.bombLocation(xAxis, yAxis) == 1) {
- System.out.println("Your Bomb Hit The Opponent's Ship");
- } else if (gameManager.bombLocation(xAxis, yAxis) == 2) {
- System.out.println("You Destroyed Your Opponent's Ship");
- } else System.out.println("You Have Already Bombed This Location!");
- }
- }
-
- public void showPlayerGameBoard() {
- for (int i = 0; i < gameManager.getTurnsOwnBoard().getDimension(); i++) {
- System.out.print("|");
- for (int j = 0; j < gameManager.getTurnsOwnBoard().getDimension(); j++) {
- if (gameManager.getTurnsOwnBoard().getLocation(i, j).getContent().equalsIgnoreCase(""))
- System.out.print(" " + "|");
- else System.out.print(gameManager.getTurnsOwnBoard().getLocation(i, j).getContent() + "|");
- }
- System.out.println();
- }
- }
-
- public void showOpponentGameBoard() {
- for (int i = 0; i < gameManager.getTurnsOpponentBoard().getDimension(); i++) {
- System.out.print("|");
- for (int j = 0; j < gameManager.getTurnsOpponentBoard().getDimension(); j++) {
- if (gameManager.getTurnsOpponentBoard().getLocation(i, j).getContent().equalsIgnoreCase(""))
- System.out.print(" " + "|");
- else System.out.print(gameManager.getTurnsOpponentBoard().getLocation(i, j).getContent() + "|");
- }
- System.out.println();
- }
- }
-
- public void showShips(String setting) {
-
- }
-
- public void showBombardLocations(String setting) {
-
- }
-
- public void showScores() {
- System.out.println(gameManager.getFirstPlayer().getFirstname() + " " + gameManager.getFirstPlayer().getLastname() + " : " + gameManager.getFirstPlayerScore() +
- gameManager.getSecondPlayer().getFirstname() + " " + gameManager.getSecondPlayer().getLastname() + " : " + gameManager.getSecondPlayerScore());
- }
-
- public void changeTurn() {
- System.out.println("Next Player's Turn!");
- }
-
-}
diff --git a/src/main/java/BattleSea/View/StartingPage.java b/src/main/java/BattleSea/View/StartingPage.java
deleted file mode 100644
index e611dbc..0000000
--- a/src/main/java/BattleSea/View/StartingPage.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package BattleSea.View;
-
-import Plato.View.Page;
-
-public class StartingPage extends Page {
-
-
-
- public Page run() {
- return null;
- }
-}
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
deleted file mode 100644
index 6f929bb..0000000
--- a/src/main/java/Main.java
+++ /dev/null
@@ -1,21 +0,0 @@
-import Plato.Controller.LoginPageController;
-import Plato.Model.Game;
-import Plato.View.LoginPage;
-import Plato.View.Page;
-
-import java.io.FileNotFoundException;
-
-public class Main {
-
- public static void main(String[] args) {
- Page page = LoginPage.getInstance();
-
- //update and read resourses shoud add in this line
-
- LoginPageController.addTheGames();
-
- while (page != null) {
- page = page.run();
- }
- }
-}
diff --git a/src/main/java/Plato/Model/Admin.java b/src/main/java/Plato/Model/Admin.java
deleted file mode 100644
index a37b8ce..0000000
--- a/src/main/java/Plato/Model/Admin.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package Plato.Model;
-
-import java.util.ArrayList;
-
-public class Admin extends User{
- private static ArrayList admins =new ArrayList();
- private static ArrayList messages = new ArrayList();
- public static ArrayList getAdmins() {
- return admins;
- }
-
- public void addNewAdmin(String username, String password, String email, String firstname, String lastname, String phoneNumber) throws Exception {
- for (User allUser : User.getAllUsers()) {
- if ((allUser.getUsername().equals(username))||(allUser.getEmail().equals(email)))
- {
- Exception exception = new Exception();
- throw exception;
- }
- }
- Admin admin = new Admin();
- admin.setAdmin(true);
- admin.setEmail(email);
- admin.setFirstname(firstname);
- admin.setLastname(lastname);
- admin.setPassword(password);
- admin.setPhoneNumber(phoneNumber);
- admin.setUsername(username);
- admin.setUserID(User.getAllUsers().size()+1);
- User.getAllUsers().add(admin);
- admins.add(admin);
-
- }
-
- public Admin() {
- }
-
- public static ArrayList getMessages() {
- return messages;
- }
-}
diff --git a/src/main/java/Plato/Model/Game.java b/src/main/java/Plato/Model/Game.java
deleted file mode 100644
index 8e82113..0000000
--- a/src/main/java/Plato/Model/Game.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package Plato.Model;
-
-import BattleSea.Controller.BattleSea;
-import Reversi.ReversiController;
-import java.util.ArrayList;
-
-public class Game {
- private static ArrayList games = new ArrayList();
- private String name;
- private int gameID;
-
-
- public static ArrayList getGames() {
- return games;
- }
-
- public String getName() {
- return name;
- }
-
- public int getGameID() {
- return gameID;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setGameID(int gameID) {
- this.gameID = gameID;
- }
-}
diff --git a/src/module-info.java b/src/module-info.java
new file mode 100644
index 0000000..d8c47c5
--- /dev/null
+++ b/src/module-info.java
@@ -0,0 +1,5 @@
+module graphical {
+ requires javafx.fxml;
+ requires javafx.controls;
+ opens sample;
+}
\ No newline at end of file
diff --git a/src/sample/AdminGraphicalMainPageController.java b/src/sample/AdminGraphicalMainPageController.java
new file mode 100644
index 0000000..20d34c3
--- /dev/null
+++ b/src/sample/AdminGraphicalMainPageController.java
@@ -0,0 +1,4 @@
+package sample;
+
+public class AdminGraphicalMainPageController {
+}
diff --git a/src/sample/AdminMainPage.fxml b/src/sample/AdminMainPage.fxml
new file mode 100644
index 0000000..bd6be13
--- /dev/null
+++ b/src/sample/AdminMainPage.fxml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/sample/Controller.java b/src/sample/Controller.java
new file mode 100644
index 0000000..a1251ca
--- /dev/null
+++ b/src/sample/Controller.java
@@ -0,0 +1,58 @@
+package sample;
+
+import Plato.Controller.LoginPageController;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.PasswordField;
+import javafx.scene.control.TextField;
+
+public class Controller {
+ @FXML
+ private static Label message ;
+ @FXML
+ private static TextField fusername ;
+ @FXML
+ private static TextField femail ;
+ @FXML
+ private static TextField ffname ;
+ @FXML
+ private static TextField flname;
+ @FXML
+ private static TextField fpnumber ;
+ @FXML
+ private static PasswordField fpassword;
+
+ public static void register()
+ {
+ boolean result = LoginPageController.loginPageController.register(fusername.getText(),fpassword.getText(),femail.getText(),ffname.getText(),flname.getText(),fpnumber.getText());
+ if (!result)
+ {
+ message.setText("username is used");
+ message.setVisible(true);
+
+ }
+ else {
+ message.setText("you are succesfully registered");
+ message.setVisible(true);
+ }
+
+ }
+ public static void login()
+ {
+ String result = LoginPageController.loginPageController.loginController(fusername.getText(),fpassword.getText());
+ if (result.equalsIgnoreCase("invalid information"))
+ {
+ message.setText("invalid information");
+ message.setVisible(true);
+
+ }
+ else if (result.equalsIgnoreCase("found admin")){
+
+ }
+ else if (result.equalsIgnoreCase("found player"))
+ {
+
+ }
+ }
+}
diff --git a/src/sample/Main.java b/src/sample/Main.java
new file mode 100644
index 0000000..5333744
--- /dev/null
+++ b/src/sample/Main.java
@@ -0,0 +1,23 @@
+package sample;
+
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+
+public class Main extends Application {
+
+ @Override
+ public void start(Stage primaryStage) throws Exception{
+ Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
+ primaryStage.setTitle("Hello World");
+ primaryStage.setScene(new Scene(root, 300, 275));
+ primaryStage.show();
+ }
+
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+}
diff --git a/src/sample/PlayerGraphicalMainPageController.java b/src/sample/PlayerGraphicalMainPageController.java
new file mode 100644
index 0000000..d93fea7
--- /dev/null
+++ b/src/sample/PlayerGraphicalMainPageController.java
@@ -0,0 +1,4 @@
+package sample;
+
+public class PlayerGraphicalMainPageController {
+}
diff --git a/src/sample/PlayerMainPage.fxml b/src/sample/PlayerMainPage.fxml
new file mode 100644
index 0000000..99b11c7
--- /dev/null
+++ b/src/sample/PlayerMainPage.fxml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/sample/sample.fxml b/src/sample/sample.fxml
new file mode 100644
index 0000000..c72db1a
--- /dev/null
+++ b/src/sample/sample.fxml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+