June is Combung
사다리게임 본문
package week2;
import java.util.Scanner;
public class Day10_1 {
/*
* # 사다리 게임 1. 인덱스 0~4를 하나선택한다. 2. 숫자 0 을 만나면 그냥 아래로 내려간다. 3. 숫자 1 을 만나면 오른쪽으로
* 이동후 내려간다. 4. 숫자 2 를 만나면 완쪽으로 이동후 내려간다. 5. 오늘의 메뉴 출력
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String menu[] = { "떡라면", "돈까스", "짜장면", "쫄면", "된장찌개" };
int ladder[][]= {
{0,0,0,0,0},
{1,2,0,1,2},
{0,1,2,0,0},
{0,0,1,2,0},
{1,2,0,0,0},
{0,1,2,0,0},
{1,2,0,0,0},
{0,0,0,1,2},
{0,0,0,0,0}};
boolean check[][] = new boolean[ladder.length][ladder[0].length];
int x = 0;
int y = 0;
Scanner sc = new Scanner(System.in);
System.out.println(" 1 2 3 4 5 ");
for (int i = 0; i < ladder.length; i++) {
for(int j=0; j<ladder[i].length; j++) {
if(ladder[i][j] == 0) {
System.out.print(" │ ");
}else if(ladder[i][j] == 1) {
System.out.print(" ├─");
}else if(ladder[i][j] == 2) {
System.out.print("─┤ ");
}
}
System.out.println();
}
System.out.println();
System.out.println("선택 1 to 5 ");
x = sc.nextInt();
x--;
for(int i=0; i<ladder.length; i++) {
check[y][x] = true;
if(ladder[y][x] == 1) {
x += 1;
}else if(ladder[y][x] == 2) {
x -= 1;
}
check[y][x] = true;
y += 1;
}
System.out.println("오늘 메뉴는 " + menu[x]);
for(int i=0; i<ladder.length; i++) {
for(int j=0; j<ladder[i].length; j++) {
if(check[i][j] == true) {
System.out.print(" * ");
}else {
if(ladder[i][j] == 0) {
System.out.print(" │ ");
}else if(ladder[i][j] == 1) {
System.out.print(" ├─");
}else if(ladder[i][j] == 2) {
System.out.print("─┤ ");
}
}
}
System.out.println();
}
for (int i = 0; i < menu.length; i++) {
System.out.print(menu[i] + ",");
}
}
}
Comments