Skip to content

Commit

Permalink
Add: 지뢰 랜덤으로 1개 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
kyupid committed Dec 14, 2020
1 parent f199dc9 commit ec70e8e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Game.java
@@ -1,26 +1,32 @@
import java.util.Random;
import java.util.Scanner;

class Game {
private final String PLAYER = "P ";
private final String BACKGROUND = "* ";
private final String MINE = "M ";

private final String[][] map = new String[11][11];
private final Scanner sc = new Scanner(System.in);
private final Random rd = new Random();

private char dir;

Game() {
initMap();
initPlayer();
initMine();

while(true) {
while (true) {
printAll();
getDirPlayer();
movePlayer(dir);
}
}


private void movePlayer(char dir) {
// TODO : 배열 벗어나지 않도록 조건문 만들기
int[] locationPlayer = retrievePlayer();
map[locationPlayer[0]][locationPlayer[1]] = BACKGROUND;
switch (dir) {
Expand Down Expand Up @@ -50,15 +56,27 @@ private int[] retrievePlayer() {
}
}
}
return new int[] {row, col};
return new int[]{row, col};
}

private void getDirPlayer() {
System.out.println("원하는 방향(W,A,S,D)을 입력해주세요.");
dir = sc.next().charAt(0);
// TODO : WASD 중 다른 방향이 들어왔을 때, 다시 입력받기
}


private void initMine() {
// TODO : 나중에 마인 여러개 만들기
int row, col;
row = rd.nextInt(10) - 1;
col = rd.nextInt(10) - 1;
map[row][col] = MINE;
while (row == 5 && col == 5) {
row = rd.nextInt(10) - 1;
col = rd.nextInt(10) - 1;
map[row][col] = MINE;
}
}

private void initMap() {
for (int i = 0; i < map.length; i++) {
Expand Down

0 comments on commit ec70e8e

Please sign in to comment.