private void paintMenu(Graphics2D g2d) {
   if (showMenu == true) {
     if (c.getPoints() > c.getHighscore().getLowestPointsInTable() && c.getLifes() == 0) {
       menu.setState(4);
     }
     menu.draw(g2d);
   }
 }
  /**
   * Create a new board
   *
   * @param c
   */
  public Board(Game c) {
    // add leap motion controller
    leapAdapter = new SensorAdapter(c);
    sensorListener = new SensorListener(leapAdapter);
    shootListener = new ShootListener(leapAdapter);
    leapController = new Controller();
    leapController.addListener(sensorListener);
    leapController.addListener(shootListener);

    addKeyListener(new KeyboardAdapter(c, this));

    this.menu = new Menu(this, c);
    setFocusable(true);
    setDoubleBuffered(true);
    this.c = c;
    c.setPlayer(ItemFactory.createPlayer());
    c.setBackground(ItemFactory.createBackground());
  }
 private void paintItems(Graphics2D g2d) {
   for (Item item : c.getAllStuff()) {
     if (item != null) {
       if (item.flicker()) {
         g2d.drawImage(
             item.getImage(), item.getPosition().getX(), item.getPosition().getY(), this);
       }
     }
   }
 }
 private void paintLifes(Graphics2D g2d) {
   int lifes = c.getLifes();
   for (int i = 0; i < lifes; i++) {
     ImageIcon imageIcon =
         new ImageIcon(
             ItemFactory.class.getResource(Config.getImagePath() + Level.getLevel().getLife()));
     Life life =
         ItemFactory.createLife(
             Config.getBoardDimension().getLength() - (2 + i) * imageIcon.getIconWidth(),
             0,
             imageIcon);
     g2d.drawImage(life.getImage(), life.getPosition().getX(), life.getPosition().getY(), this);
   }
 }
  @Override
  public void paint(Graphics g) {
    super.paint(g);

    // menu on game over
    if (c.getLifes() < 1) {
      showMenu = true;
    }

    this.paintBackground((Graphics2D) g);
    this.paintItems((Graphics2D) g);
    this.paintLifes((Graphics2D) g);
    this.paintScore((Graphics2D) g);
    this.paintMenu((Graphics2D) g);

    Toolkit.getDefaultToolkit().sync();
    g.dispose();
  }
 private void paintBackground(Graphics2D g2d) {
   int x = c.getBackground().getPosition().getX();
   int y = c.getBackground().getPosition().getY();
   g2d.drawImage(
       c.getBackground().getImage(),
       x - c.getBackground().getDimension().getLength(),
       y,
       Config.getBoardDimension().getLength(),
       Config.getBoardDimension().getHeight(),
       this);
   g2d.drawImage(
       c.getBackground().getImage(),
       x,
       y,
       Config.getBoardDimension().getLength(),
       Config.getBoardDimension().getHeight(),
       this);
   g2d.drawImage(
       c.getBackground().getImage(),
       x + c.getBackground().getDimension().getLength(),
       y,
       Config.getBoardDimension().getLength(),
       Config.getBoardDimension().getHeight(),
       this);
   if (Config.getForeground().compareTo("") == 0) {
     ImageIcon foreground =
         new ImageIcon(
             this.getClass().getResource(Config.getImagePath() + Config.getForeground()));
     g2d.drawImage(
         foreground.getImage(),
         0,
         Config.getBoardDimension().getHeight() - foreground.getIconHeight(),
         Config.getBoardDimension().getLength(),
         foreground.getIconHeight(),
         this);
   }
 }
 /** Toggle the menu */
 public void toggleMenu() {
   if (c.getLifes() > 0) {
     c.setPause(!c.isPaused());
     showMenu = !showMenu;
   }
 }
 private void paintScore(Graphics2D g2d) {
   Font font = new Font("sans", Font.PLAIN, 36);
   g2d.setColor(Color.green);
   g2d.setFont(font);
   g2d.drawString((int) c.getPoints() + "", 10, 50);
 }