/// <summary> /// Displays dialogbox if needed /// </summary> /// <param name="cell"></param> public void HandleCell(MapCell cell) { if (cell.HasItem) { if (cell.Item is DoorKey) { Game.Map.Adventurer.ApplyItem(cell.Item); updateHeroDetails(); } if (cell.Item is Door) { //Had to cast to compare Door mapDoor = (Door)cell.Item; frmGameOver gameOver = new frmGameOver(); gameOver.ShowDialog(); return; } displayMap(Game.Map); frmItem founditem = new frmItem(cell.Item); founditem.ShowDialog(); updateHeroDetails(); } if (cell.HasMonster) { displayMap(Game.Map); frmMonster foundmonster = new frmMonster(cell.Monster); foundmonster.ShowDialog(); updateHeroDetails(); checkGameState(); } }
/// <summary> /// Displays frmItem if hero's location contains an item, or frmMonster if hero's location contains a monster. /// </summary> /// <param name="needsToAct">Whether or not hero needs to act in this cell. Get from Game.Map.moveHero().</param> private static void displayForm(bool needsToAct) { if (needsToAct) // if hero's cell contains an item or monster, display frmItem or frmMonster. { if (Game.Map.HeroLocation.HasItem) // if the cell contains an item, disply frmItem. { if (Game.Map.HeroLocation.Item.GetType() == typeof(Door)) // but, if the item is a door, display the Game Over screen. { frmGameOver frmGameOver = new frmGameOver(); frmGameOver.ShowDialog(); } else // cell has item, which is not a door. display frmItem. { frmItem frmItem = new frmItem(Game.Map.HeroLocation.Item); frmItem.ShowDialog(); } } else // cell doesn't have item, but does need attention. display frmMonster. { // open new monster form window. frmMonster frmMonster = new frmMonster(Game.Map.HeroLocation.Monster); frmMonster.ShowDialog(); } } }