Greenfoot

java.lang.Object <– greenfoot.Greenfoot

public class Greenfoot extends java.lang.Object

Questa classe di utilità fornisce metodi per controllare la simulazione e interagire con il sistema.
Una funzionalità fornita da questa classe è ricevere l’input da tastiera.
Per questo scopo si utilizzano i metodi getKey() e isKeyDown() che restituiscono/riconoscono i seguenti nomi per i tasti:

  • ab, .., z (alfabeto)
    • getKey() restituisce correttamente anche i caratteri maiuscolo.
  • 0..9 (cifre)
  • la maggior parte dei segni di interpunzione…
  • updownleftright (cursore)
  • enterspacetabescapebackspace
  • F1F2, .., F12 (tasti funzione)

 



public Greenfoot()

Il costruttore.

 



public static java.lang.String getKey()

Ottiene il tasto premuto più recentemente dall’ultima volta che questo metodo è stato chiamato.

  • Se non è stato premuto alcun tasto dall’ultima chiamata restituirà null.
  • Se è stato premuto più di un tasto restituisce il tasto premuto più recentemente.

Restituisce:

il nome del tasto premuto più recentemente.

public static boolean isKeyDown(java.lang.String nomeTasto)

Controlla se un tasto dato è attualmente abbassato.
Parametro:

nomeTasto – Il nome del tasto da controllare.

Restituisce:

true se il tasto è abbassato.

 



public static boolean mousePressed(java.lang.Object oggetto)

True se il tasto del mouse è stato premuto (changed from a non-pressed state to being pressed) sull’oggetto dato.

  • If the parameter is an Actor the method will only return true if the mouse has been pressed on the given actor.
  • If there are several actors at the same place, only the top most actor will receive the press.
  • If the parameter is a World then true will be returned if the mouse was pressed on the world background.
  • If the parameter is null, then true will be returned for any mouse press, independent of the target pressed on.

Parametro:

oggetto – Un attore, il mondo oppure null.

Restituisce:

true se il tasto è stato premuto…

public static boolean mouseClicked(java.lang.Object oggetto)

True if the mouse has been clicked (pressed and released) on the given object.

  • If the parameter is an Actor the method will only return true if the mouse has been clicked on the given actor.
  • If there are several actors at the same place, only the top most actor will receive the click.
  • If the parameter is a World then true will be returned if the mouse was clicked on the world background.
  • If the parameter is null, then true will be returned for any click, independent of the target clicked on.

Parametro:

oggetto – Un attore, il mondo oppure null.

Restituisce:

true se il tasto è stato cliccato…

public static boolean mouseMoved(java.lang.Object oggetto)

True if the mouse has been moved on the given object. The mouse is considered to be moved on an object if the mouse pointer is above that object.

  • If the parameter is an Actor the method will only return true if the move is on the given actor.
  • If there are several actors at the same place, only the top most actor will receive the move.
If the parameter is a World then true will be returned if the move was on the world background.
  • If the parameter is null, then true will be returned for any move, independent of the target under the move location.

Parametro:

oggetto – Un attore, il mondo oppure null.

Restituisce:

true if the mouse has been moved as explained above.

public static boolean mouseDragged(java.lang.Object oggetto)

True if the mouse has been dragged on the given object. The mouse is considered to be dragged on an object if the drag started on that object – even if the mouse has since been moved outside of that object.

If the parameter is an Actor the method will only return true if the drag started on the given actor.
If there are several actors at the same place, only the top most actor will receive the drag.
If the parameter is a World then true will be returned if the drag action was started on the world background.
If the parameter is null, then true will be returned for any drag action, independent of the target clicked on.

Parametro:

oggetto – Typically one of Actor, World or null

Restituisce:

true if the mouse has been dragged as explained above

public static boolean mouseDragEnded(java.lang.Object oggetto)

True if a mouse drag has ended. This happens when the mouse has been dragged and the mouse button released.

If the parameter is an Actor the method will only return true if the drag started on the given actor.
If there are several actors at the same place, only the top most actor will receive the drag.
If the parameter is a World then true will be returned if the drag action was started on the world background.
If the parameter is null, then true will be returned for any drag action, independent of the target clicked on.

Parametro:

oggetto – Typically one of Actor, World or null .

Restituisce:

true if the mouse has been dragged as explained above.

public static MouseInfo getMouseInfo()

Restituisce un oggetto di informazioni del mouse con le informazioni sullo stato del mouse.
Restituisce:

le informazioni sullo stato attuale del mouse oppure null se non è successo nulla al mouse dall’ultimo controllo.

 



public static int getRandomNumber(int limite)

Restituisce:

un numero casuale tra 0 (compreso) e limite (escluso).

public static void playSound(java.lang.String nomeFile)

Emette un suono da file. Sono ammessi i formati: AIFFAU e WAV.
Il nome del file può essere

  • an absolute path
  • a base name for a file located in the project directory
  • oppure in the sounds directory of the project directory.

Parametro:

nomeFile – Normalmente il nome di un file nella cartella sounds del progetto.

Throws:

java.lang.IllegalArgumentException – Se il suono non può essere caricato.

public static void delay(int tempo)

Ritarda l’esecuzione corrente di un certo numero di intervalli di tempo.
La dimensione di ogni intervallo è definita dall’ambiente di Greenfoot (tramite cursore Velocità).
Parametro:

tempo – Il numero di intervalli.

public static void setSpeed(int velocità)

Imposta la velocità di esecuzione.
Il valore deve essere compreso nell’intervallo 1..100.
Parametro:

velocità – La nuova velocità.

public static void start()

Lancia (o riprende) l’esecuzione.

public static void stop()

Interrompe l’esecuzione.