坦克java代码 java tank程序代码( 三 )


this.direct = direct;
}
public int getDirect() {
return direct;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int getSpeed() {
return speed;
}
// 子弹的上下左右以及走的速度
public void run() {
// TODO Auto-generated method stub
while (true) {
try {
Thread.sleep(100);
} catch (Exception e) {
}
switch (direct) {
case 0:
y -= speed;
break;
case 1:
y += speed;
break;
case 2:
x -= speed;
break;
case 3:
x += speed;
break;
}
if (x400 || x0 || y400 || y0) {
this.live = false;
break;
}
}
}
}
class Tank {
protected int x;
protected int y;
protected int speed = 5;
protected int direct;
protected int color;
boolean live;
public Tank(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public void setSDC(int speed, int direct, int color) {
this.speed = speed;
this.direct = direct;
this.color = color;
}
public int getSpeed() {
return speed;
}
public int getDirect() {
return direct;
}
public int getColor() {
return color;
}
}
class MyTank extends Tank {
public MyTank(int x, int y) {
// TODO Auto-generated method stub
super(x, y);
}
VectorShot shot = new VectorShot();
Shot shota = null;
public void shott() {
switch (this.direct) {
case 0:
shota = new Shot();
shota.x = x + 18;
shota.y = y;
shota.direct = 0;
shot.add(shota);
break;
case 1:
shota = new Shot();
shota.x = x + 18;
shota.y = y + 30;
shota.direct = 1;
shot.add(shota);
break;
case 2:
shota = new Shot();
shota.x = x + 3;
shota.y = y + 15;
shota.direct = 2;
shot.add(shota);
break;
case 3:
shota = new Shot();
shota.x = x + 33;
shota.y = y + 15;
shota.direct = 3;
shot.add(shota);
break;
}
Thread t = new Thread(shota);
t.start();
}
public void moveUp() {
if (y0) {
y -= speed;
}
}// 我的坦克得在自己的类里定义怎么移动
public void moveDown() {
if (y367) {
y += speed;
}
}
public void moveLeft() {
if (x0) {
x -= speed;
}
}
public void moveRight() {
if (x365) {
x += speed;
}
}
}
(100分)Java写“坦克大战”package com.bjsxt.tank;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* 这个类的作用是坦克游戏的主窗口
* @author mashibing
*
*/
public class TankClient extends Frame {
/**
* 整个坦克游戏的宽度
*/
public static final int GAME_WIDTH = 800;
public static final int GAME_HEIGHT = 600;
Tank myTank = new Tank(50, 50, true, Direction.STOP, this);
Wall w1 = new Wall(100, 200, 20, 150, this), w2 = new Wall(300, 100, 300, 20, this);
ListExplode explodes = new ArrayListExplode();
ListMissile missiles = new ArrayListMissile();
ListTank tanks = new ArrayListTank();
Image offScreenImage = null;
Blood b = new Blood();
public void paint(Graphics g) {

推荐阅读