Created
March 8, 2012 19:41
-
-
Save Spikey3/2002923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package game; | |
import java.util.ArrayList; | |
public class RunningGame extends Minigame { | |
private int correct = 2; | |
private IconEntity arrow_left; | |
private IconEntity arrow_right; | |
private int selected = 0; | |
private int leftcount = 0; | |
private int rightcount = 0; | |
private long left_time = 0; | |
private long right_time = 0; | |
private long start_time = 0; | |
private boolean game_started = false; | |
private Entity frame; | |
public RunningGame(ArrayList<Entity> entities, ArrayList<Entity> removeList, Engine engine) { | |
super(entities, removeList, engine); | |
} | |
public void setup(){ | |
System.out.println("Setting up RunningGame"); | |
frame = new FrameEntity(engine,"sprites/background_coffee.jpg", 0, 0); | |
entities.add(frame); | |
game_started = false; | |
} | |
public void logic(){ | |
if(game_started == false){ | |
if(engine.leftPressed == true){ | |
System.out.println("Starting RunningGame!"); | |
game_started = true; | |
start_time = System.currentTimeMillis(); | |
frame.x = frame.x -5; | |
} | |
} else { | |
//we're running | |
if(engine.leftPressed){ | |
leftcount++; | |
arrow_left = new IconEntity(engine,"sprites/left_arrow.png", 450, 500); | |
entities.add(arrow_left); | |
engine.leftPressed = false; | |
left_time = System.currentTimeMillis(); | |
} | |
if(engine.rightPressed){ | |
rightcount++; | |
arrow_right = new IconEntity(engine,"sprites/right_arrow.png", 550, 500); | |
entities.add(arrow_right); | |
engine.rightPressed = false; | |
right_time = System.currentTimeMillis(); | |
} | |
long left_delta = System.currentTimeMillis() - left_time; | |
if(left_delta > 150){ | |
removeList.add(arrow_left); | |
} | |
long right_delta = System.currentTimeMillis() - right_time; | |
if(right_delta > 150){ | |
removeList.add(arrow_right); | |
} | |
//check if we're done | |
long delta = System.currentTimeMillis() - start_time; | |
if(delta > 45000){ | |
complete = true; | |
//Showing user whether they win or lose | |
if(leftcount + rightcount > 25){ | |
//you win | |
result = true; | |
Entity frame = new FrameEntity(engine,"sprites/YouWin.PNG", 0, 0); | |
entities.add(frame); | |
} else { | |
//you lose | |
result = false; | |
Entity frame = new FrameEntity(engine,"sprites/GameOver.jpg", 0, 0); | |
entities.add(frame); | |
} | |
System.out.println("Game Ended" + result); | |
System.out.println(leftcount + " " + rightcount + " "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment