・・・ |
|
|
012 |
|
public class KCEMain { |
013 |
|
|
014 |
|
//******************************************** |
015 |
|
// 定数 |
016 |
|
//******************************************** |
017 |
|
//入力・表示処理モード |
018 |
|
private static final int
MODE_GAME_1_ACT = 1;//行動処理モード(1階層目 どうする?行動コマンド) |
019 |
|
private static final int
MODE_GAME_2_TAR = 2;//対象処理モード(2階層目 なにを?対象コマンド) |
020 |
|
private static final int
MODE_GAME_3_RES = 3;//結果処理モード |
021 |
|
//行動コマンド |
022 |
|
private static final int ACT_NONE = 0;//無し |
023 |
|
private static final int ACT_MOVE = 1;//移動 |
024 |
|
private static final int ACT_LOOK = 2;//見る |
025 |
|
private static final int ACT_USE = 3;//使う |
026 |
|
//対象コマンド 移動用 部屋の現在地 |
027 |
|
private static final int TAR_ROOM_ENTRANCE = 1;//入口 |
028 |
|
private static final int TAR_ROOM_PASSAGE = 2;//廊下 |
029 |
|
private static final int TAR_ROOM_BED = 3;//寝室 |
030 |
|
//******************************************** |
031 |
|
// 変数 |
032 |
|
//******************************************** |
033 |
|
private static int inputNum = 0;//入力番号 |
034 |
|
private static int nowMode =
MODE_GAME_1_ACT;//現在の処理モード:最初は1階層目 |
035 |
|
private static int nowRoomNum =
TAR_ROOM_ENTRANCE;//現在位置:ドアの部屋から開始 |
036 |
|
|
037 |
|
/** |
038 |
|
* @param args the command line arguments |
039 |
|
*/ |
040 |
|
public static void main(String[] args) { |
041 |
|
// TODO code application logic here |
042 |
|
|
043 |
|
//******************************************** |
044 |
|
//
メイン処理 |
045 |
|
//******************************************** |
046 |
|
boolean loopFlg =
true;//ループフラグ |
047 |
|
|
048 |
|
while (loopFlg ) { |
049 |
|
|
050 |
|
///////////////////////////////////////////////////// |
051 |
|
//実行処理(選択されたコマンドによって表示) |
052 |
|
switch (nowMode) { |
053 |
|
|
054 |
|
//*************** |
055 |
|
//行動処理モード |
056 |
|
case MODE_GAME_1_ACT: |
057 |
|
//行動処理モード関数呼び出し |
058 |
|
execModeAction(); |
059 |
|
|
060 |
|
//対象処理モード(2階層目)に切り替える |
061 |
|
nowMode = MODE_GAME_2_TAR; |
062 |
|
|
063 |
|
break; |
064 |
|
//*************** |
065 |
|
//対象処理モード |
066 |
|
case MODE_GAME_2_TAR: |
067 |
|
//対象処理モード関数呼び出し |
068 |
|
execModeTarget(); |
069 |
|
|
070 |
|
//結果処理モード(3階層目)に切り替える |
071 |
|
nowMode = MODE_GAME_3_RES; |
072 |
|
|
073 |
|
break; |
074 |
|
//*************** |
075 |
|
//結果処理モード |
076 |
|
case MODE_GAME_3_RES: |
077 |
|
//結果処理モード関数呼び出し |
078 |
|
execModeResult(); |
079 |
|
|
080 |
|
//行動処理モード(1階層目)に戻す |
081 |
|
nowMode = MODE_GAME_1_ACT; |
082 |
|
|
083 |
|
break; |
084 |
|
} |
085 |
|
|
086 |
|
//キー入力処理 |
087 |
|
inputNum = scanInputData(); |
088 |
|
|
089 |
|
//表示開始の区切り |
090 |
|
printSeparateMark(); |
091 |
|
|
092 |
|
} |
093 |
|
|
094 |
|
} |
095 |
|
|
096 |
|
/** |
097 |
|
* キー入力処理 |
098 |
|
*/ |
099 |
|
private static int scanInputData() { |
100 |
|
|
101 |
|
///////////////////////////////////////////////////// |
102 |
|
//キー入力処理 そのまま書き写してください ここから |
103 |
|
int
tmpInputNum = 0;//入力番号初期化 |
104 |
|
while (true) { |
105 |
|
try { |
106 |
|
//初期化処理 |
107 |
|
final int IMPUT_MAX = 5;//最大入力値 |
108 |
|
//キー入力読込処理(int型) |
109 |
|
java.util.Scanner sc =
new
java.util.Scanner(System.in); |
110 |
|
int inputInt = sc.nextInt(); |
111 |
|
//入力値チェックと入力番号への代入 |
112 |
|
if (inputInt > 0 && inputInt <= IMPUT_MAX) { |
113 |
|
tmpInputNum = inputInt; |
114 |
|
break; |
115 |
|
}
else { |
116 |
|
System.out.println("※ コマンドは" + IMPUT_MAX +
"以下で入力して下さい ※ "); |
117 |
|
System.out.print(">"); |
118 |
|
} |
119 |
|
}
catch (Exception e) { |
120 |
|
System.out.println("※ 数字以外は入力しないで下さい ※ "); |
121 |
|
System.out.print(">"); |
122 |
|
} |
123 |
|
} |
124 |
|
//キー入力処理 そのまま書き写してください ここまで |
125 |
|
///////////////////////////////////////////////////// |
126 |
|
|
127 |
|
//入力番号を返す |
128 |
|
return tmpInputNum; |
129 |
|
} |
130 |
|
|
131 |
|
/** |
132 |
|
* 区切り処理 |
133 |
|
*/ |
134 |
|
private static void printSeparateMark() { |
135 |
|
//表示終了の区切り |
136 |
|
System.out.println(""); |
137 |
|
System.out.println("######################################################"); |
138 |
|
System.out.println(""); |
139 |
|
} |
140 |
|
|
141 |
|
/** |
142 |
|
* 行動処理モード |
143 |
|
*/ |
144 |
|
private static void execModeAction() { |
145 |
|
//***** 部屋の状況と行動のコマンドを表示する
***** |
146 |
|
|
147 |
|
//部屋の状況を表示(部屋ごとの処理) |
148 |
|
//もし入口なら |
149 |
|
if (nowRoomNum ==
TAR_ROOM_ENTRANCE) { |
150 |
|
System.out.println("S-01:ここは入口です。"); |
151 |
|
|
152 |
|
//もし廊下なら |
153 |
|
} else if (nowRoomNum ==
TAR_ROOM_PASSAGE) { |
154 |
|
System.out.println("S-02:ここは廊下です。"); |
155 |
|
|
156 |
|
//もし寝室なら |
157 |
|
} else if (nowRoomNum ==
TAR_ROOM_BED) { |
158 |
|
System.out.println("S-03:ここは寝室です。"); |
159 |
|
} |
160 |
|
|
161 |
|
//行動コマンドの一覧を表示 |
162 |
|
System.out.println(""); |
163 |
|
System.out.println("---------------------------------------------"); |
164 |
|
System.out.println("どうする?"); |
165 |
|
System.out.println("1:移動 2:見る 3:使う"); |
166 |
|
System.out.print(">"); |
167 |
|
} |
168 |
|
|
169 |
|
/** |
170 |
|
* 対象処理モード |
171 |
|
*/ |
172 |
|
private static void execModeTarget() { |
173 |
|
|
174 |
|
System.out.println("テスト:対象処理モード関数開始");
//テスト用:表示確認 |
175 |
|
System.out.print(">");
//テスト用:表示確認 |
176 |
|
|
177 |
|
} |
178 |
|
|
179 |
|
/** |
180 |
|
* 結果処理モード |
181 |
|
*/ |
182 |
|
private static void execModeResult() { |
183 |
|
|
184 |
|
System.out.println("テスト:結果処理モード関数開始");
//テスト用:表示確認 |
185 |
|
System.out.print(">");
//テスト用:表示確認 |
186 |
|
|
187 |
|
} |
188 |
|
|
189 |
|
} |
190 |
|
|