Skip to content

Instantly share code, notes, and snippets.

@Spikey3
Created March 7, 2012 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Spikey3/1990423 to your computer and use it in GitHub Desktop.
Save Spikey3/1990423 to your computer and use it in GitHub Desktop.
package game;
import java.util.ArrayList;
public class RunningGame extends Minigame {
private int correct = 2;
private IconEntity computer_key_arrow_left;
private IconEntity computer_key_arrow_right;
private int selected = 0;
private int leftcount = 0;
private int rightcount = 0;
private long start_time = 0;
private boolean game_started = false;
public RunningGame(ArrayList<Entity> entities, ArrayList<Entity> removeList, Engine engine) {
super(entities, removeList, engine);
}
public void setup(){
System.out.println("Setting up RunningGame");
Entity frame = new FrameEntity(engine,"sprites/coffee-backrounds-wallpapers.jpg", 0, 0);
entities.add(frame);
computer_key_arrow_right = new IconEntity(engine,"sprites/computer_key_arrow_right.png", 5, 5);
entities.add computer_arrow_key_right;
computer_key_arrow_left = new IconEntity(engine,"sprites/computer_key_arrow_left.png", 5, 5);
entities.add computer_arrow_key_left;
}
public void logic(){
if(game_started == false){
if(engine.leftPressed == true){
System.out.println("Starting RunningGame!");
game_started = true;
start_time = System.currentTimeMillis();
}
} else {
//we're running
if(engine.leftPressed){
leftcount++;
System.out.print(computer_key_arrow_left);
}
if(engine.rightPressed){
rightcount++;
System.out.print(computer_key_arrow_right.x);
}
//check if we're done
long delta = System.currentTimeMillis() - start_time;
if(delta > 5000){
complete = true;
if(leftcount + rightcount > 10){
//you win
result = true;
} else {
//you lose
result = false;
}
System.out.println(leftcount + " " + rightcount + " ");
}
}
long current_time = System.currentTimeMillis();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment