Decrease turn durations after players time out.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3516 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2005-04-21 00:47:17 +00:00
parent 06899b8b7a
commit 5b360afd52
2 changed files with 62 additions and 15 deletions
@@ -91,6 +91,35 @@ public interface TrickCardGameObject extends TurnGameObject
*/
public void setTrickState (int trickState);
/**
* Returns an array containing the turn duration scales for each player.
* Turn duration scales decrease each time players time out.
*
* @return the array of turn duration scales
*/
public float[] getTurnDurationScales ();
/**
* Sets the array of turn duration scales.
*
* @param turnDurationScales the array of turn duration scales
*/
public void setTurnDurationScales (float[] turnDurationScales);
/**
* Sets an element of the array of turn duration scales.
*
* @param turnDurationScale the turn duration scale
* @param index the index of the turn duration scale
*/
public void setTurnDurationScalesAt (float turnDurationScale, int index);
/**
* Returns the duration of the current turn, which may depend on the state
* of the game as well as the duration scale of the active player.
*/
public long getTurnDuration ();
/**
* Returns the name of the field that contains the history of the trick
* in terms of the cards played by each player.
@@ -22,6 +22,7 @@
package com.threerings.parlor.card.trick.server;
import java.util.ArrayList;
import java.util.Arrays;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.Interval;
@@ -98,6 +99,11 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// clear out the last cards played
_trickCardGame.setLastCardsPlayed(null);
// initialize the turn duration scales
float[] scales = new float[_cardGame.getPlayerCount()];
Arrays.fill(scales, 1.0f);
_trickCardGame.setTurnDurationScales(scales);
}
/**
@@ -138,7 +144,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
super.startTurn();
// schedule the timeout interval
_turnTimeoutInterval.schedule(getTurnTimeoutDelay());
_turnTimeoutInterval.schedule(_trickCardGame.getTurnDuration());
}
// Documentation inherited.
@@ -389,27 +395,32 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
}
}
/**
* Returns the amount of time to allow before timing out the turn
* by calling {@link #turnTimedOut}. Default implementation returns
* a minute.
*/
protected long getTurnTimeoutDelay ()
{
return 60 * 1000L;
}
/**
* Called when the current turn times out. Default implementation
* plays a random playable card if in the trick-playing state.
* reduces the turn duration and plays a random playable card if in the
* trick-playing state.
*/
protected void turnTimedOut ()
{
// reduce turn duration scale
reduceTurnDurationScale(_turnIdx);
if (_trickCardGame.getTrickState() ==
TrickCardGameObject.PLAYING_TRICK) {
int pidx = _cardGame.getPlayerIndex(
_trickCardGame.getTurnHolder());
playCard(pidx, pickRandomPlayableCard(_hands[pidx]));
playCard(_turnIdx, pickRandomPlayableCard(_hands[_turnIdx]));
}
}
/**
* Reduces the specified player's turn duration due to a time-out.
*/
protected void reduceTurnDurationScale (int pidx)
{
float oldScale = _trickCardGame.getTurnDurationScales()[pidx],
newScale = Math.max(oldScale - TURN_DURATION_SCALE_REDUCTION,
MINIMUM_TURN_DURATION_SCALE);
if (newScale != oldScale) {
_trickCardGame.setTurnDurationScalesAt(newScale, pidx);
}
}
@@ -580,4 +591,11 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
endTrick();
}
};
/** Reduce turn duration scales by this amount each time the player times
* out. */
protected static final float TURN_DURATION_SCALE_REDUCTION = 0.25f;
/** Don't let turn duration scales get below this level. */
protected static final float MINIMUM_TURN_DURATION_SCALE = 0.1f;
}