There's nothing wrong with objects knowing about other objects. That doesn't defy encapsulation.

However, I don't think anything is gained by having CreatureInstance actually store a reference to it's LayerCell. That's a needless coupling of data. It should have a "location" type, and Atlas should have a FindCell function that takes this location type.


  Or for another example if a CreatureInstance when attacking the player's CreatureInstance is able to take items from the player's inventory, and relocate them somewhere else in the dungeon, it needs access to a different Layer or AtlasCell in order to put the item where it needs to go.


What you're saying is that the CreatureInstance itself needs to directly do the following:


Detect that it's attack hit the target.
Look in the inventory of the target.
Remove some items form it.
Place those items in the world.


This is highly unnecessary. Why does the CreatureInstance have to do this? Yes, conceptually, it is the creature's attack that causes items to be removed. But why does the CreatureInstance object have to deal with that?

Here's how I would do it.

The CreatureInstance would have one or more Attacks. An Attack is an object that, when successful, can cause one or more effects. Effects include:


Dealing damage, possibly with damage types.
Removing items from the target and placing them on the map.
etc.


All the CreatureInstance has to know is what Attacks it can perform and who it can perform them on. When it decides to use the DrainItemsAttack, it simply says, "I'm using DrainItemsAttack on this target."

The DrainItemsAttack would invoke the "RemoveAndDropItems" effect. That's not a class; that's a free function (or a static member of some class, since you're using languages that don't allow free functions). It doesn't have to have state, so it doesn't need to be a type. It's just a function that takes some number of inventory items from a CreatureInstance and places them on the ground.

It is that function which needs to be able to inspect inventory, remove items, find suitable terrain to place them on, etc. Each of these operations should be its own function. So your "RemoveAndDropItems" effect would be implemented like this (pseudo-code):

bool RemoveAndDropItems(int numToRemove, CreatureInstance target, Atlas world)
{
  for(numToRemove)
  {
    ItemInstance item = target.FindSuitableItemToRemove();
    if(!item)
      return false;
    target.RemoveItem(item);
    LayerCell loc = world.FindSuitableLocationToPlaceItem(item, target.loc());
    world.PlaceItem(item, loc);
  }
  return true;
}


This way, CreatureInstance isn't responsible for finding places to put stuff. You have functions for that. Nor does it have to have knowledge of ItemInstance or other types; that's all taken care of elsewhere.

Roguelike Class Structure Makes Everything Effectively Global
I have declared a button in my CreateChildControls method in my web part page:

TableCell updateCell = new TableCell();
        Update = new Button();
        Update.Text = "Update";
        Update.OnClientClick += new EventHandler(Update_OnClick);
        updateCell.Controls.Add(Update);
        ButtonRow.Controls.Add(updateCell);


This is the eventhandler that I created:

    private void Update_OnClick(object sender, EventArgs e)
    {
        if (_TYPE == "FIXED")
        {
            Item["Retail"] = txtFixedRetail.Text;
            Item.Update();
            EmailFixedAlert();
        }
    }


However JScript throws an error:

Microsoft JScript runtime error: 'System' is undefined


And produces this in the HTML:

&lt;td&gt;&lt;input type="submit" name="ctl00$m$g_c260f907_31c1_436b_b99e_9bf79427625c$ctl11"     value="Update" onclick="System.EventHandler;" /&gt;&lt;/td&gt;


Why is the eventhandler that I declared in the WebPart not passing to the Page?
Do I have to push all events to the Client?
