|
From: <ev...@us...> - 2011-04-26 19:41:37
|
Revision: 1530
http://rails.svn.sourceforge.net/rails/?rev=1530&view=rev
Author: evos
Date: 2011-04-26 19:41:31 +0000 (Tue, 26 Apr 2011)
Log Message:
-----------
Implemented game end after share price has maxed out (for 18GA)
Modified Paths:
--------------
trunk/18xx/LocalisedText.properties
trunk/18xx/data/18GA/Game.xml
trunk/18xx/rails/game/Bank.java
trunk/18xx/rails/game/GameManager.java
trunk/18xx/rails/game/GameManagerI.java
trunk/18xx/rails/game/StockMarket.java
trunk/18xx/rails/game/StockMarketI.java
Modified: trunk/18xx/LocalisedText.properties
===================================================================
--- trunk/18xx/LocalisedText.properties 2011-04-26 15:15:37 UTC (rev 1529)
+++ trunk/18xx/LocalisedText.properties 2011-04-26 19:41:31 UTC (rev 1530)
@@ -42,8 +42,8 @@
BuyPrivatePrompt={0} from {1} for {2}...{3}
BankIsBrokenDisplayText=Bank is broken. Play continues until {0}
BankIsBrokenReportText=Bank is broken
-bankIsBrokenPlaySetOfORs=the current set of operating rounds is finished.
-bankIsBrokenPlayOnlyOR=the current operating round is finished.
+gameOverPlaySetOfORs=the current set of operating rounds is finished.
+gameOverPlayOnlyOR=the current operating round is finished.
BankHas=The Bank has {0}.
BankSizeIs=Bank size is {0}
BaseTokenSlotIsReserved=Base token slot is reserved
@@ -363,6 +363,8 @@
MapWindowTitle=Rails: Map
MapWindowORTitle=Rails: Map, Operating Round {0} ({1} of {2})
MARKET=Stock Market
+MaxedSharePriceDisplayText={0} share price has maxed at {1}. Play continues until {2}
+MaxedSharePriceReportText={0} share price has maxed at {1}
MayDiscardTrain={0} may voluntarily discard a train
MayNotBuyAndSell={0} may not both buy and sell shares
MayNotYetOperate={0} may not yet operate: {1}% sold whereas {2}% required
Modified: trunk/18xx/data/18GA/Game.xml
===================================================================
--- trunk/18xx/data/18GA/Game.xml 2011-04-26 15:15:37 UTC (rev 1529)
+++ trunk/18xx/data/18GA/Game.xml 2011-04-26 19:41:31 UTC (rev 1530)
@@ -15,7 +15,8 @@
<Bankruptcy/>
<BankBreaks limit="0" finish="currentOR"/>
<!-- "Runs out"; when "broken", -1 is the limit -->
- <!-- Also when the share value reaches $300; this is configured in the stock market XML -->
+ <!-- Also when the share value reaches $300; this is configured in the stock market XML,
+ but uses the 'finish' attribute value defined above. -->
</EndOfGame>
</Component>
<Component name="PlayerManager" class="rails.game.PlayerManager">
Modified: trunk/18xx/rails/game/Bank.java
===================================================================
--- trunk/18xx/rails/game/Bank.java 2011-04-26 15:15:37 UTC (rev 1529)
+++ trunk/18xx/rails/game/Bank.java 2011-04-26 19:41:31 UTC (rev 1530)
@@ -31,8 +31,6 @@
/** Is the bank broken (remains true once set) */
private BooleanState broken = new BooleanState("Bank.broken", false);
- // /** Is the bank just broken (returns true exactly once) */
- // private BooleanState brokenReported = new BooleanState("Bank.brokenReported", false);
/**
* The money format template. '@' is replaced by the numeric amount, the
@@ -151,16 +149,6 @@
}
}
- public boolean isBroken() {
- return broken.booleanValue();
- }
-
- // public boolean isJustBroken() {
- // boolean result = broken.booleanValue() && !brokenReported.booleanValue();
- // brokenReported.set(true);
- // return result;
- // }
-
/**
* @return Portfolio of stock in Bank Pool
*/
Modified: trunk/18xx/rails/game/GameManager.java
===================================================================
--- trunk/18xx/rails/game/GameManager.java 2011-04-26 15:15:37 UTC (rev 1529)
+++ trunk/18xx/rails/game/GameManager.java 2011-04-26 19:41:31 UTC (rev 1530)
@@ -118,6 +118,9 @@
new IntegerState("RelativeORNumber");
protected IntegerState numOfORs = new IntegerState("numOfORs");
+ /** GameOver pending, a last OR or set of ORs must still be completed */
+ protected BooleanState gameOverPending = new BooleanState ("GameOverPending", false);
+ /** GameOver is executed, no more moves */
protected BooleanState gameOver = new BooleanState("GameOver" ,false);
protected Boolean gameOverReportedUI = false;
protected BooleanState endedByBankruptcy = new BooleanState("EndedByBankruptcy", false);
@@ -415,9 +418,9 @@
bankBreaksTag.getAttributeAsInteger("limit",
gameEndsWhenBankHasLessOrEqual);
String attr = bankBreaksTag.getAttributeAsString("finish");
- if (attr.equalsIgnoreCase("SetOfORs")) {
+ if (attr.equalsIgnoreCase("setOfORs")) {
gameEndsAfterSetOfORs = true;
- } else if (attr.equalsIgnoreCase("CurrentOR")) {
+ } else if (attr.equalsIgnoreCase("currentOR")) {
gameEndsAfterSetOfORs = false;
}
}
@@ -645,7 +648,7 @@
startOperatingRound(true);
} else if (round instanceof OperatingRound) {
- if (bank.isBroken() && !gameEndsAfterSetOfORs) {
+ if (gameOverPending.booleanValue() && !gameEndsAfterSetOfORs) {
finishGame();
@@ -655,7 +658,7 @@
} else if (startPacket != null && !startPacket.areAllSold()) {
startStartRound();
} else {
- if (bank.isBroken() && gameEndsAfterSetOfORs) {
+ if (gameOverPending.booleanValue() && gameEndsAfterSetOfORs) {
finishGame();
} else {
((OperatingRound)round).checkForeignSales();
@@ -1331,17 +1334,36 @@
public void registerBrokenBank(){
+ gameOverPending.set(true);
ReportBuffer.add(LocalText.getText("BankIsBrokenReportText"));
String msgContinue;
if (gameEndsAfterSetOfORs)
- msgContinue = LocalText.getText("bankIsBrokenPlaySetOfORs");
+ msgContinue = LocalText.getText("gameOverPlaySetOfORs");
else
- msgContinue = LocalText.getText("bankIsBrokenPlayOnlyOR");
+ msgContinue = LocalText.getText("gameOverPlayOnlyOR");
String msg = LocalText.getText("BankIsBrokenDisplayText", msgContinue);
DisplayBuffer.add(msg);
addToNextPlayerMessages(msg, true);
}
+ public void registerMaxedSharePrice(PublicCompanyI company, StockSpaceI space){
+ gameOverPending.set(true);
+ ReportBuffer.add(LocalText.getText("MaxedSharePriceReportText",
+ company.getName(),
+ Bank.format(space.getPrice())));
+ String msgContinue;
+ if (gameEndsAfterSetOfORs)
+ msgContinue = LocalText.getText("gameOverPlaySetOfORs");
+ else
+ msgContinue = LocalText.getText("gameOverPlayOnlyOR");
+ String msg = LocalText.getText("MaxedSharePriceDisplayText",
+ company.getName(),
+ Bank.format(space.getPrice()),
+ msgContinue);
+ DisplayBuffer.add(msg);
+ addToNextPlayerMessages(msg, true);
+ }
+
private void finishGame() {
gameOver.set(true);
Modified: trunk/18xx/rails/game/GameManagerI.java
===================================================================
--- trunk/18xx/rails/game/GameManagerI.java 2011-04-26 15:15:37 UTC (rev 1529)
+++ trunk/18xx/rails/game/GameManagerI.java 2011-04-26 19:41:31 UTC (rev 1530)
@@ -67,7 +67,8 @@
public abstract void registerBankruptcy();
public abstract void registerBrokenBank();
-
+ public void registerMaxedSharePrice(PublicCompanyI company, StockSpaceI space);
+
public boolean isDynamicOperatingOrder();
/**
Modified: trunk/18xx/rails/game/StockMarket.java
===================================================================
--- trunk/18xx/rails/game/StockMarket.java 2011-04-26 15:15:37 UTC (rev 1529)
+++ trunk/18xx/rails/game/StockMarket.java 2011-04-26 19:41:31 UTC (rev 1530)
@@ -4,6 +4,7 @@
import java.util.*;
import rails.game.move.PriceTokenMove;
+import rails.game.state.BooleanState;
import rails.util.LocalText;
import rails.util.Tag;
@@ -20,6 +21,8 @@
protected ArrayList<StockSpaceI> startSpaces = new ArrayList<StockSpaceI>();
protected int[] startPrices;
protected StockSpaceTypeI defaultType;
+
+ GameManagerI gameManager;
/* Game-specific flags */
protected boolean upOrDownRight = false; /*
@@ -28,10 +31,8 @@
*/
/* States */
- protected boolean gameOver = false; /*
- * Some games have "rails.game over"
- * stockmarket squares
- */
+ /** GameOver becomes true if a stock market square is reached that is marked as such */
+ protected BooleanState gameOver = new BooleanState ("GameOver", false);
ArrayList<PublicCertificate> ipoPile;
@@ -155,7 +156,9 @@
*/
public void finishConfiguration (GameManagerI gameManager) {
- for (PublicCompanyI comp : GameManager.getInstance().getCompanyManager().getAllPublicCompanies()) {
+ this.gameManager = gameManager;
+
+ for (PublicCompanyI comp : gameManager.getCompanyManager().getAllPublicCompanies()) {
if (!comp.hasStarted() && comp.getStartSpace() != null) {
comp.getStartSpace().addFixedStartPrice(comp);
}
@@ -302,7 +305,7 @@
/* Check for rails.game closure */
if (to.endsGame()) {
ReportBuffer.add(LocalText.getText("GAME_OVER"));
- gameOver = true;
+ gameManager.registerMaxedSharePrice(company, to);
}
}
@@ -347,13 +350,6 @@
return null;
}
- /**
- * @return
- */
- public boolean isGameOver() {
- return gameOver;
- }
-
public PublicCertificate removeShareFromPile(PublicCertificate stock) {
if (ipoPile.contains(stock)) {
int index = ipoPile.lastIndexOf(stock);
Modified: trunk/18xx/rails/game/StockMarketI.java
===================================================================
--- trunk/18xx/rails/game/StockMarketI.java 2011-04-26 15:15:37 UTC (rev 1529)
+++ trunk/18xx/rails/game/StockMarketI.java 2011-04-26 19:41:31 UTC (rev 1530)
@@ -41,8 +41,6 @@
public StockSpaceI getStartSpace(int price);
- public boolean isGameOver();
-
public void processMove(PublicCompanyI company, StockSpaceI from,
StockSpaceI to);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|