My Project
 Todo Clases Archivos Funciones Variables
Tiempo.java
Ir a la documentación de este archivo.
1 import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
2 import java.awt.*;
3 
10 public class Tiempo extends Actor
11 {
12  protected int tiem;//Variable que indica el tiempo restante.
13  private GreenfootImage img;//Variable que se va a utilizar para crear un objeto imagen.
14  private int band;//Variable que indica el momento en el cual el tiempo inicia a decrementar.
15  private int band2;//Variable que se utiliza para saber cuanto ha pasado y si llega a su limite el tiempo se decrementa
16 
20  public Tiempo()
21  {
22  tiem = 5;
23  band = 0;
24  band2 = 0;
25  img = new GreenfootImage(Integer.toString(tiem)+"s",20,Color.BLACK,Color.WHITE);
26  setImage(img);
27  }
28 
32  public void act()
33  {
34  setImage(new GreenfootImage(Integer.toString(tiem)+"s",20,Color.BLACK,Color.WHITE));
37  }
38 
42  public void incrementaTiempo()
43  {
44  if(tiem < 500)
45  tiem = tiem + 15;
46  }
47 
51  public void decrementaTiempo()
52  {
53  if(band == 0)
54  {
55  tiem --;
56  band = 1;
57  }
58  else
59  {
60  if(band2 == 70)
61  {
62  band = 0;
63  band2 = 0;
64  }
65  else
66  band2 ++;
67  }
68  }
69 
73  public void pierdeTiempo()
74  {
75  tiem = tiem - 30;
76  }
77 
81  public void pierdePorTiempo()
82  {
83  if(tiem <= 0)
84  ((Mundo)getWorld()).pierdes();
85  }
86 }