//package gameClient;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import java.io.RandomAccessFile;
import java.util.*;
import javax.swing.border.*;
import java.awt.geom.*;
class TankInfor //用于保存敌人的坦克信息,包括当前坐标和行进方向
{
int x;
int y;
int dir; //方向,1--向上,2--向下,3--向左,4--向右a
int bomb; //是否放炮,1--YES
public TankInfor(int x, int y, int dir, int bomb)
{
this.x = x;
this.y = y;
this.dir = dir;
this.bomb = bomb;
}
}
class BombInfor //用于保存炮弹信息;
{
int x;
int y;
int dir;
public BombInfor(int x, int y, int dir)
{
this.x = x;
this.y = y;
this.dir = dir;
}
}
class MyTank //用于保存自己坦克的资料
{
int x;
int y;
int dir;
int bombRemainder; //自己所剩炮弹数,初始为MYBOMBTOTAL=20,当炮弹用尽而还没有完全消灭敌人时为输
int daodanRemainder; //自己所剩导弹数,初始为MYPAODANTOTAL=1,///////////////
public MyTank(int x, int y, int dir, int bombRemainder)
{
this.x = x;
this.y = y;
this.dir = dir;
this.bombRemainder = bombRemainder;
this.daodanRemainder = daodanRemainder;
}
}
class DaodanInfor // 用来保存自己导弹的信息 //////////////////
{
int x;
int y;
int dir;
public DaodanInfor(int x, int y, int dir)
{
this.x = x;
this.y = y;
this.dir = dir;
}
}
class JiadanInfor //用于保存加弹信息; ////////////////////
{
int x;
int y;
public JiadanInfor(int x, int y )
{
this.x = x;
this.y = y;
}
}
class WallInfor //用来保存墙的信息
{
int xWall;
int yWall;
Rectangle wallBorder;
public WallInfor(int a, int b)
{
xWall = a;
yWall = b;
wallBorder = new Rectangle(xWall, yWall, 25, 25);
}
}
public class GameClient extends JApplet implements ActionListener,ItemListener
{
//this.setLocation(100,100);
String userName;
String userPass;
//ObjectOutputStream oos;
//ObjectInputStream ois;
JLabel lUser;
JTextField tfName;
JLabel lPass;
JPasswordField pfPass;
JLabel lser; ///加的
JComboBox cbser;
JLabel lFriend;
JTextField tfFriend;
JLabel lTank,lBackMusic,lBackGround; //单选按钮
Checkbox cbt1,cbt2,cbt3;
Checkbox cbm1, cbm2, cbm3, cbm4;
Checkbox cbg1, cbg2, cbg3, cbg4;
CheckboxGroup cg1, cg2, cg3;
JButton btLogin;
JButton btReset;
JButton btHelp;
JButton btSet;
JButton btDel;
JButton btRework;
JButton btQuit;
Button btStop;
JButton btBack;
JButton btAgain;
JLabel lbinfor;
Panel cbtPanel, cbmPanel, cbgPanel;
JPanel mPanel;
JScrollPane scrollPane;
AudioClip kaishi1, kaishi2,kaishi3,kaishi4, kaishi5;
AudioClip acBack;
AudioClip acExplode;
AudioClip acGun;
AudioClip gameover;
AudioClip Win;
AudioClip Care;
int paintStage=0;
final int TANKWIDTH = 25, TANKHEIGHT = 25; //敌人坦克的宽度和高度
final int GAMEX = 15, GAMEY = 15, GAMEWIDTH = 700, GAMEHEIGHT = 540;
final int MYTANKWIDTH=25, MYTANKHEIGHT=25; //我方坦克的宽度和高度
final int jiadanWIDTH=25, jiadanHEIGHT=25; //加弹的宽度和高度
final int WALLWIDTH=25, WALLHEIGHT=25; //墙到宽度和高度
final int DIRUP=1, DIRDOWN=2, DIRLEFT=3, DIRRIGHT=4;
final int MYBOMBTOTAL = 20;
final int MYDAODANTOTAL = 1;
Image tank1, tank2, tank3, tank4; //敌人的四个行进方向的坦克;
Image myTank1,myTank2,myTank3,myTank4; //自己的四个行进方向的坦克;
Image bomb; //炮弹图片
Image daodan; //导弹图片
Image tankExa; //大坦克图片
Image ku4,paizhang; //游戏gameover win 的图片
Image jiadan; //加弹
Image cs;
Image jiayou;
Image wall; //墙的图片
Image touxiang;
Image back1,back2,back3;
Vector tankGroup; //保存敌人的敌人的坦克信息
Vector bombGroup; //保存敌人打炮信息;
MyTank me; //自己的坦克信息
Vector myBomb; //自己打出去的炮弹;
Vector myDaodan; //自己打出去的导弹信息
Vector Jiadan; //加弹的信息;
Vector vWall; //用来保存墙的信息
int score = 0;
int level = 1;
int levelBack = 1;
int levelm;
int enemy = 3;
int life =3;
int x;
int y;
int n;
//int l=0;
int t=0; //一个变量,为的是不让在gameover的时候声音出不来
int sec=0; ///////////////////////////////////////// 时间
int I=0; //当你gameove 的时候是否真的gameover??
int m = 2; //这时设定有多少次机会
String messageFromServer = "gggggggggggg";
boolean gameOver = false; //你输了,
boolean victory = false; //你赢了,应该升级
boolean looping = false;
boolean save = false; // 登陆界面的是否救出所爱??
boolean CanBonb = false; //想用来判断可不可发弹
boolean BackGame = false; //返回游戏
boolean Ok = false;
boolean GameOver = false; //这是为了让坦克能动
public void init()
{
paintStage=0;
this.addKeyListener(new KeyHandler()); //键盘监听
this.requestFocus();
//建立需要的坦克图片
tank1 = this.getImage(this.getCodeBase(),"picture\\E25.jpg");
tank2 = this.getImage(this.getCodeBase(),"picture\\E26.jpg");
tank3 = this.getImage(this.getCodeBase(),"picture\\E27.jpg");
tank4 = this.getImage(this.getCodeBase(),"picture\\E28.jpg");
myTank1 = this.getImage(this.getCodeBase(),"picture\\My1.jpg");
myTank2 = this.getImage(this.getCodeBase(),"picture\\My2.jpg");
myTank3 = this.getImage(this.getCodeBase(),"picture\\My3.jpg");
myTank4 = this.getImage(this.getCodeBase(),"picture\\My4.jpg");
bomb = this.getImage(this.getCodeBase(),"picture\\bomb.jpg");
daodan = this.getImage(this.getCodeBase(),"picture\\daodan.jpg");
tankExa = this.getImage(this.getCodeBase(),"picture\\tanke.jpg");
touxiang = this.getImage(this.getCodeBase(),"picture\\tanke.jpg");
ku4 = this.getImage(this.getCodeBase(),"picture\\ku3.GIF");
paizhang = this.getImage(this.getCodeBase(),"picture\\paizhang.GIF");
jiadan = this.getImage(this.getCodeBase(),"picture\\jiadan.jpg");
cs = this.getImage(this.getCodeBase(),"picture\\cs.GIF");
jiayou = this.getImage(this.getCodeBase(),"picture\\jiayou.GIF");
wall = this.getImage(this.getCodeBase(),"picture\\Wall.jpg");
back1 = this.getImage(this.getCodeBase(),"picture\\back2.jpg");
//建立需要的各种声音
//kaishi1 = this.getAudioClip(this.getCodeBase(), "sound\\kaishi1.wav");
//kaishi2 = this.getAudioClip(this.getCodeBase(), "sound\\kaishi2.wav");
//kaishi3 = this.getAudioClip(this.getCodeBase(), "sound\\kaishi2.wav");
//kaishi4 = this.getAudioClip(this.getCodeBase(), "sound\\kaishi4.wav");
//kaishi5 = this.getAudioClip(this.getCodeBase(), "sound\\Xian009.wav");
acBack = this.getAudioClip(this.getCodeBase(), "sound\\kaishi1.wav");
acExplode = this.getAudioClip(this.getCodeBase(), "sound\\explode.au");
acGun = this.getAudioClip(this.getCodeBase(), "sound\\pgun.au");
gameover = this.getAudioClip(this.getCodeBase(), "sound\\gameover.wav");
Win = this.getAudioClip(this.getCodeBase(), "sound\\win.wav");
Care = this.getAudioClip(this.getCodeBase(), "sound\\care.wav");
//GameClient.this.setLocation(100,100);
//this.getContentPane().setLocation(100,100);
//以下为建立第一登录界面
mPanel = (JPanel)this.getContentPane();
mPanel.setLayout(null);
lUser = new JLabel("User :");
lUser.setBounds(10, 10, 50, 20);
tfName = new JTextField(10);
tfName.setText("gaizai");
tfName.setBounds(70, 10, 160, 20);
tfName.setForeground(Color.red);
tfName.setToolTipText("Input Your Name Here ");
lPass = new JLabel("Pass :");
lPass.setBounds(10, 40, 50, 20);
pfPass = new JPasswordField(10);
评论1