Example #1
0
 public void mouseReleased(MouseEvent e) {
   if (gameover) return;
   if (!blown) {
     if (started == false) {
       started = true;
       processActionEvent(new ActionEvent(this, START_TIMER, "MineSweeper"));
     }
     if (!xy2index(e.getX(), e.getY())) return;
     if (right_clicked) {
       if (hidden[cr][cc]) {
         flagged[cr][cc] = !flagged[cr][cc];
         processActionEvent(
             new ActionEvent(this, SQUARE_FLAGGED * (!flagged[cr][cc] ? 1 : -1), "MineSweeper"));
       }
     } else {
       if (hidden[cr][cc] && !flagged[cr][cc]) hidden[cr][cc] = false;
       if (!flagged[cr][cc] && field[cr][cc] == -1) {
         blown = true;
         started = false;
         processActionEvent(new ActionEvent(this, GAME_LOST, "MineSweeper"));
         paint(getGraphics());
         return;
       }
       if (field[cr][cc] == 0) showNeighbours(cr, cc, false);
     }
     drawBlock(buffG, cr, cc, status(cr, cc));
     paint(getGraphics());
     if ((gameover = is_game_over())) end_game();
   }
 }
Example #2
0
  public void mousePressed(MouseEvent e) {
    if (gameover) return;
    if (!blown) {
      right_clicked = (e.getModifiers() == Event.META_MASK);
      if (!xy2index(e.getX(), e.getY())) return;
      drawBlock(buffG, pr, pc, status(pr, pc));
      /*if (e.modifiers == Event.ALT_MASK) {
          showNeighbours(cr,cc,true);
          return true;
      }*/
      int s = (!hidden[cr][cc] || flagged[cr][cc] ? status(cr, cc) : 7);
      if (hidden[cr][cc] && e.getModifiers() == Event.META_MASK) s = 5;

      drawBlock(buffG, cr, cc, s);
      // paint(getGraphics());
      if (getGraphics() != null) getGraphics().drawImage(buff, 0, 0, null);
      if ((gameover = is_game_over())) {
        end_game();
      }
    }
  }