ここまではforループの抜粋です。問題はスペースを減らすことですエリキシル剤のループはありません。ボードを作るにはどうすればいいですか?
for i <- 0..(row-1) do
for j <- 0..(col-1) do
if j == 0 do
IO.write"+"
end
IO.write "--+"
end
IO.puts ""
columns= col+1
for columns <- 1..columns do
if columns == 1 do
IO.write "|"
end
if spaces < 10 do
IO.write " "
IO.write spaces
IO.write "|"
end
end
spaces = spaces - 1 <- This won't decrement after it goes through the forloop again!
end
end
私はこのようなものを出力するエリクサーでボードゲームを作る必要があります。
+---+---+---+
| 12| 11| 10|
|B | | |
+---+---+---+
| 7| 8| 9|
| a | S| e |
+---+---+---+
| 6| 5| 4|
| e | L|Ad |
+---+---+---+
| 1| 2| 3|
| | | |
+---+---+---+
私は基本的にループのために別の内ループのために使用して、次のコードを使用してJavaでそれをやったが、これは万能薬では不可能です。これにアプローチする方法はありますか?ありがとう。
EDIT:誰かが私のJavaコードを見たい場合は、ここにあります。
public class math {
static int col = 10;
static int row = 10;
static String top= "---+";
static String side= "|";
static int spaces=col*row;
static int columns;
static int dash;
static String player="A";
public static void main(String args[]){
for (int i=0; i < row; i++){
for (int j=0; j < col; j++){
if (j==0) System.out.print("+");
System.out.print(top);
}
System.out.print("\n");
columns=col+1;
while(columns > 1){
if(columns == col+1){
System.out.print("|");
}
if(spaces < 10){
System.out.print(" "+spaces+"|");}
else if (spaces <100){
System.out.print(" "+spaces+"|");
}
else{
System.out.print(""+spaces+"|");
}
spaces--;
columns--;}
System.out.print("\n");
columns=col+1;
while(columns >1){
if (columns == col +1) {System.out.print("|");}
System.out.print(" |");
columns--;}
System.out.print("\n");
if(i == row-1){
int botside = col;
while(botside !=0){
if(botside == col){
System.out.print("+");
}
System.out.print(top);
botside--;}
}
}
}
あなたの質問を実行したときに、それはあなたの必要な結果を生成示しています。あなたが問題の中核に到達するのを単純化することができれば(ある順序でボードのフィールドにアクセスし、ある州全体を維持しようとしているように)、あなたはおそらく良い答えを得るでしょう。 – nietaki