Okay.
public void keyPressed(KeyEvent ke) {
if (state == GameState.play) {
switch (ke.getKeyCode()) {
case (KeyEvent.VK_RIGHT):
player.moveWithColDetect(Direction.East);
opponent.step();
Render();
break;
case (KeyEvent.VK_LEFT):
player.moveWithColDetect(Direction.West);
opponent.step();
Render();
break;
case (KeyEvent.VK_UP):
player.moveWithColDetect(Direction.North);
opponent.step();
Render();
break;
case (KeyEvent.VK_DOWN):
player.moveWithColDetect(Direction.South);
opponent.step();
Render();
break;
default:
;
}
if (player.x == opponent.x && player.y == opponent.y) {
state = GameState.loss;
setTitle("Test RL Labyrinth. Loss!");
panel.setGameState(state);
panel.repaint();
}
if (opponent.alerted()) {
if (player.x == entr.getX() && player.y == entr.getY()) {
state = GameState.victory;
setTitle("Test RL Labyrinth. Victory!");
panel.setGameState(state);
panel.repaint();
} else
setTitle("Test RL Labyrinth. Enemy alerted!");
}
} else if (state == GameState.loss) {
start();
Render();
} else if (state == GameState.victory) {
start();
Render();
}
}
My logical circuits tell met that inn the case of, say, victory, the program should go like this:
switch -> it processes input, steps player and opponent, Renders;
if -> finds out that the player is on the entrance tile, sets state for victory, sets title for victory, transmits the state to the drawing panel, makes the drawing panel draw the victory screen.
Well, in reality, my impression is it for some reason goes like this:
switch -> it processes input, steps player and opponent Renders
immediately goes to
if -> finds out that the player is on the entrance tile, sets state for victory (doesn't set title for victory), transmits the state to the drawing panel, makes the drawing panel draw the victory screen.
Who is wrong here - me or it?