예제 #1
0
        public void TestCreateActors_AppropriateToFaction()
        {
            var adj    = new AdjectiveFactory();
            var items  = new ItemFactory();
            var actors = new ActorFactory();

            var world   = new World();
            var faction = new Faction("Fish overloards", FactionRole.Wildlife);

            world.Factions.Add(faction);
            world.ActorFactory = actors;
            world.ItemFactory  = items;

            actors.Blueprints = new List <ActorBlueprint> {
                new ActorBlueprint()
                {
                    Name = "Captain Haddock"
                }
            };

            var room = new Room("Tank Bay", world, 't')
            {
                ControllingFaction = faction
            };

            Assert.IsEmpty(room.Actors);
            actors.Create(world, room, faction, null);

            Assert.IsTrue(room.Actors.Any());
            Assert.GreaterOrEqual(room.Actors.Count(a => a.FactionMembership.Contains(faction)), 1, "Expected room to be populated with some actors belonging to the controlling faction");
        }
예제 #2
0
        public void TestCreatingRoomFromBlueprint_WithFaction(bool explicitRoomColor)
        {
            var w = new World();

            var adj = new AdjectiveFactory();

            w.Factions.Add(
                new Faction("Techno Wizards", FactionRole.Establishment)
            {
                Identifier = new Guid("bb70f169-e0f7-40e8-927b-1c181eb8740b"),
                Color      = ConsoleColor.Cyan,
            }
                );
            w.ActorFactory = new ActorFactory()
            {
                Blueprints = new List <ActorBlueprint>
                {
                    new ActorBlueprint()
                    {
                        Name = "Sandman"
                    },
                }
            };
            w.ItemFactory = new ItemFactory();

            var yaml =
                @$ "
- Name: Tunnels
  {(explicitRoomColor ? " Color : 2 " : " ")}
  Faction: bb70f169-e0f7-40e8-927b-1c181eb8740b
";
            var roomFactory = new RoomFactory {
                Blueprints = Compiler.Instance.Deserializer.Deserialize <List <RoomBlueprint> >(yaml)
            };;
            var room = roomFactory.Create(w);

            Assert.IsNotNull(room);
            Assert.AreEqual("Tunnels", room.Name);

            Assert.Greater(room.Actors.Count(), 0);
            Assert.IsTrue(room.Actors.All(a => a.Name.Equals("Sandman")));

            //if the room has no set color and it is owned by the faction it should inherit the faction color
            Assert.AreEqual(explicitRoomColor ? ConsoleColor.DarkGreen : ConsoleColor.Cyan, room.Color);
        }
예제 #3
0
        public void TestFactionActorsYaml()
        {
            var adj = new AdjectiveFactory();

            var yaml = @"
- Name: Centipede
  OptionalAdjectives:
    - Giant
    - Rusty
    - Strong
    - Tough
  Stats:
    Fight: 30
- Name: Crab
  Identifier: 24a1c3ad-fcdf-4c00-acf7-627e7f70c181
  Dialogue: 
    Verb: talk
    Next: 566ae926-a1fe-4209-9a15-fce026dbc5d1
  OptionalAdjectives:
    - Strong
  Stats:
    Fight: 40
";

            var actorFactory = new ActorFactory {
                Blueprints = Compiler.Instance.Deserializer.Deserialize <List <ActorBlueprint> >(yaml)
            };

            Assert.GreaterOrEqual(actorFactory.Blueprints.Count, 2);

            var room = InARoom(out IWorld w);

            var actor = actorFactory.Create(w, room, null, actorFactory.Blueprints[1], null);

            Assert.AreEqual("Crab", actor.Name);
            Assert.AreEqual("Strong", actor.Adjectives.Single().Name);

            Assert.AreEqual(40, actor.BaseStats[Stat.Fight]);

            Assert.AreEqual(new Guid("566ae926-a1fe-4209-9a15-fce026dbc5d1"), actor.Dialogue.Next);
            Assert.AreEqual(new Guid("24a1c3ad-fcdf-4c00-acf7-627e7f70c181"), actor.Identifier);
        }
예제 #4
0
        public NewPlayerDialog(MainWindow ui, IActor player, AdjectiveFactory adjectiveFactory)
            : base("New Character", ui.DlgWidth, ui.DlgHeight)
        {
            AdjectiveFactory = adjectiveFactory;
            var btn = new Button("Finish", true)
            {
                Clicked = () =>
                {
                    Running = false;
                    Ok      = true;
                }
            };

            var lblName = new Label("Name:")
            {
                X = 0,
                Y = 0
            };

            var tbName = new TextField("Wanderer")
            {
                X     = Pos.Right(lblName),
                Y     = lblName.Y,
                Width = 20
            };

            tbName.Changed += (o, e) => player.Name = tbName.Text?.ToString() ?? "Wanderer";

            Add(lblName);
            Add(tbName);

            //if(!RunDialog("Select Adjective","Choose an adjective for your character",out IAdjective chosen, adjectiveFactory.GetAvailableAdjectives(newWorld.Player).ToArray()))
            //  return;

            //newWorld.Player.Adjectives.Add(chosen);

            AddButton(btn);
        }