Added structure class #145 and moved many constants to config.properties

This commit is contained in:
simon
2018-05-12 20:32:10 -04:00
parent be8dd14d36
commit 4b67798180
18 changed files with 136 additions and 113 deletions

View File

@@ -1,5 +1,6 @@
package net.simon987.server.assembly;
import net.simon987.server.GameServer;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.exception.*;
import net.simon987.server.logging.LogManager;
@@ -24,7 +25,7 @@ public class Assembler {
private RegisterSet registerSet;
private static final int MEM_SIZE = 0x10000; // Size in words todo load from config
private static final int MEM_SIZE = GameServer.INSTANCE.getConfig().getInt("memory_size");
public Assembler(InstructionSet instructionSet, RegisterSet registerSet, ServerConfiguration config) {
this.instructionSet = instructionSet;

View File

@@ -274,7 +274,7 @@ public class GameUniverse {
public String getGuestUsername() {
int i = 1;
while (i < 10000) { //todo get Max guest user cap from config
while (i < 50000) {
if (getUser("guest" + String.valueOf(i)) != null) {
i++;
continue;

View File

@@ -0,0 +1,80 @@
package net.simon987.server.game.objects;
import org.bson.Document;
import java.awt.*;
/**
* Game object that is stationary.
*/
public abstract class Structure extends GameObject {
/**
* Length of the structure in tiles for the x axis
*/
private int width;
/**
* Lenght of the structure in tiles for the y axis
*/
private int height;
public Structure(Document document, int width, int height) {
super(document);
this.width = width;
this.height = height;
}
public Structure(int width, int height) {
this.width = width;
this.height = height;
}
/**
* Get the first non-blocked tile that is directly adjacent to the factory
*
* @return The coordinates of the first non-blocked tile found, null if none is found.
*/
public Point getAdjacentTile() {
//Top
for (int x = getX() - 1; x < getX() + width; x++) {
if (!getWorld().isTileBlocked(x, getY() - 1)) {
return new Point(x, getY() - 1);
}
}
//Right
for (int y = getY() + width; y < getY() + height; y++) {
if (!getWorld().isTileBlocked(getX() + width, y)) {
return new Point(getX() + width, y);
}
}
//Bottom
for (int x = getX() - 1; x < getX() + width; x++) {
if (!getWorld().isTileBlocked(x, getY() + height)) {
return new Point(x, getY() + height);
}
}
//Left
for (int y = getY() - 1; y < getY() + height; y++) {
if (!getWorld().isTileBlocked(getX() - 1, y)) {
return new Point(getX() - 1, y);
}
}
return null;
}
@Override
public boolean isAt(int x, int y) {
/*
* Object is width x height tiles, the (x,y) coordinates of the object being
* at top-left.
* # .
* . .
*/
return x >= getX() && x < getX() + width && y >= getY() && y < getY() + height;
}
}

View File

@@ -456,24 +456,6 @@ public class World implements MongoSerializable {
return res;
}
public Point getAdjacentTile(int x, int y) {
if (!isTileBlocked(x + 1, y)) {
return new Point(x + 1, y);
} else if (!isTileBlocked(x, y + 1)) {
return new Point(x, getY() + 1);
} else if (!isTileBlocked(x - 1, y)) {
return new Point(x - 1, getY());
} else if (!isTileBlocked(x, y - 1)) {
return new Point(x, y - 1);
} else {
return null;
}
}
public Collection<GameObject> getGameObjects() {
return gameObjects.values();
}

View File

@@ -1,5 +1,6 @@
package net.simon987.server.web;
import net.simon987.server.GameServer;
import spark.ModelAndView;
import spark.Request;
import spark.Response;
@@ -14,6 +15,7 @@ public class PlayPage implements TemplateViewRoute {
public ModelAndView handle(Request request, Response response) {
Map<String, Object> model = new HashMap<>(1);
model.put("session", request.session());
model.put("gamePageTitle", GameServer.INSTANCE.getConfig().getString("server_name"));
return new ModelAndView(model, "play.vm");
}

View File

@@ -1,5 +1,6 @@
package net.simon987.server.websocket;
import net.simon987.server.GameServer;
import net.simon987.server.logging.LogManager;
import org.json.simple.JSONObject;
@@ -18,7 +19,7 @@ public class CodeRequestHandler implements MessageHandler {
JSONObject response = new JSONObject();
response.put("t", "code");
response.put("code", "; Create a free account to control your own Cubot with assembly language!"); //todo load from config
response.put("code", GameServer.INSTANCE.getConfig().getString("guest_user_code"));
user.getWebSocket().getRemote().sendString(response.toJSONString());