Class Mud
java.lang.Object
|
+----Mud
- public class Mud
- extends Object
- implements MembershipListener
- Author:
- David Er-el 1999
Mud holds the main loop of control for the Multi User dungeon
program and reacts to the user actions and to internal timeout.
It builds a board with monsters , players and items and enables
multiple users to view the same picture while all of them are
moving around , fighting and manipulating the items.
The commuincation is built on JavaGroups toolkit using RMI's. Thanks to bela ban for using his library. The java version used to build and test this project is JDK 1.1.7 .
View is handled in the following way :
- JavaGroups triggers ViewAccepted
- ViewAccepted calls rmiGetUserStat for all members.
- After rmiGetUserStat is called for each member the leader is choosen.
- Leader calls processMasterInit.
- processMasterInit is invoked on the master and prepares a state.
- Send it to all other nodes using rmiStateTransfer
- rmiStateTransfer calls board initialization.
- See Also:
- JavaGroups, Item, Board, Player, Monster, MudUtil
-
d_board
-
-
d_items
-
-
d_localPlayer
-
-
d_masterAddress
-
-
d_matrix
-
-
d_monsters
-
-
d_players
-
-
d_playersColors
-
-
Mud()
-
-
Block()
-
-
getItemByCoord(Coord)
-
-
getItemByName(String)
-
-
handleItemAction(String, Item)
-
-
handleMove(Coord)
-
-
handleTimeout()
-
-
main(String[])
-
-
rmiChangeAttrib(Integer, Color, Boolean)
- Called to change the state of an Item
-
rmiGetUserStat(Long, Integer, Address)
- Get the node's status.
-
rmiMasterSaveAction(String, Vector)
- RMI to master to save current request.
-
rmiMove(Color, Coord)
- Performs a move on the board.
-
rmiMoveMonsters(Integer, View)
- Request to move the monsters in a random fashion
-
rmiStateTransfer(Vector)
- Do the state transfer.
-
rmiTakeItem(Color, Coord, String)
- Take an item that is either on board or in another player's hand
( if he is close enough to the taker ).
-
stopScheduler()
-
-
Suspect(Object)
-
-
ViewAccepted(View)
-
d_masterAddress
public Address d_masterAddress
d_board
public Board d_board
d_playersColors
public Vector d_playersColors
d_localPlayer
public Player d_localPlayer
d_items
public Vector d_items
d_players
public Vector d_players
d_monsters
public Vector d_monsters
d_matrix
public int d_matrix[][]
Mud
public Mud()
rmiMasterSaveAction
public void rmiMasterSaveAction(String action,
Vector v)
- RMI to master to save current request. It will be taken care of
during the timeout of the master
- Parameters:
- action - The name of the action to save
- v - The vector of parameters for this action.
rmiChangeAttrib
public void rmiChangeAttrib(Integer opt,
Color c,
Boolean attrib)
- Called to change the state of an Item
- Parameters:
- opt - A flag to the function 1 = arm , 2 = potion
- c - Player's color
- attrib - opt=1 ---> attrib = request to Arm ,
opt=2 ---> attrib = null ( not used )
rmiMoveMonsters
public void rmiMoveMonsters(Integer curRound,
View view)
- Request to move the monsters in a random fashion
- Parameters:
- curRound - the current round number. Every time called the function
checks for a fight between monsters and players
( actually called every 4 rounds ).
Only every 8 rounds does the function preforms a monster move.
rmiMove
public void rmiMove(Color playerColor,
Coord c)
- Performs a move on the board.
- Parameters:
- playerColor - The color of the player which is moving
- c - The coordination of the move which are in x,y:
Should be 1/-1 in one of them and 0 in the other,
Since can move only to one direction at a time.
rmiTakeItem
public void rmiTakeItem(Color newOwnerColor,
Coord c,
String itemName)
- Take an item that is either on board or in another player's hand
( if he is close enough to the taker ).
- Parameters:
- newOwnerColor - Color of player which wants to take the item.
- c - The coordination of the item.
- itemName - The item's name.
rmiStateTransfer
public void rmiStateTransfer(Vector v)
- Do the state transfer. Master will start scheduler and slaves
will update state.
( if he is close enough to the taker ).
- Parameters:
- v - The state is saved in a vector
rmiGetUserStat
public void rmiGetUserStat(Long viewId,
Integer r,
Address addr)
- Get the node's status. After processing all responses calculate master.
Calls processMasterInit in the master's node only.
- Parameters:
- viewId - The view id of the sender
- r - The round number of the sender
- addr - The address of the sender
stopScheduler
public void stopScheduler()
getItemByName
public Item getItemByName(String name)
getItemByCoord
public Item getItemByCoord(Coord c)
handleMove
public void handleMove(Coord c)
handleItemAction
public void handleItemAction(String command,
Item item)
handleTimeout
public void handleTimeout()
Block
public void Block()
Suspect
public void Suspect(Object suspected_mbr)
ViewAccepted
public void ViewAccepted(View view)
main
public static void main(String args[])