コード例 #1
0
ファイル: Moteur.java プロジェクト: nSwane/Pingouin
  private void refaire() {
    // Recuperation du contexte precedent
    precD = f.refaire();
    if (precD != null) {
      precD.setAnnulerPossible(true);
      // Mise a jour du contexte courant
      liaison.setDonnees(precD);
      d = precD;

      if (!precD.isJeuFini()) {
        for (int o = 0; o < d.getNbJoueurs(); o++) {
          ordi[o] = new Ordinateur(liaison.getDonnees(), precD.getJoueurs()[o].getDifficulte());
        }
      }
    }
  }
コード例 #2
0
ファイル: Moteur.java プロジェクト: nSwane/Pingouin
  private void placerPingouin() {
    // Recuperation du contexte courant
    copieDP = liaison.getDonnees().copie();

    if (d.getJoueurs()[d.getJoueurCourant()].getDifficulte()
        != ordi[d.getJoueurCourant()].getDifficulte()) {
      ordi[d.getJoueurCourant()] =
          new Ordinateur(d, d.getJoueurs()[d.getJoueurCourant()].getDifficulte());
    }

    if (tabj[d.getJoueurCourant()].estOrdi()) ordi[d.getJoueurCourant()].placerPingouin();
    // Recuperation des coordonnees du pengouin
    Coordonnees ci = d.getCoordPingouinInitial();

    // Placement du pengouin
    if (tabj[d.getJoueurCourant()].ajouterPengouin(ci) < 0) {
      System.out.println(tabj[d.getJoueurCourant()].getNom() + " : Placement impossible");
      return;
    } else {
      d.setAnnulerPossible(true);

      // Sauvegarde du contexte avant placement pour une eventuelle recuperation
      f.empilerAnnuler(copieDP);

      // Si tous les placements sont termines, l'indiquer aux autres
      if (placementTermine()) {
        d.setPlacementPingouinTermine(placementTermine());
        d.getTerrain().verifierBlocages(tabj);
        //			f.viderAnnuler();
      }
      //		System.out.println(placementTermine());

      // Mise a jour du joueur courant
      if (d.getJoueurCourant() == d.getNbJoueurs() - 1) {
        d.setJoueurCourant(0);
      } else {
        d.setJoueurCourant(d.getJoueurCourant() + 1);
      }
    }
  }
コード例 #3
0
ファイル: Moteur.java プロジェクト: nSwane/Pingouin
  private void jouerCoup() {
    // Recuperation du contexte courant
    copieDP = liaison.getDonnees().copie();

    if (d.getJoueurs()[d.getJoueurCourant()].getDifficulte()
        != ordi[d.getJoueurCourant()].getDifficulte()) {
      ordi[d.getJoueurCourant()] =
          new Ordinateur(d, d.getJoueurs()[d.getJoueurCourant()].getDifficulte());
    }
    // Recuperation des coordonnees Depart et arrivee
    if (tabj[d.getJoueurCourant()].estOrdi()) {
      //			System.out.println("[Moteur] Coup de l'ordi");
      ordi[d.getJoueurCourant()].prochainCoup();
    }

    //		System.out.println("[moteur jouer coup] coup de l'ordi : depart :" + d.getCoordPingouinDep()
    // + " arrivee : " + d.getCoordPingouinArr());
    Coordonnees cd = d.getCoordPingouinDep();
    Coordonnees ca = d.getCoordPingouinArr();
    //		System.out.println("[moteur jouer coup] coup recupere : depart :" + cd + " arrivee : " +
    // ca);

    if (cd != null && ca != null) {
      // Deplacement du pengouin
      if (tabj[d.getJoueurCourant()].deplacerPingouin(cd, ca) < 0) {
        System.out.println(tabj[d.getJoueurCourant()].getNom() + " : Deplacement impossible");
        return;
      } else {
        d.setAnnulerPossible(true);
      }
    } else {
      return;
    }

    // Sauvegarde du contexte avant deplacement pour une eventuelle recuperation
    f.empilerAnnuler(copieDP);

    // Mise a jour du joueur courant
    if (d.getJoueurCourant() == d.getNbJoueurs() - 1) {
      d.setJoueurCourant(0);
    } else {
      d.setJoueurCourant(d.getJoueurCourant() + 1);
    }

    // on v�rifie si le joueur suivant peut jouer, si ce n'est pas le cas il passe son tour
    // tant qu'on a pas trouv� un joueur pouvant jouer on passe au suivant
    // si tous les joueurs ne peuvent pas jouer c'est fini
    int n = d.getNbJoueurs();
    while (d.getJoueurs()[d.getJoueurCourant()].getPingouinsRestants() <= 0 && n > 0) {
      if (d.getJoueurCourant() == d.getNbJoueurs() - 1) {
        d.setJoueurCourant(0);
      } else {
        d.setJoueurCourant(d.getJoueurCourant() + 1);
      }
      n--;
    }

    // on v�rifie si tous les joueurs sont bloqu�s
    // si c'est le cas on ramasse les derni�res tuiles et trouve le gagnant
    if (n == 0) {
      d.getTerrain().ramasserTuilesFin(tabj);
      d.setGagnant(d.getTerrain().gagnantPartie(tabj));
      System.out.println("Le gagnant est: " + d.getGagnant().getNom() + "!!!");
      d.setJeuFini(true);
    }
    System.out.println("JC : " + tabj[d.getJoueurCourant()].getNom());
    System.out.println("PR : " + tabj[d.getJoueurCourant()].getPingouinsRestants());
  }