All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.barrybecker4.game.multiplayer.common.MultiGameOptions Maven / Gradle / Ivy

There is a newer version: 1.6
Show newest version
/** Copyright by Barry G. Becker, 2000-2011. Licensed under MIT License: http://www.opensource.org/licenses/MIT  */
package com.barrybecker4.game.multiplayer.common;

import com.barrybecker4.game.common.GameOptions;

/**
 * @author Barry Becker
 */
public class MultiGameOptions extends GameOptions {

    private static final int DEFAULT_PLAYER_LIMIT = 8;
    private static final int DEFAULT_NUM_ROBOT_PLAYERS = 1;

    /** no more than this many allowed at the table. */
    private int maxNumPlayers_ = DEFAULT_PLAYER_LIMIT;

    /**
     * The number of robot players at the table.
     * You can change this in the new game dlg if stand alone.
     */
    private int numRobotPlayers_ = DEFAULT_NUM_ROBOT_PLAYERS;


    protected MultiGameOptions() {
          this(DEFAULT_PLAYER_LIMIT, DEFAULT_NUM_ROBOT_PLAYERS);
    }

    protected MultiGameOptions(int maxNumPlayers, int numRobotPlayers) {
         maxNumPlayers_ = maxNumPlayers;
         numRobotPlayers_ = numRobotPlayers;
    }

    /**
     * Usually 2 but we allow for override.
     */
    public int getMinNumPlayers() {
        return 2;
    }

    @Override
    public int getMaxNumPlayers() {
        return maxNumPlayers_;
    }

    /**
     * You wont be able to add more than this many players.
     * @param playerLimit no more than this many players allowed
     */
    protected void setMaxNumPlayers(int playerLimit) {
        maxNumPlayers_ = playerLimit;
    }

    public int getNumRobotPlayers() {
        return numRobotPlayers_;
    }

    public void setNumRobotPlayers(int numRobotPlayers) {
        numRobotPlayers_ = numRobotPlayers;
    }

    /**
     * Check constraints on options to verify validity.
     * @return  null if no errors, return error messages if constraints violated.
     */
    @Override
    public String testValidity() {
        String msgs = "";
        if (getNumRobotPlayers() > getMaxNumPlayers())  {
            msgs += "The number of robot players cannot can exceed the total number of players.";
        }
        return (msgs.length() > 0)? msgs : null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy