I have a Pong game with a level editor (as long as you have the source code) where you can put walls where you want. There are also walls that only balls hit by the player can pass through, walls that only balls hit by the Cpu can pass through, and invisible walls. I'm trying to add in moving walls, and so far, my idea is this:

A character 'm' signifies a moving wall, and '-'s represent the path it will move on.
'm's ID is 4, a '-'s ID is 5.

The method to move the walls is:

public void moveMovingWalls()
    {
        for (int j=0; j<StaticPong.NUMBEROFLINES; j++) {
            for (int i=0; i<StaticPong.NUMBEROFCOLUMNS; i++) {
                if (elementArray[j][i] != null && elementArray[j][i].getID() == 4) {
                    Path element = new Path(Color.gray, 5);
                    elementArray[j][i] = element;
                    if (j+1<StaticPong.NUMBEROFLINES && elementArray[j+1][i] != null && elementArray[j+1][i].getID() == 5) {
                        MWalls element2 = new MWalls(Color.yellow, 4);
                        elementArray[j+1][i] = element2;
                    }
                    else if (j>0 && elementArray[j-1][i] != null && elementArray[j-1][i].getID() == 5) {
                        MWalls element2 = new MWalls(Color.yellow, 4);
                        elementArray[j-1][i] = element2;
                    }
                    else if (i+1<StaticPong.NUMBEROFCOLUMNS && elementArray[j][i+1] != null && elementArray[j][i+1].getID() == 5) {
                        MWalls element2 = new MWalls(Color.yellow, 4);
                        elementArray[j][i+1] = element2;
                    }
                    else if (i>0 && elementArray[j][i-1] != null && elementArray[j][i-1].getID() == 5) {
                        MWalls element2 = new MWalls(Color.yellow, 4);
                        elementArray[j][i-1] = element2;
                    }
                }
            }
        }
    }

I want it to move the 'm' along the path in a clockwise fashion, and only move each moving wall one space each time.

This works in that it looks for a 'm' and then scans around the 'm' for '-'s and then moves the 'm' to the dash if it finds one. The problem here is that after the 'm' is moved, then if the 'm' was moved right or down the loop will hit it again and move it again, so it will be moved more than once.

For example (':'s are empty):

m--
-:-
-:-
---

Then the m would be move down to the second dash because the loop would move it to the bottom then recognize the dash above it and move it back up. After that it wouldn't move again - it would keep going down then back up.

So does anybody have help with this? I was thinking boolean flags like maybe a "hasMoved" to keep it from moving more than once, but the problem with that is then you would only be allowed one moving wall on the map.

>_<.

Another problem: making a level that can be edited in-game. So-far, there's four that you can edit easily in the source-code, but I'm making one that you can edit in-game.
So far:

import java.awt.*;
import java.applet.*;

public class LevelEditor extends Board
{
public static final String row1  = "::::gggggggggggggggggg";
public static       String row2  = "::::g::::::::::::::::g";
public static       String row3  = "::::::::::::::::::::::";
public static       String row4  = "::::::::::::::::::::::";
public static       String row5  = "::::::::::::::::::::::";
public static       String row6  = "::::::::::::::::::::::";
public static       String row7  = "::::::::::::::::::::::";
public static       String row8  = "::::::::::::::::::::::";
public static       String row9  = "::::g::::::::::::::::g";
public static final String row10 = "::::gggggggggggggggggg";
String name = "YOUR LEVEL";
String[] definitions = {row1, row2, row3, row4, row5, row6, row7, row8, row9, row10};
    public LevelEditor(Component parent, Applet applet)
    {
        super(parent, applet);
        super.initializeBoard(definitions);
        super.setDefinitions(definitions);
        super.setName(name);
    }
    public void editLevel(int x, int y)
    {
        int row = x/StaticPong.NUMBEROFCOLUMNS;
        int col = y/StaticPong.NUMBEROFLINES;
        if (row!=1 && row!=10) {
            char[] line = definitions[row].toCharArray();
            if (line[col] == ':') {
                line[col] = 'g';
            }
            else if (line[col] == 'g') {
                line[col] = 'p';
            }
            else if (line[col] == 'p') {
                line[col] = 'e';
            }
            else if (line[col] == 'e') {
                line[col] = ':';
            }
            definitions[row] = line.toString();
        }
        resetLevel();
    }
    public void resetLevel()
    {
        super.initializeBoard(definitions);
        super.setDefinitions(definitions);
        super.setName(name);
    }
}

editLevel(int x, int y) is called when the player clicks during "EDITLEVEL" mode, and for some reason the program just stops then. I'm trying to figure out why.

This question has already been answered. Start a new discussion instead.