Thứ Hai, 9 tháng 3, 2015

ADF1 - Inheritance

Make a documentation of this framework by declare some variables of Actor and create some objects of GoJumpActor, JumpGoActor, asign them to the above variables and call them.


Code:

  • Class Interface Moveable:
public interface Moveable
{
    public void Jump();
    
    public void Forward();
}
  • Class abstract Actor:
public abstract class Actor implements Moveable
{
    private Circle face;
    
    public Actor(){
        face = new Circle();
        face.makeVisible();
        face.changeColor("red");
        face.changeSize(50); 
    }
    
    public void Jump(){
        face.slowMoveVertical(-30);
    }
    
    public void Forward(){
        face.slowMoveHorizontal(10);
    }
}
  • Class extend GoJumpActor:
public class GoJumpActor extends Actor
{
    public void GoAndJump(){
        Forward();
        Jump();
    }
}
  • Class extend JumpGoActor:
public class JumpGoActor extends Actor
{
    public void JumpAndGo(){
        Jump();
        Forward();
    }
}

Thứ Bảy, 7 tháng 3, 2015

ADF1 - Interface

Today, game is an important industrial of software, one of most important features that a game must have is the extensible capacity. As an architect, you know the meaning of “implement into interface not into implementation”, so you must:


Create an interface for actor that can do :
- forward()
- jump()
- blink()


Code:
  • Interface:

public interface Action
{
    public void Forward();
    
    public void Blink();
    
    public void Jump();
}

  • Class Actor:
public class Actor implements Action
{
    private Circle face;
    private Circle leftEye;
    private Circle rightEye;
    private Triangle mouth;
  
    
    public Actor(){
        
        face = new Circle();
        face.makeVisible();
        face.changeSize(70);
        face.moveHorizontal(107);
        face.moveVertical(100);
        face.changeColor("yellow");
        
        leftEye = new Circle();
        leftEye.makeVisible();
        leftEye.changeSize(15);
        leftEye.moveHorizontal(120);
        leftEye.moveVertical(120);
        leftEye.changeColor("black");
        
        rightEye = new Circle();
        rightEye.makeVisible();
        rightEye.changeSize(15);
        rightEye.moveHorizontal(150);
        rightEye.moveVertical(120);
        rightEye.changeColor("black");
        
        mouth = new Triangle();
        mouth.makeVisible();
        mouth.changeSize(8,30);
        mouth.moveHorizontal(112);
        mouth.moveVertical(192);
        mouth.changeColor("brown");
    }
    
    public void Forward(){
        face.moveHorizontal(100);
        leftEye.moveHorizontal(100);
        rightEye.moveHorizontal(100);
        mouth.moveHorizontal(100);        
    }
    
    public void Jump(){
        face.moveVertical(-100);
        leftEye.moveVertical(-100);
        rightEye.moveVertical(-100);
        mouth.moveVertical(-100);
        face.moveVertical(100);
        leftEye.moveVertical(100);
        rightEye.moveVertical(100);
        mouth.moveVertical(100);
    }
    
    public void Blink(){
        face.makeInvisible();
        leftEye.makeInvisible();
        rightEye.makeInvisible();
        mouth.makeInvisible();
        
        face.moveHorizontal(100);
        leftEye.moveHorizontal(100);
        rightEye.moveHorizontal(100);
        mouth.moveHorizontal(100);
        
        face.makeVisible();
        leftEye.makeVisible();
        rightEye.makeVisible();
        mouth.makeVisible();
    }    
     
}   




Chủ Nhật, 1 tháng 3, 2015

Ep3 - Add Behavior



  • Create methods sunRise(), sunSet() for make animation for the following scenarios




Code:

/**
 * Sun
 *
 * @author (MZ)
 * @version (1.0)
 */
public class Sun
{
    private Circle sun;
    /**
     * Constructor for objects of class Sun
     */
    public Sun()
    {
       sun = new Circle();
       sun.makeVisible();
       sun.changeColor("yellow");
       sun.changeSize(50);
       sun.moveHorizontal(220);
    }
   
    public void sunSet(){
        sun.slowMoveVertical(300);
    }
   
    public void sunRise(){
       sun.slowMoveVertical(-300);
    }

}