JAVA版超级玛丽
這是一篇關(guān)于JAVA的超級(jí)瑪麗游戲,源代碼的部分在下面正文中介紹,圖片和音頻的部分都放在百度云盤(pán),需要的自行下載。
文章目錄
- 開(kāi)發(fā)環(huán)境
- 一、下載方法
- 二、運(yùn)行效果展示
- 三、項(xiàng)目結(jié)構(gòu)以及主程序入口
- 1.項(xiàng)目結(jié)構(gòu)
- 2.主程序入口
- 四、代碼部分
- 1.代碼如下
- 2.引入額外的JAR包
- 總結(jié)
開(kāi)發(fā)環(huán)境
開(kāi)發(fā)工具:eclipse2021-12
JDK版本:JDK15.0.1
需要引入額外的JAR包,不然程序會(huì)報(bào)錯(cuò),主要是音樂(lè)加不進(jìn)來(lái)。
jl-1.0.1.jar
一、下載方法
百度云盤(pán)
鏈接:https://pan.baidu.com/s/1Nc28_UKsBV3QHGXfOjSAMg
提取碼:uqz9
編碼格式:UTF-8
二、運(yùn)行效果展示
啟動(dòng)程序以后,直接進(jìn)入游戲,游戲運(yùn)行時(shí)的畫(huà)面
三、項(xiàng)目結(jié)構(gòu)以及主程序入口
1.項(xiàng)目結(jié)構(gòu)
2.主程序入口
入口程序在MyFrame.java類中。
四、代碼部分
1.代碼如下
代碼如下:
MyFrame.java類
package com.sxt;import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List;import javax.swing.JFrame; import javax.swing.JOptionPane;import javazoom.jl.decoder.JavaLayerException;public class MyFrame extends JFrame implements KeyListener,Runnable {//用于存儲(chǔ)所有的背景private List<BackGround> allBg = new ArrayList<>();//用于存儲(chǔ)當(dāng)前的背景private BackGround nowBg = new BackGround();//用于雙緩存private Image offScreenImage = null;//馬里奧對(duì)象private Mario mario = new Mario();//定義一個(gè)線程對(duì)象,用于實(shí)現(xiàn)馬里奧的運(yùn)動(dòng)private Thread thread = new Thread(this);public MyFrame() {//設(shè)置窗口的大小為800 * 600this.setSize(800,600);//設(shè)置窗口居中顯示this.setLocationRelativeTo(null);//設(shè)置窗口的可見(jiàn)性this.setVisible(true);//設(shè)置點(diǎn)擊窗口上的關(guān)閉鍵,結(jié)束程序this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置窗口大小不可變this.setResizable(false);//向窗口對(duì)象添加鍵盤(pán)監(jiān)聽(tīng)器this.addKeyListener(this);//設(shè)置窗口名稱this.setTitle("超級(jí)瑪麗");//初始化圖片StaticValue.init();//初始化馬里奧mario = new Mario(10,355);//創(chuàng)建全部的場(chǎng)景for (int i = 1;i <= 3;i++) {allBg.add(new BackGround(i, i == 3 ? true : false));}//將第一個(gè)場(chǎng)景設(shè)置為當(dāng)前場(chǎng)景nowBg = allBg.get(0);mario.setBackGround(nowBg);//繪制圖像repaint();thread.start();try {new Music();} catch (FileNotFoundException e) {e.printStackTrace();} catch (JavaLayerException e) {e.printStackTrace();}}@Overridepublic void paint(Graphics g) {if (offScreenImage == null) {offScreenImage = createImage(800,600);}Graphics graphics = offScreenImage.getGraphics();graphics.fillRect(0,0,800,600);//繪制背景graphics.drawImage(nowBg.getBgImage(),0,0,this);//繪制敵人for (Enemy e : nowBg.getEnemyList()) {graphics.drawImage(e.getShow(),e.getX(),e.getY(),this);}//繪制障礙物for (Obstacle ob : nowBg.getObstacleList()) {graphics.drawImage(ob.getShow(),ob.getX(),ob.getY(),this);}//繪制城堡graphics.drawImage(nowBg.getTower(),620,270,this);//繪制旗桿graphics.drawImage(nowBg.getGan(),500,220,this);//繪制馬里奧graphics.drawImage(mario.getShow(),mario.getX(),mario.getY(),this);//添加分?jǐn)?shù)Color c = graphics.getColor();graphics.setColor(Color.BLACK);graphics.setFont(new Font("黑體",Font.BOLD,25));graphics.drawString("當(dāng)前的分?jǐn)?shù)為: " + mario.getScore(),300,100);graphics.setColor(c);//將圖像繪制到窗口中g.drawImage(offScreenImage,0,0,this);}public static void main(String[] args) {MyFrame myFrame = new MyFrame();}@Overridepublic void keyTyped(KeyEvent e) {}//當(dāng)鍵盤(pán)按下按鍵時(shí)調(diào)用@Overridepublic void keyPressed(KeyEvent e) {//向右移動(dòng)if (e.getKeyCode() == 39) {mario.rightMove();}//向左移動(dòng)if (e.getKeyCode() == 37) {mario.leftMove();}//跳躍if (e.getKeyCode() == 38) {mario.jump();}}//當(dāng)鍵盤(pán)松開(kāi)按鍵時(shí)調(diào)用@Overridepublic void keyReleased(KeyEvent e) {//想左停止if (e.getKeyCode() == 37) {mario.leftStop();}//向右停止if (e.getKeyCode() == 39) {mario.rightStop();}}@Overridepublic void run() {while (true) {repaint();try {Thread.sleep(50);if (mario.getX() >= 775) {nowBg = allBg.get(nowBg.getSort());mario.setBackGround(nowBg);mario.setX(10);mario.setY(355);}//判斷馬里奧是否死亡if (mario.isDeath()) {JOptionPane.showMessageDialog(this,"馬里奧死亡!!!");System.exit(0);}//判斷游戲是否結(jié)束if (mario.isOK()) {JOptionPane.showMessageDialog(this,"恭喜你!成功通關(guān)了");System.exit(0);}} catch (InterruptedException e) {e.printStackTrace();}}}}StaticValue.java類
package com.sxt;import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List;public class StaticValue {//背景public static BufferedImage bg = null;public static BufferedImage bg2 = null;//馬里奧向左跳躍public static BufferedImage jump_L = null;//馬里奧向右跳躍public static BufferedImage jump_R = null;//馬里奧向左站立public static BufferedImage stand_L = null;//馬里奧向右站立public static BufferedImage stand_R = null;//城堡public static BufferedImage tower = null;//旗桿public static BufferedImage gan = null;//障礙物public static List<BufferedImage> obstacle = new ArrayList<>();//馬里奧向左跑public static List<BufferedImage> run_L = new ArrayList<>();//馬里奧向右跑public static List<BufferedImage> run_R = new ArrayList<>();//蘑菇敵人public static List<BufferedImage> mogu = new ArrayList<>();//食人花敵人public static List<BufferedImage> flower = new ArrayList<>();//路徑的前綴,方便后續(xù)調(diào)用public static String path = System.getProperty("user.dir") + "/src/images/";//初始化方法public static void init() {try {//加載背景圖片bg = ImageIO.read(new File(path + "bg.png"));bg2 = ImageIO.read(new File(path + "bg2.png"));//加載馬里奧向左站立stand_L = ImageIO.read(new File(path + "s_mario_stand_L.png"));//加載馬里奧向右站立stand_R = ImageIO.read(new File(path + "s_mario_stand_R.png"));//加載城堡tower = ImageIO.read(new File(path + "tower.png"));//加載旗桿gan = ImageIO.read(new File(path + "gan.png"));//加載馬里奧向左跳躍jump_L = ImageIO.read(new File(path + "s_mario_jump1_L.png"));//加載馬里奧向右跳躍jump_R = ImageIO.read(new File(path + "s_mario_jump1_R.png"));} catch (IOException e) {e.printStackTrace();}//加載馬里奧向左跑for (int i = 1;i <= 2;i++) {try {run_L.add(ImageIO.read(new File(path + "s_mario_run"+ i +"_L.png")));} catch (IOException e) {e.printStackTrace();}}//加載馬里奧向右跑for (int i = 1;i <= 2;i++) {try {run_R.add(ImageIO.read(new File(path + "s_mario_run"+ i +"_R.png")));} catch (IOException e) {e.printStackTrace();}}try {//加載障礙物obstacle.add(ImageIO.read(new File(path + "brick.png")));obstacle.add(ImageIO.read(new File(path + "soil_up.png")));obstacle.add(ImageIO.read(new File(path + "soil_base.png")));} catch (IOException e) {e.printStackTrace();}//加載水管for (int i = 1;i <= 4;i++) {try {obstacle.add(ImageIO.read(new File(path + "pipe"+ i +".png")));} catch (IOException e) {e.printStackTrace();}}//加載不可破壞的磚塊和旗子try {obstacle.add(ImageIO.read(new File(path + "brick2.png")));obstacle.add(ImageIO.read(new File(path + "flag.png")));} catch (IOException e) {e.printStackTrace();}//加載蘑菇敵人for (int i = 1;i <= 3;i++) {try {mogu.add(ImageIO.read(new File(path + "fungus"+i+".png")));} catch (IOException e) {e.printStackTrace();}}//加載食人花敵人for (int i = 1;i <= 2;i++) {try {flower.add(ImageIO.read(new File(path + "flower1."+i+".png")));} catch (IOException e) {e.printStackTrace();}}} }Obstacle.java類
package com.sxt;import java.awt.image.BufferedImage;public class Obstacle implements Runnable{//用于表示坐標(biāo)private int x;private int y;//用于記錄障礙物類型private int type;//用于顯示圖像private BufferedImage show = null;//定義當(dāng)前的場(chǎng)景對(duì)象private BackGround bg = null;//定義一個(gè)線程對(duì)象private Thread thread = new Thread(this);public Obstacle(int x,int y,int type,BackGround bg) {this.x = x;this.y = y;this.type = type;this.bg = bg;show = StaticValue.obstacle.get(type);//如果是旗子的話,啟動(dòng)線程if (type == 8) {thread.start();}}public int getX() {return x;}public int getY() {return y;}public int getType() {return type;}public BufferedImage getShow() {return show;}@Overridepublic void run() {while (true) {if (this.bg.isReach()) {if (this.y < 374) {this.y += 5;}else {this.bg.setBase(true);}}try {Thread.sleep(50);} catch (InterruptedException e) {e.printStackTrace();}}} }Music.java
package com.sxt;import javazoom.jl.decoder.JavaLayerException; import javazoom.jl.player.Player;import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException;public class Music {public Music() throws FileNotFoundException, JavaLayerException {Player player;String str = System.getProperty("user.dir") + "/src/Music/music.wav";BufferedInputStream name = new BufferedInputStream(new FileInputStream(str));player = new Player(name);player.play();} }Mario.java
package com.sxt;import java.awt.image.BufferedImage;public class Mario implements Runnable{//用于表示橫縱坐標(biāo)private int x;private int y;//用于表示當(dāng)前的狀態(tài)private String status;//用于顯示當(dāng)前狀態(tài)對(duì)應(yīng)的圖像private BufferedImage show = null;//定義一個(gè)BackGround對(duì)象,用來(lái)獲取障礙物的信息private BackGround backGround = new BackGround();//用來(lái)實(shí)現(xiàn)馬里奧的動(dòng)作private Thread thread = null;//馬里奧的移動(dòng)速度private int xSpeed;//馬里奧的跳躍速度private int ySpeed;//定義一個(gè)索引private int index;//表示馬里奧上升的時(shí)間private int upTime = 0;//用于判斷馬里奧是否走到了城堡的門(mén)口private boolean isOK;//用于判斷馬里奧是否死亡private boolean isDeath = false;//表示分?jǐn)?shù)private int score = 0;public Mario() {}public Mario (int x,int y) {this.x = x;this.y = y;show = StaticValue.stand_R;this.status = "stand--right";thread = new Thread(this);thread.start();}//馬里奧的死亡方法public void death() {isDeath = true;}//馬里奧向左移動(dòng)public void leftMove() {//改變速度xSpeed = -5;//判斷馬里奧是否碰到旗子if (backGround.isReach()) {xSpeed = 0;}//判斷馬里奧是否處于空中if (status.indexOf("jump") != -1) {status = "jump--left";}else {status = "move--left";}}//馬里奧向右移動(dòng)public void rightMove() {xSpeed = 5;//判斷馬里奧是否碰到旗子if (backGround.isReach()) {xSpeed = 0;}if (status.indexOf("jump") != -1) {status = "jump--right";}else {status = "move--right";}}//馬里奧向左停止public void leftStop() {xSpeed = 0;if (status.indexOf("jump") != -1) {status = "jump--left";}else {status = "stop--left";}}//馬里奧向右停止public void rightStop() {xSpeed = 0;if (status.indexOf("jump") != -1) {status = "jump--right";}else {status = "stop--right";}}//馬里奧跳躍public void jump() {if (status.indexOf("jump") == -1) {if (status.indexOf("left") != -1) {status = "jump--left";}else {status = "jump--right";}ySpeed = -10;upTime = 7;}//判斷馬里奧是否碰到旗子if (backGround.isReach()) {ySpeed = 0;}}//馬里奧下落public void fall() {if (status.indexOf("left") != -1) {status = "jump--left";}else {status = "jump--right";}ySpeed = 10;}@Overridepublic void run() {while (true) {//判斷是否處于障礙物上boolean onObstacle = false;//判斷是否可以往右走boolean canRight = true;//判斷是否可以往左走boolean canLeft = true;//判斷馬里奧是否到達(dá)旗桿位置if (backGround.isFlag() && this.x >= 500) {this.backGround.setReach(true);//判斷旗子是否下落完成if (this.backGround.isBase()) {status = "move--right";if (x < 690) {x += 5;}else {isOK = true;}}else {if (y < 395) {xSpeed = 0;this.y += 5;status = "jump--right";}if (y > 395) {this.y = 395;status = "stop--right";}}}else {//遍歷當(dāng)前場(chǎng)景里所有的障礙物for (int i = 0; i < backGround.getObstacleList().size(); i++) {Obstacle ob = backGround.getObstacleList().get(i);//判斷馬里奧是否位于障礙物上if (ob.getY() == this.y + 25 && (ob.getX() > this.x - 30 && ob.getX() < this.x + 25)) {onObstacle = true;}//判斷是否跳起來(lái)頂?shù)酱u塊if ((ob.getY() >= this.y - 30 && ob.getY() <= this.y - 20) && (ob.getX() > this.x - 30 && ob.getX() < this.x + 25)) {if (ob.getType() == 0) {backGround.getObstacleList().remove(ob);score += 1;}upTime = 0;}//判斷是否可以往右走if (ob.getX() == this.x + 25 && (ob.getY() > this.y - 30 && ob.getY() < this.y + 25)) {canRight = false;}//判斷是否可以往左走if (ob.getX() == this.x - 30 && (ob.getY() > this.y - 30 && ob.getY() < this.y + 25)) {canLeft = false;}}//判斷馬里奧是否碰到敵人死亡或者踩死蘑菇敵人for (int i = 0;i < backGround.getEnemyList().size();i++) {Enemy e = backGround.getEnemyList().get(i);if (e.getY() == this.y + 20 && (e.getX() - 25 <= this.x && e.getX() + 35 >= this.x)) {if (e.getType() == 1) {e.death();score += 2;upTime = 3;ySpeed = -10;}else if (e.getType() == 2) {//馬里奧死亡death();}}if ((e.getX() + 35 > this.x && e.getX() - 25 < this.x) && (e.getY() + 35 > this.y && e.getY() - 20 < this.y)) {//馬里奧死亡death();}}//進(jìn)行馬里奧跳躍的操作if (onObstacle && upTime == 0) {if (status.indexOf("left") != -1) {if (xSpeed != 0) {status = "move--left";} else {status = "stop--left";}} else {if (xSpeed != 0) {status = "move--right";} else {status = "stop--right";}}} else {if (upTime != 0) {upTime--;} else {fall();}y += ySpeed;}}if ((canLeft && xSpeed < 0) || (canRight && xSpeed > 0)) {x += xSpeed;//判斷馬里奧是否到了最左邊if (x < 0) {x = 0;}}//判斷當(dāng)前是否是移動(dòng)狀態(tài)if (status.contains("move")) {index = index == 0 ? 1 : 0;}//判斷是否向左移動(dòng)if ("move--left".equals(status)) {show = StaticValue.run_L.get(index);}//判斷是否向右移動(dòng)if ("move--right".equals(status)) {show = StaticValue.run_R.get(index);}//判斷是否向左停止if ("stop--left".equals(status)) {show = StaticValue.stand_L;}//判斷是否向右停止if ("stop--right".equals(status)) {show = StaticValue.stand_R;}//判斷是否向左跳躍if ("jump--left".equals(status)) {show = StaticValue.jump_L;}//判斷是否向右跳躍if ("jump--right".equals(status)) {show = StaticValue.jump_R;}try {Thread.sleep(50);} catch (InterruptedException e) {e.printStackTrace();}}}public int getX() {return x;}public void setX(int x) {this.x = x;}public int getY() {return y;}public void setY(int y) {this.y = y;}public BufferedImage getShow() {return show;}public void setShow(BufferedImage show) {this.show = show;}public void setBackGround(BackGround backGround) {this.backGround = backGround;}public boolean isOK() {return isOK;}public boolean isDeath() {return isDeath;}public int getScore() {return score;} }Enemy.java
package com.sxt;import java.awt.image.BufferedImage;public class Enemy implements Runnable{//存儲(chǔ)當(dāng)前坐標(biāo)private int x;private int y;//存儲(chǔ)敵人類型private int type;//判斷敵人運(yùn)動(dòng)的方向private boolean face_to = true;//用于顯示敵人的當(dāng)前圖像private BufferedImage show;//定義一個(gè)背景對(duì)象private BackGround bg;//食人花運(yùn)動(dòng)的極限范圍private int max_up = 0;private int max_down = 0;//定義線程對(duì)象private Thread thread = new Thread(this);//定義當(dāng)前的圖片的狀態(tài)private int image_type = 0;//蘑菇敵人的構(gòu)造函數(shù)public Enemy(int x,int y,boolean face_to,int type,BackGround bg) {this.x = x;this.y = y;this.face_to = face_to;this.type = type;this.bg = bg;show = StaticValue.mogu.get(0);thread.start();}//食人花敵人的構(gòu)造函數(shù)public Enemy(int x,int y,boolean face_to,int type,int max_up,int max_down,BackGround bg) {this.x = x;this.y = y;this.face_to = face_to;this.type = type;this.max_up = max_up;this.max_down = max_down;this.bg = bg;show = StaticValue.flower.get(0);thread.start();}//死亡方法public void death() {show = StaticValue.mogu.get(2);this.bg.getEnemyList().remove(this);}public int getX() {return x;}public int getY() {return y;}public BufferedImage getShow() {return show;}public int getType() {return type;}@Overridepublic void run() {while (true) {//判斷是否是蘑菇敵人if (type == 1) {if (face_to) {this.x -= 2;}else {this.x += 2;}image_type = image_type == 1 ? 0 : 1;show = StaticValue.mogu.get(image_type);}//定義兩個(gè)布爾變量boolean canLeft = true;boolean canRight = true;for (int i = 0;i < bg.getObstacleList().size();i++) {Obstacle ob1 = bg.getObstacleList().get(i);//判斷是否可以右走if (ob1.getX() == this.x + 36 && (ob1.getY() + 65 > this.y && ob1.getY() - 35 < this.y)) {canRight = false;}//判斷是否可以左走if (ob1.getX() == this.x - 36 && (ob1.getY() + 65 > this.y && ob1.getY() - 35 < this.y)) {canLeft = false;}}if (face_to && !canLeft || this.x == 0) {face_to = false;}else if ((!face_to) && (!canRight) || this.x == 764) {face_to = true;}//判斷是否是食人花敵人if (type == 2) {if (face_to) {this.y -= 2;}else {this.y += 2;}image_type = image_type == 1 ? 0 : 1;//食人花是否到達(dá)極限位置if (face_to && (this.y == max_up)) {face_to = false;}if ((!face_to) && (this.y == max_down)) {face_to = true;}show = StaticValue.flower.get(image_type);}try {Thread.sleep(50);} catch (InterruptedException e) {e.printStackTrace();}}} }BackGround.java
package com.sxt;import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List;public class BackGround {//當(dāng)前場(chǎng)景要顯示的圖像private BufferedImage bgImage = null;//記錄當(dāng)前是第幾個(gè)場(chǎng)景private int sort;//判斷是否是最后一個(gè)場(chǎng)景private boolean flag;//用于存放我們的所有障礙物private List<Obstacle> obstacleList = new ArrayList<>();//用于存放我們的所有敵人private List<Enemy> enemyList = new ArrayList<>();//用于顯示旗桿private BufferedImage gan = null;//用于顯示城堡private BufferedImage tower = null;//判斷馬里奧是否到達(dá)旗桿位置private boolean isReach = false;//判斷旗子是否落地private boolean isBase = false;public BackGround() {}public BackGround(int sort,boolean flag) {this.sort = sort;this.flag = flag;if (flag) {bgImage = StaticValue.bg2;}else {bgImage = StaticValue.bg;}//判斷是否是第一關(guān)if (sort == 1) {//繪制第一關(guān)的地面,上地面type=1,下地面type=2for (int i = 0;i < 27;i++) {obstacleList.add(new Obstacle(i*30,420,1,this));}for (int j = 0;j <= 120;j += 30) {for (int i = 0;i < 27;i++) {obstacleList.add(new Obstacle(i*30,570-j,2,this));}}//繪制磚塊Afor (int i = 120;i <= 150;i += 30) {obstacleList.add(new Obstacle(i,300,7,this));}//繪制磚塊B-Ffor (int i = 300;i <= 570;i += 30) {if (i == 360 || i == 390 || i == 480 || i == 510 || i == 540) {obstacleList.add(new Obstacle(i,300,7,this));} else {obstacleList.add(new Obstacle(i,300,0,this));}}//繪制磚塊Gfor (int i = 420;i <= 450;i += 30) {obstacleList.add(new Obstacle(i,240,7,this));}//繪制水管for (int i = 360;i <= 600;i += 25) {if (i == 360) {obstacleList.add(new Obstacle(620,i,3,this));obstacleList.add(new Obstacle(645,i,4,this));}else {obstacleList.add(new Obstacle(620,i,5,this));obstacleList.add(new Obstacle(645,i,6,this));}}//繪制第一關(guān)的蘑菇敵人enemyList.add(new Enemy(580,385,true,1,this));//繪制第一關(guān)的食人花敵人enemyList.add(new Enemy(635,420,true,2,328,428,this));}//判斷是否是第二關(guān)if (sort == 2) {//繪制第二關(guān)的地面,上地面type=1,下地面type=2for (int i = 0;i < 27;i++) {obstacleList.add(new Obstacle(i*30,420,1,this));}for (int j = 0;j <= 120;j += 30) {for (int i = 0;i < 27;i++) {obstacleList.add(new Obstacle(i*30,570-j,2,this));}}//繪制第一個(gè)水管for (int i = 360;i <= 600;i += 25) {if (i == 360) {obstacleList.add(new Obstacle(60,i,3,this));obstacleList.add(new Obstacle(85,i,4,this));}else {obstacleList.add(new Obstacle(60,i,5,this));obstacleList.add(new Obstacle(85,i,6,this));}}//繪制第二個(gè)水管for (int i = 330;i <= 600;i += 25) {if (i == 330) {obstacleList.add(new Obstacle(620,i,3,this));obstacleList.add(new Obstacle(645,i,4,this));}else {obstacleList.add(new Obstacle(620,i,5,this));obstacleList.add(new Obstacle(645,i,6,this));}}//繪制磚塊CobstacleList.add(new Obstacle(300,330,0,this));//繪制磚塊B,E,Gfor (int i = 270;i <= 330;i += 30) {if (i == 270 || i == 330) {obstacleList.add(new Obstacle(i,360,0,this));}else {obstacleList.add(new Obstacle(i,360,7,this));}}//繪制磚塊A,D,F,H,Ifor (int i = 240;i <= 360;i += 30) {if (i == 240 || i == 360) {obstacleList.add(new Obstacle(i,390,0,this));}else {obstacleList.add(new Obstacle(i,390,7,this));}}//繪制妨礙1磚塊obstacleList.add(new Obstacle(240,300,0,this));//繪制空1-4磚塊for (int i = 360;i <= 540;i += 60) {obstacleList.add(new Obstacle(i,270,7,this));}//繪制第二關(guān)的第一個(gè)食人花敵人enemyList.add(new Enemy(75,420,true,2,328,418,this));//繪制第二關(guān)的第二個(gè)食人花敵人enemyList.add(new Enemy(635,420,true,2,298,388,this));//繪制第二關(guān)的第一個(gè)蘑菇敵人enemyList.add(new Enemy(200,385,true,1,this));//繪制第二關(guān)的第二個(gè)蘑菇敵人enemyList.add(new Enemy(500,385,true,1,this));}//判斷是否是第三關(guān)if (sort == 3) {//繪制第三關(guān)的地面,上地面type=1,下地面type=2for (int i = 0;i < 27;i++) {obstacleList.add(new Obstacle(i*30,420,1,this));}for (int j = 0;j <= 120;j += 30) {for (int i = 0;i < 27;i++) {obstacleList.add(new Obstacle(i*30,570-j,2,this));}}//繪制第三個(gè)背景的A-O磚塊int temp = 290;for (int i = 390;i >= 270;i -= 30) {for (int j = temp;j <= 410;j += 30) {obstacleList.add(new Obstacle(j,i,7,this));}temp += 30;}//繪制第三個(gè)背景的P-R磚塊temp = 60;for (int i = 390;i >= 360;i -= 30) {for (int j = temp;j <= 90;j += 30) {obstacleList.add(new Obstacle(j,i,7,this));}temp += 30;}//繪制旗桿gan = StaticValue.gan;//繪制城堡tower = StaticValue.tower;//添加旗子到旗桿上obstacleList.add(new Obstacle(515,220,8,this));//繪制第三關(guān)的蘑菇敵人enemyList.add(new Enemy(150,385,true,1,this));}}public BufferedImage getBgImage() {return bgImage;}public int getSort() {return sort;}public boolean isFlag() {return flag;}public List<Obstacle> getObstacleList() {return obstacleList;}public BufferedImage getGan() {return gan;}public BufferedImage getTower() {return tower;}public boolean isReach() {return isReach;}public void setReach(boolean reach) {isReach = reach;}public boolean isBase() {return isBase;}public void setBase(boolean base) {isBase = base;}public List<Enemy> getEnemyList() {return enemyList;} }2.引入額外的JAR包
創(chuàng)建lib文件夾,統(tǒng)一存放需要導(dǎo)入的jar包(若已有l(wèi)ib文件,則直接可以進(jìn)行第二步)
將jar復(fù)制粘貼到lib文件夾內(nèi)
選中jar,右鍵-----》Build Path-----》Add to Build Path
導(dǎo)入JAR包后的樣子,因?yàn)槲业腏AR包已經(jīng)導(dǎo)入過(guò)了,所以上面的也有同樣的目錄。
總結(jié)
游戲挺好玩,還原度也夠。
鏈接:https://pan.baidu.com/s/1Nc28_UKsBV3QHGXfOjSAMg
提取碼:uqz9
歡迎交流,共同進(jìn)步。
總結(jié)
- 上一篇: 【机械设计】Catia V5-6R201
- 下一篇: kali 2022.2 解决make 命