java小游戏源码_分享几款java小游戏源码

一:坦克大战

源码import java.util.ArrayList;

import java.awt.*;

import java.awt.event.*;

import java.util.List;

import javax.swing.JOptionPane;

public class TankClient extends Frame implements ActionListener {

/**

*

*/

private static final long serialVersionUID = 1L;

public static final int Fram_width = 800; //

public static final int Fram_length = 600;

public static boolean printable = true;

MenuBar jmb = null;

Menu jm1 = null, jm2 = null, jm3 = null, jm4 = null;

MenuItem jmi1 = null, jmi2 = null, jmi3 = null, jmi4 = null, jmi5 = null,

jmi6 = null, jmi7 = null, jmi8 = null, jmi9 = null;

Image screenImage = null;

Tank homeTank = new Tank(300, 560, true, Direction.STOP, this);//

GetBlood blood = new GetBlood();

Home home = new Home(373, 545, this);

List theRiver = new ArrayList();

List tanks = new ArrayList();

List bombTanks = new ArrayList();

List bullets = new ArrayList();

List trees = new ArrayList();

List homeWall = new ArrayList();

List otherWall = new ArrayList();

List metalWall = new ArrayList();

public void update(Graphics g) {

screenImage = this.createImage(Fram_width, Fram_length);

Graphics gps = screenImage.getGraphics();

Color c = gps.getColor();

gps.setColor(Color.GRAY);

gps.fillRect(0, 0, Fram_width, Fram_length);

gps.setColor(c);

framPaint(gps);

g.drawImage(screenImage, 0, 0, null);

}

public void framPaint(Graphics g) {

Color c = g.getColor();

g.setColor(Color.green);

Font f1 = g.getFont();

g.setFont(new Font("TimesRoman", Font.BOLD, 20));

g.drawString("最高分: ", 200, 70);

g.setFont(new Font("TimesRoman", Font.ITALIC, 30));

g.drawString("" + tanks.size(), 400, 70);

g.setFont(new Font("TimesRoman", Font.BOLD, 20));

g.drawString("得分ֵ: ", 500, 70);

g.setFont(new Font("TimesRoman", Font.ITALIC, 30));

g.drawString("" + homeTank.getLife(), 650, 70);

g.setFont(f1);

if (tanks.size() == 0 && home.isLive() && homeTank.isLive()) {

Font f = g.getFont();

g.setFont(new Font("TimesRoman", Font.BOLD, 60));

this.otherWall.clear();

g.drawString(" ", 310, 300);

g.setFont(f);

}

if (homeTank.isLive() == false) {

Font f = g.getFont();

g.setFont(new Font("TimesRoman", Font.BOLD, 40));

tanks.clear();

bullets.clear();

g.setFont(f);

}

g.setColor(c);

for (int i = 0; i < theRiver.size(); i++) {

River r = theRiver.get(i);

r.draw(g);

}

for (int i = 0; i < theRiver.size(); i++) {

River r = theRiver.get(i);

homeTank.collideRiver(r);

r.draw(g);

}

home.draw(g);

homeTank.draw(g);

homeTank.eat(blood);

for (int i = 0; i < bullets.size(); i++) {

Bullets m = bullets.get(i);

m.hitTanks(tanks);

m.hitTank(homeTank);

版权属于:逍遥子大表哥

按照知识共享署名-非商业性使用 4.0 国际协议进行许可,转载引用文章应遵循相同协议。

你可能感兴趣的:(java小游戏源码)