-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey.java
More file actions
37 lines (36 loc) · 1.04 KB
/
Copy pathKey.java
File metadata and controls
37 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Key here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Key extends Robot
{
public enum Keys{
LEFT,CENTER,RIGHT,UNKNOWN
}
public Keys key=Keys.UNKNOWN;
public Key(){
while(key==Keys.UNKNOWN){
int rand = (int) Math.ceil(Math.random()*3);
if(rand == 1){
key=Keys.LEFT;
}else if(rand== 2){
key=Keys.CENTER;
}else if(rand== 3){
key=Keys.RIGHT;
}
}
GreenfootImage keys = new GreenfootImage("Key: " + key,25,greenfoot.Color.BLACK,greenfoot.Color.WHITE);
setImage(keys);
}
/**
* Act - do whatever the Key wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
}