Ferrell
Ferrell

Reputation: 13

2D game design - y variable not resolved?

I have my code as the following.

package net.ferrell.wrathoftuemdaym;

import java.awt.*;

public class Level {
    public Block[][] block = new Block[50][50];

    public Level() {
        for(int x = 0; x < block.length; x++) {
            for(int y = 0; y < block[0].length; y++);
                block[x][y] = new Block(new Rectangle(x * Tile.tileSize, y * Tile.tileSize, Tile.tileSize, Tile.tileSize), Tile.air);
        }

    }

    public void generateLevel() {
        for(int x = 0; x < block.length; x++) {
            for(int y = 0; y < block[0].length; y++);
                if(x == 0 || y == 0 || x == block.length-1 || y == block[0].length-1) {
                    block[x][y].id = Tile.earth;
                }
        }

    }

    public void tick() {


    }

    public void render(Graphics g) {
        for(int x = 0; x < block.length; x++) {
            for(int y = 0; y < block[0].length; y++);
                block[x][y].render(g);
        }


    }
}

In a line that says " block[x][y] ", y cannot be resolved to a variable. I do not know the fix for this and it is only in this class that the problem exists. Please help me. I do not understand because the x CAN be resolved...

Upvotes: 1

Views: 78

Answers (1)

BevynQ
BevynQ

Reputation: 8269

this is your culprit

for(int y = 0; y < block[0].length; y++);

it should be

for(int y = 0; y < block[0].length; y++)

Personally I always put braces in code blocks even if it is just one line.

Upvotes: 4

Related Questions