public class Playground extends GameGrid
Modifier and Type | Field and Description |
---|---|
static int |
BIGSIZE
Constants for the turtle magnification (augmented to double the standard size).
|
static int |
BLACK
Short for Color.BLACK.
|
static int |
BLUE
Short for Color.BLUE.
|
static int |
CYAN
Short for Color.CYAN.
|
static int |
DKGRAY
Short for Color.DKGRAY.
|
static int |
GRAY
Short for Color.GRAY.
|
static int |
GREEN
Short for Color.GREEN.
|
static int |
LTGRAY
Short for Color.LTGRAY.
|
static int |
MAGENTA
Short for Color.MAGENTA.
|
static int |
MAXSPEED
Maximum speed (no animation).
|
static int |
MEDIUMSIZE
Constants for the turtle magnification (standard size).
|
static int |
RED
Short for Color.RED.
|
static int |
SMALLSIZE
Constants for the turtle magnification (reduced to half the standard size).
|
static int |
TRANSPARENT
Short for Color.TRANSPARENT.
|
static int |
WHITE
Short for Color.WHITE.
|
static int |
YELLOW
Short for Color.YELLOW.
|
turtleImage
DEFAULT_KEYS_DIALER, DEFAULT_KEYS_DISABLE, DEFAULT_KEYS_SEARCH_GLOBAL, DEFAULT_KEYS_SEARCH_LOCAL, DEFAULT_KEYS_SHORTCUT, RESULT_CANCELED, RESULT_FIRST_USER, RESULT_OK
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_NOT_FOREGROUND, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MODE_APPEND, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NOTIFICATION_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, TELEPHONY_SERVICE, UI_MODE_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
Constructor and Description |
---|
Playground()
Creates a square sized playground that fits the device screen.
|
Playground(java.lang.String turtleImage)
Same as Playground(), but the turtle seed image is loaded from the sdcard.
|
Modifier and Type | Method and Description |
---|---|
Turtle |
back(double s)
Moves the global turtle back.
|
static void |
beep()
Emits a beep (1000 Hz sine wave of 100 ms duration).
|
Turtle |
bk(double s)
Short for back().
|
static void |
clean()
Erases the playground by filling it with the current playground color.
|
static void |
clean(int color)
Erases the playground by filling it with the given color.
|
static void |
clear()
Clears the playground by filling it with the current playground color.
|
static void |
clear(int color)
Clears the playground by filling it with the given color.
|
Turtle |
clone()
Creates a clone of the current global turtle by performing a
deep copy of all its properties.
|
static void |
delay(long timeout)
Halts the current thread for the given time.
|
double |
distance(double x,
double y)
Returns the distance from the current position of the
global turtle to the given position.
|
Turtle |
dot()
Draws a single point (dot) at the current turtle position using the
current pen color.
|
Turtle |
fd(double s)
Short for forward().
|
Turtle |
fill()
Same as fill(x, y), but using the current turtle position.
|
Turtle |
fill(double x,
double y)
Fills a bounded region of the playground with the current
pen color (flood fill).
|
Turtle |
fillOff()
Stops the filling started by calling fillToPoint(),
fillToHorizontal() or fillToVertical().
|
Turtle |
fillToHorizontal(double y)
Draws a imaginary horizonatal line at given y coordinate.
|
Turtle |
fillToPoint(double x,
double y)
Attachs a imaginary rubber band between the global turtle and the given
anchor point.
|
Turtle |
fillToVertical(double x)
Draws a imaginary vertical line at given x coordinate.
|
Turtle |
forward(double s)
Moves the global turtle forward.
|
int |
getColor()
Returns the current global turtle color.
|
double |
getHeading()
Returns the current heading (moving direction) of the global turtle.
|
int |
getPenColor()
Returns the current pen color of the global turtle.
|
int |
getPenWidth()
Returns the current pen width of the global turtle.
|
int |
getPlaygroundColor()
Returns the color of the playground.
|
int |
getSpeed()
Returns the current speed (0..10, -1 for MAXSPEED) of the global turtle.
|
Turtle |
getTopTurtleNear(double xCenter,
double yCenter,
double radius)
Returns the topmost turtle reference that intersect with
the given circle.
|
java.util.ArrayList<Turtle> |
getTurtlesNear(double xCenter,
double yCenter,
double radius)
Returns the list of turtles that intersect with the given circle
(in paint order: subsequent turtle in the list are painted on top
of preceding actors.
|
double |
getX()
Returns the current x coordinate of the global turtle.
|
double |
getY()
Returns the current y coordinate of the global turtle.
|
double |
getZoomFactor()
Returns the quotient between pixel and turtle distances.
|
Turtle |
hideTurtle()
Hides the global turtle.
|
Turtle |
home()
Puts the global turtle at home (center of playground, coordinates (0, 0).
|
Turtle |
ht()
Short for hideTurtle().
|
boolean |
isBackValid(double s)
Checks if the backward movement using the given step moves
the turtle to a position outside the visible playground.
|
boolean |
isForwardValid(double s)
Checks if the forward movement using the given step moves
the turtle to a position outside the visible playground.
|
boolean |
isHidden()
Reports the current visibility of the global turtle.
|
boolean |
isOnBoarder(int borderId)
Returns true, if the turtle is on the selected border line.
|
boolean |
isOnBorder()
Returns true, if the global turtle is on any of the 4 border lines.
|
boolean |
isPenDown()
Reports the current pen state of the global turtle.
|
Turtle |
label(java.lang.String text)
Same as label(text, textColor, textSize) with textColor = Color.WHITE
and textSize = 15.
|
Turtle |
label(java.lang.String text,
int textColor,
int textSize)
Paints the given text with given text color and given text height
at the current global turtle position
|
Turtle |
left(double angle)
Turns global the turtle to the left (counter clockwise).
|
Turtle |
lt(double angle)
Short for left().
|
Turtle |
moveTo(double x,
double y)
Puts the global turtle to the given position.
|
Turtle |
pd()
Short for penDown().
|
Turtle |
penDown()
Lowers the global turtle's pen, so it draws traces when it moves.
|
Turtle |
penUp()
Lifts the global turtle's pen, so is does not draw traces when it moves.
|
void |
playgroundClicked(double x,
double y)
Event notification when the playground is clicked.
|
void |
playgroundDragged(double x,
double y)
Event notification when the playground is dragged.
|
void |
playgroundLongPressed(double x,
double y)
Event notification when the playground is long pressed.
|
void |
playgroundPressed(double x,
double y)
Event notification when the playground is pressed.
|
void |
playgroundReleased(double x,
double y)
Event notification when the playground is released.
|
Turtle |
pu()
Short for penUp().
|
double |
readDouble(java.lang.String title,
java.lang.String prompt)
Same as readDouble(title, prompt, init), but no initial value is displayed.
|
double |
readDouble(java.lang.String title,
java.lang.String prompt,
double init) |
int |
readInt(java.lang.String title,
java.lang.String prompt)
Same as readInt(title, prompt, init), but no initial value is displayed.
|
int |
readInt(java.lang.String title,
java.lang.String prompt,
int init) |
java.lang.String |
readString(java.lang.String title,
java.lang.String prompt)
Same as readString(title, prompt, init), but no initial value is displayed.
|
java.lang.String |
readString(java.lang.String title,
java.lang.String prompt,
java.lang.String init) |
java.lang.String |
readStringWithCancel(java.lang.String title,
java.lang.String prompt,
java.lang.String init) |
Turtle |
right(double angle)
Turns the global turtle to the right (clockwise).
|
Turtle |
rt(double angle)
Short for right().
|
Turtle |
setColor(int color)
Sets the current global turtle color.
|
Turtle |
setHeading(double heading)
Sets the current heading (moving direction) of the gloabal turtle.
|
Turtle |
setPenColor(int color)
Sets the current pen color of the global turtle.
|
Turtle |
setPenWidth(int width)
Sets the current pen width.
|
Turtle |
setPos(double x,
double y)
Puts the global turtle to the given position.
|
Turtle |
setSize(int size)
Sets the current turtle size.
|
Turtle |
setSpeed(int speed)
Sets the global turtle's speed.
|
Turtle |
setX(double x)
Puts the global turtle to the given x coordinate.
|
Turtle |
setY(double y)
Puts the global turtle to the given y coordinate.
|
void |
showToast(java.lang.String text)
Displays an Android "toast" message (notification that pops
up shortly) at system defined position.
|
Turtle |
showTurtle()
Shows the global turtle if it was hidden before.
|
void |
showValue(java.lang.String title,
boolean value)
Displays a modal information dialog with an Ok button.
|
void |
showValue(java.lang.String title,
double value)
Displays a modal information dialog with an Ok button.
|
void |
showValue(java.lang.String title,
float value)
Displays a modal information dialog with an Ok button.
|
void |
showValue(java.lang.String title,
int value)
Displays a modal information dialog with an Ok button.
|
void |
showValue(java.lang.String title,
long value)
Displays a modal information dialog with an Ok button.
|
void |
showValue(java.lang.String title,
short value)
Displays a modal information dialog with an Ok button.
|
void |
showValue(java.lang.String title,
java.lang.String value)
Displays a modal information dialog with an Ok button.
|
static void |
sleep(int time)
Delays the execution for the given time.
|
Turtle |
st()
Short for showTurtle().
|
double |
towards(double x,
double y)
Returns the direction (heading) of the global turtle
from the current position to the given position.
|
void |
turtleClicked(Turtle turtle,
double x,
double y)
Event notification when a turtle is clicked.
|
void |
turtleDragged(Turtle turtle,
double x,
double y)
Event notification when a turtle is dragged.
|
void |
turtleLongPressed(Turtle turtle,
double x,
double y)
Event notification when a turtle is long pressed.
|
void |
turtlePressed(Turtle turtle,
double x,
double y)
Event notification when a turtle is pressed.
|
void |
turtleReleased(Turtle turtle,
double x,
double y)
Event notification when a turtle is released.
|
act, addStatusBar, addStatusBar, onCompletion, onConfigurationChanged, onKeyDown, onKeyLongPress, onKeyUp, playgroundDragged, playgroundFlung, playgroundPointerPressed, playgroundPointerReleased, playgroundPressed, playgroundReleased, playSound, playSound, refresh, setDragEnabled, setMultiDragEnabled, setMultiTouchEnabled, setTouchEnabled
addContentView, closeContextMenu, closeOptionsMenu, createPendingResult, dismissDialog, dispatchKeyEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, findViewById, finish, finishActivity, finishActivityFromChild, finishFromChild, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getCurrentFocus, getInstanceCount, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLocalClassName, getMenuInflater, getParent, getPreferences, getRequestedOrientation, getSystemService, getTaskId, getTitle, getTitleColor, getVolumeControlStream, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, getWindow, getWindowManager, hasWindowFocus, isChild, isFinishing, isTaskRoot, managedQuery, moveTaskToBack, onAttachedToWindow, onBackPressed, onContentChanged, onContextItemSelected, onContextMenuClosed, onCreateContextMenu, onCreateDescription, onCreateOptionsMenu, onCreatePanelMenu, onCreatePanelView, onCreateThumbnail, onCreateView, onDetachedFromWindow, onKeyMultiple, onLowMemory, onMenuItemSelected, onMenuOpened, onOptionsItemSelected, onOptionsMenuClosed, onPanelClosed, onPrepareOptionsMenu, onPreparePanel, onRetainNonConfigurationInstance, onSearchRequested, onTouchEvent, onTrackballEvent, onUserInteraction, onWindowAttributesChanged, onWindowFocusChanged, openContextMenu, openOptionsMenu, overridePendingTransition, registerForContextMenu, removeDialog, requestWindowFeature, runOnUiThread, setContentView, setContentView, setContentView, setDefaultKeyMode, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setIntent, setPersistent, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setResult, setSecondaryProgress, setTitle, setTitle, setTitleColor, setVisible, setVolumeControlStream, showDialog, showDialog, startActivity, startActivityForResult, startActivityFromChild, startActivityIfNeeded, startIntentSender, startIntentSenderForResult, startIntentSenderFromChild, startManagingCursor, startNextMatchingActivity, startSearch, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterForContextMenu
bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getWallpaper, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, sendStickyOrderedBroadcast, setWallpaper, setWallpaper, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
public static final int SMALLSIZE
public static final int MEDIUMSIZE
public static final int BIGSIZE
public static int MAXSPEED
public static final int BLACK
public static final int BLUE
public static final int CYAN
public static final int DKGRAY
public static final int GRAY
public static final int GREEN
public static final int LTGRAY
public static final int MAGENTA
public static final int RED
public static final int TRANSPARENT
public static final int WHITE
public static final int YELLOW
public Playground(java.lang.String turtleImage)
turtleImage
- the relative path to the image file (best is png format)
e.g "sprites/car.png"public Playground()
public int getPlaygroundColor()
public double getZoomFactor()
public void playgroundPressed(double x, double y)
playgroundPressed
in class GameGrid
x
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void playgroundReleased(double x, double y)
playgroundReleased
in class GameGrid
x
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void playgroundLongPressed(double x, double y)
playgroundLongPressed
in class GameGrid
x
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void playgroundClicked(double x, double y)
playgroundClicked
in class GameGrid
x
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void playgroundDragged(double x, double y)
playgroundDragged
in class GameGrid
x
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void turtleClicked(Turtle turtle, double x, double y)
turtleClicked
in class GameGrid
turtle
- the reference of the touched turtlex
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtlec oordinate system)public void turtleDragged(Turtle turtle, double x, double y)
turtleDragged
in class GameGrid
turtle
- the reference of the touched turtlex
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void turtlePressed(Turtle turtle, double x, double y)
turtlePressed
in class GameGrid
turtle
- the reference of the touched turtlex
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void turtleReleased(Turtle turtle, double x, double y)
turtleReleased
in class GameGrid
turtle
- the reference of the touched turtlex
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void turtleLongPressed(Turtle turtle, double x, double y)
turtleLongPressed
in class GameGrid
turtle
- the reference of the touched turtlex
- the x coordinate of the touch event (turtle coordinate system)y
- the y coordinate of the touch event (turtle coordinate system)public void showToast(java.lang.String text)
text
- the message to displaypublic java.util.ArrayList<Turtle> getTurtlesNear(double xCenter, double yCenter, double radius)
xCenter
- the x coordinate of the center (turtle coordinate system)yCenter
- the y coordinate of the center (turtle coordinate system)radius
- the radius of the circle (turtle coordinates)public Turtle getTopTurtleNear(double xCenter, double yCenter, double radius)
xCenter
- the x coordinate of the center (turtle coordinate system)yCenter
- the y coordinate of the center (turtle coordinate system)radius
- the radius of the circle (turtle coordinates)public Turtle setSpeed(int speed)
speed
- the speed of the turtle (0..10, MAXSPEED)public int getSpeed()
public Turtle forward(double s)
s
- the step to move forward, if s < 0 moves backpublic Turtle fd(double s)
public Turtle back(double s)
s
- the step to move back, if s < 0 moves forwardpublic Turtle bk(double s)
public Turtle right(double angle)
angle
- the turning angle (in degrees), if angle < 0 turns leftpublic Turtle rt(double angle)
public Turtle left(double angle)
angle
- the turning angle (in degrees), if angle < 0 turns rightpublic Turtle lt(double angle)
public static void beep()
public static void clean()
public static void clean(int color)
public static void clear()
public static void clear(int color)
public Turtle hideTurtle()
public Turtle ht()
public boolean isHidden()
public Turtle showTurtle()
public Turtle st()
public int getColor()
public Turtle setColor(int color)
public Turtle setSize(int size)
size
- one of the constants Playground.SMALLSIZE, Playground.MEDIUMSIZE,
Playground.BIGSIZEpublic double getHeading()
public Turtle setHeading(double heading)
heading
- in degrees, 0 to north, clockwisepublic double towards(double x, double y)
x
- the x coordinate of the target positiony
- the y coordinate of the target positionpublic Turtle home()
public boolean isPenDown()
public Turtle penDown()
public Turtle pd()
public Turtle penUp()
public Turtle pu()
public int getPenWidth()
public Turtle setPenWidth(int width)
width
- the pen width in pixels (independent of current screen resolution)public int getPenColor()
public Turtle setPenColor(int color)
color
- the color of the penpublic Turtle label(java.lang.String text)
public Turtle label(java.lang.String text, int textColor, int textSize)
text
- the text to showtextColor
- the text colortextSize
- the text size in turtle coordinatespublic double distance(double x, double y)
x
- the x coordinate of the target positiony
- the y coordinate of the target positionpublic double getX()
public double getY()
public Turtle setPos(double x, double y)
x
- the new turtle's x coordinatey
- the new turtle's y coordinatepublic Turtle moveTo(double x, double y)
x
- the new turtle's x coordinatey
- the new turtle's y coordinatepublic Turtle setX(double x)
x
- the new turtle's x coordinatepublic Turtle setY(double y)
y
- the new turtle's y coordinatepublic static void sleep(int time)
time
- the time to wait (in ms)public Turtle fill(double x, double y)
x
- the x coordinate of a point inside the regiony
- the y coordinate of a point inside the regionpublic Turtle fill()
public Turtle dot()
public boolean isOnBorder()
public boolean isOnBoarder(int borderId)
borderId
- 0: top border, 1: right border, 2: bottom border, 3: left borderpublic boolean isForwardValid(double s)
s
- the step to move forward, if s < 0 moves backpublic boolean isBackValid(double s)
s
- the step to move back, if s < 0 moves forwardpublic Turtle fillToPoint(double x, double y)
x
- the x coordinate of the anchor pointy
- the y coordinate of the anchor pointpublic Turtle fillToHorizontal(double y)
y
- the y coordinate of the horizontal linepublic Turtle fillToVertical(double x)
x
- the x coordinate of the vertical linepublic Turtle fillOff()
public Turtle clone()
clone
in class java.lang.Object
public static void delay(long timeout)
timeout
- the time (in ms) the current thread sleepspublic java.lang.String readString(java.lang.String title, java.lang.String prompt, java.lang.String init)
public java.lang.String readString(java.lang.String title, java.lang.String prompt)
title
- the title text of the dialog boxprompt
- the prompt text of the dialog boxpublic java.lang.String readStringWithCancel(java.lang.String title, java.lang.String prompt, java.lang.String init)
public int readInt(java.lang.String title, java.lang.String prompt, int init)
public int readInt(java.lang.String title, java.lang.String prompt)
title
- the title text of the dialog boxprompt
- the prompt text of the dialog boxpublic double readDouble(java.lang.String title, java.lang.String prompt, double init)
public double readDouble(java.lang.String title, java.lang.String prompt)
title
- the title text of the dialog boxprompt
- the prompt text of the dialog boxpublic void showValue(java.lang.String title, java.lang.String value)
title
- the title of the dialog boxvalue
- the string value to displaypublic void showValue(java.lang.String title, short value)
title
- the title of the dialog boxvalue
- the short value to displaypublic void showValue(java.lang.String title, int value)
title
- the title of the dialog boxvalue
- the int value to displaypublic void showValue(java.lang.String title, long value)
title
- the title of the dialog boxvalue
- the long value to displaypublic void showValue(java.lang.String title, float value)
title
- the title of the dialog boxvalue
- the float value to displaypublic void showValue(java.lang.String title, double value)
title
- the title of the dialog boxvalue
- the double value to displaypublic void showValue(java.lang.String title, boolean value)
title
- the title of the dialog boxvalue
- the boolean value to display