From 2b3a65c948d2951b2d9e682e9bc29b233f55c459 Mon Sep 17 00:00:00 2001 From: Danial Gharib Date: Mon, 18 Apr 2022 17:09:55 +0430 Subject: [PATCH] =?UTF-8?q?some=20changes=20to=20menu=20structure=20=D8=AE?= =?UTF-8?q?=D8=AF=D8=A7=DB=8C=D8=A7=20=D8=B4=D8=A8=20=D9=82=D8=AF=D8=B1=20?= =?UTF-8?q?=D9=86=D8=B2=D8=AF=DB=8C=DA=A9=D9=87=20=D9=87=D8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 8 ++++---- src/main/java/View/GameMenu.java | 7 +++---- src/main/java/View/LoginMenu.java | 7 +++---- src/main/java/View/MainMenu.java | 10 +++++----- src/main/java/View/Menu.java | 12 ++++++++++++ src/main/java/View/ProfileMenu.java | 15 ++++++++++----- 6 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 src/main/java/View/Menu.java diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 4d6bca8..39c0f6a 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -16,10 +16,10 @@ public static void main(String[] args){ GameMenu gameMenu = new GameMenu(scanner , new GameMenuController()); while(MenuName.getCurrentMenu() != MenuName.TERMINATE) { - LoginMenu.run(); - MainMenu.run(); - ProfileMenu.run(); - GameMenu.run(); + loginMenu.run(); + mainMenu.run(); + profileMenu.run(); + gameMenu.run(); } System.out.println("khaste nabashi ayoub jan!"); } diff --git a/src/main/java/View/GameMenu.java b/src/main/java/View/GameMenu.java index 321c7bc..c2257fc 100644 --- a/src/main/java/View/GameMenu.java +++ b/src/main/java/View/GameMenu.java @@ -7,16 +7,15 @@ import java.util.Scanner; import java.util.regex.Matcher; -public class GameMenu{ +public class GameMenu extends Menu{ private final GameMenuController gameMenuController; - private static Scanner scanner; public GameMenu(Scanner scanner, GameMenuController gameMenuController){ + super(scanner); this.gameMenuController = gameMenuController; - GameMenu.scanner = scanner; } - public static void run() { + public void run() { String input; Matcher matcher; diff --git a/src/main/java/View/LoginMenu.java b/src/main/java/View/LoginMenu.java index 44c3534..57bd33e 100644 --- a/src/main/java/View/LoginMenu.java +++ b/src/main/java/View/LoginMenu.java @@ -6,16 +6,15 @@ import java.util.Scanner; import java.util.regex.Matcher; -public class LoginMenu { +public class LoginMenu extends Menu{ private final LoginMenuController loginMenuController; - private static Scanner scanner; public LoginMenu(Scanner scanner , LoginMenuController loginMenuController) { - LoginMenu.scanner = scanner; + super(scanner); this.loginMenuController = loginMenuController; } - public static void run() { + public void run() { String input; Matcher matcher; diff --git a/src/main/java/View/MainMenu.java b/src/main/java/View/MainMenu.java index 571e751..b85fd8f 100644 --- a/src/main/java/View/MainMenu.java +++ b/src/main/java/View/MainMenu.java @@ -5,19 +5,19 @@ import java.util.Scanner; import java.util.regex.Matcher; -public class MainMenu { +public class MainMenu extends Menu{ private final MainMenuController mainMenuController; - private static Scanner scanner; + public MainMenu(Scanner scanner , MainMenuController mainMenuController) { - MainMenu.scanner = scanner; + super(scanner); this.mainMenuController = mainMenuController; } - public static void run() { + public void run() { String input; Matcher matcher; - while (MenuName.getCurrentMenu() == MenuName.MAIN_MENU) { + input = scanner.nextLine(); //TODO commands! } } diff --git a/src/main/java/View/Menu.java b/src/main/java/View/Menu.java new file mode 100644 index 0000000..a73ec79 --- /dev/null +++ b/src/main/java/View/Menu.java @@ -0,0 +1,12 @@ +package View; + +import java.util.Scanner; +import java.util.regex.Matcher; + +public abstract class Menu { + + protected Scanner scanner; + public abstract void run(); + + public Menu(Scanner scanner) {this.scanner = scanner;} +} diff --git a/src/main/java/View/ProfileMenu.java b/src/main/java/View/ProfileMenu.java index 3386b23..4017470 100644 --- a/src/main/java/View/ProfileMenu.java +++ b/src/main/java/View/ProfileMenu.java @@ -1,18 +1,23 @@ package View; import Controller.menu.ProfileMenuController; - +import Enum.MenuName; import java.util.Scanner; +import java.util.regex.Matcher; -public class ProfileMenu { +public class ProfileMenu extends Menu{ private final ProfileMenuController profileMenuController; private static Scanner scanner; public ProfileMenu(Scanner scanner, ProfileMenuController profileMenuController){ - ProfileMenu.scanner = scanner; + super(scanner); this.profileMenuController = profileMenuController; } - public static void run() { - + public void run() { + String input; + Matcher matcher; + while (MenuName.getCurrentMenu() == MenuName.PROFILE_MENU) { + input = scanner.nextLine(); + } } }