コード例 #1
0
        public void TestActionStringToClass()
        {
            var list = new List <KeyValuePair <string, BaseAction> >
            {
                new KeyValuePair <string, BaseAction>("feed", new FeedAction()),
                new KeyValuePair <string, BaseAction>("hug", new HugAction()),
                new KeyValuePair <string, BaseAction>("play", new PlayAction()),
                new KeyValuePair <string, BaseAction>("sleep", new SleepAction())
            };

            list.ForEach(pair =>
            {
                Assert.AreEqual(Converter.ActionToClass(pair.Key).GetType(), pair.Value.GetType());
            });

            Assert.AreEqual(Converter.ActionToClass("test"), null);
        }
コード例 #2
0
        //////////
        // Actions

        public bool DoAction(string action)
        {
            if (CurrentAction != null)
            {
                return(false);
            }

            if (CurrentTamagotchi.Statuses.Contains(Status.Crazy) && new Random(GetHashCode()).Next(1, 100) > 50)
            {
                CurrentTamagotchi.Deceased = true;
            }

            var baseAction = Converter.ActionToClass(action);

            if (baseAction == null)
            {
                return(false);
            }

            CurrentAction = baseAction.Start(CurrentTamagotchi, () => CurrentAction = null);

            return(true);
        }