Thread: tell me why this code wont work

Results 1 to 3 of 3
  1. #1 tell me why this code wont work 
    Registered Member Andrew's Avatar
    Join Date
    Nov 2008
    Posts
    2,892
    Thanks given
    613
    Thanks received
    207
    Discord
    View profile
    Rep Power
    551
    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..."); 
    	}
    }
    Reply With Quote  
     

  2. #2  
    RuneFatality

    Join Date
    May 2009
    Age
    24
    Posts
    2,355
    Thanks given
    1,099
    Thanks received
    388
    Rep Power
    531
    Fist of all, most of it is commented out.
    Secondly, explain what isn't working.
    Thirdly, tell us where you added the code to use that class.
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Jan 2010
    Posts
    3,665
    Thanks given
    533
    Thanks received
    918
    Rep Power
    0
    fuck off.

    What is wrong, what did you add, is it a compile/technical difficulty, wtf....

    no description whatsoever, what is the code SUPPOSED to do and what is it currently doing.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •