Package cero.games

Examples of cero.games.Game


  public Game getNewGame(String gameName) {
    GamePlugin gp = gamePlugins.get(gameName);
    if (gp == null)
      return null;

    Game game = gp.newGameInstance();
    // adds the interface to the game, so that they become aware of it
    for (UserInterface ui : uiInstances)
      game.addGameListener(ui);

    return game;
  }
View Full Code Here


  /**
   * @param args
   */
  public static void main(String[] args) {
    PluginManager manager = PluginManager.getInstance();
    Game game = (Game) manager.getNewGame("Cero official uno");
    for (Rule r : manager.getGameRules(game.getGameName()))
      game.getRules().add(r);

    // 1 joueur humain suffira
    /*
     * Player p = (Player) pmanager.getNewPlayer(game.getGameName());
     * game.getPlayers().add(p); player = p;
     */

    // 3 AI de chaque
    game.getPlayers().add(
        manager.getNewAI(game.getGameName(), "Standard AI"));
    game.getPlayers().add(
        manager.getNewAI(game.getGameName(), "Standard AI"));
    game.getPlayers().add(
        manager.getNewAI(game.getGameName(), "Standard AI"));
    // game.getPlayers().add(manager.getNewAI(game.getGameName(), "Standard
    // AI"));
    game.getPlayers()
        .add(manager.getNewAI(game.getGameName(), "Random AI"));
    game.getPlayers().get(0).setPlayerName("Toi");
    game.getPlayers().get(1).setPlayerName("Tom");
    game.getPlayers().get(2).setPlayerName("Léa");
    // game.getPlayers().get(3).setPlayerName("Gru");
    game.getPlayers().get(3).setPlayerName("Boulay");

    for (GameInitializer init : manager.getGameInitializers(game
        .getGameName()))
      game.getGameInitializers().add(init);

    game.addGameListener(new listener());

    try {
      game.startGame();
    } catch (InitializationException e) {
      e.printStackTrace();
    } catch (ValidationException e) {
      e.printStackTrace();
    }
View Full Code Here

  public String toString() {
    return "list elements of the game";
  }

  public boolean executer(String parametres) {
    Game game = CommandLineLauncher.getGame();
    if (game == null || parametres.trim() == "")
      return false;
    String[] split = parametres.split(":");

    Collection collection = null;
    if (split[0].equals("p"))
      collection = game.getPlayers().getSortedList();
    else if (split[0].equals("a"))
      collection = game.getActions();
    else if (split[0].equals("r"))
      collection = game.getRules();
    else if (split[0].equals("z")) {
      if (split.length == 1)
        collection = game.getZones();
      else {
        collection = game.getPlayers().get(Integer.valueOf(split[1]))
            .getZones();
      }
    } else if (split[0].equals("c")) {
      if (split.length == 2) {
        Zone zone = game.getZones().get(split[1]);
        if (zone != null)
          collection = zone.getSortedList();
        else
          System.out.println("no such zone");
      }
      if (split.length == 3) {
        collection = game.getPlayers().get(Integer.valueOf(split[1]))
            .getZones().get(split[2]).getSortedList();
      }
    } else if (split[0].equals("rounds"))
      collection = game.getRounds();
    else if (split[0].equals("ar"))
      collection = game.getActionRules().getSortedList();
    else {
      System.out.println("bad argument(s)");
    }

    if (collection != null)
View Full Code Here

    if (game.getPlayers().size() <= 2)
      throw new ValidationException("There must be at least 2 players");
  }

  public void roundStart(RoundEvent e) {
    Game game = e.getGame();
    ZonesGroup zones = game.getZones();

    Zone dealsource = zones.get("Deal Source");

    for (Zone zone : zones)
      zone.moveCards(dealsource);
   
    for (cero.games.Player p : game.getPlayers())
      for (Zone z : p.getZones())
        z.moveCards(dealsource);

    // shuffling
    dealsource.setSorter(new ShuffleSorter());
    dealsource.sort();

    // dealing
    int playernum = 0;
    for (Card card : dealsource.getSortedList()) {
      playernum = (playernum) % (game.getPlayers().size());
      dealsource.moveCard(card, game.getPlayers().get(playernum)
          .getZones().get("stock"));
      playernum++;
    }

  }
View Full Code Here

  public String toString() {
    return "see a zone like a player";
  }

  public boolean executer(String parametres) {
    Game game = CommandLineLauncher.getGame();
    if (game == null || parametres.trim() == "")
      return false;
    String[] split = parametres.split(":");
    game.addActionListener(this);

    Collection collection = null;
    if (split[0].equals("listz")) {
      if (split.length == 1)
        collection = game.getZones();
      else {
        collection = game.getPlayers().get(Integer.valueOf(split[1]))
            .getZones();
      }
      print(collection);
    } else if (split[0].equals("z")) {
      if (split.length == 2) {
View Full Code Here

  }

  @Override
  public boolean executer(String parametres) {
    String[] arg = parametres.split(":");
    Game game = CommandLineLauncher.getGame();
    Zone from;
    Zone to;
    List<Card> cards = new ArrayList<Card>();
    if (arg.length == 3) {
      String[] split = arg[0].split("-");
      if (split.length == 1)
        from = game.getZones().get(split[0]);
      else if (split.length == 2)
        try {
          from = game.getPlayers().get(Integer.valueOf(split[0]))
              .getZones().get(split[1]);
        } catch (NumberFormatException e) {
          System.out.println("Player number conversion error");
          return false;
        }
      else
        return false;

      split = arg[1].split("-");
      if (split.length == 1)
        to = game.getZones().get(split[0]);
      else if (split.length == 2)
        try {
          to = game.getPlayers().get(Integer.valueOf(split[0]))
              .getZones().get(split[1]);
        } catch (NumberFormatException e) {
          System.out.println("Player number conversion error");
          return false;
        }
      else
        return false;

      for (Card card : from.getSortedList()) {
        if (card.getCardId() == Integer.valueOf(arg[2])) {
          ActionPlayYourCards action = null;
          for (Action act : game.getActions()) {
            if (act instanceof ActionPlayYourCards) {
              //FIXME : et si y'a plusieurs ActionplayCards ? et bah plouf ! => il faut utiliser les modules  :)
              try {
                action = (ActionPlayYourCards) act.getClass()
                    .newInstance();
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }
          cards.add(card);
          try {
            action.playerActed(new ActionEvent(game,
                CommandLineLauncher.getCurrentPlayer(), from,
                to, cards));
          } catch (ActionException e) {
            System.out.println("error during playing cards");
          }
          game.registerAction(action);
          return true;
        }
      }

    }
View Full Code Here

  public boolean executer(String parametres) {
    if (parametres.trim() == "")
      return false;
    if (parametres.equals("bataille")) {
      PluginManager pmanager = PluginManager.getInstance();
      Game game = pmanager.getNewGame("Cero official bataille");
      for (Rule r : pmanager.getGameRules(game.getGameName()))
        game.getRules().add(r);

      // 1 joueur humain suffira
      for (int i = 0; i < 1; i++)
        game.getPlayers().add(pmanager.getNewPlayer(game.getGameName()));
      // une AI de chaque
      for (String aip : pmanager.getAIsName(game.getGameName()))
        game.getPlayers().add(pmanager.getNewAI(game.getGameName(), aip));

      for (GameInitializer init : pmanager.getGameInitializers(game.getGameName()))
        game.getGameInitializers().add(init);
      try {
        game.startGame();
      } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        return false;
      }
      return true;
    } else if (parametres.equals("uno")) {
      PluginManager pmanager = PluginManager.getInstance();
      Game game = pmanager.getNewGame("Cero official uno");
      for (Rule r : pmanager.getGameRules(game.getGameName()))
        game.getRules().add(r);
     
      // 1 joueur humain suffira
      for (int i = 0; i < 1; i++)
        game.getPlayers().add(pmanager.getNewPlayer(game.getGameName()));
      // 3 AI de chaque
      for (String aip : pmanager.getAIsName(game.getGameName()))
        for (int i = 0; i < 3; i++)
          game.getPlayers().add(pmanager.getNewAI(game.getGameName(), aip));
     
      for (GameInitializer init : pmanager.getGameInitializers(game.getGameName()))
        game.getGameInitializers().add(init);

      try {
        game.startGame();
      } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        return false;
      }
View Full Code Here

    return instance;
  }

  @Override
  public boolean executer(String parametres) {
    Game game = CommandLineLauncher.getGame();
    Player player = CommandLineLauncher.getCurrentPlayer();
    Zone from = player.getZones().get("Hand");
    Zone to = game.getZones().get("Talon");
    int cardid;
    try {
      cardid = Integer.valueOf(parametres);
    } catch (Exception e) {
      System.out.println("incorrect card id");
      return false;
    }
    Card playedcard = null;
    for (Card card : from.getSortedList()) {
      if (card.getCardId() == cardid) {
        playedcard = card;
        break;
      }
    }
    if (playedcard == null) {
      System.out.println("incorrect card id");
      return false;
    }

    ActionPlayACard action = new ActionPlayACard();
    ArrayList<Card> colcards = new ArrayList<Card>();
    colcards.add(playedcard);
    try {
      action
          .playerActed(new ActionEvent(game, player, from, to,
              colcards));
    } catch (ActionException e) {
      // there shouldn't be any problem here !
      e.printStackTrace();
    }
    game.registerAction(action);
    return true;
  }
View Full Code Here

    return instance;
  }

  @Override
  public boolean executer(String parametres) {
    Game game = CommandLineLauncher.getGame();
    Player player = CommandLineLauncher.getCurrentPlayer();
    Zone from = game.getZones().get("Stock");
    Zone to = player.getZones().get("Hand");
    //FIXME : use top card instead !
    Card playedcard = from.getSortedList().get(0);
    ArrayList<Card> colcards = new ArrayList<Card>();
    colcards.add(playedcard);

    ActionPick action = new ActionPick();
    try {
      action
          .playerActed(new ActionEvent(game, player, from, to,
              colcards));
    } catch (ActionException e) {
      // there shouldn't be any problem here !
      e.printStackTrace();
    }
    game.registerAction(action);
    return true;
  }
View Full Code Here

    return instance;
  }

  @Override
  public boolean executer(String parametres) {
    Game game = CommandLineLauncher.getGame();
    Player player = CommandLineLauncher.getCurrentPlayer();

    ActionSkipTurn action = new ActionSkipTurn();
    try {
      action.playerActed(new ActionEvent(game, player, null, null, null));
    } catch (ActionException e) {
      // there shouldn't be any problem here !
      e.printStackTrace();
    }
    game.registerAction(action);
    return true;
  }
View Full Code Here

TOP

Related Classes of cero.games.Game

Copyright © 2018 www.massapicom. 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.