Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Game {
- public static final int boardWidth = 20;
- public static final int squareSize = 30; //in pixels
- GameObject[][] gameGrid;
- GameObject head;
- DIR direction;
- ArrayList<GameObject> hadica;
- public enum DIR {
- UP,
- DOWN,
- LEFT,
- RIGHT;
- }
- Game() {
- Platno platno = Platno.dajPlatno("Snake", boardWidth * squareSize, boardWidth * squareSize, Color.WHITE);
- this.hadica = new ArrayList<GameObject>();
- this.direction = DIR.RIGHT;
- for (int i = 0; i < boardWidth; i++ ) {
- for (int j = 0; j < boardWidth; j++ ) {
- gameGrid[i][j] = new GameObject(ObjectType.EMPTY,i,j);
- }
- }
- this.hadica.add(new GameObject(ObjectType.SNAKE,3,4));
- this.hadica.add(new GameObject(ObjectType.SNAKE,3,5));
- this.hadica.add(new GameObject(ObjectType.SNAKE,3,6));
- head = this.hadica.get(0);
- }
- public void tik() {
- GameObject prdel = this.hadica.remove(this.hadica.size()-1);
- prdel.setX(this.hadica.get(0).getX() + 1); //V pripade ze DIR je RIGHT
- prdel.setY(this.hadica.get(0).getY())
- prdel.presunStvorec(getX * squareSize, getY * squareSize);
- this.hadica.insert(prdel,0);
- }
- }
- //===
- public class GameObject {
- public enum ObjectType {
- EMPTY,
- SNAKE,
- APPLE;
- }
- ObjectType druhObjektu;
- int x; //suradcnice na ploche
- int y;
- Stvorec stvorec //suradnice na okne
- GameObject(ObjectType type, int x, int y) {
- this.druhObjektu = type;
- this.x = x;
- this.y = y;
- }
- public int getX() {
- return this.x;
- }
- public int getY() {
- return this.y;
- }
- public int getObjectType() {
- return this.druhObjektu;
- }
- }
- // ====
- public static class main {
- private static Manazer manazer;
- private static Game game;
- main() {
- game = new Game();
- manazer = new Manazer();
- manazer.spravujObjekt(game);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement