Пример #1
0
 private void move(Direction direction) {
   switch (direction) {
     case RIGHT:
       if (isBreaked(x, y, x + 2, y)) {
         x = x + 2;
         y = y;
       }
       break;
     case LEFT:
       if (isBreaked(x, y, x - 2, y)) {
         x = x - 2;
         y = y;
       }
       break;
     case DOWN:
       if (isBreaked(x, y, x, y + 2)) {
         x = x;
         y = y + 2;
       }
       break;
     case UP:
       if (isBreaked(x, y, x, y - 2)) {
         x = x;
         y = y - 2;
       }
       break;
   }
   if (x == properties.END_CELL_X && y == properties.END_CELL_Y) {
     isEnd = true;
     kFrame.getKCanvas().removeKeyListener(keyListener);
     showWinMessage();
   }
 }
Пример #2
0
  public Game(KFrame kFrame, Properties properties, Cell[][] cells) {
    this.kFrame = kFrame;
    this.properties = properties;
    this.cells = cells;

    x = properties.BIGIN_CELL_X;
    y = properties.BEGIN_CELL_Y;

    kFrame.addKeyListener(keyListener);
  }