Computer Science > Research Paper > Rocket.java (All)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Rocket here. * * @author (your name) * @version (a version number or a date) */ ... public class Rocket extends Actor { /** * Act - do whatever the Rocket wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ private boolean east = true; public void act() { // Add your action code here. if(canMove() == true && east == true) { moveEast(); } else if(canMove() == true && east != true) { moveWest(); } } public void moveEast() { setLocation(getX() + 2, getY()); } public void moveWest() { setLocation(getX() - 2, getY()); } public boolean canMove() { World myWorld = getWorld(); int x = getX(); int y = getY(); if(x >= myWorld.getWidth()-1) { east = false; } else if(x <= 0) { east = true; } [Show More]
Last updated: 1 year ago
Preview 1 out of 2 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Add to cartInstant download
We Accept:
Connected school, study & course
About the document
Uploaded On
Apr 18, 2021
Number of pages
2
Written in
This document has been written for:
Uploaded
Apr 18, 2021
Downloads
0
Views
36
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·