Exemplo n.º 1
0
        public string Use(IGameCreature target)
        {
            foreach (string type in types)
            {
                if (type.ToLower() == "projectile")
                {
                    foreach (string type2 in types)
                    {
                        if (type2.ToLower() == "weapon")
                        {
                            return(target.updateHealth(-rarity));
                        }
                        if (type2.ToLower() == "heal")
                        {
                            return(target.updateHealth(rarity));
                        }
                    }
                }

                if (type.ToLower() == "trade")
                {
                    foreach (string type2 in types)
                    {
                        if (type2.ToLower() == "trinket")
                        {
                            return("Traded " + name + " for " + rarity + " gold\n");
                        }
                    }
                }
            }
            return("");
        }
Exemplo n.º 2
0
        public string attack(IGameCreature creature)
        {
            int hitValue = StoryGenerationClass.Instance.getRandomNumber(100);

            if (hitValue > creature.getCreature().getValue() * 5)
            {
                // hit
                int hitDamage;
                if (weapon != null)
                {
                    hitDamage = StoryGenerationClass.Instance.getRandomNumber(weapon.getRarity() + 1) + 1;
                }
                else
                {
                    hitDamage = StoryGenerationClass.Instance.getRandomNumber(2) + 1;
                }

                creature.updateHealth(-hitDamage);
                return("You dealt " + hitDamage + " damage to " + creature.getCreature().getName() + "\n" + creature.getCreature().getName() + " has " + creature.getHealth() + " health left\n");
            }
            else
            {
                // miss
                return("You attack was blocked by " + creature.getCreature().getName() + "\n");
            }
        }
Exemplo n.º 3
0
        public string attack(IGameCreature creature)
        {
            int hitValue = StoryGenerationClass.Instance.getRandomNumber(100);
            if(hitValue > creature.getCreature().getValue() * 5)
            {
                // hit
                int hitDamage;
                if(weapon != null)
                {
                    hitDamage = StoryGenerationClass.Instance.getRandomNumber(weapon.getRarity() + 1) + 1;
                }
                else hitDamage = StoryGenerationClass.Instance.getRandomNumber(2) + 1;

                creature.updateHealth(-hitDamage);
                return "You dealt " + hitDamage + " damage to " + creature.getCreature().getName() + "\n" + creature.getCreature().getName() + " has " + creature.getHealth() + " health left\n";
            }
            else
            {
                // miss
                return "You attack was blocked by " + creature.getCreature().getName() + "\n";
            }
        }
Exemplo n.º 4
0
 public void look(IGameCreature c)
 {
     // output crateures stats, desc
     AddOutputMessage("From what you can tell from the creature:");
     AddOutputMessage(c.outputData());
 }
Exemplo n.º 5
0
        public string Use(IGameCreature target)
        {
            foreach (string type in types)
            {
                if (type.ToLower() == "projectile")
                {
                    foreach (string type2 in types)
                    {
                        if (type2.ToLower() == "weapon")
                        {
                            return target.updateHealth(-rarity);
                        }
                        if( type2.ToLower() == "heal")
                        {
                            return target.updateHealth(rarity);
                        }
                    }

                }

                if (type.ToLower() == "trade")
                {
                    foreach (string type2 in types)
                    {
                        if (type2.ToLower() == "trinket")
                        {
                            return "Traded " + name + " for " + rarity + " gold\n";
                        }
                    }
                }
            }
            return "";
        }
Exemplo n.º 6
0
 public void look(IGameCreature c)
 {
     // output crateures stats, desc
     AddOutputMessage("From what you can tell from the creature:");
     AddOutputMessage(c.outputData());
 }
