Package pdp.scrabble.game.impl

Source Code of pdp.scrabble.game.impl.ResolutionImpl

package pdp.scrabble.game.impl;

import java.util.List;
import javax.swing.JOptionPane;
import pdp.scrabble.Game;
import pdp.scrabble.game.AIConfig;
import pdp.scrabble.game.Letter;
import pdp.scrabble.game.BestPlacement;
import pdp.scrabble.game.Placement;
import pdp.scrabble.game.Player;
import pdp.scrabble.game.Resolution;
import pdp.scrabble.utility.Anagram;
import pdp.scrabble.utility.Display;
import static pdp.scrabble.Language.getGameLang;

public class ResolutionImpl implements Resolution {

    private Game game = null;

    public ResolutionImpl(Game game) {
  this.game = game;
    }

    @Override
    public String showPossibilities(String letters) {

  // Create all possible combinaison with letters
  Anagram ana = new Anagram(this.game, letters);

  // Show result
  Object[] str = ana.toArray();
  String selected = null;
  if (str.length > 0) {
      Object result = JOptionPane.showInputDialog(
        null, getGameLang("Choice"), letters,
        JOptionPane.INFORMATION_MESSAGE, null, str, str[0]);

      if (result != null) {
    selected = (String) result;
      }
      else {
    selected = null;
      }
  }
  else {
      Display.information("Show possibilities", "No available word !");
  }

  ana.clear();

  return selected;
    }

    @Override
    public Placement suggestPlacement(
      Player player, AIConfig config, List<Letter> required,
      List<Letter> excluded) {

  BestPlacement bestPlacement = new BestPlacementImpl(this.game);
  return bestPlacement.find(player, config, required, excluded);
    }
}
TOP

Related Classes of pdp.scrabble.game.impl.ResolutionImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.