Code:
import java.util.ArrayList;
public class PestControl extends Thread {
private static final ArrayList<Player> PLAYERS = new ArrayList<Player>();
private static final int END_GAME = 0;
private static final int[] TIMES = {2,1}; // in Minutes.
private static final int START_GAME = (TIMES[0] * 60);
private static final int NEW_GAME = ((TIMES[1] + TIMES[0]) * 60);
private static PestControl pestControl;
private static boolean pestGameIsRunning = false;
private static int gameTimer = NEW_GAME;
protected PestControl() {
this.pestGameIsRunning = true;
}
protected static void setInstance(PestControl pestControl) {
pestControl = pestControl;
}
protected static PestControl getInstance() {
return pestControl;
}
/*public void addPlayer(Player p, String color2) {
ArrayList<Player> color = color2 == "blue" ? BLUE_PLAYERS : RED_PLAYERS;
if(!RED_PLAYERS.contains(p) && !BLUE_PLAYERS.contains(p))
color.add(p);
}*/
/*public void removePlayer(Player p) {
if (p != null) {
if(PLAYERS.contains(p)) {
PLAYERS.remove(p);
p.closedAreasReset();
p.toX = 2441;
p.toY = 3091;
}
}
}*/
private static void startGame() {
//Checks all Players Once instead of every step they take
//Teles all players into arena.
for (Player p : PLAYERS) {
if (p != null) {
p.teleportToClosedArea(5);
p.c(p).wildysigndisappear2();
p.c(p).setInterfaceWalkable(13588);
}
}
}
protected boolean isInGame(Player p) {
return (PLAYERS.contains(p));
}
private static void endGame() {
for (Player p : PLAYERS) {
if (p != null) {
if (p.getIsInClosedArea(4)) {
p.closedAreasReset();
p.currentHealth = p.playerLevel[p.playerHitpoints]; //brb
p.toX = 2441;
p.toY = 3091;
p.c(p).wildysigndisappear2();
}
}
}
PLAYERS.clear();
}
private void editTimer() {
if (gameTimer > END_GAME && gameTimer < START_GAME) { //if timer is > 0 and timer < 300 countunue.
endGame();
gameTimer = END_GAME;
} else { //else
gameTimer = NEW_GAME; //if time is <= 0 or timer >= 300 then timer = 300 kk save+compile? yeah.
}
}
private void sendWaitingRoomTimer() {
for (Player p : Server.playerHandler.players) {
if (p != null) {
if ((p.getIsInClosedArea(4))) {
p.c(p).sendFrame126("@[email protected] In Team:"+PLAYERS.size(),13589);
p.c(p).sendFrame126("@[email protected]",13593);
p.c(p).sendFrame126("@[email protected] Left: "+getModifidTimer(gameTimer - START_GAME),13591);
}
}
}
}
private void sendStrings() {
for (Player p : PLAYERS) {
if (p != null) {
if (p.c(p).getIsInClosedArea(5)) {
p.c(p).setInterfaceWalkable(13588);
p.c(p).sendFrame126("Test ",13591);
p.c(p).sendFrame126("TEST ",13592);
p.c(p).sendFrame126("@[email protected] Left: "+getModifidTimer(gameTimer - END_GAME),13593);
}
}
}
}
private String getModifidTimer(int time) {
int minutes = (time / 60);
int seconds = (time - (minutes * 60));
return ("Time: "+minutes+":"+(seconds < 10 ? "0"+seconds : seconds));
}
public void run() {
while(pestGameIsRunning) {
if (START_GAME == gameTimer) { //180
startGame();
}
if (END_GAME == gameTimer) {
endGame();
}
sendStrings();
sendWaitingRoomTimer();
editTimer();//the timer wont go down eaither :\ its not even runing it sec.
System.out.println("TIME: "+gameTimer+" PLAYER_SIZE: "+PLAYERS.size());
try {
Thread.sleep(1000);
} catch (Exception e){ e.printStackTrace(); }
}
//System.out.println("Game Crashed...");
}
}