Increase turn durations when players manage not to time out.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3517 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -143,7 +143,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
{
|
{
|
||||||
super.startTurn();
|
super.startTurn();
|
||||||
|
|
||||||
// schedule the timeout interval
|
// initialize the timeout flag and schedule the timeout interval
|
||||||
|
_turnTimedOut = false;
|
||||||
_turnTimeoutInterval.schedule(_trickCardGame.getTurnDuration());
|
_turnTimeoutInterval.schedule(_trickCardGame.getTurnDuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +154,14 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
// cancel the timeout interval
|
// cancel the timeout interval
|
||||||
_turnTimeoutInterval.cancel();
|
_turnTimeoutInterval.cancel();
|
||||||
|
|
||||||
|
// reduce or increase the turn duration scale
|
||||||
|
if (_turnTimedOut) {
|
||||||
|
reduceTurnDurationScale(_turnIdx);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
increaseTurnDurationScale(_turnIdx);
|
||||||
|
}
|
||||||
|
|
||||||
super.endTurn();
|
super.endTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,6 +277,9 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
throw new InvocationException("m.card_not_playable");
|
throw new InvocationException("m.card_not_playable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// since the player managed to avoid a timeout, increase turn duration
|
||||||
|
increaseTurnDurationScale(pidx);
|
||||||
|
|
||||||
// play the card
|
// play the card
|
||||||
playCard(pidx, card);
|
playCard(pidx, card);
|
||||||
}
|
}
|
||||||
@@ -397,14 +409,10 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the current turn times out. Default implementation
|
* Called when the current turn times out. Default implementation
|
||||||
* reduces the turn duration and plays a random playable card if in the
|
* plays a random playable card if in the trick-playing state.
|
||||||
* trick-playing state.
|
|
||||||
*/
|
*/
|
||||||
protected void turnTimedOut ()
|
protected void turnTimedOut ()
|
||||||
{
|
{
|
||||||
// reduce turn duration scale
|
|
||||||
reduceTurnDurationScale(_turnIdx);
|
|
||||||
|
|
||||||
if (_trickCardGame.getTrickState() ==
|
if (_trickCardGame.getTrickState() ==
|
||||||
TrickCardGameObject.PLAYING_TRICK) {
|
TrickCardGameObject.PLAYING_TRICK) {
|
||||||
playCard(_turnIdx, pickRandomPlayableCard(_hands[_turnIdx]));
|
playCard(_turnIdx, pickRandomPlayableCard(_hands[_turnIdx]));
|
||||||
@@ -424,6 +432,20 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increases the specified player's turn duration due to avoiding a
|
||||||
|
* time-out.
|
||||||
|
*/
|
||||||
|
protected void increaseTurnDurationScale (int pidx)
|
||||||
|
{
|
||||||
|
float oldScale = _trickCardGame.getTurnDurationScales()[pidx],
|
||||||
|
newScale = Math.min(oldScale + TURN_DURATION_SCALE_INCREASE,
|
||||||
|
1.0f);
|
||||||
|
if (newScale != oldScale) {
|
||||||
|
_trickCardGame.setTurnDurationScalesAt(newScale, pidx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random playable card from the specified hand.
|
* Returns a random playable card from the specified hand.
|
||||||
*/
|
*/
|
||||||
@@ -577,10 +599,14 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
/** The hands of each player. */
|
/** The hands of each player. */
|
||||||
protected Hand[] _hands;
|
protected Hand[] _hands;
|
||||||
|
|
||||||
|
/** Whether or not the turn timed out. */
|
||||||
|
protected boolean _turnTimedOut;
|
||||||
|
|
||||||
/** The all-purpose turn timeout interval. */
|
/** The all-purpose turn timeout interval. */
|
||||||
protected Interval _turnTimeoutInterval =
|
protected Interval _turnTimeoutInterval =
|
||||||
new Interval(PresentsServer.omgr) {
|
new Interval(PresentsServer.omgr) {
|
||||||
public void expired () {
|
public void expired () {
|
||||||
|
_turnTimedOut = true;
|
||||||
turnTimedOut();
|
turnTimedOut();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -596,6 +622,11 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
* out. */
|
* out. */
|
||||||
protected static final float TURN_DURATION_SCALE_REDUCTION = 0.25f;
|
protected static final float TURN_DURATION_SCALE_REDUCTION = 0.25f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase turn duration scales by this amount each time the player
|
||||||
|
* manages not to time out. */
|
||||||
|
protected static final float TURN_DURATION_SCALE_INCREASE = 0.5f;
|
||||||
|
|
||||||
/** Don't let turn duration scales get below this level. */
|
/** Don't let turn duration scales get below this level. */
|
||||||
protected static final float MINIMUM_TURN_DURATION_SCALE = 0.1f;
|
protected static final float MINIMUM_TURN_DURATION_SCALE = 0.1f;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user