暑假重学JavaSE第七天之小马宝莉推箱子之设计关卡

前提引入简单的二维数组知识点:

package com.meiyvluo;

public class Array {
    public static void main(String[] args) {
        int [][] a ={
                {1,2,3,4},
                {3,4,5,6,7},
                {1,2,5,7,3}
        };
         System.out.println(a.length);//二维数组的个数
        for(int i = 0;i<a.length;i++){
            int[] b = a[i];
            for(int j=0;j<b.length;j++){
                //System.out.print(b[j]+" ");
                System.out.print(a[i][j]+" ");//效果同上一行
            }
            System.out.println();
        }
    }
}

自行了解实体类,还有set和get方法

package com.meilingluo.TXZ_2;

import java.util.Arrays;

public class LevelData {//游戏关卡数据
    private String boxImgPath;//箱子图片
    private int boxLocation[];//箱子初始位置
    private String goalImgPath;//目的地图片
    private int []goalLocation;//目的地位置
    private String[] workerImgPaths;//柔柔四张图片
    private int[] workerLocation;//柔柔地址
    private int[][] wallsLocations;//墙的位置
    private String wallImgPath;//墙图片

    @Override
    public String toString() {
        return "LevelData{" +
                "boxImgPath='" + boxImgPath + '\'' +
                ", boxLocation=" + Arrays.toString(boxLocation) +
                ", goalImgPath='" + goalImgPath + '\'' +
                ", goalLocation=" + Arrays.toString(goalLocation) +
                ", workerImgPaths=" + Arrays.toString(workerImgPaths) +
                ", workerLocation=" + Arrays.toString(workerLocation) +
                ", wallsLocations=" + Arrays.toString(wallsLocations) +
                ", wallImgPath='" + wallImgPath + '\'' +
                '}';
    }

    public String getWallImgPath() {
        return wallImgPath;
    }

    public void setWallImgPath(String wallImgPath) {
        this.wallImgPath = wallImgPath;
    }

    public void setWallsLocations(int [][] wallsLocations){
        this.wallsLocations = wallsLocations;
    }
    public int[][] getWallsLocations(){
        return wallsLocations;
    }

    public int[] getWorkerLocation() {
        return workerLocation;
    }

    public void setWorkerLocation(int[] workerLocation) {
        this.workerLocation = workerLocation;
    }

    public void setWorkerImgPaths(String [] workerImgPaths){
        this.workerImgPaths = workerImgPaths;
    }
    public String[] getWorkerImgPaths(){
        return workerImgPaths;
    }

    public String getGoalImgPath() {
        return goalImgPath;
    }

    public void setGoalImgPath(String goalImgPath) {
        this.goalImgPath = goalImgPath;
    }

    public int[] getGoalLocation() {
        return goalLocation;
    }

    public void setGoalLocation(int[] goalLocation) {
        this.goalLocation = goalLocation;
    }

    public void setBoxImgPath(String boxImgPath){
        this.boxImgPath = boxImgPath;
    }
    private String getBoxImgPath(){
        return boxImgPath;
    }
    public void setBoxLocation(int []boxLocation){
        this.boxLocation=boxLocation;
    }
    public int []getBoxLocation(){
        return  boxLocation;
    }
}

package com.meilingluo.TXZ_2;

public class LevelDataManager {
    public static LevelData getNowLevelData(int index){
        LevelData levelData = new LevelData();
        if(index == 1){
            levelData.setBoxImgPath("box3.png");
            int [] boxLocation = new int[]{3,3};
            levelData.setBoxLocation(boxLocation);
            levelData.setGoalImgPath("goal3.png");
            levelData.setGoalLocation(new int[] {7,8});
            String [] workerImgPaths = {"workerLeft4.png","workerUp4.png","workerDown4.png","workerRight4.png"};
            levelData.setWorkerImgPaths(workerImgPaths);
            levelData.setWallImgPath("wall3.png");
            int [][] wallsLocations = {
                    {2, 3}, {3, 3}, {4, 3}, {5, 3},{6, 3},{7, 3},
                    {4, 5}, {5, 6}, {6, 7}, {7, 8},
                    {15, 3}, {15, 4}, {15, 5},{15, 6}

            };
            levelData.setWallsLocations(wallsLocations);
        }
        else if(index == 2){
            levelData.setBoxImgPath("box2.png");
            int [] boxLocation = new int[]{3,3};
            levelData.setBoxLocation(boxLocation);
            levelData.setGoalImgPath("goal2.png");
            levelData.setGoalLocation(new int[] {7,8});
            String [] workerImgPaths = {"workerLeft4.png","workerUp4.png","workerDown4.png","workerRight4.png"};
            levelData.setWorkerImgPaths(workerImgPaths);
            levelData.setWallImgPath("wall3.png");
            int [][] wallsLocations = {
                    {2, 3}, {3, 3}, {4, 3}, {5, 3},{6, 3},{7, 3},
                    {4, 5}, {5, 6}, {6, 7}, {7, 8},
                    {15, 3}, {15, 4}, {15, 5},{15, 6}

            };
            levelData.setWallsLocations(wallsLocations);
        }
        else if(index == 3){}
        else {
            return null;
        }
        return levelData;
    }
}
package com.meilingluo.TXZ_2;

public class Run {
    public static void main(String[] args) {
        LevelData levelData =LevelDataManager.getNowLevelData(2);
        System.out.println(levelData);

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值