Exemplo n.º 7
0
        public void Tick()
        {
            //do what input said
            // player interaction
            if (lastInMessage.StartsWith("quit") || lastInMessage.StartsWith("exit"))
            {
                Program.End();
            }
            //else if (lastInMessage.StartsWith("new "))
            //{
            //    lastInMessage = lastInMessage.Replace("new ", "");

            //    if (lastInMessage.StartsWith("story"))
            //    {
            //        Story = StoryGenerationClass.Instance.generateStory(1,1,3);
            //        GenerateWorld();
            //        OutputStory();
            //    }
            //    else
            //    {
            //        AddOutputMessage("cannot create new : " + lastInMessage);
            //    }

            //}
            else if (lastInMessage.StartsWith("attack "))
            {
                lastInMessage = lastInMessage.Replace("attack ", "");
                if (lastInMessage != "")
                {
                    foreach (IGameCreature c in currentLocation.getCreatures())
                    {
                        if (c.getCreature().getName().ToLower().Contains(lastInMessage))
                        {
                            look();
                            AddOutputMessage(player.attack(c));
                            bHasNewMessage = false;
                            return;
                        }
                    }
                }
                AddOutputMessage("Cannot attack " + lastInMessage + "\n");
            }
            else if (lastInMessage.StartsWith("look"))
            {
                if (lastInMessage.Equals("look"))
                {
                    look();
                    bHasNewMessage = false;
                    return;
                }
                lastInMessage = lastInMessage.Replace("look ", "");

                if (lastInMessage != "")
                {
                    if (lastInMessage.StartsWith("self"))
                    {
                        look(player);
                        bHasNewMessage = false;
                        return;
                    }
                    if (lastInMessage.StartsWith("story"))
                    {
                        OutputStory();
                        bHasNewMessage = false;
                        return;
                    }
                    foreach (IGameCreature c in currentLocation.getCreatures())
                    {
                        if (c.getCreature().getName().ToLower().Contains(lastInMessage))
                        {
                            look(c);
                            bHasNewMessage = false;
                            return;
                        }
                    }
                    foreach (IItem i in currentLocation.getItems())
                    {
                        if (i.getName().ToLower().Contains(lastInMessage))
                        {
                            look(i);
                            bHasNewMessage = false;
                            return;
                        }
                    }
                    if (player.getInv().Count != 0)
                    {
                        foreach (IItem i in player.getInv())
                        {
                            if (i.getName().ToLower().Contains(lastInMessage))
                            {
                                look(i);
                                bHasNewMessage = false;
                                return;
                            }
                        }
                    }
                }
                AddOutputMessage("Cannot look at " + lastInMessage + "\n");
            }
            else if (lastInMessage.StartsWith("take "))
            {
                lastInMessage = lastInMessage.Replace("take ", "");
                if (lastInMessage != "")
                {
                    Take(lastInMessage);
                }
            }
            else if (lastInMessage.StartsWith("use "))
            {
                lastInMessage = lastInMessage.Replace("use ", "");
                IGameCreature target = null;
                if (lastInMessage != "")
                {
                    // split message
                    string[] parts = lastInMessage.Split(' ');
                    if (parts.Length > 1)
                    {
                        // check targets
                        foreach (IGameCreature c in currentLocation.getCreatures())
                        {
                            if (c.getCreature().getName().ToLower().StartsWith(parts[1]))
                            {
                                target = c;
                            }
                        }
                        if (target == null)
                        {
                            look();
                            AddOutputMessage("Cannot find " + parts[1]);
                            bHasNewMessage = false;
                            return;
                        }
                    }


                    foreach (IItem inv in player.getInv())
                    {
                        if (inv.getName().ToLower().Contains(parts[0]))
                        {
                            if (target != null)
                            {
                                string output = inv.Use(target);
                                if (output != "")
                                {
                                    look();
                                    AddOutputMessage("Used " + parts[0]);
                                    AddOutputMessage(output);
                                    player.getInv().Remove(inv);
                                }
                                else
                                {
                                    look();
                                    if (target != null)
                                    {
                                        AddOutputMessage("Could not use " + parts[0] + " with " + parts[1]);
                                    }
                                    else
                                    {
                                        AddOutputMessage("Could not use " + parts[0]);
                                    }
                                }
                            }
                            else
                            {
                                string output = inv.Use(player);
                                if (output != "")
                                {
                                    AddOutputMessage("Used " + parts[0]);
                                    AddOutputMessage(output);
                                    player.getInv().Remove(inv);
                                }
                                else
                                {
                                    AddOutputMessage("Could not use " + parts[0]);
                                }
                            }
                            bHasNewMessage = false;
                            return;
                        }
                    }
                    foreach (IItem i in currentLocation.getItems())
                    {
                        if (i.getName().ToLower().Contains(parts[0]))
                        {
                            if (target != null)
                            {
                                string output = i.Use(target);
                                if (output != "")
                                {
                                    look();
                                    AddOutputMessage("Used " + parts[0]);
                                    AddOutputMessage(output);
                                    currentLocation.getItems().Remove(i);
                                }
                                else
                                {
                                    look();
                                    if (target != null)
                                    {
                                        AddOutputMessage("Could not use " + parts[0] + " with " + parts[1]);
                                    }
                                    else
                                    {
                                        AddOutputMessage("Could not use " + parts[0]);
                                    }
                                }
                            }
                            else
                            {
                                string output = i.Use(currentLocation, player);
                                if (output != "")
                                {
                                    look();
                                    AddOutputMessage("Used " + parts[0]);
                                    AddOutputMessage(output);
                                    currentLocation.getItems().Remove(i);
                                }
                                else
                                {
                                    look();
                                    AddOutputMessage("Could not use " + parts[0] + ", perhaps pick it up first");
                                }
                            }
                            bHasNewMessage = false;
                            return;
                        }
                    }
                    look();
                    AddOutputMessage("Cannot find " + parts[0]);
                    bHasNewMessage = false;
                    return;
                }
            }
            else if ("inventory".StartsWith(lastInMessage))
            {
                look();
                AddOutputMessage(player.getItemNames());
            }
            else if ("up".StartsWith(lastInMessage) || "north".StartsWith(lastInMessage))
            {
                move(0, -1);
            }
            else if ("down".StartsWith(lastInMessage) || "south".StartsWith(lastInMessage))
            {
                move(0, 1);
            }
            else if ("left".StartsWith(lastInMessage) || "west".StartsWith(lastInMessage))
            {
                move(-1, 0);
            }
            else if ("right".StartsWith(lastInMessage) || "east".StartsWith(lastInMessage))
            {
                move(1, 0);
            }
            else
            {
                look();
                AddOutputMessage("unknown command : " + lastInMessage);
            }

            bHasNewMessage = false;
        }