-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLocalPushy.java
137 lines (129 loc) · 6.57 KB
/
LocalPushy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import javax.swing.*;
import org.lolhens.network.*;
import org.lolhens.network.packet.*;
import org.lolhens.network.protocol.*;
import org.lolhens.network.disconnect.*;
import org.lolhens.network.nio.*;
/**
* Write a description of class LocalPushy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class LocalPushy extends Pushy
{
private boolean moveAgain = false;
public void update()
{
if (moveAgain) moveAgain = move(getDir(), 1);
checkKeys();
if (extraData.getBoolean("Charged")) {
setImage("124.png");
} else {
setImage("10.png");
}
}
public void onMove() {
if (extraData.getBoolean("Farmove")) moveAgain = true;
postEvent("pushyMove");
}
private void checkKeys()
{
boolean invert = extraData.getBoolean("Invert");
if (getWorld().keyManager.isKeyHit(invert?"down":"up")) move(0, 1);
if (getWorld().keyManager.isKeyHit(invert?"left":"right")) move(1, 1);
if (getWorld().keyManager.isKeyHit(invert?"up":"down")) move(2, 1);
if (getWorld().keyManager.isKeyHit(invert?"right":"left")) move(3, 1);
if (getWorld().keyManager.isKeyHit(invert?"s":"w")) move(0, 1);
if (getWorld().keyManager.isKeyHit(invert?"a":"d")) move(1, 1);
if (getWorld().keyManager.isKeyHit(invert?"w":"s")) move(2, 1);
if (getWorld().keyManager.isKeyHit(invert?"d":"a")) move(3, 1);
if (getWorld().keyManager.isKeyHit("enter")) {
LevelFile lvlFile = new LevelFile(getWorld().getLevelFile(String.valueOf(getWorld().extraData.getInt("currLvl"))), getWorld());
lvlFile.load();
}
if (getWorld().keyManager.isKeyHit("n")) {
getWorld().extraData.setInt("currLvl", getWorld().extraData.getInt("currLvl")+1);
LevelFile lvlFile = new LevelFile(getWorld().getLevelFile(String.valueOf(getWorld().extraData.getInt("currLvl"))), getWorld());
lvlFile.load();
}
if (getWorld().keyManager.isKeyHit("b") && getWorld().extraData.getInt("currLvl")>1) {
getWorld().extraData.setInt("currLvl", getWorld().extraData.getInt("currLvl")-1);
LevelFile lvlFile = new LevelFile(getWorld().getLevelFile(String.valueOf(getWorld().extraData.getInt("currLvl"))), getWorld());
lvlFile.load();
}
if (getWorld().keyManager.isKeyHit("m")) {
System.out.println("Level "+getWorld().extraData.getInt("currLvl"));
//world.getBackground().drawString("Level "+world.extraData.getInt("currLvl"), 1, 1);
}
if (getWorld().keyManager.isKeyHit("o")) {
JFileChooser filechooser = new JFileChooser();
if (filechooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) {
LevelFile lvlFile = new LevelFile(filechooser.getSelectedFile(), getWorld());
lvlFile.load();
}
}
if (getWorld().keyManager.isKeyHit("c")) {
String serverMode = JOptionPane.showInputDialog("Server? (Y/N)");
if (serverMode != null) {
String address = JOptionPane.showInputDialog("Adress/Port");
if (address != null) {
try {
if (serverMode.toLowerCase().equals("y")) {
getWorld().networkInterface = new Server<SimplePacket>(SimpleProtocol.class) { //, address
public void receive(Client<SimplePacket> client, SimplePacket packet) {
getWorld().packetQueue.add(packet);
for (AbstractClient<SimplePacket> cClient : getClients()) {
try {
if (cClient != client) cClient.send(packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void connect(Client<SimplePacket> client) {
for (AbstractClient<SimplePacket> cClient : getClients()) {
try {
//if (cClient != client) cClient.send(new SimplePacket(4));
} catch (Exception e) {
e.printStackTrace();
}
}
for (Object obj : getWorld().getObjects(null)) {
if (obj instanceof LocalPushy) {
LocalPushy pushy = (LocalPushy)obj;
RemotePushy remotePushy = new RemotePushy();
remotePushy.client = client;
getWorld().addObject(remotePushy, pushy.getX(), pushy.getY());
break;
}
}
getWorld().forceUpdate();
getWorld().send();
}
public void disconnect(Client<SimplePacket> client, DisconnectReason reason) {
for (Object obj : getWorld().getObjects(null)) {
if (obj instanceof RemotePushy) {
if (((RemotePushy)obj).client == client) ((GameObj)obj).remove();
}
}
}
};
} else {
getWorld().networkInterface = new Client<SimplePacket>(SimpleProtocol.class) { //, address
/*public void receive(SimplePacket packet) {
getWorld().packetQueue.add(packet);
}*/
};
}
} catch (Exception e) {
}
}
}
}
}
public int getId() {
return 10;
}
}