|
@ -1,6 +1,36 @@ |
|
|
package Snake; |
|
|
package Snake; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
|
|
|
public class Controller { |
|
|
public class Controller { |
|
|
|
|
|
|
|
|
|
|
|
private enum GameState { Running }; |
|
|
|
|
|
private GameView gameView; |
|
|
|
|
|
private Snake snakeModel; |
|
|
|
|
|
private boolean inputHandled; |
|
|
|
|
|
private GameState gameState; |
|
|
|
|
|
|
|
|
|
|
|
private class MoveAction extends AbstractAction |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
private Snake.SnakeDirection direction; |
|
|
|
|
|
|
|
|
|
|
|
MoveAction(Snake.SnakeDirection direction) |
|
|
|
|
|
{ |
|
|
|
|
|
this.direction = direction; |
|
|
|
|
|
} |
|
|
|
|
|
@Override |
|
|
|
|
|
public void actionPerformed(ActionEvent e) |
|
|
|
|
|
{ |
|
|
|
|
|
if(inputHandled && gameState == GameState.Running) |
|
|
|
|
|
{ |
|
|
|
|
|
snakeModel.setDirection(direction); |
|
|
|
|
|
inputHandled = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |