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) {
推荐阅读
- chatgpt可以赚钱吗,chat币团队
- 苹果cms分类筛选页数,苹果cms首页按最新排序
- 关于postgresql客户端连接数据库失败的信息
- 搭建网盘服务器,建立网盘服务器
- 四则运算代码java 四则运算java编程
- 网易python数据分析师下载,python数据分析网站
- 2020年赛车游戏带链接,2020 赛车游戏
- 手机音频通话怎么收费的,手机语音通话收费标准
- java音乐识别代码 java编写音乐类