坦克大战游戏源代码-java源代码-J2SE
这个是java学习中的J2SE实训项目,是在2008年6月份的了。坦克大战游戏源代码-java源代码-J2SE
这个是完全的源代码,能够直接运行,但是需要那些图片,音频等文件,才能够形成一个真正的游戏,至于什么图片,可以参照我的那个实训报告书中的截图,大概了解到,并且可以按照一定的大小,然后收集那些图片。如果您需要的话,可以联系我,说明来意,如果我的硬盘没有换掉的话,都会发给一个完整的源代码和相关联的文件给你的。
以下就是坦克大战的源代码,J2SE:
package KCTankGamePak;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import TankPak.*;
public class GamePlayer extends JApplet implements ActionListener
{
JLabel label_GameWelcomeInfo;
JLabel label_User;
JLabel label_Password;
JTextField text_User;
JPasswordField secretText_Password;
JButton button_Login;
JButton button_Reset;
JPanel main_Panel;
// boolean trueOrFalse = false;
int paint_WhichScreen = 0; // 0=paint_WelcomeScreen
String user_name;
String user_password;
//==============================================
final int myTank_Width = 40, myTank_Heigth = 40;
final int enemyTank_Width = 40, enemyTank_Heigth = 40;
final int gameArea_BeginX = 10, gameArea_BeginY = 10;
final int gameArea_EndX = 590, gameArea_EndY = 590;
final int obstacle_1_BeginX = 90, obstacle_1_EndX = 370;
final int obstacle_1_BeginY = 375, obstacle_1_EndY = 415;
final int obstacle_2_BeginX = 210, obstacle_2_EndX = 490;
final int obstacle_2_BeginY = 90, obstacle_2_EndY = 170;
//final int enemyTank_BeginX = 40, enemyTank_BeginY = 20;
final int mainGame_Width = 900, mainGame_Heigth = 600;
final int dir_UP = 0, dir_DOWN = 1, dir_LEFT = 2, dir_RIGHT = 3;
int myBomb_WeightBallNumber = 100;
int myBomb_NuclearBombNumber = 10;
int myBomb_FinalHoleBombNumber = 5;
int[] enemyMoveCtrlArray;
boolean burst = false;
int playerID;
Image BackGroud_Pic;
Image gameScreenTankWar_pic_Weight_Name, gameScreenTankWar_pic_1;
Image mainGameScreen_pic_BackGroud;
Image myTank_Pic_UP_1, myTank_Pic_DOWN_1, myTank_Pic_LEFT_1, myTank_Pic_RIGHT_1;
Image myBomb_Pic_UP_1, myBomb_Pic_DOWN_1, myBomb_Pic_LEFT_1, myBomb_Pic_RIGHT_1; //重武器
Image myBomb_Pic_UP_2, myBomb_Pic_DOWN_2, myBomb_Pic_LEFT_2, myBomb_Pic_RIGHT_2; //核弹
Image myBomb_Pic_UP_3, myBomb_Pic_DOWN_3, myBomb_Pic_LEFT_3, myBomb_Pic_RIGHT_3; //终极黑洞
Image weightBombShow, FinalHoleBombShow, weightBombEat;
Image enemyTank_Pic_UP_1, enemyTank_Pic_DOWN_1, enemyTank_Pic_LEFT_1, enemyTank_Pic_RIGHT_1;
Image enemyTank_Pic_Burst;
Image enemyBomb_Pic_UP_1, enemyBomb_Pic_DOWN_1, enemyBomb_Pic_LEFT_1, enemyBomb_Pic_RIGHT_1;
AudioClip audio_BackGroud;
AudioClip audio_MyBomb;
AudioClip audio_enemyExplode;
AudioClip audio_EnemyBomb;
AudioClip audio_Collide;
Vector enemyTank_GroupInfo; //enemy
Vector enemyBomb_GroupInfo;
MyTank_classInfo myTank; //mine
Vector myBomb_GroupInfo;
Vector encourageWeapon_GroupInfo;
int game_Score = 0;
int game_Level = 1;
float myTank_Gas_Remain = 246;
int myTank_Damage_Degree = 246;
boolean gameReallyOver = false;
boolean game_victory = false;
boolean eatThePrice;
//public void init(){
// TankGamePlayerLogin tgpm = new TankGamePlayerLogin();
// tgpm.playerLoginPanel();
// }
//==============================================
public void init()
{
// TankGamePlayerLogin tgpm = new TankGamePlayerLogin();
// tgpm.playerLoginPanel();
//8888888888888888888888888888888888888888888888888888
main_Panel = (JPanel) this.getContentPane();
main_Panel.setBackground(Color.white);
main_Panel.setLayout(null);
//if(!trueOrFalse){
label_GameWelcomeInfo = new JLabel("WelCome to Tank Game");
//label_GameWelcomeInfo
label_GameWelcomeInfo.setFont(new Font("宋体", Font.BOLD, 50));
label_GameWelcomeInfo.setForeground(Color.red);
label_GameWelcomeInfo.setBounds(150, 120, 600, 50);
label_User = new JLabel("User Identy:");
label_Password = new JLabel("User Password:");
secretText_Password = new JPasswordField(10);
text_User = new JTextField(10);
label_User.setBounds(250, 250, 120, 30);
label_Password.setBounds(250, 300, 120, 30);
text_User.setBounds(350, 250, 160, 30);
secretText_Password.setBounds(350, 300, 160, 30);
button_Login = new JButton("Login");
button_Reset = new JButton("Reset");
button_Login.setBounds(250, 350, 100, 30);
button_Reset.setBounds(400, 350, 100, 30);
button_Login.addActionListener(this); ///////////////////////////
button_Reset.addActionListener(this);
/*}
if(!trueOrFalse){
mainGameStart();
dealWithData_RandomTank_Thread random_TankThread =
new dealWithData_RandomTank_Thread();
random_TankThread.start(); //Main Game really Start
}
System.out.println(trueOrFalse);
*/
main_Panel.add(label_GameWelcomeInfo);
main_Panel.add(label_User);
main_Panel.add(label_Password);
main_Panel.add(text_User);
main_Panel.add(secretText_Password);
main_Panel.add(button_Login);
main_Panel.add(button_Reset);
//======================================
BackGroud_Pic = this.getImage(this.getCodeBase(), "BackGroud_Pic.jpg");
gameScreenTankWar_pic_Weight_Name = this.getImage(this.getCodeBase(), "gameScreenTankWar_pic_Weight_Name.jpg");
gameScreenTankWar_pic_1 = this.getImage(this.getCodeBase(), "gameScreenTankWar_pic_1.jpg");
mainGameScreen_pic_BackGroud = this.getImage(this.getCodeBase(), "mainGameScreen_pic_BackGroud.jpg");
//mainTankPIC = this.getImage(this.getCodeBase(),"tank12.jpg");
enemyMoveCtrlArray = new int[120];
int[] enemyMoveCtrlArray = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
//EnemyTank and MyTank PIC
myTank_Pic_UP_1 = this.getImage(this.getCodeBase(), "myTank_Pic_UP_1.jpg");
myTank_Pic_DOWN_1 = this.getImage(this.getCodeBase(), "myTank_Pic_DOWN_1.jpg");
myTank_Pic_LEFT_1 = this.getImage(this.getCodeBase(), "myTank_Pic_LEFT_1.jpg");
myTank_Pic_RIGHT_1 = this.getImage(this.getCodeBase(), "myTank_Pic_RIGHT_1.jpg");
myBomb_Pic_UP_1 = this.getImage(this.getCodeBase(), "myBomb_Pic_UP_1.jpg"); //myBomb
myBomb_Pic_DOWN_1 = this.getImage(this.getCodeBase(), "myBomb_Pic_DOWN_1.jpg");
myBomb_Pic_LEFT_1 = this.getImage(this.getCodeBase(), "myBomb_Pic_LEFT_1.jpg");
myBomb_Pic_RIGHT_1 = this.getImage(this.getCodeBase(), "myBomb_Pic_RIGHT_1.jpg");
myBomb_Pic_UP_2 = this.getImage(this.getCodeBase(), "myBomb_Pic_UP_2.jpg"); // my Bomb__2 Bomb
myBomb_Pic_DOWN_2 = this.getImage(this.getCodeBase(), "myBomb_Pic_DOWN_2.jpg");
myBomb_Pic_LEFT_2 = this.getImage(this.getCodeBase(), "myBomb_Pic_LEFT_2.jpg");
myBomb_Pic_RIGHT_2 = this.getImage(this.getCodeBase(), "myBomb_Pic_RIGHT_2.jpg");
weightBombShow = this.getImage(this.getCodeBase(), "weightBombShow.jpg");
FinalHoleBombShow = this.getImage(this.getCodeBase(), "FinalHoleBombShow.jpg");
weightBombEat = this.getImage(this.getCodeBase(), "weightBombEat.jpg");
enemyTank_Pic_UP_1 = this.getImage(this.getCodeBase(), "enemyTank_Pic_UP_1.jpg");
enemyTank_Pic_DOWN_1 = this.getImage(this.getCodeBase(), "enemyTank_Pic_DOWN_1.jpg");
enemyTank_Pic_LEFT_1 = this.getImage(this.getCodeBase(), "enemyTank_Pic_LEFT_1.jpg");
enemyTank_Pic_RIGHT_1 = this.getImage(this.getCodeBase(), "enemyTank_Pic_RIGHT_1.jpg");
enemyTank_Pic_Burst = this.getImage(this.getCodeBase(), "enemyTank_Pic_.jpg"); //enemy Tank Bourst
enemyBomb_Pic_UP_1 = this.getImage(this.getCodeBase(), "enemyBomb_Pic_UP_1.jpg"); // enemy Bomb
enemyBomb_Pic_DOWN_1 = this.getImage(this.getCodeBase(), "enemyBomb_Pic_DOWN_1.jpg");
enemyBomb_Pic_LEFT_1 = this.getImage(this.getCodeBase(), "enemyBomb_Pic_LEFT_1.jpg");
enemyBomb_Pic_RIGHT_1 = this.getImage(this.getCodeBase(), "enemyBomb_Pic_RIGHT_1.jpg");
audio_BackGroud = this.getAudioClip(this.getCodeBase(), "audio_BackGroud.au");
audio_MyBomb = this.getAudioClip(this.getCodeBase(), "audio_MyBomb.au");
audio_enemyExplode = this.getAudioClip(this.getCodeBase(), "audio_enemyExplode.au");
audio_EnemyBomb = this.getAudioClip(this.getCodeBase(), "audio_EnemyBomb.au");
audio_Collide = this.getAudioClip(this.getCodeBase(), "audio_Collide.au");
myTank = new MyTank_classInfo(270, 550, 0);
enemyTank_GroupInfo = new Vector(8); //
enemyTank_GroupInfo.addElement(new EnemyTank_classInfo(50, 50, 1, 0, 5000));
enemyTank_GroupInfo.addElement(new EnemyTank_classInfo(150, 50, 1, 0, 5000));
enemyTank_GroupInfo.addElement(new EnemyTank_classInfo(300, 50, 1, 0, 5000));
enemyTank_GroupInfo.addElement(new EnemyTank_classInfo(450, 50, 1, 0, 5000));
myBomb_GroupInfo = new Vector(10);
enemyBomb_GroupInfo = new Vector(10);
encourageWeapon_GroupInfo = new Vector(10);
} //function init() over
public void start()
{
audio_BackGroud.loop();
}
public void stop()
{
audio_BackGroud.stop();
}
public void update(Graphics grap)
{
//for(int i = 0; i<5 ; i++)
//System.out.println("===== " + " update sucessfull !!! ");
paintIMG(grap);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button_Login)
{
System.out.println("Login sucessfull !!! ");
/* user_name = text_User.getText();
if(text_User.getText().length() == 0)
{
user_name = new String("Administrator");
}
//try
*/ //888888888888888888888888888888888888888888888888888888888888
//JTextField text_User;
// charsecretText_Password
String sUser = text_User.getText();
char[] inputPass = secretText_Password.getPassword();
secretText_Password.setText("");
if(sUser.length() == 0) JOptionPane.showMessageDialog(this, "请您输入用户保后再登陆!");
else
{
if(inputPass.length == 0)
{
JOptionPane.showMessageDialog(this, "请您输入密码后再登陆!", "温馨提示", JOptionPane.WARNING_MESSAGE);
secretText_Password.grabFocus(); //若密码框没有输入,即密码框取得焦点,便于管理用户输入
}
else
{
StringBuffer inputpass = new StringBuffer();
for(int i = 0; i < inputPass.length; i++)
{
inputpass.append(inputPass[i]);
}
String inputpass2 = new String(inputpass);
for(int i = 0; i < inputPass.length; i++)
{
inputPass[i] = 0;
}
connectDatabase conData = new connectDatabase();
playerID = conData.validateUsernameAndPass(sUser, inputpass2, 1);
user_name = sUser;
System.out.println(playerID);
if(playerID == 0)
{
return;
}
mainGameStart();
dealWithData_RandomTank_Thread random_TankThread = new dealWithData_RandomTank_Thread();
random_TankThread.start(); //Main Game really Start
}
}
// TankGamePlayerLogin tgpm = new TankGamePlayerLogin();
// boolean i = tgpm.playerLoginPanel();
//return;
// if(i ){
}
// }
else if(e.getSource() == button_Reset)
{
System.out.println("Reset sucessfull !!! ");
}
else
{
System.out.println("Error !!! ");
}
}
public void mainGameStart()
{
main_Panel.removeAll();
paint_WhichScreen = 1;
this.addKeyListener(new KeyHandler());
this.dispatchEvent(new FocusEvent(this, FocusEvent.FOCUS_GAINED, true));
this.requestFocusInWindow(); //得到焦点,监听键盘
this.resize(900, 600);
this.repaint();
}
class KeyHandler extends KeyAdapter
{
public void keyPressed(KeyEvent ke)
{
switch(ke.getKeyCode())
{
case KeyEvent.VK_UP:
myTank.dir = dir_UP;
myTank.y -= 11;
if(myTank.y < gameArea_BeginY)
{
myTank.y = gameArea_BeginY;
}
if(myTank.y < obstacle_1_EndY && myTank.y > obstacle_1_BeginY && myTank.x < obstacle_1_EndX && myTank.x > obstacle_1_BeginX - myTank_Width)
{
myTank.y = obstacle_1_EndY;
}
if(myTank.y < obstacle_2_EndY && myTank.y > obstacle_2_BeginY && myTank.x < obstacle_2_EndX && myTank.x > obstacle_2_BeginX - myTank_Width)
{
myTank.y = obstacle_2_EndY;
}
break;
case KeyEvent.VK_DOWN:
myTank.dir = dir_DOWN;
myTank.y += 11;
if(myTank.y > gameArea_EndY - myTank_Heigth)
{
myTank.y = gameArea_EndY - myTank_Heigth;
}
if(myTank.y > obstacle_1_BeginY - myTank_Heigth && myTank.y < obstacle_1_EndY && myTank.x < obstacle_1_EndX && myTank.x > obstacle_1_BeginX - myTank_Width)
{
myTank.y = obstacle_1_BeginY - myTank_Heigth;
}
if(myTank.y > obstacle_2_BeginY - myTank_Heigth && myTank.y < obstacle_2_EndY && myTank.x < obstacle_2_EndX && myTank.x > obstacle_2_BeginX - myTank_Width)
{
myTank.y = obstacle_2_BeginY - myTank_Heigth;
}
break;
case KeyEvent.VK_LEFT:
myTank.dir = dir_LEFT;
myTank.x -= 11;
if(myTank.x < gameArea_BeginX)
{
myTank.x = gameArea_BeginX;
}
if(myTank.x < obstacle_1_EndX && myTank.x > obstacle_1_BeginX && myTank.y > obstacle_1_BeginY - myTank_Heigth && myTank.y < obstacle_1_EndY)
{
myTank.x = obstacle_1_EndX;
}
if(myTank.x < obstacle_2_EndX && myTank.x > obstacle_2_BeginX && myTank.y > obstacle_2_BeginY - myTank_Heigth && myTank.y < obstacle_2_EndY)
{
myTank.x = obstacle_2_EndX;
}
break;
case KeyEvent.VK_RIGHT:
myTank.dir = dir_RIGHT;
myTank.x += 11;
if(myTank.x > gameArea_EndX - myTank_Width)
{
myTank.x = gameArea_EndX - myTank_Width;
}
if(myTank.x > obstacle_1_BeginX - myTank_Width && myTank.x < obstacle_1_EndX && myTank.y > obstacle_1_BeginY - myTank_Heigth && myTank.y < obstacle_1_EndY)
{
myTank.x = obstacle_1_BeginX - myTank_Width;
}
if(myTank.x > obstacle_2_BeginX - myTank_Width && myTank.x < obstacle_2_EndX && myTank.y > obstacle_2_BeginY - myTank_Heigth && myTank.y < obstacle_2_EndY)
{
myTank.x = obstacle_2_BeginX - myTank_Width;
}
break;
case KeyEvent.VK_S:
if(myBomb_NuclearBombNumber > 0)
{
myBomb_GroupInfo.addElement(new AllBomb_classInfo(myTank.x, myTank.y, myTank.dir, 2));
myBomb_NuclearBombNumber--;
}
break;
case KeyEvent.VK_O:
if(myBomb_FinalHoleBombNumber > 0)
{
myBomb_GroupInfo.addElement(new AllBomb_classInfo(myTank.x, myTank.y, myTank.dir, 3));
myBomb_FinalHoleBombNumber--;
}
break;
default:
if(myBomb_WeightBallNumber > 0)
{
audio_MyBomb.play();
myBomb_GroupInfo.addElement(new AllBomb_classInfo(myTank.x, myTank.y, myTank.dir, 1));
myBomb_WeightBallNumber--;
}
else
{
gameReallyOver = false;
}
break;
}
}
}
public void paintIMG(Graphics grap)
{ //paintMainScreen
//System.out.println("========== REDO ----paint sucessfull !!! ");
if(paint_WhichScreen == 0)
{
main_Panel.repaint();
label_GameWelcomeInfo.repaint();
label_User.repaint();
label_Password.repaint();
text_User.repaint();
secretText_Password.repaint();
button_Login.repaint();
button_Reset.repaint();
}
else
{ // if(paint_WhichScreen == 1){
Image mainScreen = this.createImage(this.getWidth(), this.getHeight());
Graphics gpOBJ = mainScreen.getGraphics();
gpOBJ.setColor(Color.gray);
gpOBJ.fillRect(getX(), getY(), getWidth(), getHeight());
gpOBJ.drawImage(BackGroud_Pic, 1, 1, this);
gpOBJ.setColor(Color.YELLOW);
gpOBJ.fillRect(5, 5, 590, 590);
//gpOBJ.setColor(Color.GREEN);
//gpOBJ.fillRect(10, 10, 580, 580); //gameArea = 580*580
gpOBJ.drawImage(mainGameScreen_pic_BackGroud, 10, 10, this);
//System.out.println("========== DDDDDDDDDDDDDDDD DRAW !!! ");
//海水----不可以通过
//gpOBJ.setColor(Color.blue);
//gpOBJ.fillRect(100,100,40,200);
// 障碍物
/*gpOBJ.setColor(Color.PINK);
gpOBJ.fillRect(100,100,40,200);
gpOBJ.setColor(Color.darkGray);
gpOBJ.fillRect(400,100,40,200);
gpOBJ.setColor(Color.magenta);
gpOBJ.fillRect(200,100,200,40);*/
if(game_victory)
{
drawWinGameInfo(gpOBJ);
}
draw_AllTank(gpOBJ);
draw_AllBomb(gpOBJ);
//System.out.println("========== DDDDDDDDDDDDDDDD DRAW ! over!! ");
gpOBJ.drawImage(gameScreenTankWar_pic_Weight_Name, 610, 10, this);
gpOBJ.drawImage(gameScreenTankWar_pic_1, 720, 520, this);
gpOBJ.setFont(new Font("楷体", Font.BOLD, 20)); //
gpOBJ.setColor(Color.green);
gpOBJ.drawString("剩余炸弹数量:", 600, 180);
gpOBJ.setFont(new Font("楷体", Font.BOLD, 40)); //
gpOBJ.setColor(Color.red);
gpOBJ.drawString("" + myBomb_WeightBallNumber, 670, 220);
gpOBJ.setFont(new Font("楷体", Font.BOLD, 20)); //
gpOBJ.setColor(Color.green);
gpOBJ.drawString("剩余原子核弹头:" + myBomb_NuclearBombNumber, 600, 260);
for(int bn = 0; bn < myBomb_NuclearBombNumber; bn++)
{
gpOBJ.drawImage(weightBombShow, 600 + bn * 20, 270, this);
}
gpOBJ.setFont(new Font("楷体", Font.BOLD, 20)); //
//gpOBJ.setColor(Color.red);
gpOBJ.drawString("黑洞弹头:", 600, 380);
for(int bn = 0; bn < myBomb_FinalHoleBombNumber; bn++)
{
gpOBJ.drawImage(FinalHoleBombShow, 700 + bn * 30, 360, this);
}
gpOBJ.setFont(new Font("楷体", Font.BOLD, 18)); //
gpOBJ.setColor(Color.red);
gpOBJ.drawString("剩余汽油: " + (int) myTank_Gas_Remain, 610, 420);
gpOBJ.setColor(Color.BLUE);
gpOBJ.fillRect(610, 423, 250, 14);
gpOBJ.setColor(Color.red);
gpOBJ.fillRect(612, 425, (int) myTank_Gas_Remain, 10);
gpOBJ.setFont(new Font("楷体", Font.BOLD, 18)); //
gpOBJ.setColor(Color.red);
gpOBJ.drawString("坦克寿命: " + myTank_Damage_Degree, 610, 460);
gpOBJ.setColor(Color.YELLOW);
gpOBJ.fillRect(610, 463, 250, 20);
gpOBJ.setColor(Color.red);
gpOBJ.fillRect(612, 465, myTank_Damage_Degree, 16);
gpOBJ.setFont(new Font("宋体", Font.BOLD, 16)); //
gpOBJ.setColor(Color.ORANGE);
gpOBJ.drawString("用户名: " + user_name, 600, 520);
gpOBJ.drawString("得 分: " + game_Score, 600, 540);
gpOBJ.drawString("等 级: " + game_Level, 600, 560); //
gpOBJ.setColor(Color.GREEN);
if(game_Score < 100)
{
gpOBJ.drawString("军 衔: " + "列兵", 600, 580); //
}
if(game_Score >= 100 && game_Score <= 200)
{
gpOBJ.drawString("军 衔: " + "三等兵", 600, 580); //
}
if(game_Score >= 200 && game_Score < 300)
{
gpOBJ.drawString("军 衔: " + "二等兵", 600, 580); //
}
if(game_Score >= 300 && game_Score < 500)
{
gpOBJ.drawString("军 衔: " + "一等兵", 600, 580); //
}
if(game_Score >= 500 && game_Score < 800)
{
gpOBJ.drawString("军 衔: " + "下士", 600, 580); //
}
else if(game_Score >= 800 && game_Score < 1000)
{
gpOBJ.drawString("军 衔: " + "上士", 600, 580); //
}
else if(game_Score >= 1000 && game_Score < 2000)
{
gpOBJ.drawString("军 衔: " + "下尉", 600, 580); //
}
else if(game_Score >= 2000 && game_Score < 3000)
{
gpOBJ.drawString("军 衔: " + "下校", 600, 580); //
}
else if(game_Score >= 3000 && game_Score < 5000)
{
gpOBJ.drawString("军 衔: " + "中校", 600, 580); //
}
else if(game_Score >= 5000 && game_Score < 8000)
{
gpOBJ.drawString("军 衔: " + "大校", 600, 580); //
}
else if(game_Score >= 8000 && game_Score < 15000)
{
gpOBJ.drawString("军 衔: " + "准将", 600, 580); //
}
else if(game_Score >= 15000 && game_Score < 25000)
{
gpOBJ.drawString("军 衔: " + "少将", 600, 580); //
}
else if(game_Score >= 25000 && game_Score < 60000)
{
gpOBJ.drawString("军 衔: " + "中将", 600, 580); //
}
else if(game_Score >= 60000)
{
gpOBJ.drawString("军 衔: " + "大将", 600, 580); //
}
if(gameReallyOver)
{
gpOBJ.setFont(new Font("楷体", Font.BOLD, 60));
gpOBJ.setColor(Color.red);
gpOBJ.drawString("== Game 0ver ==", 50, 280);
}
grap.drawImage(mainScreen, 0, 0, this);
}
}
public void draw_AllTank(Graphics gp)
{
for(int i = 0; i < enemyTank_GroupInfo.size(); i++)
{ //画敌人的坦克
EnemyTank_classInfo enemyOBJ = (EnemyTank_classInfo) enemyTank_GroupInfo.elementAt(i);
if(enemyOBJ.life == 5000)
{
switch(enemyOBJ.dir)
{
case dir_UP:
gp.drawImage(enemyTank_Pic_UP_1, enemyOBJ.x, enemyOBJ.y, this); //enemy_BombInfoOBJ.x
break;
case dir_DOWN:
gp.drawImage(enemyTank_Pic_DOWN_1, enemyOBJ.x, enemyOBJ.y, this);
break;
case dir_LEFT:
gp.drawImage(enemyTank_Pic_LEFT_1, enemyOBJ.x, enemyOBJ.y, this);
break;
case dir_RIGHT:
gp.drawImage(enemyTank_Pic_RIGHT_1, enemyOBJ.x, enemyOBJ.y, this);
break;
default:
break;
}
}
else if(enemyOBJ.life == 0)
{
gp.drawImage(enemyTank_Pic_Burst, enemyOBJ.x, enemyOBJ.y, this); //enemy_BombInfoOBJ.x
System.out.println("BBBBBBB.......BURST");
//enemyTank_GroupInfo.removeElement(enemyOBJ);
}
//gp.drawImage(enemyTank_Pic_Burst, enemyOBJ.x, enemyOBJ.y, this);
}
switch(myTank.dir)
{ //画我的坦克
case dir_UP:
gp.drawImage(myTank_Pic_UP_1, myTank.x, myTank.y, this);
break;
case dir_DOWN:
gp.drawImage(myTank_Pic_DOWN_1, myTank.x, myTank.y, this);
break;
case dir_LEFT:
gp.drawImage(myTank_Pic_LEFT_1, myTank.x, myTank.y, this);
break;
case dir_RIGHT:
gp.drawImage(myTank_Pic_RIGHT_1, myTank.x, myTank.y, this);
break;
default:
break;
}
//gp.drawImage(mainTankPIC,100, 100,this);
//repaint();
}
public void draw_AllBomb(Graphics gp)
{
for(int i = 0; i < myBomb_GroupInfo.size(); i++)
{
AllBomb_classInfo mybomb = (AllBomb_classInfo) myBomb_GroupInfo.elementAt(i);
if(mybomb.bombKinds == 1)
{
switch(mybomb.dir)
{
case dir_UP:
if(mybomb.y >= 20)
{
gp.drawImage(myBomb_Pic_UP_1, mybomb.x + 18, mybomb.y + 18, this);
}
else if(mybomb.y < 20)
{
gp.drawImage(myBomb_Pic_UP_1, mybomb.x + 18, mybomb.y, this);
}
break;
case dir_DOWN:
if(mybomb.y <= 590)
{
gp.drawImage(myBomb_Pic_DOWN_1, mybomb.x + 18, mybomb.y + 18, this);
}
break;
case dir_LEFT:
if(mybomb.x >= 20)
{
gp.drawImage(myBomb_Pic_LEFT_1, mybomb.x + 18, mybomb.y + 18, this);
}
else if(mybomb.x < 20)
{
gp.drawImage(myBomb_Pic_LEFT_1, mybomb.x, mybomb.y + 18, this);
}
break;
case dir_RIGHT:
if(mybomb.x <= 590)
{
gp.drawImage(myBomb_Pic_RIGHT_1, mybomb.x, mybomb.y + 18, this);
}
break;
}
}
else if(mybomb.bombKinds == 2)
{
switch(mybomb.dir)
{
case dir_UP:
if(mybomb.y >= 20)
{
gp.drawImage(myBomb_Pic_UP_2, mybomb.x + 18, mybomb.y + 18, this);
}
else if(mybomb.y < 20)
{
gp.drawImage(myBomb_Pic_UP_2, mybomb.x + 18, mybomb.y, this);
}
break;
case dir_DOWN:
if(mybomb.y <= 590)
{
gp.drawImage(myBomb_Pic_DOWN_2, mybomb.x + 18, mybomb.y + 18, this);
}
break;
case dir_LEFT:
if(mybomb.x >= 20)
{
gp.drawImage(myBomb_Pic_LEFT_2, mybomb.x + 18, mybomb.y + 18, this);
}
else if(mybomb.x < 20)
{
gp.drawImage(myBomb_Pic_LEFT_2, mybomb.x, mybomb.y + 18, this);
}
break;
case dir_RIGHT:
if(mybomb.x <= 590)
{
gp.drawImage(myBomb_Pic_RIGHT_2, mybomb.x, mybomb.y + 18, this);
}
break;
}
}
}
for(int i = 0; i < enemyBomb_GroupInfo.size(); i++)
{
AllBomb_classInfo enemybomb = (AllBomb_classInfo) enemyBomb_GroupInfo.elementAt(i);
switch(enemybomb.dir)
{
case dir_UP:
if(enemybomb.y >= 20)
{
gp.drawImage(enemyBomb_Pic_UP_1, enemybomb.x + 20, enemybomb.y + 20, this);
}
else if(enemybomb.y < 20)
{
gp.drawImage(enemyBomb_Pic_UP_1, enemybomb.x + 20, enemybomb.y, this);
}
break;
case dir_DOWN:
if(enemybomb.y < 570)
{
gp.drawImage(enemyBomb_Pic_DOWN_1, enemybomb.x + 20, enemybomb.y + 20, this);
}
break;
case dir_LEFT:
if(enemybomb.x >= 20)
{
gp.drawImage(enemyBomb_Pic_LEFT_1, enemybomb.x + 20, enemybomb.y + 20, this);
}
else if(enemybomb.x < 20)
{
gp.drawImage(enemyBomb_Pic_LEFT_1, enemybomb.x, enemybomb.y + 20, this);
}
break;
case dir_RIGHT:
if(enemybomb.x < 570)
{
gp.drawImage(enemyBomb_Pic_RIGHT_1, enemybomb.x + 20, enemybomb.y + 20, this);
}
break;
default:
break;
}
}
for(int i = 0; i < encourageWeapon_GroupInfo.size(); i++)
{
EncourageWeapon_classInfo ecw = (EncourageWeapon_classInfo) encourageWeapon_GroupInfo.elementAt(i);
switch(ecw.dir)
{
case dir_UP:
gp.drawImage(weightBombEat, ecw.x, ecw.y, this);
break;
case dir_DOWN:
gp.drawImage(weightBombEat, ecw.x, ecw.y, this);
break;
case dir_LEFT:
gp.drawImage(weightBombEat, ecw.x, ecw.y, this);
break;
case dir_RIGHT:
gp.drawImage(weightBombEat, ecw.x, ecw.y, this);
break;
default:
break;
}
}
//weightBombEat
}
public void drawWinGameInfo(Graphics gp)
{
gp.setColor(Color.red);
gp.fillRect(150, 100, 280, 350);
gp.setColor(Color.black);
gp.setFont(new Font("宋体", Font.BOLD, 20)); //
gp.drawString("编号-89757 坦克阻击战", 180, 130);
gp.setFont(new Font("楷体", Font.BOLD, 40)); //
gp.drawString("战绩", 240, 180);
gp.setColor(Color.gray);
gp.setFont(new Font("宋体", Font.BOLD, 15)); //
gp.drawString("现在您的积分为: " + game_Score, 200, 230);
game_Level += 1;
gp.drawString("目前您的等级为: " + game_Level, 200, 250);
gp.setColor(Color.yellow);
gp.drawString(" ************************* ", 170, 280);
gp.drawString("剩余汽油为: " + (int) myTank_Gas_Remain, 200, 300);
gp.drawString("坦克寿命为: " + myTank_Damage_Degree, 200, 320);
gp.setColor(Color.BLUE);
gp.drawString("+++++ 剩余武器 +++++", 200, 350);
gp.drawString("普通炮弹: " + myBomb_WeightBallNumber, 200, 370);
gp.drawString("核弹弹头: " + myBomb_NuclearBombNumber, 200, 390);
gp.drawString("黑洞弹头: " + myBomb_FinalHoleBombNumber, 200, 410);
}
public class dealWithData_RandomTank_Thread extends Thread
{
Random rand = new Random();
//后台处理数据线程开始
public void run()
{
int i, j;
while(!gameReallyOver)
{
for(i = 0; i < enemyTank_GroupInfo.size(); i++)
{ //Move Enemy Tank
EnemyTank_classInfo enemyTank = (EnemyTank_classInfo) enemyTank_GroupInfo.elementAt(i);
if(enemyMoveCtrlArray[i] >= 25 || enemyMoveCtrlArray[i] == 0)
{
enemyMoveCtrlArray[i] = 0;
enemyTank.dir = rand.nextInt(4);
}
switch(enemyTank.dir)
{
case dir_UP:
enemyTank.y -= 6;
if(enemyTank.y < gameArea_BeginY)
{
enemyTank.y = gameArea_BeginY;
}
if(enemyTank.y < obstacle_1_EndY && enemyTank.y > obstacle_1_BeginY && enemyTank.x < obstacle_1_EndX && enemyTank.x > obstacle_1_BeginX - enemyTank_Width)
{
enemyTank.y = obstacle_1_EndY;
}
if(enemyTank.y < obstacle_2_EndY && enemyTank.y > obstacle_2_BeginY && enemyTank.x < obstacle_2_EndX && enemyTank.x > obstacle_2_BeginX - enemyTank_Width)
{
enemyTank.y = obstacle_2_EndY;
}
break;
case dir_DOWN:
enemyTank.y += 6;
if(enemyTank.y > gameArea_EndY - enemyTank_Heigth)
{
enemyTank.y = gameArea_EndY - enemyTank_Heigth;
}
if(enemyTank.y > obstacle_1_BeginY - enemyTank_Heigth && enemyTank.y < obstacle_1_EndY && enemyTank.x < obstacle_1_EndX && enemyTank.x > obstacle_1_BeginX - enemyTank_Width)
{
enemyTank.y = obstacle_1_BeginY - enemyTank_Heigth;
}
if(enemyTank.y > obstacle_2_BeginY - enemyTank_Heigth && enemyTank.y < obstacle_2_EndY && enemyTank.x < obstacle_2_EndX && enemyTank.x > obstacle_2_BeginX - enemyTank_Width)
{
enemyTank.y = obstacle_2_BeginY - enemyTank_Heigth;
}
break;
case dir_LEFT:
enemyTank.x -= 6;
if(enemyTank.x < gameArea_BeginX)
{
enemyTank.x = gameArea_BeginX;
}
if(enemyTank.x < obstacle_1_EndX && enemyTank.x > obstacle_1_BeginX && enemyTank.y > obstacle_1_BeginY - enemyTank_Heigth && enemyTank.y < obstacle_1_EndY)
{
enemyTank.x = obstacle_1_EndX;
}
if(enemyTank.x < obstacle_2_EndX && enemyTank.x > obstacle_2_BeginX && enemyTank.y > obstacle_2_BeginY - enemyTank_Heigth && enemyTank.y < obstacle_2_EndY)
{
enemyTank.x = obstacle_2_EndX;
}
break;
case dir_RIGHT:
enemyTank.x += 6;
if(enemyTank.x > gameArea_EndX - enemyTank_Width)
{
enemyTank.x = gameArea_EndX - enemyTank_Width;
}
if(enemyTank.x > obstacle_1_BeginX - enemyTank_Width && enemyTank.x < obstacle_1_EndX && enemyTank.y > obstacle_1_BeginY - enemyTank_Heigth && enemyTank.y < obstacle_1_EndY)
{
enemyTank.x = obstacle_1_BeginX - enemyTank_Width;
}
if(enemyTank.x > obstacle_2_BeginX - enemyTank_Width && enemyTank.x < obstacle_2_EndX && enemyTank.y > obstacle_2_BeginY - enemyTank_Heigth && enemyTank.y < obstacle_2_EndY)
{
enemyTank.x = obstacle_2_BeginX - enemyTank_Width;
}
break;
default:
System.out.println("dir Error !!enemyTank.dir=== " + enemyTank.dir);
break;
}
enemyMoveCtrlArray[i] ++;
gameReallyOver = dealWithData_IfCollision(enemyTank, myTank); //判断是否相撞
if(gameReallyOver)
{
inputScoreClass isc = new inputScoreClass(); //把玩家的ID和分数(调用函数)录入数据库
isc.inputScore(playerID, game_Score);
System.out.println(" 相撞 aim");
return;
}
enemyTank.bomb = rand.nextInt(20);
if(enemyTank.bomb == 8)
{
//audio_EnemyBomb.play();
enemyBomb_GroupInfo.addElement(new AllBomb_classInfo(enemyTank.x, enemyTank.y, enemyTank.dir, 1));
//audioGun
}
}
for(i = 0; i < enemyBomb_GroupInfo.size(); i++)
{ //Move Enemy Bomb
AllBomb_classInfo enemy_BombInfoOBJ = (AllBomb_classInfo)
enemyBomb_GroupInfo.elementAt(i);
switch(enemy_BombInfoOBJ.dir)
{
case dir_UP:
enemy_BombInfoOBJ.y -= 15; //rand.nextInt(10) + 5;
if(enemy_BombInfoOBJ.y < gameArea_BeginY)
{
enemy_BombInfoOBJ.y = gameArea_BeginY;
enemyBomb_GroupInfo.removeElement(enemy_BombInfoOBJ);
i--;
}
if(enemy_BombInfoOBJ.y < obstacle_1_EndY - 20 && enemy_BombInfoOBJ.y > obstacle_1_BeginY - 20 && enemy_BombInfoOBJ.x < obstacle_1_EndX - 20 && enemy_BombInfoOBJ.x > obstacle_1_BeginX - 20)
{
enemyBomb_GroupInfo.removeElement(enemy_BombInfoOBJ);
}
break;
case dir_DOWN:
enemy_BombInfoOBJ.y += 15;
if(enemy_BombInfoOBJ.y > gameArea_EndY)
{
enemy_BombInfoOBJ.y = gameArea_EndY;
enemyBomb_GroupInfo.removeElement(enemy_BombInfoOBJ);
i--;
}
if(enemy_BombInfoOBJ.y > obstacle_1_BeginY - 20 && enemy_BombInfoOBJ.y < obstacle_1_EndY - 20 && enemy_BombInfoOBJ.x < obstacle_1_EndX - 20 && enemy_BombInfoOBJ.x > obstacle_1_BeginX - 20)
{
enemyBomb_GroupInfo.removeElement(enemy_BombInfoOBJ);
}
break;
case dir_LEFT:
enemy_BombInfoOBJ.x -= 15;
if(enemy_BombInfoOBJ.x < gameArea_BeginX)
{
enemy_BombInfoOBJ.x = gameArea_BeginX;
enemyBomb_GroupInfo.removeElement(enemy_BombInfoOBJ);
i--;
}
if(enemy_BombInfoOBJ.x < obstacle_1_EndX - 20 && enemy_BombInfoOBJ.x > obstacle_1_BeginX - 20 && enemy_BombInfoOBJ.y > obstacle_1_BeginY - 20 && enemy_BombInfoOBJ.y < obstacle_1_EndY - 20)
{
enemyBomb_GroupInfo.removeElement(enemy_BombInfoOBJ);
}
break;
case dir_RIGHT:
enemy_BombInfoOBJ.x += 15;
if(enemy_BombInfoOBJ.x > gameArea_EndX)
{
enemy_BombInfoOBJ.x = gameArea_EndX;
enemyBomb_GroupInfo.removeElement(enemy_BombInfoOBJ);
i--;
}
if(enemy_BombInfoOBJ.x > obstacle_1_BeginX - 20 && enemy_BombInfoOBJ.x < obstacle_1_EndX - 20 && enemy_BombInfoOBJ.y > obstacle_1_BeginY - 20 && enemy_BombInfoOBJ.y < obstacle_1_EndY - 20)
{
enemyBomb_GroupInfo.removeElement(enemy_BombInfoOBJ);
}
break;
default:
break;
}
gameReallyOver = dealWithData_IfShootMyTank(enemy_BombInfoOBJ, myTank); //判断我方是否中弹
if(gameReallyOver)
{
System.out.println(" 中弹 aim");
return;
}
}
for(i = 0; i < myBomb_GroupInfo.size(); i++)
{ //Move My Bomb
AllBomb_classInfo my_BombInfoOBJ = (AllBomb_classInfo)
myBomb_GroupInfo.elementAt(i);
switch(my_BombInfoOBJ.dir)
{
case dir_UP:
my_BombInfoOBJ.y -= 15; //rand.nextInt(10) + 5;
if(my_BombInfoOBJ.y < gameArea_BeginY)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
if(my_BombInfoOBJ.bombKinds == 1 && my_BombInfoOBJ.y < obstacle_1_EndY - 20 && my_BombInfoOBJ.y > obstacle_1_BeginY - 20 && my_BombInfoOBJ.x < obstacle_1_EndX - 20 && my_BombInfoOBJ.x > obstacle_1_BeginX - 20)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
if(my_BombInfoOBJ.bombKinds == 2 && my_BombInfoOBJ.y < obstacle_2_EndY - 20 && my_BombInfoOBJ.y > obstacle_2_BeginY - 20 && my_BombInfoOBJ.x < obstacle_2_EndX - 20 && my_BombInfoOBJ.x > obstacle_2_BeginX - 20)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
break;
case dir_DOWN:
my_BombInfoOBJ.y += 15;
if(my_BombInfoOBJ.y > gameArea_EndY)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
if(my_BombInfoOBJ.bombKinds == 1 && my_BombInfoOBJ.y > obstacle_1_BeginY - 20 && my_BombInfoOBJ.y < obstacle_1_EndY - 20 && my_BombInfoOBJ.x < obstacle_1_EndX - 20 && my_BombInfoOBJ.x > obstacle_1_BeginX - 20)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
if(my_BombInfoOBJ.bombKinds == 2 && my_BombInfoOBJ.y > obstacle_2_BeginY - 20 && my_BombInfoOBJ.y < obstacle_2_EndY - 20 && my_BombInfoOBJ.x < obstacle_2_EndX - 20 && my_BombInfoOBJ.x > obstacle_2_BeginX - 20)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
break;
case dir_LEFT:
my_BombInfoOBJ.x -= 15;
if(my_BombInfoOBJ.x < gameArea_BeginX)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
if(my_BombInfoOBJ.bombKinds == 1 && my_BombInfoOBJ.x < obstacle_1_EndX - 20 && my_BombInfoOBJ.x > obstacle_1_BeginX - 20 && my_BombInfoOBJ.y > obstacle_1_BeginY - 20 && my_BombInfoOBJ.y < obstacle_1_EndY - 20)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
if(my_BombInfoOBJ.bombKinds == 2 && my_BombInfoOBJ.x < obstacle_2_EndX - 20 && my_BombInfoOBJ.x > obstacle_2_BeginX - 20 && my_BombInfoOBJ.y > obstacle_2_BeginY - 20 && my_BombInfoOBJ.y < obstacle_2_EndY - 20)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
break;
case dir_RIGHT:
my_BombInfoOBJ.x += 15;
if(my_BombInfoOBJ.x > gameArea_EndX)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
if(my_BombInfoOBJ.bombKinds == 1 && my_BombInfoOBJ.x > obstacle_1_BeginX - 20 && my_BombInfoOBJ.x < obstacle_1_EndX - 20 && my_BombInfoOBJ.y > obstacle_1_BeginY - 20 && my_BombInfoOBJ.y < obstacle_1_EndY - 20)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
if(my_BombInfoOBJ.bombKinds == 2 && my_BombInfoOBJ.x > obstacle_2_BeginX - 20 && my_BombInfoOBJ.x < obstacle_2_EndX - 20 && my_BombInfoOBJ.y > obstacle_2_BeginY - 20 && my_BombInfoOBJ.y < obstacle_2_EndY - 20)
{
myBomb_GroupInfo.removeElement(my_BombInfoOBJ);
i--;
}
break;
default:
break;
}
game_victory = dealWithData_IfShootEnemyTank(my_BombInfoOBJ, enemyTank_GroupInfo); //判断是否打中敌人
if(game_victory)
{
enemyTank_GroupInfo.removeAllElements();
enemyBomb_GroupInfo.removeAllElements();
myBomb_GroupInfo.removeAllElements();
try
{
sleep(5000);
}
catch(Exception ecpt_1)
{}
//game_Level ++;
myBomb_WeightBallNumber += 10 + game_Level * 2;
myBomb_NuclearBombNumber += 1;
//myBomb_FinalHoleBombNumber +=1;
for(int passnext = 0; passnext < game_Level + 3; passnext++)
{
if(passnext <= 4)
{
enemyTank_GroupInfo.addElement(new EnemyTank_classInfo(60 + passnext * 40, 50, 1, 0, 5000));
}
else
{
enemyTank_GroupInfo.addElement(new EnemyTank_classInfo(300, 50, 1, 0, 5000));
}
}
game_victory = false;
myTank.x = 270;
myTank.y = 550;
}
}
if(encourageWeapon_GroupInfo.size() < 3)
{ // move the encourage Weapon
j = rand.nextInt(100);
if(j == 5)
{
encourageWeapon_GroupInfo.addElement(new EncourageWeapon_classInfo(100, 100, 0));
}
}
for(i = 0; i < encourageWeapon_GroupInfo.size(); i++)
{
EncourageWeapon_classInfo ewci = (EncourageWeapon_classInfo) encourageWeapon_GroupInfo.elementAt(i);
ewci.dir = rand.nextInt(4);
switch(ewci.dir)
{
case dir_UP:
ewci.y -= 5;
if(ewci.y < gameArea_BeginY)
{
ewci.y = gameArea_BeginY;
}
break;
case dir_DOWN:
ewci.y += 10;
if(ewci.y > gameArea_EndY - 40)
{
ewci.y = gameArea_EndY - 40;
}
break;
case dir_LEFT:
ewci.x -= 10;
if(ewci.x < gameArea_BeginX)
{
ewci.x = gameArea_BeginX;
}
break;
case dir_RIGHT:
ewci.x += 10;
if(ewci.x > gameArea_EndX - 40)
{
ewci.x = gameArea_EndX - 40;
}
break;
default:
System.out.println("dir Error !!");
break;
}
eatThePrice = dealWithData_IfEatTheWeapon(ewci, myTank);
if(eatThePrice)
{
myBomb_NuclearBombNumber++;
encourageWeapon_GroupInfo.removeElement(ewci);
}
}
try
{
sleep(80);
}
catch(Exception ecpt_1)
{}
myTank_Gas_Remain -= 0.04;
repaint();
}
}
}
public boolean dealWithData_IfCollision(EnemyTank_classInfo eTank, MyTank_classInfo mTank)
{
boolean bool_1 = false, bool_2 = false, bool_3 = false;
switch(eTank.dir)
{
case dir_UP:
bool_1 = (eTank.y >= mTank.y) && (eTank.y <= mTank.y + myTank_Heigth);
bool_2 = (eTank.x >= mTank.x) && (eTank.x <= mTank.x + myTank_Width);
bool_3 = (mTank.x >= eTank.x) && (mTank.x <= eTank.x + enemyTank_Width);
break;
case dir_DOWN:
bool_1 = (mTank.y >= eTank.y) && (mTank.y <= eTank.y + enemyTank_Heigth);
bool_2 = (eTank.x >= mTank.x) && (eTank.x <= mTank.x + myTank_Width);
bool_3 = (mTank.x >= eTank.x) && (mTank.x <= eTank.x + enemyTank_Width);
break;
case dir_LEFT:
bool_1 = (eTank.x >= mTank.x) && (eTank.x <= mTank.x + myTank_Width);
bool_2 = (eTank.y >= mTank.y) && (eTank.y <= mTank.y + myTank_Heigth);
bool_3 = (mTank.y >= eTank.y) && (mTank.y <= eTank.y + enemyTank_Heigth);
break;
case dir_RIGHT:
bool_1 = (eTank.x >= mTank.x) && (eTank.x <= mTank.x + myTank_Width);
bool_2 = (eTank.y >= mTank.y) && (eTank.y <= mTank.y + myTank_Heigth);
bool_3 = (mTank.y >= eTank.y) && (mTank.y <= eTank.y + enemyTank_Heigth);
break;
}
if(bool_1 && (bool_2 || bool_3))
{
//audio_Collide.play();
//myTank_Damage_Degree -=50;
return true; //gameReallyOver;
}
else return false;
}
public boolean dealWithData_IfShootEnemyTank(AllBomb_classInfo myBombOBJ, Vector enemyTankVET)
{
int i, j;
boolean bool_1 = false, bool_2 = false;
if(myBombOBJ.bombKinds == 1)
{
j = enemyTankVET.size();
for(i = 0; i < j; i++)
{
EnemyTank_classInfo enemyTankOBJ = (EnemyTank_classInfo) enemyTankVET.elementAt(i);
switch(myBombOBJ.dir)
{
case dir_UP:
bool_1 = (myBombOBJ.y + 20 >= enemyTankOBJ.y) && (myBombOBJ.y + 20 <= enemyTankOBJ.y + enemyTank_Heigth);
bool_2 = (myBombOBJ.x + 20 >= enemyTankOBJ.x) && (myBombOBJ.x + 20 <= enemyTankOBJ.x + enemyTank_Width);
break;
case dir_DOWN:
bool_1 = (myBombOBJ.y + 20 >= enemyTankOBJ.y) && (myBombOBJ.y + 20 <= enemyTankOBJ.y + enemyTank_Heigth);
bool_2 = (myBombOBJ.x + 20 >= enemyTankOBJ.x) && (myBombOBJ.x + 20 <= enemyTankOBJ.x + enemyTank_Width);
break;
case dir_LEFT:
bool_1 = (myBombOBJ.x + 20 >= enemyTankOBJ.x) && (myBombOBJ.x + 20 <= enemyTankOBJ.x + enemyTank_Width);
bool_2 = (myBombOBJ.y + 20 >= enemyTankOBJ.y) && (myBombOBJ.y + 20 <= enemyTankOBJ.y + enemyTank_Heigth);
break;
case dir_RIGHT:
bool_1 = (myBombOBJ.x + 20 >= enemyTankOBJ.x) && (myBombOBJ.x + 20 <= enemyTankOBJ.x + enemyTank_Width);
bool_2 = (myBombOBJ.y + 20 >= enemyTankOBJ.y) && (myBombOBJ.y + 20 <= enemyTankOBJ.y + enemyTank_Heigth);
break;
default:
System.out.println(" myBombOBJ.dir Error = " + myBombOBJ.dir);
break;
}
if(bool_1 && bool_2)
{
//audio_enemyExplode.play();
//enemyTankOBJ.life = 0;
//burst = true;
enemyTankVET.removeElement(enemyTankOBJ);
game_Score += 100;
System.out.println("Game score + .....11111111...100");
j--;
i--;
}
}
}
else if(myBombOBJ.bombKinds == 2)
{
for(i = 0; i < enemyTankVET.size(); i++)
{
EnemyTank_classInfo enemyTankOBJ = (EnemyTank_classInfo) enemyTankVET.elementAt(i);
switch(myBombOBJ.dir)
{
case dir_UP:
bool_1 = (myBombOBJ.y + 20 >= enemyTankOBJ.y - 100) && (myBombOBJ.y + 20 <= enemyTankOBJ.y + enemyTank_Heigth + 100);
bool_2 = (myBombOBJ.x + 20 >= enemyTankOBJ.x - 100) && (myBombOBJ.x + 20 <= enemyTankOBJ.x + enemyTank_Width + 100);
break;
case dir_DOWN:
bool_1 = (myBombOBJ.y + 20 >= enemyTankOBJ.y - 100) && (myBombOBJ.y + 20 <= enemyTankOBJ.y + enemyTank_Heigth + 100);
bool_2 = (myBombOBJ.x + 20 >= enemyTankOBJ.x - 100) && (myBombOBJ.x + 20 <= enemyTankOBJ.x + enemyTank_Width + 100);
break;
case dir_LEFT:
bool_1 = (myBombOBJ.x + 20 >= enemyTankOBJ.x - 100) && (myBombOBJ.x + 20 <= enemyTankOBJ.x + enemyTank_Width + 100);
bool_2 = (myBombOBJ.y + 20 >= enemyTankOBJ.y - 100) && (myBombOBJ.y + 20 <= enemyTankOBJ.y + enemyTank_Heigth + 100);
break;
case dir_RIGHT:
bool_1 = (myBombOBJ.x + 20 >= enemyTankOBJ.x - 100) && (myBombOBJ.x + 20 <= enemyTankOBJ.x + enemyTank_Width + 100);
bool_2 = (myBombOBJ.y + 20 >= enemyTankOBJ.y - 100) && (myBombOBJ.y + 20 <= enemyTankOBJ.y + enemyTank_Heigth + 100);
break;
default:
System.out.println(" myBBBBBBBig_______BombOBJ.dir Error = " + myBombOBJ.dir);
break;
}
if(bool_1 && bool_2)
{
//audio_enemyExplode.play();
enemyTankOBJ.life = 0;
//enemyTankOBJ.life -=2500;
enemyTankVET.removeElement(enemyTankOBJ);
game_Score += 100;
System.out.println("Game score + ....222222222....100");
i--;
}
}
}
else if(myBombOBJ.bombKinds == 3)
{
enemyTankVET.removeAllElements();
game_Score += 100;
//i--;
}
if(enemyTankVET.size() == 0)
{ // Win The Game
return true;
}
else return false;
}
public boolean dealWithData_IfShootMyTank(AllBomb_classInfo enemybombOBJ, MyTank_classInfo myTank)
{
boolean bool_1 = false, bool_2 = false;
switch(enemybombOBJ.dir)
{
case dir_UP:
bool_1 = (enemybombOBJ.y + 20 >= myTank.y) && (enemybombOBJ.y + 20 <= myTank.y + myTank_Heigth);;
bool_2 = (enemybombOBJ.x + 20 >= myTank.x) && (enemybombOBJ.x + 20 <= myTank.x + myTank_Width);
break;
case dir_DOWN:
bool_1 = (enemybombOBJ.y + 20 >= myTank.y) && (enemybombOBJ.y + 20 <= myTank.y + myTank_Heigth);
bool_2 = (enemybombOBJ.x + 20 >= myTank.x) && (enemybombOBJ.x + 20 <= myTank.x + myTank_Width);
break;
case dir_LEFT:
bool_1 = (enemybombOBJ.x + 20 >= myTank.x) && (enemybombOBJ.x + 20 <= myTank.x + myTank_Width);
bool_2 = (enemybombOBJ.y + 20 >= myTank.y) && (enemybombOBJ.y + 20 <= myTank.y + myTank_Heigth);
break;
case dir_RIGHT:
bool_1 = (enemybombOBJ.x + 20 >= myTank.x) && (enemybombOBJ.x + 20 <= myTank.x + myTank_Width);
bool_2 = (enemybombOBJ.y + 20 >= myTank.y) && (enemybombOBJ.y + 20 <= myTank.y + myTank_Heigth);
break;
default:
System.out.println(" enemybombOBJ.dir Error = " + enemybombOBJ.dir);
break;
}
if(bool_1 && bool_2)
{
myTank_Damage_Degree -= 4;
if(myTank_Damage_Degree <= 0 || myTank_Gas_Remain <= 0)
{
return true;
}
}
//else
return false;
}
public boolean dealWithData_IfEatTheWeapon(EncourageWeapon_classInfo ewciOBJ, MyTank_classInfo mtciOBJ)
{
boolean bool_1 = false, bool_2 = false, bool_3 = false;
switch(mtciOBJ.dir)
{
case dir_UP:
bool_1 = (ewciOBJ.y >= mtciOBJ.y) && (ewciOBJ.y <= mtciOBJ.y + 40);
bool_2 = (ewciOBJ.x >= mtciOBJ.x) && (ewciOBJ.x <= mtciOBJ.x + 40);
bool_3 = (mtciOBJ.x >= ewciOBJ.x) && (mtciOBJ.x <= ewciOBJ.x + 20);
break;
case dir_DOWN:
bool_1 = (mtciOBJ.y >= ewciOBJ.y) && (mtciOBJ.y <= ewciOBJ.y + 20);
bool_2 = (ewciOBJ.x >= mtciOBJ.x) && (ewciOBJ.x <= mtciOBJ.x + 40);
bool_3 = (mtciOBJ.x >= ewciOBJ.x) && (mtciOBJ.x <= ewciOBJ.x + 20);
break;
case dir_LEFT:
bool_1 = (ewciOBJ.x >= mtciOBJ.x) && (ewciOBJ.x <= mtciOBJ.x + 40);
bool_2 = (ewciOBJ.y >= mtciOBJ.y) && (ewciOBJ.y <= mtciOBJ.y + 40);
bool_3 = (mtciOBJ.y >= ewciOBJ.y) && (mtciOBJ.y <= ewciOBJ.y + 20);
break;
case dir_RIGHT:
bool_1 = (ewciOBJ.x >= mtciOBJ.x) && (ewciOBJ.x <= mtciOBJ.x + 40);
bool_2 = (ewciOBJ.y >= mtciOBJ.y) && (ewciOBJ.y <= mtciOBJ.y + 40);
bool_3 = (mtciOBJ.y >= ewciOBJ.y) && (mtciOBJ.y <= ewciOBJ.y + 20);
break;
}
if(bool_1 && (bool_2 || bool_3))
{
return true;
}
else return false;
}
}
class EnemyTank_classInfo
{
int x, y, dir, bomb, life;
public EnemyTank_classInfo(int x, int y, int dir, int bomb, int life)
{
this.x = x;
this.y = y;
this.dir = dir;
this.bomb = bomb;
this.life = life;
}
}
class MyTank_classInfo
{
int x, y, dir;
public MyTank_classInfo(int x, int y, int dir)
{
this.x = x;
this.y = y;
this.dir = dir;
//this.bombRemain = bomb;
}
}
class AllBomb_classInfo
{
int x, y, dir, bombKinds;
public AllBomb_classInfo(int x, int y, int dir, int bombKinds)
{
this.x = x;
this.y = y;
this.dir = dir;
this.bombKinds = bombKinds;
}
}
class EncourageWeapon_classInfo
{
int x, y, dir;
public EncourageWeapon_classInfo(int x, int y, int dir)
{
this.x = x;
this.y = y;
this.dir = dir;
}
}