001 /**
002 * A GameSettings object encapsulates the options for a new game of Antichess.
003 *
004 * @specfield whiteHuman : true if white will be a human player, else false
005 * @specfield whiteTime : the time allotted to white, in milliseconds
006 * @specfield blackHuman : true if black will be a human player, else false
007 * @specfield blackTime : the time allotted to black, in milliseconds
008 * @specfield powerups : determines the location of powerups on the board
009 */
010
011 package ui;
012
013 import core.*;
014
015 public class GameSettings {
016 private boolean whiteHuman; // True if the white player is human
017 private int whiteTime; // Time in milliseconds allotted to White
018 private boolean blackHuman;
019 private int blackTime;
020 private String powerupString;
021
022 /**
023 * Abstraction Function AF(r) = gs
024 * gs.whiteHuman = r.whiteHuman
025 * gs.whiteTime = r.whiteTime
026 * gs.blackHuman = r.blackHuman
027 * gs.blackTime = r.blackTime
028 * gs.powerups : determined by r.powerupString
029 */
030
031 /**
032 * Constructor that does not specify number of powerups. The default is 0.
033 */
034 public GameSettings(boolean wHuman, int wTime,
035 boolean bHuman, int bTime) {
036 this(wHuman, wTime, bHuman, bTime, 0);
037 }
038
039 /**
040 * @param wHuman : true if white is human
041 * @param wTime :Time in milliseconds allotted to white player
042 * @param bHuman : true if black player is human
043 * @param bTime : Time in milliseconds allotted to black player
044 * @param numPairs : The number of pairs of powerups on the board. Defaults
045 * to 0 if numPairs < 0; defaults to 16 if numPairs > 16.
046 */
047 public GameSettings(boolean wHuman, int wTime,
048 boolean bHuman, int bTime, int numPairs) {
049 whiteHuman = wHuman;
050 whiteTime = wTime;
051 blackHuman = bHuman;
052 blackTime = bTime;
053
054 if (numPairs < 0) {
055 numPairs = 0;
056 }
057 else if (numPairs > 16) {
058 numPairs = 16;
059 }
060
061 powerupString = PowerupHelper.randomPowerupString(numPairs);
062 }
063
064 /**
065 * @return true if the white side will be played by a human
066 */
067 public boolean isWhiteHuman() {
068 return whiteHuman;
069 }
070
071 /**
072 * @return true if the black side will be played by a human
073 */
074 public boolean isBlackHuman() {
075 return blackHuman;
076 }
077
078 /**
079 * @return the time in milliseconds white will have in this game
080 */
081 public int getWhiteTime() {
082 return whiteTime;
083 }
084
085 /**
086 * @return the time in milliseconds black will have in this game
087 */
088 public int getBlackTime() {
089 return blackTime;
090 }
091
092 /**
093 * @return the string describing the positions of this.powerups
094 */
095 public String getPowerupString() {
096 return powerupString;
097 }
098 }