私はJavaでAndroidベースのアプリケーションとして書いたテキストベースの端末rpgを再設計しようとしています。私は、ゲームの小さな部分に取り組んでいます。プレイヤーは1つの部屋から別の部屋に歩くことができます。ユーザー入力を待ちますか?
コードが停止し、端末アプリケーションで入力を求めるメッセージが表示された場合、コードは最後まですべて実行され、入力は行われません。
public class MainActivity extends AppCompatActivity {
//rooms
Room r1 = new Room("The Great Hall", "A long wide room draped here and there in curtains.");
Room r2 = new Room("The Side Study", "a small cluttered room.");
Room r3 = new Room("The Gardens", "a misty path between beds, once carefully tended now overgrown and disturbed by the encroaching weeds.");
Room r4 = new Room("A Long Passage", "a narrow hallway lined with brooding portraits. Set into the walls to your left and right are blank grey doors, three to a side. They are locked.");
Room currentRoom;
//room maps
HashMap<String, Room> mapR1 = new HashMap<>();
HashMap<String, Room> mapR2 = new HashMap<>();
HashMap<String, Room> mapR3 = new HashMap<>();
HashMap<String, Room> mapR4 = new HashMap<>();
//user
String userDir;
String endgame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//begin setup
//
//map for great hall
mapR1.put("north", r4);
mapR1.put("east", r2);
mapR1.put("west", r3);
r1.setRoomMap(mapR1);
//map for side study
mapR2.put("west", r1);
r2.setRoomMap(mapR2);
//map for gardens
mapR3.put("east", r1);
r3.setRoomMap(mapR3);
//map for long passage
mapR4.put("south", r1);
r4.setRoomMap(mapR4);
//init
currentRoom = r1;
endgame = "non";
//views
final TextView textView = (TextView) findViewById(R.id.youmum);
final EditText editText = (EditText) findViewById(R.id.editText);
//
//end setup
//the actual game play
//
assert textView != null;
textView.setText("You are in the " + currentRoom.getRoomTitle() + "; " + currentRoom.getRoomDescription());
textView.append("\nThere are exits to the, ");
for (String ky : currentRoom.getRoomMap().keySet()) {
textView.append(ky + " ");
}
textView.append("\nChoose a direction");
assert editText != null;
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendMessage();
handled = true;
}
return handled;
}
private void sendMessage() {
userDir = editText.getText().toString().toLowerCase();
if (userDir.contains("go") || userDir.contains("walk") || userDir.contains("move")) {
boolean notDir = false;
for (String kee : currentRoom.getRoomMap().keySet()) {
if (userDir.contains(kee)) {
currentRoom = currentRoom.getExitRoom(kee);
notDir = false;
break;
} else {
notDir = true;
}
}
if (notDir) {
textView.setText("You cannot go that way.\n");
}
}
}
});
textView.setText("You are in the " + currentRoom.getRoomTitle() + "; " + currentRoom.getRoomDescription());
textView.append("\nThere are exits to the, ");
for (String ky : currentRoom.getRoomMap().keySet()) {
textView.append(ky + " ");
}
textView.append("\nChoose a direction");
}
}
私は、Androidに非常に新しいです(これは実際に私の最初の進出である)ので、私はちょうど何かを明らかに行方不明ですと仮定しています。