package com.yeqiuzs.mota;
/*
* 魔塔版本1.9
*增加了游戏介绍,和简单配置文件。
*
*/
import java.awt.Button;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.util.ArrayList;
import java.util.List;
public class MotaServer extends Frame {
Image offScreenImage = null;
Person p = new Person(250, 70, this);
Jiemian j = new Jiemian(this);
/*
* private static Toolkit tk = Toolkit.getDefaultToolkit(); private static
* Image backgroundImage = null;
*
* static { backgroundImage =
* tk.getImage(Pass.class.getClassLoader().getResource(
* "images/background.jpg"));
*
* }
*/
Map map = null;
int yellowKey, blueKey, grayKey, censhu = 1;
int yellowkeycount, bluekeycount, redkeycount;
BufferedReader bf;
DataInputStream dfdis;
List<Wall> walls = new ArrayList<Wall>();
List<Key> yellowKeys = new ArrayList<Key>();
List<Key> blueKeys = new ArrayList<Key>();
List<Key> redKeys = new ArrayList<Key>();
List<Door> doors = new ArrayList<Door>();
List<Information> infos = new ArrayList<Information>();
List<Monster> monsters = new ArrayList<Monster>();
List<DrawAttack> drawAttacks = new ArrayList<DrawAttack>();
List<DefenceJewel> jewels = new ArrayList<DefenceJewel>();
List<LiveLotio> lives = new ArrayList<LiveLotio>();
List<Pass> passs = new ArrayList<Pass>();
List<NPCperson> nps = new ArrayList<NPCperson>();
// Frame 初始化
static class chushi extends Frame implements ActionListener {
int game_width=Integer.parseInt(PropertyMy.getProperty("GAME_WIDTH"));
int game_height=Integer.parseInt(PropertyMy.getProperty("GAME_HEIGHT"));
Panel pp;
chushi() {
setBounds(500, 200, game_width, game_height);
setVisible(true);
setResizable(false);
setTitle("魔塔之骷髅大侠");
setFont(new Font("微软雅黑", Font.BOLD, 30));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
});
pp = new Panel();
pp.setBackground(Color.darkGray);
pp.setSize(650, 520);
pp.setLayout(new GridLayout(5,3, 5, 30));
Button b1 = new Button("开始游戏");
Button b2 = new Button("游戏简介");
b2.setSize(50, 20);
Button b3 = new Button("游戏设置");
b3.setSize(50, 20);
b1.addActionListener(this);
pp.add(new Label());
pp.add(new Label());
pp.add(new Label());
pp.add(new Label());
pp.add(b1);
pp.add(new Label());
pp.add(new Label());
pp.add(b2);
pp.add(new Label());
pp.add(new Label());
pp.add(b3);
pp.add(new Label());
pp.add(new Label());
pp.add(new Label());
pp.add(new Label());
pp.setVisible(true);
add(pp);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "开始游戏") {
this.removeAll();
this.dispose();
MotaServer mt; mt=new MotaServer();
mt.lauchFrame();
} else if (e.getActionCommand() == "游戏简介") {
/*
this.remove(pp);
Panel pp2=new Panel();
pp2.setSize(650, 520);
pp2.setBackground(Color.gray);
Label l=new Label("魔塔之地狱十八层");
pp2.add(l);
pp2.setVisible(true);
add(pp2);
*/
}
}
}
public void lauchFrame() {
// 菜单
MenuBar myb = new MenuBar();
Menu m1 = new Menu("游戏");
Menu m2 = new Menu("帮助");
Menu m11 = new Menu("难度");
MenuItem m12 = new MenuItem("重新开始");
MenuItem m13 = new MenuItem("退出游戏");
MenuItem m21 = new MenuItem("关于作者");
MenuItem m22 = new MenuItem("关于魔塔");
MenuShortcut m121 = new MenuShortcut(KeyEvent.VK_F2);
MenuShortcut m131 = new MenuShortcut(KeyEvent.VK_F3);
m12.setShortcut(m121);
m13.setShortcut(m131);
m11.add("简单");
m11.add("困难");
m1.add(m12);
m1.add(m11);
m1.add(m13);
m2.add(m21);
m2.add(m22);
setMenuBar(myb);
myb.add(m1);
myb.add(m2);
int game_width=Integer.parseInt(PropertyMy.getProperty("GAME_WIDTH"));
int game_height=Integer.parseInt(PropertyMy.getProperty("GAME_HEIGHT"));
setBounds(500, 200, game_width, game_height);
this.setBackground(Color.black);
setVisible(true);
setResizable(false);
setTitle("魔塔之骷髅大侠");
setFont(new Font("微软雅黑", Font.BOLD, 23));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
});
this.addKeyListener(new keylisten());
// 地图
map = new Map(this);
map.lanchMap();
p.floor = 1;
// 启动线程
MotaThread m = new MotaThread();
new Thread(m).start();
}
/*
* 画出游戏界面
*
* @see java.awt.Window#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
for (int i = 0; i < walls.size(); i++) {
Wall w = walls.get(i);
switch (this.censhu) {
case 1:
if (w.floor == 1) {
p.hintWall(w);
w.draw(g);
}
break;
case 2:
if (w.floor == 2) {
p.hintWall(w);
w.draw(g);
}
break;
case 3:
if (w.floor == 3) {
p.hintWall(w);
w.draw(g);
}
break;
case 4:
if (w.floor == 4) {
p.hintWall(w);
w.draw(g);
}
break;
}
}
for (int i = 0; i < yellowKeys.size(); i++) {
Key k = yellowKeys.get(i);
switch (this.censhu) {
case 1:
if (k.floor == 1) {
p.eatKey(k);
k.draw(g);
}
break;
case 2:
if (k.floor == 2) {
p.eatKey(k);
k.draw(g);
}
break;
case 3:
if (k.floor == 3) {
p.eatKey(k);
k.draw(g);
}
break;
case 4:
if (k.floor == 4) {
p.eatKey(k);
k.draw(g);
}
break;
}
}
for (int i = 0; i < blueKeys.size(); i++) {
Key k = blueKeys.get(i);
switch (this.censhu) {
case 1:
if (k.floor == 1) {
p.eatKey(k);
k.draw(g);
}
break;
case 2:
if (k.floor == 2) {
p.eatKey(k);
k.draw(g);
}
break;
case 3:
if (k.floor == 3) {
p.eatKey(k);
k.draw(g);
}
break;
case 4:
if (k.floor == 4) {
p.eatKey(k);
k.draw(g);
}
break;
}
}
for (int i = 0; i < redKeys.size(); i++) {
Key k = redKeys.get(i);
switch (this.censhu) {
case 1:
if (k.floor == 1) {
p.eatKey(k);
k.draw(g);
}
break;
case 2:
if (k.floor == 2) {
p.eatKey(k);
k.draw(g);
}
break;
case 3:
if (k.floor == 3) {
p.eatKey(k);
k.draw(g);
}
break;
case 4:
if (k.floor == 4) {
p.eatKey(k);
k.draw(g);
}
break;
}
}
for (int i = 0; i < doors.size(); i++) {
Door d = doors.get(i);
switch (this.censhu) {
case 1:
if (d.floor == 1) {
p.canPassDoor(d);
d.draw(g);
}
break;
case 2:
if (d.floor == 2) {
p.canPassDoor(d);
d.draw(g);
}
break;
case 3:
if (d.floor == 3) {
p.canPassDoor(d);
d.draw(g);
}
break;
case 4:
if (d.floor == 4) {
p.canPassDoor(d);
d.draw(g);
}
break;
}
}
for (int i = 0; i < infos.size(); i++) {
Information ii = infos.get(i);
ii.sendInformationToOpenDoors(doors);
// ii.meetnps(nps,g);
ii.killMonsters(monsters);
ii.InforHint