0

I am a very beginner programmer, so I follow a youtube-tutorial that shows me how to build a simple snake app. The men at the youtube-tutorial got an older version of AndroidStudio than me. He uses AndroidStudio version 2.1.2, I use AndroidStudio version 2.2.2 with java language.

My problem is that he uses the commands getMap and map and it works. When I do that it doesn't work.My guestion is what i have to replace in the >methods "getMap" and "map"

The youtube-tutorial that I follow: https://www.youtube.com/watch?v=bPlG7ra83lo At 12:00 he uses this command first time.

Game Engine

package pelgrom.laurens.snake101.engine;

import android.service.quicksettings.Tile;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import pelgrom.laurens.snake101.Classes.Coordinate;
import pelgrom.laurens.snake101.enums.TileType;

/**
 * Created by Laptop on 23-1-2017.
 */

public class GameEngine {
    public static final int GameWidth = 28;
    public static final int Gameheight = 42;

    private List<Coordinate> walls = new ArrayList<>();


    public GameEngine() {

    }

    public void initGame(){

        AddWalls();

    }

    public TileType()() getMap() {
        TileType()() map = new TileType(GameWidth) (Gameheight);

        for (int x = 0; x < GameWidth; x++) {
            for (int y = 0; y < Gameheight; y++) {
                map(X)(Y) = TileType.Nothing;
            }
        }

        for (Coordinate wall: walls) {
            map(wall.getX())(wall.getY()) = TileType.Wall;
        }

        return map;


    }
           //fout zit hem in de "map" en de  "getMap"




    private void AddWalls() {
        //Top and bottom walls
        for (int x = 0; x < GameWidth; x ++) {
            walls.add(new Coordinate(x,0));
            walls.add(new Coordinate(x,Gameheight-1));
        }

        //Left and Right walls
        for (int y = 1; y < Gameheight; y++){
            walls.add(new Coordinate(0,y));
            walls.add (new Coordinate(GameWidth -1 , y));

        }

    }
}
`

SnakeView

`package pelgrom.laurens.snake101.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import pelgrom.laurens.snake101.enums.TileType;

/**
 * Created by Laptop on 23-1-2017.
 */

public class SnakeView extends View {
    private Paint mPaint = new Paint();
    private TileType snakeViewMap()();

    public SnakeView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setSnakeViewMap(TileType()() map )( this.snakeViewMap = map; )

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if( snakeViewMap != null ){
            float tileSizeX = canvas.getWidth() / snakeViewMap.length;
            float tileSizeY = canvas.getHeight() / snakeViewMap.length;

            float circleSize = Math.min(tileSizeX, tileSizeY) / 2;

            for (int x = 0; x < snakeViewMap.lenght; x++) {
                for (int y = 0; y < snakeViewMap(x). lenght; y++) {
                    switch (snakeViewMap(x)) {

                        case Nothing:
                            mPaint.setColor(Color.WHITE);
                            break;
                        case Wall:
                            mPaint.setColor(Color.GREEN);
                            break;
                        case SnakeHead:
                            mPaint.setColor(Color.RED);
                            break;
                        case SnakeTail:
                            mPaint.setColor(Color.GREEN);
                            break;
                        case Apple:
                            mPaint.setColor(Color.RED);
                            break;

                    }

                    canvas.drawCircle(x * tileSizeX + tileSizeX / 2f + circleSize / 2, y * tileSizeY + tileSizeY / 2f + circleSize / 2, circleSize, mPaint);
                }
            }
        }
    }
 }
`

main activity

`package pelgrom.laurens.snake101;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import pelgrom.laurens.snake101.engine.GameEngine;
import pelgrom.laurens.snake101.views.SnakeView;

public class Activity extends AppCompatActivity {

    private GameEngine gameEngine;
    private SnakeView snakeView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);

        gameEngine = new GameEngine();
        gameEngine.initGame();

        snakeView = (SnakeView)findViewById(R.id.snakeView);
        snakeView.setSnakeViewMap(gameEngine.getMapAsync());
        snakeView.invalidate();
    }
}
`
  • post whatever code you have mate – Mushirih Jan 24 '17 at 11:11
  • Sorry for the link, the link is https://www.youtube.com/watch?v=bPlG7ra83lo –  Jan 24 '17 at 11:11
  • 3
    Possible duplicate of [Cannot resolve method getMap()](http://stackoverflow.com/questions/38232747/cannot-resolve-method-getmap) – smoggers Jan 24 '17 at 11:12
  • yes, ehh i don't know how i can post the code. When you give your e-mail i will send it to you –  Jan 24 '17 at 11:12
  • just edit your question and copy paste the code you have written in your android studio. simple – M.Waqas Pervez Jan 24 '17 at 11:16
  • @smoggers That is my problem, thanks. I will use getMapAsync() instead of getMap. The only thing i also want to know is what is use instead of "map". –  Jan 24 '17 at 11:18
  • This is better @M.WaqasPervez –  Jan 24 '17 at 11:48

1 Answers1

0

The problem with your code is that you are using Round Bracket () while it has to square brackets [] since you are declaring two dimensional arrays. Replace them like :

public TileType[][] getMap() {
    TileType[][] map = new TileType[GameWidth][Gameheight];

    for (int x = 0; x < GameWidth; x++) {
        for (int y = 0; y < Gameheight; y++) {
            map[x][y] = TileType.Nothing;
        }
    }

    for (Coordinate wall: walls) {
        map[wall.getX()][wall.getY()] = TileType.Wall;
    }

    return map;


 }

PS: you really need to start with the basics.

M.Waqas Pervez
  • 2,492
  • 2
  • 19
  • 33
  • `public void setSnakeViewMap( TileType[][] map )[ this.snakeViewMap = map; ]` Everything in my code works except this public void –  Jan 24 '17 at 16:15
  • you have to replace `private TileType snakeViewMap()();` with `private TileType snakeViewMap[][];` too. – M.Waqas Pervez Jan 26 '17 at 08:21