import java.util.*;
abstract class GameObject {
protected int distance;
protected int x,y;
public GameObject(int startX,int startY,int distance) {this.x = startX; this.y = startY;this.distance = distance;}
public int getX() {return x;}
public int getY() {return y;}
public boolean collide(GameObject p) {
if(this.x == p.getX() && this.y == p.getY())
return true;
else
return false;
}
protected abstract void move();
protected abstract char getShape();
}
class Bear extends GameObject{
Scanner sc = new Scanner(System.in);
public Bear(int startX, int startY, int distance) {
super(startX, startY, distance);
this.x = startX; this.y = startY;this.distance = distance;
}
public void move() {
System.out.print("왼쪽(a),아래(s),위(w),오른쪽(d) >> ");
String answer = sc.next();
char key = answer.charAt(0);
if(key=='a'&&y-distance>=1) y-=distance;
else if(key=='s'&&x+distance<=10) x+=distance;
else if(key=='d'&&y+distance<=20) y+=distance;
else if(key=='w'&&x-distance>=1) x-=distance;
}
public char getShape() {
return 'B';
}
}
class Fish extends GameObject{
public Fish(int startX, int startY, int distance) {
super(startX, startY, distance);
this.x = startX; this.y = startY;this.distance = distance;
}
public void move() {
//Math.random() 0~ 1미만의 랜덤 실수
//Math.random()*10 0~ 10미만의 랜덤 실수
//(int)(Math.random()*10) 0~10미만 랜덤 정수
//(int)(Math.random()*10)+1 1~10이하 랜덤 정수
int dir = (int)(Math.random()*4)+1;
if(dir==1&&x+distance<=10) {
x++;
}
else if(dir==2&&x-distance>=1) {
x--;
}
else if(dir==3&&y+distance<=20) {
y++;
}
else if(dir==4&&y-distance>=1) {
y--;
}
}
public char getShape() {
return '@';
}
}
class Main {
public static void main(String[] args) {
System.out.println("--- 곰의 생선먹기 게임을 시작합니다. ---");
Bear b = new Bear(1, 1, 1);
Fish f = new Fish(4, 4, 1);
while(true) {
for(int i=1 ; i<=10 ; i++) {
for(int j=1 ; j<=20 ; j++) {
if(i==b.getX()&&j==b.getY()) System.out.print(b.getShape());
else if(i==f.getX()&&j==f.getY()) System.out.print(f.getShape());
else System.out.print("~");
}
System.out.println();
}
if(b.collide(f)) {
System.out.println("Bear wins!");
return ;
}
b.move();
f.move();
}
}
}