示例#1
0
        public void AddLocation(string name, LocationType type, int position, APerson owner = null)
        {
            if (Locations.FindIndex(l => l.Position == position) == -1)
            {
                switch (type)
                {
                case LocationType.Home:
                    Locations.Add(new Locations.Home(name, position));
                    break;

                case LocationType.Tavern:
                    Locations.Add(new Locations.Tavern(name, position));
                    break;

                case LocationType.Square:
                    Locations.Add(new Locations.Square(name, position));
                    break;
                }

                foreach (var ch in Characters)
                {
                    ch.KnownLocations.Add(Locations.Last());
                }
            }
            else
            {
                Console.WriteLine("This position is already occypied!");
            }
        }
示例#2
0
        void CharacterChangedLocation(CharacterChangeLocationEventArgs e)
        {
            APerson ch            = Characters.Find(c => c.id == e.characterId);
            var     destination   = Locations.Find(l => l.Position == e.DestinationTarget);
            var     startLocation = Locations.Find(l => l.Position == e.PreviousLocation);

            try
            {
                startLocation.CharacterLeft(ch);
            }
            catch
            {
                Stopwatch stp = new Stopwatch();
                stp.Start();

                while (stp.ElapsedMilliseconds < 1000)
                {
                }
                stp.Stop();
                CharacterChangedLocation(e);
            }

            destination.CharacterEnter(ch);

            ch.CurrentPosition = e.DestinationTarget;

            Console.WriteLine("{0} has left {1} and entered {2}", ch.Name, startLocation.Name, destination.Name);
        }