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();
    }    
     
}   




Không có nhận xét nào:

Đăng nhận xét