Package com.barrybecker4.game.common.player

Examples of com.barrybecker4.game.common.player.PlayerAction


        }
        controller_.reset();
        controller_.setPlayers(newPlayers);

        // if getFirstPlayer returns null, then it is not a turn based game
        Player firstPlayer = controller_.getPlayers().getFirstPlayer();
        if (firstPlayer != null && !firstPlayer.isHuman()) {
            controller_.computerMovesFirst();
        }
    }
View Full Code Here


     * @param responses at the least this will be the players action that we received, but it may contain robot
     *       actions for the robots on the server that play immediately after the player.
     */
    private void doPlayerAction(GameCommand cmd, List<GameCommand> responses) {

        PlayerAction action = (PlayerAction) cmd.getArgument();
        GameContext.log(0, "ServerCmdProc: doPlayerAction (" + action + "). Surrogates to handle");
        controller_.handlePlayerAction(action);

        responses.add(cmd);

View Full Code Here

     */
    @Override
    public synchronized boolean handleServerUpdate(GameCommand cmd) {

        if (cmd.getName() == GameCommand.Name.DO_ACTION) {
            PlayerAction action = (PlayerAction) cmd.getArgument();
            if (action.getPlayerName().equals(player.getName())) {
                GameContext.log(0, "Setting surrogate(" + player.getName()
                        + ") action="+action + " on "+this+",  Thread=" + Thread.currentThread().getName());
                synchronized (player) {
                    player.setAction(action);
                    player.notifyAll()// unblock the wait below
View Full Code Here

        try {
            long t1 = System.currentTimeMillis();
            System.out.println(player.getName() + " now waiting for surrogate action on "
                    + this + ",  Thread=" + Thread.currentThread().getName());

            PlayerAction action = null;
            synchronized (player) {

                while (action == null) {
                    player.wait(TIMEOUT_DURATION);
                    if ((System.currentTimeMillis() - t1) > (TIMEOUT_DURATION - 10)) {
View Full Code Here

     */
    @Override
    public boolean handleServerUpdate(GameCommand cmd) {

         if (cmd.getName() == GameCommand.Name.DO_ACTION) {
            PlayerAction action = (PlayerAction) cmd.getArgument();
            if (action.getPlayerName().equals(player.getName())) {
                return true;
            }
        }
        return true;
    }
View Full Code Here

    public boolean doComputerMove(Player player) {
        assert(!player.isHuman());
        PokerRobotPlayer robot = (PokerRobotPlayer)player.getActualPlayer();
        PokerController pc = (PokerController) controller_;

        PlayerAction action = robot.getAction(pc);
        String msg = applyAction(action, robot);
        pc.addRecentRobotAction(action);

        JOptionPane.showMessageDialog(parent_, msg, robot.getName(), JOptionPane.INFORMATION_MESSAGE);
        refresh();
View Full Code Here

    private void startGame(OnlineGameTable table) {

        GameContext.log(0, "Now starting game on Server! "+ table);

        // Create players from the table and start.
        PlayerList players = table.getPlayers();
        assert (players.size() == table.getNumPlayersNeeded());
        PlayerList newPlayers = new PlayerList();
        for (Player player : players) {
            if (player.isHuman()) {
                newPlayers.add(player.createSurrogate(controller_.getServerConnection()));
            } else {
                newPlayers.add(player);
            }
        }
        controller_.reset();
        controller_.setPlayers(newPlayers);
View Full Code Here

    private OnlineGameTable(String name, Player owner, Player[] initialPlayers, GameOptions options) {
        name_ = name;
        owner_ = owner;
        newestHumanPlayer_ = owner;
        players_ = new PlayerList();
        gameOptions_ = options;
        players_.addAll(Arrays.asList(initialPlayers));
    }
View Full Code Here

    @Override
    public PlayerList getPlayers() {

        TableModel model = table_.getModel();
        int nRows = model.getRowCount();
        PlayerList players = new PlayerList();
        for (int i=0; i<nRows; i++) {
            char planetName = (Character) model.getValueAt(i, HOME_PLANET_INDEX);
            Planet planet = Galaxy.getPlanet(planetName);
            planet.setProductionCapacity((Integer) model.getValueAt(i, PRODUCTION_INDEX));
            planet.setNumShips((Integer) (model.getValueAt(i, NUM_SHIPS_INDEX)));
            ImageIcon icon = (ImageIcon) (model.getValueAt(i, ICON_INDEX));
            players.add(GalacticPlayer.createGalacticPlayer(
                                    (String) model.getValueAt(i, NAME_INDEX),
                                    planet,
                                    (Color) model.getValueAt(i, COLOR_INDEX),
                                    ((Boolean) model.getValueAt(i, HUMAN_INDEX)), icon));
        }
View Full Code Here

     * Factory method to create the game controller via reflection.
     * The server should not have a ui component.
     */
    private void createController(String gameName) {

        GamePlugin plugin = PluginManager.getInstance().getPlugin(gameName);
        GameContext.loadResources(gameName);

        // for now, also create a corresponding viewer. The server should really not have knowledge of a UI component.
        // fix this by doing plugin.getModelInstance, then getting the controller from that.
        GamePanel panel  = plugin.getPanelInstance();
        panel.init(null);
        GameBoardViewer viewer = panel.getViewer();

        controller_ = viewer.getController();
    }
View Full Code Here

TOP

Related Classes of com.barrybecker4.game.common.player.PlayerAction

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.