2D葫芦娃v1

2017-10-26  本文已影响20人  lucia320

2D葫芦娃v1

Main函数(上帝之手)

上帝先创造世界:一个20*20的方形舞台。

    public static void main(String args[]){
        int N = 20;
        Stage stage = new Stage(N);

然后创造生物:7个葫芦兄弟brothers、12只小妖怪们monsters、1个爷爷grandpa和1只蛇精snake

        //Create Huluwa Brothers
        HuLuWa[] brothers = new HuLuWa[7];
        for (int i = 0; i<brothers.length; i++){
            brothers[i] = new HuLuWa(RANK.values()[i], COLOR.values()[i]);
        }
        //Create Monsters
        Creature[] monsters = new Creature[12];
        for ( int i = 0; i < monsters.length; i++){
            if ( i == 0 ) monsters[i] = new Scorpion();
            else{
                monsters[i] = new LouLuo();
            }
        }
        //Create Grandpa
        Grandpa grandpa = new Grandpa();
        //Create Snake
        Snake snake= new Snake();

上帝将世界舞台的左半侧划分给葫芦兄弟阵营,让他们排成长蛇阵型;然后,将世界右半侧划分给妖怪阵营,让小妖怪们以蝎子精为首排成箭阵。

        CreatureQueue hulu_q = new CreatureQueue(brothers, stage.get_space(), 1, N/2-1, 0, N);
        CreatureQueue mst_q = new CreatureQueue(monsters, stage.get_space(), N-2,N/2, 0, N);
        Pattern ls_p= new LongSnakePattern();
        ls_p.Reform(hulu_q);
        Pattern arrow_p = new ArrowPattern();
        arrow_p.Reform(mst_q);

上帝把爷爷和蛇精放在各自势力范围的最后方,让他们加油鼓劲。

        grandpa.set_pos(stage.get_space()[N/2][0]);
        snake.set_pos(stage.get_space()[N/2][N-1]);

展示舞台,上帝觉得不是很满意。

        stage.printStage();

于是让妖怪们又变换成了新月阵型,展示舞台,上帝觉得很满意。

        Pattern crescent_p = new CrescentPattern();
        crescent_p.Reform(mst_q);
        stage.printStage();
位置相关类
1. Stage舞台类
2. Position位置类
    private boolean avail;
    private Creature holder;
    private Coord coord;

Coord类型有x,y两个成员,代表坐标

生物相关类
1. 抽象类Creature
2. 比较接口Comparable

public boolean BiggerThan(Comparable another);对生物比较行为的抽象。

3. HuLuWa葫芦娃类
    private RANK rank;
    private COLOR color;

Creature抽象类的基础上,增加color rank属性

4. 其他生物子类

Scorpion蝎子精类,代表符号为
Snake蛇精类,代表符号为
LouLuo小喽啰类,代表符号为
Grandpa爷爷类,代表符号为

移动排队类
1. CreatureQueue生物队列类
private int bound_x1;
private int bound_x2;
private int bound_y1;
private int bound_y2;

规定生物队列可活动的矩形范围, bound_x1 < bound_x2 则代表队列头部朝向右侧,队列在舞台左半场活动;反之头部朝向左侧,在舞台右半场活动

    public Creature[] get_creatures();
    public Position[][] getSpace();
    public int getBound_x1();
    public int getBound_x2()
    public int getBound_y1();
    public int getBound_y2();
2. 抽象类Pattern
2. 具体阵型子类
上一篇 下一篇

猜你喜欢

热点阅读