Java
1package basic; 2import java.io.IOException; 3import java.util.Scanner; 4 5class RPG { 6 7 8 static Scanner scanner; 9 static int Maximumhp = 10; 10 static int Playerhp = 10; //プレイヤーHP 11 static int PlayerAttack = 30; //プレイヤ―の攻撃力 12 static String Player; //プレイヤーの名前 13 static String Command; //コマンド 14 static int menu = 0; //メニュー 15 static int PlayerLv = 1; //プレイヤーレベル 16 static int Defence = 15; //プレイヤー防御 17 static int SuicideAttack = 30; //プレイヤー特攻 18 static int SuicideDefence = 15; //プレイヤー特防 19 static int Agility = 30; //プレイヤー素早さ 20 21 public static void main(String[] args) throws IOException{ 22 menu b = new menu();; 23 if (!(Playerhp <= Maximumhp)) { 24 System.out.println("エラーが発生しました。プログラムを終了します。"); 25 System.exit(1); 26 } 27 28 System.out.println("名前を入力してください。"); 29 30 scanner = new Scanner(System.in); 31 32 Player = scanner.next(); //プレイヤーの名前を入力 33 34 System.out.println("何かコマンドを入力してください"); 35 Command = scanner.next(); //コマンド入力 36 37 if (Command.equals("/menu")) { 38 try { 39 menu(); 40 } catch (IOException e) { 41 e.printStackTrace(); 42 } 43 }else if(Command.equals("/battle")) { 44 battle(); 45 }else { 46 System.out.println("コマンドが間違っています。"); 47 return; 48 } 49 switch (menu){ 50 case 1: 51 b.status(); 52 break; 53 case 2: 54 b.MonsterPictureBook(); 55 case 3: 56 57 case 4: 58 59 case 5: 60 } 61 } 62 public static void battle() { 63 64 } 65 public static void menu () throws IOException{ 66 scanner = new Scanner(System.in); 67 68 System.out.println("メニュー"); 69 System.out.println("1:ステータス"); 70 System.out.println("2:モンスター図鑑"); 71 System.out.println("3:所持アイテム一覧"); 72 73 74 menu = scanner.nextInt(); 75 } 76} 77class Players { 78 79} 80class Battle { 81 int Enemy; 82} 83 84class menu { 85 public menu() throws IOException { 86 System.out.println("メニュー"); 87 System.out.println("1:ステータス"); 88 System.out.println("2:モンスター図鑑"); 89 System.out.println("3:所持アイテム一覧"); 90 RPG.menu = scanner.nextInt(); 91 } 92 public void status() { 93 System.out.println(RPG.Player + "のステータス"); //プレイヤーのステータス表示 94 System.out.println("LV:" + RPG.PlayerLv); 95 System.out.println("HP:" + RPG.Playerhp); 96 System.out.println("攻撃:" + RPG.PlayerAttack); 97 System.out.println("防御:" + RPG.Defence); 98 System.out.println("特攻:" + RPG.SuicideAttack); 99 System.out.println("特防:" + RPG.SuicideDefence); 100 System.out.println("素早さ:" + RPG.Agility); 101 } 102 public void MonsterPictureBook() { 103 System.out.println("|---------------------------------|"); 104 System.out.println("|--名-L-H-攻-防-特攻-特防-素早さ--|"); 105 } 106 public void PossessionItemList() { 107 108 } 109}
昨日のRPGの続きです。オブジェクト指向化はできたのですがimport文がmenuクラスでは使えません。何か使えるようにする方法はないのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/11 11:06