Pushed reportWinnersAndLosers and related methods up to GameManager, MouseInputAdapter instead of MouseAdapter/MouseMotionAdapter.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3221 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
package com.threerings.parlor.card.client;
|
package com.threerings.parlor.card.client;
|
||||||
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseMotionAdapter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.swing.event.MouseInputAdapter;
|
||||||
|
|
||||||
import com.samskivert.swing.Controller;
|
import com.samskivert.swing.Controller;
|
||||||
import com.samskivert.swing.event.CommandEvent;
|
import com.samskivert.swing.event.CommandEvent;
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ public abstract class CardPanel extends VirtualMediaPanel
|
|||||||
{
|
{
|
||||||
super(frameManager);
|
super(frameManager);
|
||||||
|
|
||||||
MouseAdapter ma = new MouseAdapter() {
|
MouseInputAdapter mia = new MouseInputAdapter() {
|
||||||
public void mousePressed (MouseEvent me) {
|
public void mousePressed (MouseEvent me) {
|
||||||
if (_activeSprite != null && !isManaged(_activeSprite)) {
|
if (_activeSprite != null && !isManaged(_activeSprite)) {
|
||||||
_activeSprite = null;
|
_activeSprite = null;
|
||||||
@@ -188,11 +188,6 @@ public abstract class CardPanel extends VirtualMediaPanel
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
addMouseListener(ma);
|
|
||||||
|
|
||||||
MouseMotionAdapter mma = new MouseMotionAdapter() {
|
|
||||||
public void mouseMoved (MouseEvent me)
|
public void mouseMoved (MouseEvent me)
|
||||||
{
|
{
|
||||||
Sprite newActiveSprite = null;
|
Sprite newActiveSprite = null;
|
||||||
@@ -252,8 +247,9 @@ public abstract class CardPanel extends VirtualMediaPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
addMouseMotionListener(mma);
|
addMouseListener(mia);
|
||||||
|
addMouseMotionListener(mia);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// $Id: PuzzleCodes.java 3184 2004-10-28 19:20:27Z mdb $
|
||||||
|
//
|
||||||
|
// Narya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||||
|
// http://www.threerings.net/code/narya/
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
package com.threerings.parlor.game;
|
||||||
|
|
||||||
|
import com.threerings.presents.data.InvocationCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constants relating to the game services.
|
||||||
|
*/
|
||||||
|
public interface GameCodes extends InvocationCodes
|
||||||
|
{
|
||||||
|
/** The name of the message event to a placeObject that reports
|
||||||
|
* the winners and losers of a game. */
|
||||||
|
public static final String WINNERS_AND_LOSERS = "winnersAndLosers";
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: GameManager.java,v 1.76 2004/10/22 19:27:54 ray Exp $
|
// $Id$
|
||||||
//
|
//
|
||||||
// Narya library - tools for developing networked games
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||||
@@ -33,6 +33,8 @@ import com.threerings.util.Name;
|
|||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.ClientObject;
|
||||||
import com.threerings.presents.dobj.AttributeChangeListener;
|
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||||
|
import com.threerings.presents.dobj.DObject;
|
||||||
|
import com.threerings.presents.dobj.OidList;
|
||||||
import com.threerings.presents.server.util.SafeInterval;
|
import com.threerings.presents.server.util.SafeInterval;
|
||||||
|
|
||||||
import com.threerings.crowd.chat.server.SpeakProvider;
|
import com.threerings.crowd.chat.server.SpeakProvider;
|
||||||
@@ -56,7 +58,7 @@ import com.threerings.parlor.server.ParlorSender;
|
|||||||
* bodies in that location.
|
* bodies in that location.
|
||||||
*/
|
*/
|
||||||
public class GameManager extends PlaceManager
|
public class GameManager extends PlaceManager
|
||||||
implements ParlorCodes, GameProvider, AttributeChangeListener
|
implements ParlorCodes, GameCodes, GameProvider, AttributeChangeListener
|
||||||
{
|
{
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected void didInit ()
|
protected void didInit ()
|
||||||
@@ -253,6 +255,22 @@ public class GameManager extends PlaceManager
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user object for the player with the specified index or
|
||||||
|
* null if the player at that index is not online.
|
||||||
|
*/
|
||||||
|
public BodyObject getPlayer (int playerIdx)
|
||||||
|
{
|
||||||
|
// if we have their oid, use that
|
||||||
|
int ploid = _playerOids[playerIdx];
|
||||||
|
if (ploid > 0) {
|
||||||
|
return (BodyObject)CrowdServer.omgr.getObject(ploid);
|
||||||
|
}
|
||||||
|
// otherwise look them up by name
|
||||||
|
Name name = getPlayerName(playerIdx);
|
||||||
|
return (name == null) ? null : CrowdServer.lookupBody(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the specified player as an AI with the specified skill. It is
|
* Sets the specified player as an AI with the specified skill. It is
|
||||||
* assumed that this will be set soon after the player names for all
|
* assumed that this will be set soon after the player names for all
|
||||||
@@ -739,6 +757,17 @@ public class GameManager extends PlaceManager
|
|||||||
Arrays.fill(winners, false);
|
Arrays.fill(winners, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether game conclusion antics such as rating updates
|
||||||
|
* should be performed when an in-play game is ended. Derived classes
|
||||||
|
* may wish to override this method to customize the conditions under
|
||||||
|
* which the game is concluded.
|
||||||
|
*/
|
||||||
|
public boolean shouldConcludeGame ()
|
||||||
|
{
|
||||||
|
return (_gameobj.state == GameObject.GAME_OVER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the game is about to end, but before the game end
|
* Called when the game is about to end, but before the game end
|
||||||
* notification has been delivered to the players. Derived classes
|
* notification has been delivered to the players. Derived classes
|
||||||
@@ -776,9 +805,44 @@ public class GameManager extends PlaceManager
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// report the winners and losers if appropriate
|
||||||
|
int winnerCount = _gameobj.getWinnerCount();
|
||||||
|
if (shouldConcludeGame() && winnerCount > 0 && !_gameobj.isDraw()) {
|
||||||
|
reportWinnersAndLosers();
|
||||||
|
}
|
||||||
|
|
||||||
// calculate ratings and all that...
|
// calculate ratings and all that...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report winner and loser oids to each room that any of the
|
||||||
|
* winners/losers is in.
|
||||||
|
*/
|
||||||
|
protected void reportWinnersAndLosers ()
|
||||||
|
{
|
||||||
|
OidList winners = new OidList();
|
||||||
|
OidList losers = new OidList();
|
||||||
|
OidList places = new OidList();
|
||||||
|
|
||||||
|
Object[] args = new Object[] { winners, losers };
|
||||||
|
|
||||||
|
for (int ii=0, nn=_playerOids.length; ii < nn; ii++) {
|
||||||
|
BodyObject user = getPlayer(ii);
|
||||||
|
if (user != null) {
|
||||||
|
places.add(user.location);
|
||||||
|
(_gameobj.isWinner(ii) ? winners : losers).add(user.getOid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now send a message event to each room
|
||||||
|
for (int ii=0, nn = places.size(); ii < nn; ii++) {
|
||||||
|
DObject place = CrowdServer.omgr.getObject(places.get(ii));
|
||||||
|
if (place != null) {
|
||||||
|
place.postMessage(WINNERS_AND_LOSERS, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the game is to be reset to its starting state in
|
* Called when the game is to be reset to its starting state in
|
||||||
* preparation for a new game without actually ending the current
|
* preparation for a new game without actually ending the current
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: PuzzleManager.java,v 1.17 2004/10/28 19:29:59 mdb Exp $
|
// $Id$
|
||||||
//
|
//
|
||||||
// Narya library - tools for developing networked games
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||||
@@ -67,22 +67,6 @@ public abstract class PuzzleManager extends GameManager
|
|||||||
return _boards;
|
return _boards;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the user object for the player with the specified index or
|
|
||||||
* null if the player at that index is not online.
|
|
||||||
*/
|
|
||||||
public BodyObject getPlayer (int playerIdx)
|
|
||||||
{
|
|
||||||
// if we have their oid, use that
|
|
||||||
int ploid = _playerOids[playerIdx];
|
|
||||||
if (ploid > 0) {
|
|
||||||
return (BodyObject)CrowdServer.omgr.getObject(ploid);
|
|
||||||
}
|
|
||||||
// otherwise look them up by name
|
|
||||||
Name name = getPlayerName(playerIdx);
|
|
||||||
return (name == null) ? null : CrowdServer.lookupBody(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the board summary for the given player index.
|
* Returns the board summary for the given player index.
|
||||||
*/
|
*/
|
||||||
@@ -172,17 +156,6 @@ public abstract class PuzzleManager extends GameManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether game conclusion antics such as rating updates
|
|
||||||
* should be performed when an in-play game is ended. Derived classes
|
|
||||||
* may wish to override this method to customize the conditions under
|
|
||||||
* which the game is concluded.
|
|
||||||
*/
|
|
||||||
public boolean shouldConcludeGame ()
|
|
||||||
{
|
|
||||||
return (_puzobj.state == PuzzleObject.GAME_OVER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player has been marked as knocked out but before the
|
* Called when a player has been marked as knocked out but before the
|
||||||
* knock-out status update has been sent to the players. Any status
|
* knock-out status update has been sent to the players. Any status
|
||||||
@@ -444,44 +417,9 @@ public abstract class PuzzleManager extends GameManager
|
|||||||
// send along one final status update
|
// send along one final status update
|
||||||
sendStatusUpdate();
|
sendStatusUpdate();
|
||||||
|
|
||||||
// report the winners and losers if appropriate
|
|
||||||
int winnerCount = _puzobj.getWinnerCount();
|
|
||||||
if (shouldConcludeGame() && winnerCount > 0 && !_puzobj.isDraw()) {
|
|
||||||
reportWinnersAndLosers();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.gameDidEnd();
|
super.gameDidEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Report winner and loser oids to each room that any of the
|
|
||||||
* winners/losers is in.
|
|
||||||
*/
|
|
||||||
protected void reportWinnersAndLosers ()
|
|
||||||
{
|
|
||||||
OidList winners = new OidList();
|
|
||||||
OidList losers = new OidList();
|
|
||||||
OidList places = new OidList();
|
|
||||||
|
|
||||||
Object[] args = new Object[] { winners, losers };
|
|
||||||
|
|
||||||
for (int ii=0, nn=_playerOids.length; ii < nn; ii++) {
|
|
||||||
BodyObject user = getPlayer(ii);
|
|
||||||
if (user != null) {
|
|
||||||
places.add(user.location);
|
|
||||||
(_puzobj.isWinner(ii) ? winners : losers).add(user.getOid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// now send a message event to each room
|
|
||||||
for (int ii=0, nn = places.size(); ii < nn; ii++) {
|
|
||||||
DObject place = CrowdServer.omgr.getObject(places.get(ii));
|
|
||||||
if (place != null) {
|
|
||||||
place.postMessage(WINNERS_AND_LOSERS, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report to the knocked-out player's room that they were knocked out.
|
* Report to the knocked-out player's room that they were knocked out.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user