简体   繁体   English

找不到我的Java游戏的解决方案

[英]can't find solution for my Java Game

For school i have to make a game that already exists. 为了上学,我必须做一个已经存在的游戏。 this is the link to the game: Game link 这是游戏的链接游戏链接

a short explanation: each level you receive( on the right side of the screen) a set of arrows that you can place on the screen and when you push the "Go" button the cow starts to move. 简短说明:您收到的每个级别(在屏幕右侧)都有一组箭头,您可以将它们放置在屏幕上,当您按下“开始”按钮时,母牛开始移动。 When he moves on a arrow he will change his direction in the direction of that arrow. 当他在箭头上移动时,他将沿该箭头的方向改变方向。 So you have to guide the cow with the arrow to his end destination ( a trophy) without touching any obstacles ( like a wall or a tree ... ). 因此,您必须使用箭头将母牛引导到他的最终目的地(奖杯),而不要碰到任何障碍物(例如墙壁或树木...)。

We MUST implement the Model-View-Presenter design pattern. 我们必须实现Model-View-Presenter设计模式。 So i started with my model because that's my game logic. 所以我从我的模型开始,因为那是我的游戏逻辑。

my problem: every level should be read with a simple .txt file here under a example of my level 1: 我的问题:在我的等级示例下,每个等级都应使用简单的.txt文件读取:

26,6
xxxxxxxxxxxxxxxxxxxxxxxxxx
xGRGGBGxGGRGGGGGGGGGGBGGTx
xGGGGRGGGGFGxGGGGGGGGGGGGx
xGFGGLGGGGGGGLGGGGGGGGGGGG
xGGGGSGGGxGGGGGGxGGGGGGGGx
xxxxxxxxxxxxxxxxxxxxxxxxxx

x=obstacle 
G=grass
T=trophy
S= Start position of the cow
L= Fixed left arrow  
R= Fixed right arrow
F= fixed front arrow
B= fixed back arrow

i read the file and with a case statement place every char in a line (every char represents an object) in a 2D array. 我读取了文件,并使用case语句将每个字符放在2D数组的一行中(每个字符代表一个对象)。

My problem is: that you have 2 sets of Arrows: a FixedArrow(It's already on the field and you can't change it's position) and a VariableArrow(the arrows on the right side of the screen where the user can place them on the field, if the field is free or with other words if it's on a Grass object. but how can i do this? how can i create an seperate screen where i can put arrows that the user can put on the field? 我的问题是:您有2组箭头:FixedArrow(它已经在字段上,您不能更改其位置)和VariableArrow(屏幕右边的箭头,用户可以将它们放置在字段,如果该字段是免费的,或者如果该字段位于Grass对象上,则换句话说,但是我该怎么做?如何创建一个单独的屏幕,在其中可以放置用户可以放置在该字段上的箭头?

i know that my explanation is vague so i hope you guys open the link i posted above and play 1 level so you understand better what i mean. 我知道我的解释含糊不清,所以我希望你们打开我上面发布的链接并打1级,这样您才能更好地理解我的意思。

i'll post a part of my code and class diagram here under. 我将在下面发布我的代码和类图的一部分。 path= is the path to the .txt file i explained here above. path =是我在上文中解释的.txt文件的路径。

My Class Diagramm 我的班级图

public class Board {
private Tile[][] tiles;

    public Board(Path path) {

        try {

            int yRow = 0;
            Scanner scanner = new Scanner(path);
            String[] split = scanner.nextLine().split(",");
            tiles = new Tile[Integer.parseInt(split[1])][Integer.parseInt(split[0])];
            while (scanner.hasNext()) {
                String line = scanner.nextLine();

                for (int xRow = 0; xRow < line.length(); xRow++) {
                    char character = line.charAt(xRow);
                    switch (character) {
                        case 'x':
                            tiles[yRow][xRow] = new Tile(new Obstacle());
                            break;
                        case 'G':
                            tiles[yRow][xRow] = new Tile(new Grass());
                            break;
                        case 'S':
                            tiles[yRow][xRow] = new Tile(new Grass());
                            //cow.setStartPosition(xRow,yRow);
                            break;
                        case 'L':
                            tiles[yRow][xRow] = new Tile(new FixedArrow(Direction.LEFT));
                            break;
                        case 'R':
                            tiles[yRow][xRow] = new Tile(new FixedArrow(Direction.RIGHT));
                            break;
                        case 'F':
                            tiles[yRow][xRow] = new Tile(new FixedArrow(Direction.FRONT));
                            break;
                        case 'B':
                            tiles[yRow][xRow] = new Tile(new FixedArrow(Direction.BACK));
                            break;
                        case 'T':
                            tiles[yRow][xRow] = new Tile(new Trophy());
                            break;
                        //How should i read a set of arrows in without placing them in the game field but on the right side of the screen
                    }


                }

                ++yRow;
            }

        } catch (IOException e) {
            e.getMessage();
        }
    }

}

You only need to set the variable arrows with an input scanner or something else. 您只需要使用输入扫描仪或其他工具设置可变箭头。 The variable arrows should be in the two dimension array. 可变箭头应位于二维数组中。 You need to compare your variable arrow coordinates from your input with the sign at these points in the array and check if you can put there a new arrow or if its not allowed. 您需要将输入中的可变箭头坐标与数组中这些点处的符号进行比较,并检查是否可以在其中放置新箭头或是否不允许使用。 If its allowed then replace this sign with your new arrow sign or you reuse your fixed arrow signs. 如果允许,则用新的箭头符号替换该符号,或者重新使用固定的箭头符号。

I hope i've understand your question correctly and this helps :) 希望我能正确理解您的问题,这对您有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM