package zombievsplants.controller;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import zombievsplants.model.Card;
import zombievsplants.model.CherryBomb;
import zombievsplants.model.Peashooter;
import zombievsplants.model.Plant;
import zombievsplants.model.SunFlower;
import zombievsplants.model.WallNut;
import zombievsplants.model.Zombie;
import zombievsplants.view.GameView;
//游戏关卡的设置
public class Level {
public static JLabel finalwave; //提醒最后一波僵尸即将到来的标签
public static JLabel largewave; //提醒一大波僵尸即将到来的标签
public static JLabel levelName; //关卡的名称的标签
public static int theLevel = 3; //当前游戏关卡
//所有关卡都一样的初始设定
//游戏一轮循环为20ms,50*20=1000ms,即1s
public static void removeAndAdd() {
//把所有的植物和僵尸先remove再add,防止植物和僵尸遮挡住字
for(Plant p :GameController.allPlant) {
GameView.frame.remove(p.getPlant());
GameView.frame.add(p.getPlant());
for(JLabel pb:p.getProducts()) {
GameView.frame.remove(pb);
GameView.frame.add(pb);
}
}
for(Zombie z:GameController.allzom) {
GameView.frame.remove(z.getZom());
GameView.frame.add(z.getZom());
}
}
public static void level0() {
//提示准备安放植物
if(GameController.i==1*50) {
GameView.prepare = new JLabel(new ImageIcon("src/zombievsplants/photos/PrepareGrowPlants1.gif"));
GameView.frame.add(GameView.prepare);
GameView.prepare.setBounds(350, 300, GameView.prepare.getIcon().getIconWidth(), GameView.prepare.getIcon().getIconHeight());
}
if(GameController.i==2*50) {
GameView.prepare.setIcon(new ImageIcon("src/zombievsplants/photos/PrepareGrowPlants2.gif"));
GameView.frame.repaint();
}
if(GameController.i==3*50) {
GameView.prepare.setIcon(new ImageIcon("src/zombievsplants/photos/PrepareGrowPlants3.gif"));
GameView.frame.repaint();
}
if(GameController.i==4*50) {
GameView.frame.remove(GameView.prepare);
GameView.frame.repaint();
//在窗口中加入鼠标监听器
GameView.frame.addMouseListener(GameController.panell);
GameView.frame.addMouseMotionListener(GameController.panell);
}
}
public static void level1() { //第一关
level0();
//生成卡片,并将除第3行外的草坪设为不可安放植物的状态
if(GameController.i==4*50) {
new Card(new SunFlower());
new Card(new Peashooter());
for(int i=0;i<9;i++) {
for(int j=0;j<5;j++) {
if(j!=2) {
GameView.hasPlant[i][j]=true;
}
else {
GameView.hasPlant[i][j]=false;
}
}
}
//右下角添加游戏关卡名字的标签
levelName = new JLabel(new ImageIcon("src/zombievsplants/photos/关卡1.png"));
GameView.frame.add(levelName);
levelName.setBounds(800 , 615, levelName.getIcon().getIconWidth(), levelName.getIcon().getIconHeight());
}
//初始缓慢生成僵尸
if(GameController.i<120*50) {
if (GameController.i%1000==900) {
AddZombie.addZombie(3,theLevel);
}
}
else if(GameController.i<160*50){
if (GameController.i%1000==1) {
AddZombie.addZombie(3,theLevel);
AddZombie.addZombie(3,theLevel);
}
}
//提醒一大波僵尸即将到来
if(GameController.i==160*50) {
largewave = new JLabel(new ImageIcon("src/zombievsplants/photos/LargeWave.gif"));
GameView.frame.add(largewave);
largewave.setBounds(350, 300, largewave.getIcon().getIconWidth(),largewave.getIcon().getIconHeight());
Level.removeAndAdd();
}
if(GameController.i==162*50) {
GameView.frame.remove(largewave);
}
//提醒最后一波到来
if(GameController.i==169*50) {
finalwave = new JLabel(new ImageIcon("src/zombievsplants/photos/FinalWave.gif"));
GameView.frame.add(finalwave);
finalwave.setBounds(350, 300, finalwave.getIcon().getIconWidth(),finalwave.getIcon().getIconHeight());
Level.removeAndAdd();
}
//最后一波
if(GameController.i>=170*50&&GameController.i<=190*50) {
GameView.frame.remove(finalwave);
if(GameController.i%100==0) {
AddZombie.addZombie(3,theLevel);
}
}
//胜利
if(GameController.i>190*50) {
if(GameController.allzom.size()==0) {
GameController.run = Integer.MAX_VALUE;
GameController.i=0;
}
}
}
public static void level2() { //第二关
level0();
//生成卡片,并将第1、5行的草坪设为不可安放植物的状态
if(GameController.i==4*50) {
new Card(new SunFlower());
new Card(new Peashooter());
new Card(new WallNut());
for(int i=0;i<9;i++) {
for(int j=0;j<5;j++) {
if(j==0||j==4) {
GameView.hasPlant[i][j]=true;
}
else {
GameView.hasPlant[i][j]=false;
}
}
}
JLabel l = new JLabel(new ImageIcon("src/zombievsplants/photos/关卡2.png"));
GameView.frame.add(l);
l.setBounds(800 , 615, l.getIcon().getIconWidth(), l.getIcon().getIconHeight());
}
//初始缓慢生成僵尸
if(GameController.i<120*50) {
if (GameController.i%1000==900) {
Random rand = new Random();
AddZombie.addZombie(rand.nextInt(3)+2,1);
}
}
else if(GameController.i<210*50){
if (GameController.i%1000==1) {
Random rand = new Random();
AddZombie.addZombie(rand.nextInt(3)+2,theLevel);
AddZombie.addZombie(rand.nextInt(3)+2,theLevel);
}
}
//提醒一大波僵尸即将到来
if(GameController.i==210*50) {
largewave = new JLabel(new ImageIcon("src/zombievsplants/photos/LargeWave.gif"));
GameView.frame.add(largewave);
largewave.setBounds(350, 300, largewave.getIcon().getIconWidth(),largewave.getIcon().getIconHeight());
Level.removeAndAdd();
}
if(GameController.i==212*50) {
GameView.frame.remove(largewave);
}
//第一波
if(GameController.i>=220*50&&GameController.i<=240*50) {
if(GameController.i%60==0) {
Random rand = new Random();
AddZombie.addZombie(rand.nextInt(3)+2,theLevel);
}
}
//中间缓冲
if(GameController.i>=270*50&&GameController.i<=330*50) {
if(GameController.i%500==0) {
Random rand = new Random();
AddZombie.addZombie(rand.nextInt(3)+2,theLevel);
}
}
//提醒一大波僵尸即将到来
if(GameController.i==335*50) {
largewave = new JLabel(new ImageIcon("src/zombievsplants/photos/LargeWave.gif"));
GameView.frame.add(largewave);
largewave.setBounds(350, 300, largewave.getIcon().getIconWidth(),largewave.getIcon().getIconHeight());
Level.removeAndAdd();
}
if(GameController.i==337*50) {
GameView.frame.remove(largewave);
}
//提醒最后一波
if(GameController.i==343*50) {
finalwave = new JLabel(new ImageIcon("src/zombievsplants/photos/FinalWave.gif"));
GameView.frame.add(finalwave);
finalwave.setBounds(350, 300, finalwave.getIcon().getIconWidth(),finalwave.getIcon().getIconHeight());
Level.removeAndAdd();
}
//最后一波
if(GameController.i>=350*50&&GameController.i<=370*50) {
GameView.frame.remove(finalwave);
if(GameController.i%50==0) {
Random rand = new Random();
AddZombie.addZombie(rand.nextInt(3)+2,theLevel);
}
}
//胜利
if(GameController.i>370*50) {
if(GameController.allzom.size()==0) {
GameController.run = Integer.MAX_VALUE;
GameController.i=0;
}
}
}
public static void level3() { //第三关
level0();
//生成卡片,并将所有草坪设置为可安放植物的状态
if(GameController.i==4*50) {
new Card(new SunFlower());
new Card(new Peashooter());
new Card(new WallNut());
new Card(new CherryBomb());
for(int i=0;i<9;i++) {
for(int j=0;j<5;j++) {
GameView.hasPlant[i][j]=false;
}
}
JLabel l = new JLabel(new ImageIcon("src/zombievsplants/photo
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java实现的植物大战僵尸 (194个子文件)
Level.class 6KB
PlantAct.class 4KB
ButtonController.class 4KB
Plant.class 4KB
Zombie.class 4KB
GameController.class 3KB
GameView.class 3KB
ZombieWon.class 3KB
Remove.class 3KB
Music.class 3KB
PlantWon.class 3KB
Initialize.class 3KB
LawnCleanerAct.class 3KB
ZombieAct.class 3KB
Card.class 3KB
PanelListener.class 2KB
SunAct.class 2KB
LawnCleaner.class 2KB
AddPlant.class 2KB
AddZombie.class 2KB
CherryBomb.class 2KB
Peashooter.class 2KB
SunFlower.class 2KB
CardController.class 2KB
WallNut.class 1KB
Start.class 1KB
CardAct.class 1KB
PlantWon$1.class 1KB
SunClick.class 1KB
ZombieWon$1.class 1KB
BucketheadZombie.class 1KB
ConeheadZombie.class 1KB
Common.class 998B
.classpath 301B
background3.gif 280KB
background3.gif 280KB
background1.gif 240KB
background1.gif 240KB
ConeheadZombie.gif 76KB
ConeheadZombie.gif 76KB
Zombie.gif 70KB
Zombie.gif 70KB
OptionsMenuback32.gif 69KB
OptionsMenuback32.gif 69KB
Walk1.gif 69KB
Walk1.gif 69KB
FlagZombie.gif 65KB
FlagZombie.gif 65KB
ZombieAttack.gif 61KB
ZombieAttack.gif 61KB
Boom.gif 55KB
Boom.gif 55KB
BucketheadZombie.gif 53KB
BucketheadZombie.gif 53KB
BucketheadZombieAttack.gif 47KB
BucketheadZombieAttack.gif 47KB
Sun.gif 44KB
Sun.gif 44KB
ConeheadZombieAttack.gif 42KB
ConeheadZombieAttack.gif 42KB
SunFlower1.gif 41KB
SunFlower1.gif 41KB
gameOver.gif 29KB
gameOver.gif 29KB
Wallnut_cracked2.gif 28KB
Wallnut_cracked2.gif 28KB
游戏胜利.gif 27KB
游戏胜利.gif 27KB
ZombiesWon.gif 26KB
ZombiesWon.gif 26KB
Peashooter.gif 23KB
Peashooter.gif 23KB
WallNut.gif 22KB
WallNut.gif 22KB
CherryBomb.gif 17KB
CherryBomb.gif 17KB
Wallnut_cracked1.gif 15KB
Wallnut_cracked1.gif 15KB
maoxian2.gif 14KB
maoxian2.gif 14KB
maoxian1.gif 13KB
maoxian1.gif 13KB
tryAgain.gif 7KB
tryAgain.gif 7KB
下一关.gif 6KB
下一关.gif 6KB
CherryBomb0.gif 4KB
CherryBomb0.gif 4KB
LargeWave.gif 4KB
LargeWave.gif 4KB
FinalWave.gif 4KB
FinalWave.gif 4KB
PrepareGrowPlants3.gif 3KB
PrepareGrowPlants3.gif 3KB
LawnCleaner.gif 3KB
LawnCleaner.gif 3KB
PrepareGrowPlants1.gif 2KB
PrepareGrowPlants1.gif 2KB
PB00.gif 2KB
PB00.gif 2KB
共 194 条
- 1
- 2
资源评论
- 本本纲目2023-07-27这个文件提供了很有趣的游戏玩法,让我沉浸其中,一丝不损的享受游戏的乐趣。
- 嗨了伐得了2023-07-27通过使用Java语言实现,这个文件让我深刻体验到了植物和僵尸之间的紧张对峙,让我感受到了作战的刺激感。
- 巴蜀明月2023-07-27植物大战僵尸这个文件的操作简单明了,让我可以轻松上手,快速享受到这款经典游戏的乐趣。
- Jaihwoe2023-07-27这个文件的图像和音效设计可以说是恰到好处,恰如其分的营造出了僵尸入侵的紧张氛围,让我更加沉浸其中。
- 陈莽昆2023-07-27植物大战僵尸这个文件通过恰到好处的难度设置,给予了我足够的挑战,让我不断去思考和尝试更好的战略。
鲸羽
- 粉丝: 64
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于JAVA-JSP的现代数字化电子政务网管理系统论文-20240403更新
- 西部钻探工程有限公司安全环保问责管理办法.doc
- Using Model-Based Design to Develop SOA Applications
- PHP Decrypt跨平台解密PHP源码的扩展
- SimHei MAC字体资源
- 2024全国行政区域编码
- 数据源-数据可视化(七):Pandas香港酒店数据高级分析,涉及相关系数,协方差,数据离散化,透视表等精美可视化展示
- linux常用命令大全.doc
- 格拉斯哥大学空缺职位申请详细介绍Applicant Guide.pdf
- mmexport1702953347189.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功