/*
* Cero Project - Copyright 2006 The Cero Developement Team
* (Michael Laguerre, Camille Roux, Matthieu Segret, Mathieu Sivade)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
package cero.games.bataille;
import cero.games.Card;
import cero.games.Game;
import cero.games.InitializationException;
import cero.games.RoundEvent;
import cero.games.RoundListener;
import cero.games.Rule;
import cero.games.ValidationException;
import cero.games.Zone;
import cero.games.ZonesGroup;
import cero.games.base.ShuffleSorter;
public class Deal implements Rule, RoundListener {
public String getRuleName() {
return "Card dealing";
}
public String getRuleDescription() {
return "deals cards equally between players";
}
public String getRuleConstraints() {
return "2 players min";
}
public void validateGame(Game game) throws ValidationException {
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++;
}
}
public void roundEnd(RoundEvent e) {
// nothing to do about that
}
public void initializeRule(Game game) throws InitializationException {
game.getRounds().get(0).addRoundListener(this);
}
}