This site requires JavaScript, please enable it in your browser!
Greenfoot back
Hamza_Abdulla03
Hamza_Abdulla03 wrote ...

2017/4/16

Can you please help identify my code blocks and annotate my coding?

Hamza_Abdulla03 Hamza_Abdulla03

2017/4/16

#
import greenfoot.*; /** * Write a description of class Airplane here. * * @author (your name) * @version (a version number or a date) */ public class Airplane extends AnimBase { GreenfootSound Bullet = new GreenfootSound ("Bullet.wav"); GreenfootSound Grenade = new GreenfootSound ("Grenade.wav"); GreenfootSound GameOver = new GreenfootSound ("GameOver.wav"); GreenfootSound backgroundMusic = new GreenfootSound("Background.wav"); int bulletStep=0; protected int Score = 0; protected int Point = 0; /** * Act - do whatever the Airplane wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void stopped () { Point = 0; Score = 0; } public void act() { move (1); Actor Ok = getOneIntersectingObject(Ok.class); if(Ok!= null && Greenfoot.isKeyDown("Left")) { move (+10); } bombDetect(); { catchKey(); } stopped(); } private void catchKey() { catchKeyMove(); catchKeyShoot(); } private void catchKeyMove() { if (Greenfoot.isKeyDown("left")) { setLocation(getX()-5, getY()); } if (Greenfoot.isKeyDown("right")) { setLocation(getX()+5, getY()); } if (Greenfoot.isKeyDown("Up")) { setLocation(getX(), getY()-3); } if (Greenfoot.isKeyDown("Down")) { setLocation(getX(), getY()+3); } } private void catchKeyShoot() { if(Greenfoot.isKeyDown("space")) { Bullet.play (); bulletStep++; if(bulletStep==10) { Bullets b = new Bullets(); int posX = getX()+Math.floorDiv(getImage().getWidth(),2)+Math.floorDiv(b.getImage().getWidth(),2); getWorld().addObject(b, posX, getY()); bulletStep=0; } } } public void bombDetect() { GameOver gameover = new GameOver(); if (isTouching ( Bomb.class)) { Grenade.play (); Greenfoot.setWorld(gameover); backgroundMusic.stop (); GameOver.play (); } } } import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Bullets here. * * @author (your name) * @version (a version number or a date) */ public class Bullets extends AnimBase { /** * Act - do whatever the Bullets wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (isTouching (Robot.class)) { removeTouching (Robot.class); } detectCollision (); if(getY()<getWorld().getWidth()-getImage().getWidth()/2) { move (10); } else getWorld().removeObject(this); } public void detectCollision() { if (getY()>5000) { getWorld().removeObject(this); } } } import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Bomb here. * * @author (your name) * @version (a version number or a date) */ public class Bomb extends AnimBase { /** * Act - do whatever the Bomb wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(getY()<getWorld().getWidth()-getImage().getWidth()/2) move (-2); else getWorld().removeObject(this); } public void RemoveBomb () { if (isTouching(Ok.class)) { Score = 0; getWorld().removeObject(this); } } } import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Robot here. * * @author (your name) * @version (a version number or a date) */ public class Robot extends AnimBase { /** * Act - do whatever the Robot wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ protected int Score = 0; public void act() { animCounter = 0; move (20); turn(Greenfoot.getRandomNumber(20)); { animCounter++; animMove(); detectCollision(); } } private void animMove() { if(animCounter<10) { setLocation(getX(), getY()-2); turn(Greenfoot.getRandomNumber(10)); //Greenfoot.delay(5); } else if(animCounter<30) { setLocation(getX(), getY()+2); turn(Greenfoot.getRandomNumber(10)); //Greenfoot.delay(5); } else if(animCounter<40) { setLocation(getX(), getY()-2); turn(Greenfoot.getRandomNumber(10)); //Greenfoot.delay(5); } else { animCounter=-1; } } private void detectCollision() { if(isTouching(Bullets.class)) { removeTouching(Bullets.class); updatePoint(); checkLast(); getWorld().removeObject(this); } } private void updatePoint() { point++; getWorld().showText("Score :"+point,60, 10); } YouWin youwin = new YouWin(); private void checkLast() { if(point==30) { getWorld().showText("Finish Score "+point,getWorld().getWidth()/2, getWorld().getHeight()/2); removeBullet(); removeHero(); Greenfoot.stop(); Greenfoot.setWorld (youwin); } } public void removeBullet() { if(getWorld().getObjects(Bullets.class)!=null) for(Bullets b : getWorld().getObjects(Bullets.class)) { getWorld().removeObject(b); } } public void removeHero() { if(getWorld().getObjects(Airplane.class)!=null) getWorld().removeObject(getWorld().getObjects(Airplane.class).get(0)); } }
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/16

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class Background extends World { GreenfootSound backgroundMusic = new GreenfootSound("Background.wav"); private static final String bgImageName = "space1.jpg"; private static final double scrollSpeed = 2.5; private static final int picWidth = (new GreenfootImage(bgImageName)).getWidth(); private GreenfootImage bgImage, bgBase; private int scrollPosition = 0; public Background() { super(5000, 400, 1); backgroundMusic.playLoop(); setBackground(bgImageName); bgImage = new GreenfootImage(getBackground()); bgBase = new GreenfootImage(picWidth, getHeight()); bgBase.drawImage(bgImage, 0, 0); prepare(); } public void act() { scrollPosition -= scrollSpeed; while(scrollSpeed > 0 && scrollPosition < -picWidth) scrollPosition += picWidth; while(scrollSpeed < 0 && scrollPosition > 0) scrollPosition -= picWidth; paint(scrollPosition); } private void paint(int position) { GreenfootImage bg = getBackground(); bg.drawImage(bgBase, position, 0); bg.drawImage(bgImage, position + picWidth, 0); }
Yehuda Yehuda

2017/4/16

#
What do you want me to do? (You seem to have cut your Background class in half.)
sinlessclown sinlessclown

2017/4/16

#
Hey Hamza. Is this your computing IPM by any chance?
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/17

#
i just need to know what a command block is and an example of annotation
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/17

#
also what is a control structure
Hamza_Abdulla03 Hamza_Abdulla03

2017/4/17

#
and an abstraction
danpost danpost

2017/4/17

#
Hamza_Abdulla03 wrote...
i just need to know what a command block is and an example of annotation
A command block is any codes between matching braces -- i.e. { int x = a + b; } Examples of annotation are '@Author', '@override' and '@SuppressWarnings'. The java tutorials has a page on annotations. A control structure is any code, or set of codes, that is used to alter the top-down, step-by-step, execution of code. Examples are 'switch', 'for' and 'do-while' structures. Wikipedia has a section on the 'Abstraction' page for computer related abstraction.
TheCoolCoder321 TheCoolCoder321

2017/4/17

#
It looks to me that u copied everything from elsewhere cos the code is really messy.
CharlieC CharlieC

2017/4/17

#
sinlessclown wrote...
Hey Hamza. Is this your computing IPM by any chance?
no its definitely not hamza
rishitandon rishitandon

2017/4/17

#
hi Hamza
You need to login to post a reply.