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 :
See Also:
JavaGroups, Item, Board, Player, Monster, MudUtil

Variable Index

 o d_board
 o d_items
 o d_localPlayer
 o d_masterAddress
 o d_matrix
 o d_monsters
 o d_players
 o d_playersColors

Constructor Index

 o Mud()

Method Index

 o Block()
 o getItemByCoord(Coord)
 o getItemByName(String)
 o handleItemAction(String, Item)
 o handleMove(Coord)
 o handleTimeout()
 o main(String[])
 o rmiChangeAttrib(Integer, Color, Boolean)
Called to change the state of an Item
 o rmiGetUserStat(Long, Integer, Address)
Get the node's status.
 o rmiMasterSaveAction(String, Vector)
RMI to master to save current request.
 o rmiMove(Color, Coord)
Performs a move on the board.
 o rmiMoveMonsters(Integer, View)
Request to move the monsters in a random fashion
 o rmiStateTransfer(Vector)
Do the state transfer.
 o 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 ).
 o stopScheduler()
 o Suspect(Object)
 o ViewAccepted(View)

Variables

 o d_masterAddress
 public Address d_masterAddress
 o d_board
 public Board d_board
 o d_playersColors
 public Vector d_playersColors
 o d_localPlayer
 public Player d_localPlayer
 o d_items
 public Vector d_items
 o d_players
 public Vector d_players
 o d_monsters
 public Vector d_monsters
 o d_matrix
 public int d_matrix[][]

Constructors

 o Mud
 public Mud()

Methods

 o 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.
 o 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 )
 o 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.
 o 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.
 o 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.
 o 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
 o 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
 o stopScheduler
 public void stopScheduler()
 o getItemByName
 public Item getItemByName(String name)
 o getItemByCoord
 public Item getItemByCoord(Coord c)
 o handleMove
 public void handleMove(Coord c)
 o handleItemAction
 public void handleItemAction(String command,
                              Item item)
 o handleTimeout
 public void handleTimeout()
 o Block
 public void Block()
 o Suspect
 public void Suspect(Object suspected_mbr)
 o ViewAccepted
 public void ViewAccepted(View view)
 o main
 public static void main(String args[])