プレーヤーが入力するステップに基づいて、それぞれの隣接方向を返したいとします。入力はcharにすることはできません。intにする必要があります(ちょうど南に行くと言うことはできませんが、地図の階段を下に置く必要があります)。 nextAreaメソッドで失われた気分。 私には答えを書かないでください。ちょっとしたガイダンスが必要です。switchステートメントからすべての可能な結果を返します
これらは)
public void walk(){
current = gameOne.getCurrentArea();
walk = sc.nextInt();
// pick a direction to walk into
// from that space show connected areas
}
public void pickMove(){
System.out.print("walk shoot, quit or reset?");
answer = sc.nextLine();
//walk
//if area not connected: alert
//if into village: alert that they are healed
//if containing wolf: altert they are bitten, if already bitten game ends
switch(answer) {
case "walk":System.out.print("from " + current + " a direction to walk into south(3), east(1), west(2), north(6),");
this.walk();
gameOne.tryWalk(walk);
gameOne.getCurrentArea();
//what I want>>>get current areas to s, e, w and n
私の現在の試みはWereWolfenstein2Dクラスで次のようになりますgameOne.nextArea(GameWorldクラス
/**
* Returns true if areas s1 and s2 are connected, false otherwise.
* Also returns false if either area is an invalid area identifier.
* @param s1 the first area
* @param s2 the second area
* @return true if areas are connected, false otherwise
*/
private boolean areasConnected(int s1, int s2) {
if (Math.min(s1, s2) >= 0 && Math.max(s1, s2) < numAreas) { //valid areas...
//...but are they connected?
return east[s1] == s2 || north[s1] == s2 || west[s1] == s2 || south[s1] == s2;
}
//Either s1 or s2 is not a valid area identifier
return false;
}
/**
* Determine ID number of an adjacent area given its direction from the
* current area.
* @param direction the direction to look (n for north, e for east, s for south, w for west)
* @return number of the area in that direction
* @throws IllegalArgumentException if direction is null
*/
public int nextArea(char direction) {
int nextIs; // area number of area in indicated direction
//Valid values
final char N = 'n', E = 'e', S = 's', W = 'w';
trace("nextArea() starts...");
// examine adjacent areas
switch (direction) {
case N: trace("determining number of area to the north");
nextIs = north[currentArea];
break;
case E: trace("determining number of area to the east");
nextIs = east[currentArea];
break;
case S: trace("determining number of area to the south");
nextIs = south[currentArea];
break;
case W: trace("determining number of area to the west");
nextIs = west[currentArea];
break;
default: throw new IllegalArgumentException("Direction must be one of " + N + ", " + E + ", " + S + " or " + W);
}
trace("...nextArea() ends with value for '" + direction + "' of " + nextIs);
return nextIs;
}
からメソッドです。
break;
case "shoot":
break;
case "quit": System.out.print("would you like to start again? (yes/no)");
restart = sc.nextLine();
if (restart.equals("yes")) {
gameOne.reset();
}
else {
System.out.println("Thanks for playing");
}
break;
case "reset": //gameOne.reset();
this.pickDifficulity();
break;
}
}
これは私が正しくあなたの質問を解釈していた場合
//This map is _deliberately_ confusing, although it actually a regular layout
private int[] east = {1,2,0,4,5,3,7,8,6}; // areas to east of current location (index)
private int[] west = {2,0,1,5,3,4,8,6,7}; // areas to west of current location (index)
private int[] north = {6,7,8,0,1,2,3,4,5}; // areas to north of current location (index)
private int[] south = {3,4,5,6,7,8,0,1,2}; // areas to south of current location (index)
private int numAreas = south.length; // number of areas in the "world"
もう少し詳しく説明できますか?入力が、配列内のインデックスである「場所」のセットであり、各ステップを実行するために取らなければならない指示を返す必要があることを意味しますか? – sprinter
入力は、人が向かいたい場所です。リターンには、ロケーション配列(またはマップ)に従って、どの領域番号を囲むかを示す必要があります。 – Button
入力は、人が向かいたい場所です。リターンには、ロケーション配列(またはマップ)に従って、どの領域番号を囲むかを示す必要があります。 – Button