@Override
  public void actionPerformed(ActionEvent e) {
    if (reiniciar == e.getSource()) reinicio();
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (botones[i][j] == e.getSource()) {
          matriz[i][j] = 0;
          botones[i][j].setText("X");
          botones[i][j].setEnabled(false);
          logger.info("Jugador " + nombres[0] + " le dio en el boton" + i + " " + j);
          this.regla(i, j);

          IA inteligenciaArtificial = new IA();
          inteligenciaArtificial.PosiblesJugada(matriz);
          int[] posicion = inteligenciaArtificial.getJugadaFinal();
          matriz[posicion[0]][posicion[1]] = 1;
          botones[posicion[0]][posicion[1]].setText("0");
          botones[posicion[0]][posicion[1]].setEnabled(false);
          logger.info("la Computadora le dio en el boton " + posicion[0] + " " + posicion[1]);
          this.regla(posicion[0], posicion[1]);
        }
      }
    }
  }
  public void update(Graphics g) {
    dbImage = createImage(700, 500);

    dbg = dbImage.getGraphics();

    dbg.setColor(new Color(109, 233, 238));
    dbg.fillRect(0, 0, 700, 500);

    if (vidas > 0 && victoria == false) {
      for (int x = 0; x < largo; x++) {
        for (int y = 0; y < alto; y++) {
          if (stage != null) {

            if (stage[x][y].equals("0")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image heroe = t.getImage(this.getClass().getResource("/recursos/mario.png"));
              dbg.drawImage(heroe, (x * casillax), (y * casillay), this);

              posx = x;
              posy = y;

            } else if (stage[x][y].equals("1")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image goal = t.getImage(this.getClass().getResource("/recursos/final.png"));
              dbg.drawImage(goal, (x * casillax), (y * casillay), this);

            } else if (stage[x][y].equals("2")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image goomba = t.getImage(this.getClass().getResource("/recursos/goomba.png"));
              dbg.drawImage(goomba, (x * casillax), (y * casillay), this);

            } else if (stage[x][y].equals("3")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image koopa = t.getImage(this.getClass().getResource("/recursos/koopa.png"));
              dbg.drawImage(koopa, (x * casillax), (y * casillay), this);

            } else if (stage[x][y].equals("4")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image pared = t.getImage(this.getClass().getResource("/recursos/pared.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay), this);

            } else if (stage[x][y].equals("5")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image piso = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(piso, (x * casillax), (y * casillay) + 50, this);

            } else if (stage[x][y].equals("6")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image moneda = t.getImage(this.getClass().getResource("/recursos/ficha.png"));
              dbg.drawImage(moneda, (x * casillax), (y * casillay), this);

            } else if (stage[x][y].equals("7")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image vida = t.getImage(this.getClass().getResource("/recursos/vida.png"));
              dbg.drawImage(vida, (x * casillax), (y * casillay), this);

            } else if (stage[x][y].equals("50")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image heroe = t.getImage(this.getClass().getResource("/recursos/mario.png"));
              dbg.drawImage(heroe, (x * casillax), (y * casillay), this);

              posx = x;
              posy = y;

              Image pared = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay) + 50, this);

            } else if (stage[x][y].equals("25")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image goomba = t.getImage(this.getClass().getResource("/recursos/goomba.png"));
              dbg.drawImage(goomba, (x * casillax), (y * casillay), this);

              Image pared = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay) + 50, this);
            } else if (stage[x][y].equals("15")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image goal = t.getImage(this.getClass().getResource("/recursos/final.png"));
              dbg.drawImage(goal, (x * casillax), (y * casillay), this);

              Image pared = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay) + 50, this);
            } else if (stage[x][y].equals("35")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image koopa = t.getImage(this.getClass().getResource("/recursos/koopa.png"));
              dbg.drawImage(koopa, (x * casillax), (y * casillay), this);

              Image pared = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay) + 50, this);
            } else if (stage[x][y].equals("256")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image goomba = t.getImage(this.getClass().getResource("/recursos/goomba.png"));
              dbg.drawImage(goomba, (x * casillax), (y * casillay), this);

              Image moneda = t.getImage(this.getClass().getResource("/recursos/ficha.png"));
              dbg.drawImage(moneda, (x * casillax), (y * casillay), this);

              Image pared = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay) + 50, this);
            } else if (stage[x][y].equals("356")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image koopa = t.getImage(this.getClass().getResource("/recursos/koopa.png"));
              dbg.drawImage(koopa, (x * casillax), (y * casillay), this);

              Image moneda = t.getImage(this.getClass().getResource("/recursos/ficha.png"));
              dbg.drawImage(moneda, (x * casillax), (y * casillay), this);

              Image pared = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay) + 50, this);
            } else if (stage[x][y].equals("257")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image goomba = t.getImage(this.getClass().getResource("/recursos/goomba.png"));
              dbg.drawImage(goomba, (x * casillax), (y * casillay), this);

              Image vida = t.getImage(this.getClass().getResource("/recursos/vida.png"));
              dbg.drawImage(vida, (x * casillax), (y * casillay), this);

              Image pared = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay) + 50, this);
            } else if (stage[x][y].equals("357")) {

              Toolkit t = Toolkit.getDefaultToolkit();
              Image koopa = t.getImage(this.getClass().getResource("/recursos/koopa.png"));
              dbg.drawImage(koopa, (x * casillax), (y * casillay), this);

              Image vida = t.getImage(this.getClass().getResource("/recursos/vida.png"));
              dbg.drawImage(vida, (x * casillax), (y * casillay), this);

              Image pared = t.getImage(this.getClass().getResource("/recursos/piso.png"));
              dbg.drawImage(pared, (x * casillax), (y * casillay) + 50, this);
            }
          }
        }
      }

    } else {
      if (victoria) {
        gravedad.stop();
        IA.stop();
        tiempoh.stop();
        dbg.setColor(Color.GREEN);
        dbg.setFont(new Font("Calibri", Font.BOLD, 40));
        dbg.drawString("Victoria", 250, 250);
      } else {
        gravedad.stop();
        IA.stop();
        tiempoh.stop();
        dbg.setColor(Color.BLACK);
        dbg.setFont(new Font("Impact", Font.BOLD, 40));
        dbg.drawString("GAME OVER", 250, 250);
      }
    }

    dbg.setColor(Color.BLACK);
    if (cuadricula) {
      for (int i = 0; i <= largo; i++) {

        dbg.drawLine(0, (i * casillay), 1000, (i * casillay));
      }

      for (int j = 0; j <= alto; j++) {
        dbg.drawLine((j * casillax), 0, (j * casillax), 1000);
      }
    }

    dbg.setFont(new Font("Calibri", Font.BOLD, 18));
    if (jugando) {
      dbg.drawString("Vidas:", 10, 20);
      dbg.setColor(Color.RED);
      dbg.drawString(String.valueOf(vidas), 60, 20);
      dbg.setColor(Color.BLACK);
      dbg.drawString("Puntos:", 80, 20);
      dbg.setColor(Color.RED);
      dbg.drawString(String.valueOf(puntos), 150, 20);
      dbg.setColor(Color.BLACK);
      dbg.drawString("Tiempo:", 170, 20);
      dbg.setColor(Color.RED);
      dbg.drawString(String.valueOf(tiempo), 240, 20);
    }

    g.drawImage(dbImage, 0, 0, null);
    repaint();
  }
Beispiel #3
0
 @Override
 public void update(int delta) {
   super.update(delta);
 }
Beispiel #4
0
 @Override
 public void render(Graphics g) {
   super.render(g);
 }