Example #1
0
        public void Tick(object sender, EventArgs e)
        {
            Thread.Sleep(16); // 60 fps
            if (bHasNewMessage)
            {
                Tick();


                bool bBeenAttacked = false;
                // check enemies state
                foreach (IGameCreature gc in currentLocation.getCreatures())
                {
                    // check if enemy is dead
                    if (gc.getHealth() <= 0)
                    {
                        player.updateScore(gc.getCreature().getValue());
                        if (gc.getCreature().getValue() < 10)
                        {
                            currentLocation.addNewItem(null, null, null, gc.getCreature().getValue());
                        }
                        currentLocation.getCreatures().Remove(gc);
                        AddOutputMessage("You have defeated " + gc.getCreature().getName());
                        if (Story.getPlot().getModifier().ToLower() == "creature" && gc.getCreature().getName() == Story.getTargetName())
                        {
                            player.updateScore(100);
                            EndGame("You have won, congratulations.\nYour Score: " + player.getScore());
                        }
                        break;
                    }
                    //attack
                    if (gc.getIsHostile())
                    {
                        bBeenAttacked = true;
                        AddOutputMessage(gc.attack(player));
                    }
                }
                if (Story.getPlot().getModifier().ToLower() == "item" && !bBeenAttacked)
                {
                    foreach (IItem i in player.getInv())
                    {
                        if (i.getName().ToLower() == Story.getTargetName().ToLower())
                        {
                            player.updateScore(100);
                            EndGame("You have won, congratulations.\nYour Score: " + player.getScore());
                        }
                    }
                }
                //check end game
                if (player.getHealth() <= 0)
                {
                    EndGame("You have died, you lose.\nYour Score: " + player.getScore());
                }
            }
        }