コード例 #1
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());
  }