黑马程序员技术交流社区

标题: android小游戏海盗船船5 [打印本页]

作者: woshiku    时间: 2015-9-13 09:47
标题: android小游戏海盗船船5
package xieyan;

import xieyan.system.Control;
import xieyan.system.EmceeException;

public class ControlInterface {
       
        /**
         * 创建并开始某一关卡游戏。必须要先调用此方法后,
         * 才能调用攻击和移动的方法。
         * @param stage 关卡数
         */
        public void start(int stage){
                Control.getControl().start(stage);
        }
       
        /**
         * 强制结束当前关卡游戏,过关或用户退出正在玩的游戏时调用
         */
        public void endStage(){
                Control.getControl().endStage();
        }

        /**
         * 尝试让自己的船向某个点移动
         * @param dir 要去的点
         * @return 是否移动成功
         */
        public boolean moveMyBoat(Point point){
                boolean ok=false;
                try {
                        ok=Control.getControl().move(point);
                } catch (EmceeException e) {
                        // TODO 自动生成的 catch 块
                        e.printStackTrace();
                }
                return ok;
        }
        /**
         * 尝试向攻击敌人
         * @return 击中敌人返回true
         */
        public boolean openFire(){
                boolean ok=false;
                try {
                        ok=Control.getControl().openFire();
                } catch (EmceeException e) {
                        // TODO 自动生成的 catch 块
                        e.printStackTrace();
                }
                return ok;
        }
        /**
         * 添加一个游戏失败监听者
         */
        public void addGameOverListener(GameOverListener listener){
                Control.getControl().addGameOverListener(listener);
        }
        /**
         * 移除一个游戏失败监听者
         */
        public void removeGameOverListener(GameOverListener listener){
                Control.getControl().removeGameOverListener(listener);
        }
        /**
         * 清除监听者列表
         */
        public void clearGameOverListener(){
                Control.getControl().clearGameOverListener();
        }
        public void destroyControl(){
                Control.destroyControl();
        }
}
package xieyan;

import java.util.ArrayList;
import java.util.HashMap;

import xieyan.system.Coordinate;
import xieyan.system.Data;
import xieyan.unit.Unit;

public class DataInterface {
       
       
        /**
         * @return 包含地图上所有单位的注册表
         */
        public HashMap<Point, Unit> getUnitRegistry(){
                return Data.getInstance().getUnits();
        }
        /**
         *
         * @return 当前剩余的生命值
         */
        public int getLife(){
                return Data.getLife();
        }
        /**
         *
         * @return 当前的分数
         */
        public int getScore(){
                return Data.getScore();
        }
       
        /**
         *
         * @return 地图的列数
         */
        public int getMapColumns(){
                return Data.getInstance().getColumns();
        }
        /**
         *
         * @return 地图的行数
         */
        public int getMapRows(){
                return Data.getInstance().getRows();
        }
        /**
         * @return 主角当前所在的坐标点
         */
        public Point getMyLocation(){
                return Data.getInstance().getMyLocation();
        }
        /**
         * @return 主角下一步可以到达的点
         */
        public ArrayList<Point> getMyCanMovePoint(){
                return Data.getInstance().getMe().detectMove();
        }
        /**
         * @return 如果主角此时开火,能击中的敌人所在的点
         */
        public ArrayList<Point> getCanHitEnemyDirection(){
                return Data.getInstance().getMe().getCanHitEnemyDirection();
        }
        /**
         * @return 上次开火或者移动后,发生爆炸的点
         */
        public ArrayList<Point> getBoomPoint(){
                return Data.getInstance().getBoomPoint();
        }
        /**
         * @return 剩余敌人的数量
         */
        public int getEnemyQty(){
                return Data.getInstance().getEnemys().size();
        }
        /**
         * 获得坐标系中的一个点
         * @param row 行
         * @param column 列
         * @return
         */
        public Point getPoint(int row,int column){
                return Coordinate.getCoordinate().getPoint(row, column);
        }
        public void setLife(int life){
                Data.setLife(life);
        }
        public void setScore(int score){
                Data.setScore(score);
        }
}

package xieyan;

public enum Direction {
        North,South,East,West,Northwest,Northeast,Southwest,Southeast;
       
        public Direction turnRight(int step){
                Direction[] dirs={North,Northeast,East,Southeast,South,Southwest,West,Northwest};
               
                int index=0;
                while(index<8){
                        if(this.equals(dirs[index]))
                                break;
                        index++;
                }
                index+=step;
                while(index>7)
                        index-=8;
                while(index<0)
                        index+=8;
               
                return dirs[index];
        }
       
        public Direction turnLeft(int step){
                return this.turnRight(-step);
        }
}








欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2