자바 탱크 대전 게임 실현
1.실현 하 는 기능
1.게임 방법 소개
2.사용자 정의 게임(게임 난이도,관문 등 선택)
3,사용자 정의 유저 이름
4.데이터 의 동적 표시
2.절차 기본 구조
3.주요 인터페이스
1)게임 홈 페이지
2)사용자 정의 게임 페이지
3)게임 소개
4)게임 시작,유저 이름 사용자 정의
5)게임 홈 페이지
주요 코드
1)데이터 초기 화 클래스
public class Data {
public static boolean isRestart=false;
public static boolean isGameOver=false;
public static int start = 0;// 1 0
public static int levle = 1;//
public static int pouse = 0;//0 1
public static String name = "";
public static int time = 0;
public static int b = 0;
public static int a = 1;// 1 2 3 4
public static int count; //
public static int hit = 0; //
public static Player player = new Player(200, 560, 3, 1);//
public static home home = new home(280, 560, 1);//
// jpg png gif
public static final Image IMG_ST = new ImageIcon("image/timg (2).jpg").getImage();
public static final Image IMG_buleUp = new ImageIcon("image/buleUp.gif").getImage();
public static final Image IMG_buledown = new ImageIcon("image/buledown.gif").getImage();
public static final Image IMG_buleLeft = new ImageIcon("image/buleLeft.gif").getImage();
public static final Image IMG_buleRight = new ImageIcon("image/buleRight.gif").getImage();
public static final Image IMG_pinkDown = new ImageIcon("image/pinkDown.gif").getImage();
public static final Image IMG_pinkLeft = new ImageIcon("image/pinkLeft.gif").getImage();
public static final Image IMG_pinkRight = new ImageIcon("image/pinkRight.gif").getImage();
public static final Image IMG_pinkUp = new ImageIcon("image/pinkUp.gif").getImage();
public static final Image IMG_yellowDown = new ImageIcon("image/yellowDown.gif").getImage();
public static final Image IMG_yellowLeft = new ImageIcon("image/yellowLeft.gif").getImage();
public static final Image IMG_yellowRight = new ImageIcon("image/yellowRight.gif").getImage();
public static final Image IMG_yellowUp = new ImageIcon("image/yellowUp.gif").getImage();
public static final Image IMG_tie = new ImageIcon("image/tie4.gif").getImage();
public static final Image IMG_warter = new ImageIcon("image/water.gif").getImage();
public static final Image IMG_grass = new ImageIcon("image/grass.gif").getImage();
public static final Image IMG_wall = new ImageIcon("image/walls.gif").getImage();
public static final Image IMG_smallwall = new ImageIcon("image/smallwalls.gif").getImage();
public static final Image IMG_PLAYER1 = new ImageIcon("image/player1.gif").getImage();
public static final Image IMG_PLAYER2 = new ImageIcon("image/player2.gif").getImage();
public static final Image IMG_PLAYER3 = new ImageIcon("image/player3.gif").getImage();
public static final Image IMG_PLAYER4 = new ImageIcon("image/player4.gif").getImage();
public static final Image IMG_home = new ImageIcon("image/symbol.gif").getImage();
public static final Image IMG_bullet = new ImageIcon("image/bullet.gif").getImage();
public static final Image IMG_over = new ImageIcon("image/gameOver.gif").getImage();
public static final Image IMG_win = new ImageIcon("image/gameWin.jpeg").getImage();
public static final Image IMG_hp = new ImageIcon("image/hp.png").getImage();
public static final Image IMG_speed = new ImageIcon("image/124.png").getImage();
public static final Image IMG_bomb = new ImageIcon("image/128.png").getImage();
public static final Image IMG_gia1 = new ImageIcon("image/i1.jpg").getImage();
public static final Image IMG_gia2 = new ImageIcon("image/i2.jpg").getImage();
public static final Image IMG_gia3 = new ImageIcon("image/i3.jpg").getImage();
//
public static ArrayList<Bullet> zdList = new ArrayList<Bullet>();
public static ArrayList<EnBullet> enzdList = new ArrayList<EnBullet>();
//
public static ArrayList<Enemy> enemyList = new ArrayList<Enemy>();
//
public static ArrayList<Enemy> backlist = new ArrayList<Enemy>();
//
public static ArrayList<Enemy> yellowcount = new ArrayList<Enemy>();
public static ArrayList<Enemy> bulecount = new ArrayList<Enemy>();
public static ArrayList<Enemy> pinkcount = new ArrayList<Enemy>();
//
public static ArrayList<stage> stagelList = new ArrayList<stage>();
public static void initenemy(int num) {
Random ran = new Random();
for (int i = 0; i < num; i++) {
int key = ran.nextInt(3);
Enemy en = null;
if (key == 0) {
en = new YellowEnemy(0, 0, 1, 0, 0,100);
yellowcount.add(en);
} else if (key == 1) {
en = new BuleEnemy(560, 0, 1, 0, 0,100);
bulecount.add(en);
} else {
en = new PinkEnemy(250, 0, 1, 0, 0,100);
pinkcount.add(en);
}
backlist.add(en);
}
}
}
2)게임 시작
public class StartAction implements ActionListener {
private GameFrame f;
private GameArea ga;
public StartAction(GameFrame f) {
super();
this.f = f;
}
public void actionPerformed(ActionEvent e) {
String startaction = e.getActionCommand();
if (startaction.equals("start")) {
String title = JOptionPane.showInputDialog(null, " ", " ", JOptionPane.PLAIN_MESSAGE);
Data.name = title;
Data.start = 1;
Data.initenemy(3);
f.getGm().getStartgame().setEnabled(false);
f.getGm().getRestart().setEnabled(true);
} else if (startaction.equals("restart")) {
Data.enemyList.clear();
Data.backlist.clear();
Data.yellowcount.clear();
Data.bulecount.clear();
Data.pinkcount.clear();
Data.stagelList.clear();
Data.player.setX(200);
Data.player.setY(560);
Data.initenemy(3);
Data.b = 0;
Player.setHP(3);
Data.isGameOver = true;
Data.isRestart =true;
} else if (startaction.equals("exit")) {
System.exit(0);
} else if (startaction.equals("game")) {
JOptionPane.showMessageDialog(null," W S A D ,J ,P ,O 。
: ---- ----- ---- !
!!!",
" !", JOptionPane.INFORMATION_MESSAGE);
} else if (startaction.equals("self")) {
new GameSelf();
}
}
}
3)감청 버튼 클래스
public class PlayerKeyListener extends KeyAdapter {
private Player player;
@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
int key = e.getKeyCode();
if (key == KeyEvent.VK_W) {
if (Data.pouse == 0 && Data.player.getY() > 0) {
Data.player.up();
Data.a = 1;
}
}
if (key == KeyEvent.VK_S) {
if (Data.pouse == 0 && Data.player.getY() < 560) {
Data.player.down();
Data.a = 2;
}
}
if (key == KeyEvent.VK_A) {
if (Data.pouse == 0 && Data.player.getX() > 0) {
Data.player.left();
Data.a = 3;
}
}
if (key == KeyEvent.VK_D) {
if (Data.pouse == 0 && Data.player.getX() < 560) {
Data.player.right();
Data.a = 4;
}
}
if (key == KeyEvent.VK_P) {
Data.pouse = 1;
}
if (key == KeyEvent.VK_O) {
Data.pouse = 0;
}
}
@Override
public void keyReleased(KeyEvent e) {
super.keyReleased(e);
int key = e.getKeyCode();
if (key == KeyEvent.VK_J) {
if (Data.pouse == 0 && Data.a == 1) {
int x = Data.player.getX() + 16;
int y = Data.player.getY() - 5;
Bullet bullet = new Bullet(x, y, Data.a);
Data.zdList.add(bullet);
return;
}
if (Data.pouse == 0 && Data.a == 2) {
int x = Data.player.getX() + 16;
int y = Data.player.getY() + 32;
Bullet bullet = new Bullet(x, y, Data.a);
Data.zdList.add(bullet);
return;
}
if (Data.pouse == 0 && Data.a == 3) {
int x = Data.player.getX() - 10;
int y = Data.player.getY() + 15;
Bullet bullet = new Bullet(x, y, Data.a);
Data.zdList.add(bullet);
return;
}
if (Data.pouse == 0 && Data.a == 4) {
int x = Data.player.getX() + 38;
int y = Data.player.getY() + 15;
Bullet bullet = new Bullet(x, y, Data.a);
Data.zdList.add(bullet);
return;
}
}
}
}
원본 다운로드:탱크 게임이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.