import java.util.*;
public class Game
{
private EnemyShip enemy1;
private EnemyShip enemy2;
private EnemyShip enemy3;
private PlayerShip player;
Scanner keyboard = new Scanner(System.in);
public Game(int initialX)
{
player = new PlayerShip(initialX);
enemy1 = new EnemyShip(0,1);
enemy2 = new EnemyShip(-4,1);
enemy3 = new EnemyShip(2,-1);
}
public Game()
{
System.out.println("Enemy #1");
System.out.print("- Initial x ");
int x = keyboard.nextInt();
System.out.print("- Initial velocity: ");
int y = keyboard.nextInt();
enemy1 = new EnemyShip(x,y);
System.out.println("Enemy #2");
System.out.print("- Initial x ");
int x1 = keyboard.nextInt();
System.out.print("- Initial velocity: ");
int y1 = keyboard.nextInt();
enemy2 = new EnemyShip(x1,y1);
System.out.println("Enemy #3");
System.out.print("- Initial x ");
int x2 = keyboard.nextInt();
System.out.print("- Initial velocity: ");
int y2 = keyboard.nextInt();
enemy3 = new EnemyShip(x2,y2);
player = new PlayerShip(0);
}
public String toString()
{
return "Enemy("+enemy1.getPosition() +") Enemy("+enemy2.getPosition()+") Enemy("+enemy3.getPosition()+") Player["+player.getPosition()+", "+player.getPts()+ "pts]";
}
public int getPts()
{
int playerPts = player.getPts();
return getPts();
}
public void movePlayer()
{
System.out.print("move: ");
String s = keyboard.nextLine();
char first = s.charAt(0);
if(s.charAt(0) =='l' || s.charAt(0) == 'L')
{
player.moveLeft();
}
if(s.charAt(0) =='r' || s.charAt(0) == 'R')
{
player.moveRight();
}
if(s.charAt(0) =='f' || s.charAt(0) == 'F')
{
player.useWeapons(); //<------------이쪽부분 수정필요한거같아용
}
}
public void moveEnemies()
{
enemy1.moveEnemy();
enemy2.moveEnemy();
enemy3.moveEnemy();
}
}
public class EnemyShip
{
private int x;
private int direction;
private int life;
private boolean justHit;
public EnemyShip(int initialX, int initialDirection)
{
x = initialX;
direction = initialDirection;
life = 10;
justHit = false;
}
public int getPosition()
{
return x;
}
public int moveEnemy()
{
if(direction > 0)
{
if(x >= 6)
{
return x = x - 1;
}
return x = x+1;
}
if(direction < 0)
{
if( x <= -6)
{
return x = x+1;
}
return x = x-1;
}
return x = x;
}
}
public class Gun
{
private int x;
private int power;
private int points;
private int bonus;
private boolean justFired;
public Gun(int X, int Power)
{
x = X;
power = Power;
points = 0;
bonus = 1;
justFired = false;
}
public int getPts()
{
return points;
}
public int gunMove()
{
return x;
}
}
public class PlayerShip
{
private int x;
private Gun gun1;
private Gun gun2;
public PlayerShip(int initialX)
{
x = initialX;
gun1 = new Gun(x-1,5);
gun2 = new Gun(x+1,5);
}
public int getPosition()
{
return x;
}
public int getPts()
{
return gun1.getPts();
}
public int moveLeft()
{
if( x > -5)
{
return x = x-1;
}
return x = x;
}
public int moveRight()
{
if(x < 5)
{
return x = x + 1;
}
return x = x;
}
public void useWeapons() //<--이쪽부분도
{
}
}
---------------------
간단한 비행슈팅게임 과제 하는중인데요 여기가지 코드를 짯거든요
근데 이제 player 가 f 나 F 키를 눌렀을대 양쪽 무기앞에있는 적을 쏴서 적의 라이프를 무기 파워만큼 감소시키고 적이파괴되면 (life =0) 포인트를 얻는
법을 만들라고하는데 도저히 모르겠네요 ㅠㅠ방법좀없을까요
public class Game
{
private EnemyShip enemy1;
private EnemyShip enemy2;
private EnemyShip enemy3;
private PlayerShip player;
Scanner keyboard = new Scanner(System.in);
public Game(int initialX)
{
player = new PlayerShip(initialX);
enemy1 = new EnemyShip(0,1);
enemy2 = new EnemyShip(-4,1);
enemy3 = new EnemyShip(2,-1);
}
public Game()
{
System.out.println("Enemy #1");
System.out.print("- Initial x ");
int x = keyboard.nextInt();
System.out.print("- Initial velocity: ");
int y = keyboard.nextInt();
enemy1 = new EnemyShip(x,y);
System.out.println("Enemy #2");
System.out.print("- Initial x ");
int x1 = keyboard.nextInt();
System.out.print("- Initial velocity: ");
int y1 = keyboard.nextInt();
enemy2 = new EnemyShip(x1,y1);
System.out.println("Enemy #3");
System.out.print("- Initial x ");
int x2 = keyboard.nextInt();
System.out.print("- Initial velocity: ");
int y2 = keyboard.nextInt();
enemy3 = new EnemyShip(x2,y2);
player = new PlayerShip(0);
}
public String toString()
{
return "Enemy("+enemy1.getPosition() +") Enemy("+enemy2.getPosition()+") Enemy("+enemy3.getPosition()+") Player["+player.getPosition()+", "+player.getPts()+ "pts]";
}
public int getPts()
{
int playerPts = player.getPts();
return getPts();
}
public void movePlayer()
{
System.out.print("move: ");
String s = keyboard.nextLine();
char first = s.charAt(0);
if(s.charAt(0) =='l' || s.charAt(0) == 'L')
{
player.moveLeft();
}
if(s.charAt(0) =='r' || s.charAt(0) == 'R')
{
player.moveRight();
}
if(s.charAt(0) =='f' || s.charAt(0) == 'F')
{
player.useWeapons(); //<------------이쪽부분 수정필요한거같아용
}
}
public void moveEnemies()
{
enemy1.moveEnemy();
enemy2.moveEnemy();
enemy3.moveEnemy();
}
}
public class EnemyShip
{
private int x;
private int direction;
private int life;
private boolean justHit;
public EnemyShip(int initialX, int initialDirection)
{
x = initialX;
direction = initialDirection;
life = 10;
justHit = false;
}
public int getPosition()
{
return x;
}
public int moveEnemy()
{
if(direction > 0)
{
if(x >= 6)
{
return x = x - 1;
}
return x = x+1;
}
if(direction < 0)
{
if( x <= -6)
{
return x = x+1;
}
return x = x-1;
}
return x = x;
}
}
public class Gun
{
private int x;
private int power;
private int points;
private int bonus;
private boolean justFired;
public Gun(int X, int Power)
{
x = X;
power = Power;
points = 0;
bonus = 1;
justFired = false;
}
public int getPts()
{
return points;
}
public int gunMove()
{
return x;
}
}
public class PlayerShip
{
private int x;
private Gun gun1;
private Gun gun2;
public PlayerShip(int initialX)
{
x = initialX;
gun1 = new Gun(x-1,5);
gun2 = new Gun(x+1,5);
}
public int getPosition()
{
return x;
}
public int getPts()
{
return gun1.getPts();
}
public int moveLeft()
{
if( x > -5)
{
return x = x-1;
}
return x = x;
}
public int moveRight()
{
if(x < 5)
{
return x = x + 1;
}
return x = x;
}
public void useWeapons() //<--이쪽부분도
{
}
}
---------------------
간단한 비행슈팅게임 과제 하는중인데요 여기가지 코드를 짯거든요
근데 이제 player 가 f 나 F 키를 눌렀을대 양쪽 무기앞에있는 적을 쏴서 적의 라이프를 무기 파워만큼 감소시키고 적이파괴되면 (life =0) 포인트를 얻는
법을 만들라고하는데 도저히 모르겠네요 ㅠㅠ방법좀없을까요
답변부탁드립니당 ㅠ
선입금
얼마면되나요
굽신굽신 ㅠ
답변드리면 제가 피자든뭐든 쏘겠습니다 ㅠㅠ 메일주소나 연락처남겨주시면..