Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lol.jacklyon3;
- import java.util.Timer;
- import java.util.TimerTask;
- /**
- * @author jacklyon3
- * Handles timing for the display and update rate.
- */
- public class Timers {
- public static final int BLUE = 0, RED = 1, TOP = 2, MID = 3, BOT = 4;
- private Display d;
- private Timer primary;
- private int gameTime;
- private int dragon, baron, yours[], enemys[];
- //ALL TIMING IS IN SECONDS
- //6 mins for dragon, 7 mins for baron, 5 mins for red and blue, 5 mins for inhib
- private int dragon_respawn = 6*60, baron_respawn = 7*60, blue_respawn = 5*60, red_respawn = 5*60, inhib_respawn = 5*60;
- private int dragon_spawn = 2*60+30, baron_spawn = 15*60, red_spawn = 60+55, blue_spawn = 60+55;
- private boolean gamePaused;
- //this needs to see the display because the timer ticks will call it's label update
- public Timers(Display d) {
- this.d = d;
- this.dragon = 0;
- this.baron = 0;
- this.yours = new int[5];
- this.enemys = new int[5];
- this.gamePaused = false;
- this.gameTime = 0;
- }
- public void togglePaused() {
- this.gamePaused = !gamePaused;
- }
- public void startGameTimer() {
- //set all params first to avoid problems
- //with arbitrary interleaving and concurrency
- //before the actual timertask
- this.gameTime = 0;
- this.gamePaused = false;
- dragon = dragon_spawn;
- baron = baron_spawn;
- yours[BLUE] = blue_spawn;
- enemys[BLUE] = blue_spawn;
- yours[RED] = red_spawn;
- enemys[RED] = red_spawn;
- yours[TOP] = -1;
- yours[MID] = -1;
- yours[BOT] = -1;
- enemys[TOP] = -1;
- enemys[MID] = -1;
- enemys[BOT] = -1;
- //update every second
- this.primary = new Timer();
- this.primary.scheduleAtFixedRate(new TimerTask(){
- public void run() {
- updateTime();
- }
- }, 0, 1000);
- }
- public void resetGameTimer() {
- this.primary.cancel();
- this.gameTime = -1;
- this.gamePaused = false;
- }
- public void updateTime() {
- if ( !gamePaused ) {
- this.gameTime++;
- dragon--;
- baron--;
- for ( int i = 0; i < yours.length; i++ ) {
- yours[i]--;
- enemys[i]--;
- }
- d.updateLabels();
- }
- }
- public int gameTime() {
- return this.gameTime;
- }
- public int getDragon() {
- return this.dragon;
- }
- public int getBaron() {
- return this.baron;
- }
- public int yourTime(int timer) {
- return yours[timer];
- }
- public int enemyTime(int timer) {
- return enemys[timer];
- }
- public void startBaron() {
- this.baron = baron_respawn;
- }
- public void startDragon() {
- this.dragon = dragon_respawn;
- }
- public void startYour(int timer) {
- if (timer == BLUE ) {
- this.yours[timer] = blue_respawn;
- }
- else if ( timer == RED ) {
- this.yours[timer] = red_respawn;
- }
- else {
- this.yours[timer] = inhib_respawn;
- }
- }
- public void startEnemy(int timer) {
- if (timer == BLUE ) {
- this.enemys[timer] = blue_respawn;
- }
- else if ( timer == RED ) {
- this.enemys[timer] = red_respawn;
- }
- else {
- this.enemys[timer] = inhib_respawn;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement