private void Button_Click_(object sender, RoutedEventArgs e)
 {
     c = new cat(words);
     d = new dog(words);
     p = new pig(words);
     if (textBox.Text  == "cat" || textBox.Text == "Cat") {
         Say += c.saying;
         Say(this, new myEventArgs(times++));
         Say -= c.saying;
     } else if (textBox.Text == "dog" || textBox.Text == "Dog")
     {
         Say += d.saying;
         Say(this, new myEventArgs(times++));
         Say -= d.saying;
     }
     else if (textBox.Text == "pig" || textBox.Text == "Pig")
     {
         Say += p.saying;
         Say(this, new myEventArgs(times++));
         Say -= p.saying;
     }
     else { }
     textBox.Text = "";
 }
        private void Bt2_Click_1(object sender, RoutedEventArgs e)
        {
            Random ran = new Random();
            int RandKey = ran.Next(1, 4);

            if (RandKey == 1)
            {

                c = new cat(words);

                //注册事件
                Say += new AnimalSaying(c.saying);

                //执行事件
                Say(this, new myEventArgs(itsName));//事件中传递参数itsName

                Say -= new AnimalSaying(c.saying);//注销事件*/
            }

            else if (RandKey == 2)
            {

                d = new dog(words);

                //注册事件
                Say += new AnimalSaying(d.saying);

                //执行事件
                Say(this, new myEventArgs(itsName));//事件中传递参数itsName

                Say -= new AnimalSaying(d.saying);//注销事件*/
            }

            else if (RandKey == 3)
            {
                itsName = "pig";
                p = new pig(words);

                //注册事件
                Say += new AnimalSaying(p.saying);

                //执行事件
                Say(this, new myEventArgs(itsName));//事件中传递参数itsName

                Say -= new AnimalSaying(p.saying);//注销事件*/
            }
        }
Exemplo n.º 3
1
 private void RanSay_Click(object sender, RoutedEventArgs e)
 {
     if (t2 == 0)
     {
         c = new cat(words);
         d = new dog(words);
         p = new pig(words);
     }
     int n = rdm.Next(3);
     switch(n) 
     {
         case 0:
             RanSay = new AnimalSaying(c.saying);
             break;
         case 1:
             RanSay = new AnimalSaying(d.saying);
             break;
         case 2:
             RanSay = new AnimalSaying(p.saying);
             break;
     }
     RanSay(this, new myEventArgs(t2++));
 }
Exemplo n.º 4
1
        private void SpeSay_Click(object sender, RoutedEventArgs e)
        {
            if (t1 == 0)
            {
                c = new cat(words);
                d = new dog(words);
                p = new pig(words);
            }
            string s = ani.Text;
            if (s != "")
            {
                if (s == "cat")
                {
                    SpeSay = new AnimalSaying(c.saying);
                    SpeSay(this, new myEventArgs(t1++));
                    SpeSay -= new AnimalSaying(c.saying);
                }
                else if (s == "dog")
                {
                    SpeSay = new AnimalSaying(d.saying);
                    SpeSay(this, new myEventArgs(t1++));
                    SpeSay -= new AnimalSaying(d.saying);
                }
                else if (s == "pig")
                {
                    SpeSay = new AnimalSaying(p.saying);
                    SpeSay(this, new myEventArgs(t1++));
                    SpeSay -= new AnimalSaying(p.saying);
                }
                ani.Text = "";
            }

        }
        private void Bt1_Click(object sender, RoutedEventArgs e)
        {
            itsName = Input.Text;
            if (itsName == "cat") {

                c = new cat(words);

                //注册事件
                Say += new AnimalSaying(c.saying);

                //执行事件
                Say(this, new myEventArgs(itsName));//事件中传递参数itsName

                Say -= new AnimalSaying(c.saying);//注销事件*/
            }

            else if (itsName == "dog")
            {

                d = new dog(words);

                //注册事件
                Say += new AnimalSaying(d.saying);

                //执行事件
                Say(this, new myEventArgs(itsName));//事件中传递参数itsName

                Say -= new AnimalSaying(d.saying);//注销事件*/
            }

            else if (itsName == "pig")
            {

                p = new pig(words);

                //注册事件
                Say += new AnimalSaying(p.saying);

                //执行事件
                Say(this, new myEventArgs(itsName));//事件中传递参数itsName

                Say -= new AnimalSaying(p.saying);//注销事件*/
            }

            Input.Text = "";
        }
Exemplo n.º 6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.textBlock.Text = "";
            if (times == 0)
            {
                c = new cat(this.textBlock);
                d = new dog(this.textBlock);
                p = new pig(this.textBlock);
            }
            Random i = new Random();
            int    x = i.Next(3);

            switch (x)
            {
            case 0:
                Say += new AnimalSaying(c.saying);
                Say(this, new myEventArgs(times++));
                break;

            case 1:
                Say += new AnimalSaying(d.saying);
                Say(this, new myEventArgs(times++));
                // Say -= new AnimalSaying(d.saying);
                break;

            case 2:
                Say += new AnimalSaying(p.saying);
                Say(this, new myEventArgs(times++));
                // Say -= new AnimalSaying(p.saying);
                break;
            }
        }
Exemplo n.º 7
0
        private void button_Copy_Click(object sender, RoutedEventArgs e)
        {
            words.Text = "";
            c          = new cat(words);
            d          = new dog(words);
            p          = new pig(words);
            Random rd  = new Random();
            int    num = rd.Next(0, 3);

            switch (num)
            {
            case 0:
                Say = new AnimalSaying(p.saying);
                Say(p);
                break;

            case 1:
                Say = new AnimalSaying(d.saying);
                Say(d);
                break;

            case 2:
                Say = new AnimalSaying(c.saying);
                Say(c);
                break;
            }
        }
Exemplo n.º 8
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     if (textBox.Text == "cat")
     {
         c    = new cat(words);
         Say += new AnimalSaying(c.saying);
         Say(this, new myEventArgs(times++));
         Say         -= new AnimalSaying(c.saying);
         textBox.Text = "";
     }
     else if (textBox.Text == "dog")
     {
         d    = new dog(words);
         Say += new AnimalSaying(d.saying);
         Say(this, new myEventArgs(times++));
         Say         -= new AnimalSaying(d.saying);
         textBox.Text = "";
     }
     else if (textBox.Text == "pig")
     {
         p    = new pig(words);
         Say += new AnimalSaying(p.saying);
         Say(this, new myEventArgs(times++));
         Say         -= new AnimalSaying(p.saying);
         textBox.Text = "";
     }
     else
     {
         textBox.Text = "";
     }
 }
Exemplo n.º 9
0
        private void RanSay_Click(object sender, RoutedEventArgs e)
        {
            if (t2 == 0)
            {
                c = new cat(words);
                d = new dog(words);
                p = new pig(words);
            }
            int n = rdm.Next(3);

            if (n == 0)
            {
                RanSay += c.saying;
                RanSay(this, new myEventArgs(t2++));
                RanSay -= c.saying;
            }
            else if (n == 1)
            {
                RanSay += d.saying;
                RanSay(this, new myEventArgs(t2++));
                RanSay -= d.saying;
            }
            else if (n == 2)
            {
                RanSay += p.saying;
                RanSay(this, new myEventArgs(t2++));
                RanSay -= p.saying;
            }
        }
Exemplo n.º 10
0
        private void SpeSay_Click(object sender, RoutedEventArgs e)
        {
            if (t1 == 0)
            {
                c = new cat(words);
                d = new dog(words);
                p = new pig(words);
            }
            string s = ani.Text;

            if (s != "")
            {
                if (s == "cat")
                {
                    SpeSay += c.saying;
                    SpeSay(this, new myEventArgs(t1++));
                    SpeSay -= c.saying;
                }
                else if (s == "dog")
                {
                    SpeSay += d.saying;
                    SpeSay(this, new myEventArgs(t1++));
                    SpeSay -= d.saying;
                }
                else if (s == "pig")
                {
                    SpeSay += p.saying;
                    SpeSay(this, new myEventArgs(t1++));
                    SpeSay -= p.saying;
                }
                ani.Text = "";
            }
        }
Exemplo n.º 11
0
 private void ok_Click(object sender, RoutedEventArgs e)
 {
     if (word_in.Text == "dog")
     {
         word_out.Text = "";
         d             = new dog(word_out);
         Say          += new AnimalSaying(d.saying);
         Say(this, new myEventArgs(times++));  //事件中传递参数times
     }
     else if (word_in.Text == "cat")
     {
         word_out.Text = "";
         c             = new cat(word_out);
         Say          += new AnimalSaying(c.saying);
         Say(this, new myEventArgs(times++));  //事件中传递参数times
     }
     else if (word_in.Text == "pig")
     {
         word_out.Text = "";
         p             = new pig(word_out);
         Say          += new AnimalSaying(p.saying);
         Say(this, new myEventArgs(times++));  //事件中传递参数times
     }
     word_in.Text = "";
 }
Exemplo n.º 12
0
            static void Main(string[] args)
            {
                pig mypig = new pig(); //object declaration.

                mypig.Animalsound();   //calling method.
                mypig.sleep();
            }
Exemplo n.º 13
0
        private void Button_Click1(object sender, RoutedEventArgs e)
        {
            this.textBlock.Text = "";
            if (ttimes == 0)
            {
                c = new cat(this.textBlock);
                d = new dog(this.textBlock);
                p = new pig(this.textBlock);
                ttimes++;
            }
            switch (this.textBox.Text)
            {
            case "cat":
                Say += new AnimalSaying(c.saying);
                Say(this, new myEventArgs(times++));
                // Say -= new AnimalSaying(c.saying);
                break;

            case "dog":
                Say += new AnimalSaying(d.saying);
                Say(this, new myEventArgs(times++));
                // Say -= new AnimalSaying(d.saying);
                break;

            case "pig":
                Say += new AnimalSaying(p.saying);
                Say(this, new myEventArgs(times++));
                // Say -= new AnimalSaying(p.saying);
                break;

            default:
                break;
            }
            this.textBox.Text = "";
        }
Exemplo n.º 14
0
        private void speak_btn_Click(object sender, RoutedEventArgs e)
        {
            Random ran = new Random();
            int    n   = ran.Next(0, 3);

            textBlock.Text = "";
            if (n == 0)
            {
                p      = new pig(textBlock);
                Speak += new animal_speak(p.saying);
            }
            else if (n == 1)
            {
                d      = new dog(textBlock);
                Speak += new animal_speak(d.saying);
            }
            else
            {
                c      = new cat(textBlock);
                Speak += new animal_speak(c.saying);
            }
            Speak(this, new EventArgs());
            switch (n)
            {
            case 0: Speak -= new animal_speak(p.saying); break;

            case 1: Speak -= new animal_speak(d.saying); break;

            case 2: Speak -= new animal_speak(c.saying); break;
            }
        }
Exemplo n.º 15
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            int flag = 0;

            if (times % 18 == 0)
            {
                textBlock.Text = "";
            }
            if (textBox.Text == "cat")
            {
                c    = new cat(textBlock);
                Say += new AnimalSaying(c.saying);
            }
            else if (textBox.Text == "dog")
            {
                d    = new dog(textBlock);
                Say += new AnimalSaying(d.saying);
            }
            else if (textBox.Text == "pig")
            {
                p    = new pig(textBlock);
                Say += new AnimalSaying(p.saying);
            }
            else
            {
                flag = 1;
            }
            if (flag != 1)
            {
                Say(this, new myEventArgs(times++));
                Say = null;
            }
            textBox.Text = "";
        }
Exemplo n.º 16
0
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            words.Text = "";
            c          = new cat(words);
            d          = new dog(words);
            p          = new pig(words);
            //获取输入
            string inputAnimal = this.textBox.Text;

            if (inputAnimal == "cat")
            {
                Say -= new AnimalSaying(d.saying);
                Say -= new AnimalSaying(p.saying);
                Say += new AnimalSaying(c.saying);
            }
            else if (inputAnimal == "dog")
            {
                Say -= new AnimalSaying(c.saying);
                Say -= new AnimalSaying(p.saying);
                Say += new AnimalSaying(d.saying);
            }
            else if (inputAnimal == "pig")
            {
                Say -= new AnimalSaying(c.saying);
                Say -= new AnimalSaying(d.saying);
                Say += new AnimalSaying(p.saying);
            }
            this.textBox.Text = "";
            //执行事件
            Say(this, new myEventArgs());
        }
Exemplo n.º 17
0
        private void speakButton_Click(object sender, RoutedEventArgs e)
        {
            words.Text = "";
            c          = new cat(words);
            d          = new dog(words);
            p          = new pig(words);
            //获取随机数
            Random r       = new Random();
            int    RandKey = r.Next(0, 30);

            //根据随机数来注销事件和注册事件
            if (RandKey >= 0 && RandKey < 10)
            {
                Say -= new AnimalSaying(d.saying);
                Say -= new AnimalSaying(p.saying);
                Say += new AnimalSaying(c.saying);
            }
            else if (RandKey >= 10 && RandKey < 20)
            {
                Say -= new AnimalSaying(c.saying);
                Say -= new AnimalSaying(p.saying);
                Say += new AnimalSaying(d.saying);
            }
            else
            {
                Say -= new AnimalSaying(c.saying);
                Say -= new AnimalSaying(d.saying);
                Say += new AnimalSaying(p.saying);
            }
            //执行事件
            Say(this, new myEventArgs());
        }
Exemplo n.º 18
0
 private void OK(object sender, RoutedEventArgs e)
 {
     if (input.Text == "cat")
     {
         c          = new cat(words);
         words.Text = "";
         Say       += new AnimalSaying(c.saying);
         Say(this);
     }
     if (input.Text == "dog")
     {
         d          = new dog(words);
         words.Text = "";
         Say       += new AnimalSaying(d.saying);
         Say(this);
     }
     if (input.Text == "pig")
     {
         p          = new pig(words);
         words.Text = "";
         Say       += new AnimalSaying(p.saying);
         Say(this);
     }
     input.Text = "";
 }
Exemplo n.º 19
0
 //当用户点击OK按钮对应的操作,实现指定发言
 private void Button_ClickofOK(object sender, RoutedEventArgs e)
 {
     c = new cat(words);
     d = new dog(words);
     p = new pig(words);
     //对应cat
     if (name.Text == "cat")
     {
         Say += new AnimalSaying(c.saying);   //添加事件
         Say(this, new myEventArgs(times++)); //执行事件
         Say -= new AnimalSaying(c.saying);   //删除事件
     }
     //对应dog
     else if (name.Text == "dog")
     {
         Say += new AnimalSaying(d.saying);
         Say(this, new myEventArgs(times++));
         Say -= new AnimalSaying(d.saying);
     }
     //对应pig
     else if (name.Text == "pig")
     {
         Say += new AnimalSaying(p.saying);
         Say(this, new myEventArgs(times++));
         Say -= new AnimalSaying(p.saying);
     }
     name.Text = "";
 }
Exemplo n.º 20
0
        private void button_sure_Click(object sender, RoutedEventArgs e)
        {
            string s = who.Text;

            if (s == "cat")
            {
                c   = new cat(words);
                Say = new AnimalSaying(c.saying);
            }
            else if (s == "dog")
            {
                d   = new dog(words);
                Say = new AnimalSaying(d.saying);
            }
            else if (s == "pig")
            {
                p   = new pig(words);
                Say = new AnimalSaying(p.saying);
            }
            else
            {
                who.Text = "";
                return;
            }
            Say(this);
            scroll.ChangeView(null, scroll.ScrollableHeight, null);
            who.Text = "";
        }
Exemplo n.º 21
0
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     if (c == null)
     {
         c = new cat(words);
         d = new dog(words);
         p = new pig(words);
     }
     if (textBox.Text == "cat")
     {
         words.Text = "";
         Say       += new AnimalSaying(c.saying);
         Say(this, EventArgs.Empty);
         textBox.Text = "";
     }
     else if (textBox.Text == "dog")
     {
         words.Text = "";
         Say       += new AnimalSaying(d.saying);
         Say(this, EventArgs.Empty);
         textBox.Text = "";
     }
     else if (textBox.Text == "pig")
     {
         words.Text = "";
         Say       += new AnimalSaying(p.saying);
         Say(this, EventArgs.Empty);
         textBox.Text = "";
     }
 }
Exemplo n.º 22
0
 private void Button_Click_(object sender, RoutedEventArgs e)
 {
     c = new cat(words);
     d = new dog(words);
     p = new pig(words);
     if (textBox.Text == "cat" || textBox.Text == "Cat")
     {
         Say += c.saying;
         Say(this, new myEventArgs(times++));
         Say -= c.saying;
     }
     else if (textBox.Text == "dog" || textBox.Text == "Dog")
     {
         Say += d.saying;
         Say(this, new myEventArgs(times++));
         Say -= d.saying;
     }
     else if (textBox.Text == "pig" || textBox.Text == "Pig")
     {
         Say += p.saying;
         Say(this, new myEventArgs(times++));
         Say -= p.saying;
     }
     else
     {
     }
     textBox.Text = "";
 }
Exemplo n.º 23
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            words.Text = ""; //C#事件的绑定机制决定了必须每次清空
            if (c == null)
            {
                c = new cat(words);
                d = new dog(words);
                p = new pig(words);
            }

            Random rd   = new Random(); //产生随机数
            int    flag = rd.Next();

            if (flag % 3 == 0) //用取模的结果限定随机输出
            {
                Say += new AnimalSaying(c.saying);
            }
            else if (flag % 3 == 1)
            {
                Say += new AnimalSaying(d.saying);
            }
            else
            {
                Say += new AnimalSaying(p.saying);
            }
            //执行事件
            Say(this, EventArgs.Empty);
        }
Exemplo n.º 24
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (times % 18 == 0)
            {
                textBlock.Text = "";
            }
            Random ran       = new Random();
            int    RandomKey = ran.Next(0, 6);

            if (RandomKey == 0 || RandomKey == 3)
            {
                c    = new cat(textBlock);
                Say += new AnimalSaying(c.saying);
            }
            else if (RandomKey == 1 || RandomKey == 4)
            {
                d    = new dog(textBlock);
                Say += new AnimalSaying(d.saying);
            }
            else
            {
                p    = new pig(textBlock);
                Say += new AnimalSaying(p.saying);
            }
            Say(this, new myEventArgs(times++));
            Say = null;;
        }
Exemplo n.º 25
0
        private void sure_btn_Click(object sender, RoutedEventArgs e)
        {
            this.textBlock.Text = "";
            string name = this.textBox.Text;

            switch (name)
            {
            case "pig": p = new pig(textBlock); Speak += new animal_speak(p.saying); break;

            case "dog": d = new dog(textBlock); Speak += new animal_speak(d.saying); break;

            case "cat": c = new cat(textBlock); Speak += new animal_speak(c.saying); break;

            default: this.textBox.Text = ""; return;
            }
            Speak(this, new EventArgs());
            switch (name)
            {
            case "pig": Speak -= new animal_speak(p.saying); break;

            case "dog": Speak -= new animal_speak(d.saying); break;

            case "cat": Speak -= new animal_speak(c.saying); break;

            default: return;
            }
            this.textBox.Text = "";
        }
Exemplo n.º 26
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            c = new cat(textBlock);
            d = new dog(textBlock);
            p = new pig(textBlock);
            Random ran     = new Random();
            int    RandKey = ran.Next(1, 4);

            switch (RandKey)
            {
            case 1:
                Say += new AnimalSay(c.say);
                break;

            case 2:
                Say += new AnimalSay(d.say);
                break;

            case 3:
                Say += new AnimalSay(p.say);
                break;
            }
            Say(this);
            Say = null;
        }
Exemplo n.º 27
0
        private void ifIsFirstTime()
        {
            words.Text = String.Empty;
            c          = new cat(words);
            d          = new dog(words);
            p          = new pig(words);

            isFirstTime = false;
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            PolarBear polarbear = new PolarBear();

            polarbear.Sleep();
            Console.WriteLine("yes i do sleep");
            polarbear.Breastfeed();


            pig pig = new pig();

            pig.Eat();
            pig.Sleep();
            pig.hair();
        }
Exemplo n.º 29
0
        //当用户点击speak按钮时对应的操作,实现随机发言
        private void Button_ClickofSpeak(object sender, RoutedEventArgs e)
        {
            c = new cat(words);
            d = new dog(words);
            p = new pig(words);
            //生成随机数,产生0、1、2的随机数,分别对应cat、dog、pig
            Random number = new Random();
            int    num    = number.Next(3);

            //注册事件
            if (num == 0)
            {
                Say += new AnimalSaying(c.saying);          //对应cat
            }
            if (num == 1)
            {
                Say += new AnimalSaying(d.saying);          //对应dog
            }
            if (num == 2)
            {
                Say += new AnimalSaying(p.saying);          //对应pig
            }
            //执行事件
            Say(this, new myEventArgs(times++));  //事件中传递参数times
            //删除事件
            if (num == 0)
            {
                Say -= new AnimalSaying(c.saying);
            }
            if (num == 1)
            {
                Say -= new AnimalSaying(d.saying);
            }
            if (num == 2)
            {
                Say -= new AnimalSaying(p.saying);
            }
        }
Exemplo n.º 30
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            textBox.Text = "";
            Random ran     = new Random();
            int    RandKey = ran.Next(0, 3);

            if (RandKey == 0)
            {
                c = new cat(words);

                Say += new AnimalSaying(c.saying);
            }
            else if (RandKey == 1)
            {
                d = new dog(words);

                Say += new AnimalSaying(d.saying);
            }
            else
            {
                p = new pig(words);

                Say += new AnimalSaying(p.saying);
            }
            Say(this, new myEventArgs(times++));
            if (RandKey == 0)
            {
                Say -= new AnimalSaying(c.saying);
            }
            else if (RandKey == 1)
            {
                Say -= new AnimalSaying(d.saying);
            }
            else
            {
                Say -= new AnimalSaying(p.saying);
            }
        }
Exemplo n.º 31
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Random rd = new Random();
            int    i  = rd.Next(1, 4);

            c          = new cat(words);
            d          = new dog(words);
            p          = new pig(words);
            words.Text = "";
            if (i == 3)
            {
                Say += new AnimalSaying(c.saying);
            }
            if (i == 1)
            {
                Say += new AnimalSaying(d.saying);
            }
            if (i == 2)
            {
                Say += new AnimalSaying(p.saying);
            }
            Say(this);
        }
Exemplo n.º 32
0
 private void btn_say_Click(object sender, RoutedEventArgs e)
 {
     num = new Random().Next() % 3;
     if (num == 0)
     {
         c   = new cat(words);
         Say = new AnimalSaying(c.saying);
     }
     else if (num == 1)
     {
         d   = new dog(words);
         Say = new AnimalSaying(d.saying);
     }
     else if (num == 2)
     {
         p   = new pig(words);
         Say = new AnimalSaying(p.saying);
     }
     //执行事件
     Say(this);
     //滚动到底部
     scroll.ChangeView(null, scroll.ScrollableHeight, null);
 }
Exemplo n.º 33
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            word_out.Text = "";
            Random ran = new Random();
            int    key = ran.Next(1, 4);

            if (key == 1)
            {
                c    = new cat(word_out);
                Say += new AnimalSaying(c.saying);
            }
            else if (key == 2)
            {
                d    = new dog(word_out);
                Say += new AnimalSaying(d.saying);
            }
            else if (key == 3)
            {
                p    = new pig(word_out);
                Say += new AnimalSaying(p.saying);
            }

            Say(this, new myEventArgs(times++));  //事件中传递参数times
        }
        public static void InitializeContent()
        {
            #region tutorial step 2
            #region arena
            var map = new Point(2000, 2000);

            var arena = new ArenaControl();

            arena.Layers.Canvas.style.backgroundColor =
                Color.FromGray(0xc0);
            arena.SetLocation(
                Rectangle.Of(0, 0, Native.window.Width, Native.window.Height));

            arena.SetCanvasSize(map);

            arena.Control.AttachToDocument();


            arena.DrawTextToInfo(Title, new Point(8, 8), Color.Blue);

            Native.window.onresize +=
                delegate
                {
                    arena.SetLocation(
                        Rectangle.Of(0, 0, Native.window.Width, Native.window.Height));

                    arena.SetCanvasPosition(
                        arena.CurrentCanvasPosition
                        );
                };
            #endregion
            #endregion


            var pending = default(Dude2);

            #region arsenal
            var arsenal = new Dictionary<string, DudeAnimationInfo>
            {
                {"Soldier", 
                    new DudeAnimationInfo 
                    { 
                        Frames_Stand = Frames.WolfSoldier,
                        Frames_Walk = Frames.WolfSoldier_Walk
                    }
                },
                {"Imp", 
                    new DudeAnimationInfo 
                    { 
                        Frames_Stand = Frames.DoomImp,
                        Frames_Walk = Frames.DoomImp_Walk
                    }
                }
            };
            #endregion


            #region tutorial step 3

            Func<DudeAnimationInfo, Point, Dude2> CreateActor =
                (_frames, _coords) =>
                {
                    var actor = new Dude2();

                    actor.Frames = _frames.Frames_Stand;
                    actor.AnimationInfo.Frames_Stand = _frames.Frames_Stand;
                    actor.AnimationInfo.Frames_Walk = _frames.Frames_Walk;
                    actor.Zoom.DynamicZoomFunc = a => 1;
                    actor.SetSize(48, 72);
                    actor.TeleportTo(_coords.X, _coords.Y);
                    actor.Zoom.StaticZoom = DefaultActiorZoom;
                    actor.Direction = Math.PI * 0.5;
                    actor.Control.AttachTo(arena.Layers.Canvas);
                    //actor.HasShadow = _frames.Frames_Stand.Length > 1;
                    if (_frames.Frames_Stand.Length == 1)
                        actor.Shadow.style.Opacity = 0.4;
                    actor.AnimationInfo.WalkAnimationInterval = 1000 / 30;
                    return actor;
                };

            var actors = new List<Dude2>
            {

            };

            var selection = from i in actors
                            where i.IsSelected
                            select i;

            arena.ApplySelection +=
                (rect, ev) =>
                {
                    if (pending != null)
                        return;

                    foreach (var v in actors)
                        v.IsSelected = rect.Contains(v.CurrentLocation.ToInt32());
                };

            var Argh = new Argh();
            var Affirmative = new Affirmative();
            var ghoullaugh = new ghoullaugh();
            var sheep = new sheep();
            var pig = new pig();
            var click = new click().AttachToDocument();

            arena.SelectionClick +=
                (p, ev) =>
                {
                    if (pending != null)
                        return;

                    foreach (var v in selection)
                    {
                        if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.ManWithHorns.Frames_Stand[0].Source)
                        {
                            ghoullaugh.play();
                            ghoullaugh = new ghoullaugh();
                        }
                        else if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.ThePig.Frames_Stand[0].Source)
                        {
                            pig.play();
                            pig = new pig();
                        }
                        else if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.TheSheep.Frames_Stand[0].Source)
                        {
                            sheep.play();
                            sheep = new sheep();
                        }
                        else if (v.AnimationInfo.Frames_Stand[0].Source == Frames.WolfSoldier[0].Source)
                        {
                            Affirmative.play();
                            Affirmative = new Affirmative();
                        }
                        else
                        {
                            Argh.play();
                            Argh = new Argh();
                        }



                        v.WalkTo(p.ToDouble());

                        // move in group formation
                        p.X += 16;
                        p.Y += 16;
                    }
                };


            #endregion

            #region tutorial step 4



            #region CreateDialogAt
            var CreateDialogAt =
                new
                {
                    //Dialog = default(IHTMLDiv),
                    Content = default(IHTMLDiv),
                    Width = default(string)
                }
                .ToFunc(
                (Point pos, string width) =>
                {
                    var f = new Form();

                    f.Show();

                    f.SizeTo(200, 200);


                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151115/audio
                    //f.PopupInsteadOfClosing();

                    f.MoveTo(pos.X, pos.Y);
                    //f.SizeTo(


                    //var dialog = new IHTMLDiv();

                    //dialog.style.SetLocation(pos.X, pos.Y);

                    //dialog.style.backgroundColor = Color.Gray;
                    //dialog.style.padding = "1px";

                    //var caption = new IHTMLDiv().AttachTo(dialog);

                    //caption.style.backgroundColor = Color.Blue;
                    //caption.style.width = width;
                    //caption.style.height = "0.5em";
                    //caption.style.cursor = IStyle.CursorEnum.move;

                    //var drag = new DragHelper(caption);

                    //drag.Position = pos;
                    //drag.Enabled = true;
                    //drag.DragMove +=
                    //    delegate
                    //    {
                    //        dialog.style.SetLocation(drag.Position.X, drag.Position.Y);
                    //    };

                    var _content = new IHTMLDiv().AttachTo(f.GetHTMLTargetContainer());

                    _content.style.textAlign = IStyle.TextAlignEnum.center;
                    _content.style.backgroundColor = Color.White;
                    _content.style.padding = "1px";

                    //dialog.AttachToDocument();

                    return new
                    { //Dialog = dialog,
                        Content = _content,
                        Width = width
                    };
                }
            );
            #endregion

            #region dialog
            var toolbar = CreateDialogAt(new Point(2, 2), "8em");

            var combo = new IHTMLSelect();
            var build = new IHTMLButton();

            build.style.SetSize(72, 72);
            build.style.padding = "0px";

            var avatar = new IHTMLImage().AttachTo(build);
            var remove = new IHTMLButton("Remove");


            combo.AttachTo(toolbar.Content);
            new IHTMLBreak().AttachTo(toolbar.Content);
            build.AttachTo(toolbar.Content);
            new IHTMLBreak().AttachTo(toolbar.Content);
            remove.AttachTo(toolbar.Content);
            new IHTMLBreak().AttachTo(toolbar.Content);
            #endregion


            #region GetSelectedArsenal
            Func<DudeAnimationInfo> GetSelectedArsenal =
                () =>
                {
                    if (arsenal.ContainsKey(combo[combo.selectedIndex].value))
                        return arsenal[combo[combo.selectedIndex].value];

                    return null;
                };
            #endregion

            Action Refresh =
                delegate
                {
                    var i = GetSelectedArsenal();

                    if (i != null)
                        avatar.src = i.Images.Random().src;
                };

            combo.Add(arsenal.Keys.ToArray());
            Refresh();

            combo.onchange +=
                delegate
                {
                    Refresh();



                    click.play();
                    click = new click().AttachToDocument();
                };

            #region pending actor

            arena.MouseMove +=
                p =>
                {
                    if (pending == null)
                        return;

                    pending.TeleportTo(p.X, p.Y);
                };

            arena.Layers.User.oncontextmenu +=
                e =>
                {
                    e.preventDefault();

                    if (pending != null)
                    {
                        pending.Control.Orphanize();
                        pending = null;
                        arena.ShowSelectionRectangle = true;

                        return;
                    }

                    actors.ForEach(
                        k => k.IsSelected = false
                            );
                };

            arena.SelectionClick +=
                (p, ev) =>
                {
                    if (pending == null)
                    {

                        return;
                    }

                    pending.TeleportTo(p.X, p.Y);

                    actors.Add(pending);

                    pending.IsHot = false;


                    var x = GetSelectedArsenal();
                    pending = CreateActor(x,
                       new Point(
                           Native.window.Width / 2,
                           Native.window.Height / 2
                           )
                   );

                    pending.IsHot = true;


                    click.play();
                    click = new click().AttachToDocument();
                };

            build.onclick +=
                delegate
                {
                    if (pending != null)
                    {
                        pending.Control.Orphanize();
                        pending = null;

                        return;
                    }

                    var x = GetSelectedArsenal();

                    pending = CreateActor(x,
                        new Point(
                            Native.window.Width / 2,
                            Native.window.Height / 2
                            )
                    );

                    pending.IsHot = true;
                    arena.ShowSelectionRectangle = false;

                    click.play();
                    click = new click().AttachToDocument();
                };
            #endregion

            remove.onclick +=
                delegate
                {
                    foreach (var v in selection.ToArray())
                    {
                        v.Control.Orphanize();
                        actors.Remove(v);
                    }


                    click.play();
                    click = new click().AttachToDocument();
                };

            #endregion

            if (FilterToImpAndSoldier)
            { }
            else
            {
                #region step 6

                {
                    var n = "NPC";

                    arsenal.Add(n, MyFrames.NPC3);
                    combo.Add(n);
                }

                #endregion


                {
                    var n = "ManWithHorns";

                    arsenal.Add(n, MyFrames.ManWithHorns);
                    combo.Add(n);
                }
                {
                    var n = "TheSheep";

                    arsenal.Add(n, MyFrames.TheSheep);
                    combo.Add(n);
                }
                {
                    var n = "ThePig";

                    arsenal.Add(n, MyFrames.ThePig);
                    combo.Add(n);
                }

                {
                    var n = "TheCactus";

                    arsenal.Add(n, MyFrames.TheCactus);
                    combo.Add(n);
                }
            }


            if (BeforeAddingDebris != null)
                BeforeAddingDebris(arena.Layers.Canvas);

            3.Times(
              delegate()
              {
                  new DebrisImages().Images.ForEach(
                      img => img.AttachTo(arena.Layers.Canvas).style.SetLocation(map.X.Random(), map.Y.Random())
                  );
              }
      );

            16.Times(
                delegate()
                {
                    actors.Add(
                        CreateActor(arsenal.Random().Value, new Point(map.X.Random(), map.Y.Random()))
                        );
                }
            );
        }
Exemplo n.º 35
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            bool isSpeakAble = true;

            if (isFirstTime)
            {
                words.Text = "";
                c          = new cat(words);
                d          = new dog(words);
                p          = new pig(words);

                isFirstTime = false;
            }

            if (((Button)sender).Name == "OK")
            {
                switch (input.Text)
                {
                case "dog":
                    Say = new AnimalSaying(d.saying);
                    break;

                case "cat":
                    Say = new AnimalSaying(c.saying);
                    break;

                case "pig":
                    Say = new AnimalSaying(p.saying);
                    break;

                default:
                    isSpeakAble = false;
                    break;
                }
                clear_input();
            }
            else
            {
                Random ran = new Random();
                int    n   = ran.Next(1, 4);
                switch (n)
                {
                case 1:
                    Say = new AnimalSaying(d.saying);
                    break;

                case 2:
                    Say = new AnimalSaying(c.saying);
                    break;

                case 3:
                    Say = new AnimalSaying(p.saying);
                    break;
                }
            }

            //执行事件
            if (isSpeakAble)
            {
                Say(this);
            }
        }
Exemplo n.º 36
0
        public static void InitializeContent()
        {
            #region tutorial step 2
            #region arena
            var map = new Point(2000, 2000);

            var arena = new ArenaControl();

            arena.Layers.Canvas.style.backgroundColor =
                Color.FromGray(0xc0);
            arena.SetLocation(
                Rectangle.Of(0, 0, Native.window.Width, Native.window.Height));

            arena.SetCanvasSize(map);

            arena.Control.AttachToDocument();


            arena.DrawTextToInfo(Title, new Point(8, 8), Color.Blue);

            Native.window.onresize +=
                delegate
            {
                arena.SetLocation(
                    Rectangle.Of(0, 0, Native.window.Width, Native.window.Height));

                arena.SetCanvasPosition(
                    arena.CurrentCanvasPosition
                    );
            };
            #endregion
            #endregion


            var pending = default(Dude2);

            #region arsenal
            var arsenal = new Dictionary <string, DudeAnimationInfo>
            {
                { "Soldier",
                  new DudeAnimationInfo
                  {
                      Frames_Stand = Frames.WolfSoldier,
                      Frames_Walk  = Frames.WolfSoldier_Walk
                  } },
                { "Imp",
                  new DudeAnimationInfo
                  {
                      Frames_Stand = Frames.DoomImp,
                      Frames_Walk  = Frames.DoomImp_Walk
                  } }
            };
            #endregion


            #region tutorial step 3

            Func <DudeAnimationInfo, Point, Dude2> CreateActor =
                (_frames, _coords) =>
            {
                var actor = new Dude2();

                actor.Frames = _frames.Frames_Stand;
                actor.AnimationInfo.Frames_Stand = _frames.Frames_Stand;
                actor.AnimationInfo.Frames_Walk  = _frames.Frames_Walk;
                actor.Zoom.DynamicZoomFunc       = a => 1;
                actor.SetSize(48, 72);
                actor.TeleportTo(_coords.X, _coords.Y);
                actor.Zoom.StaticZoom = DefaultActiorZoom;
                actor.Direction       = Math.PI * 0.5;
                actor.Control.AttachTo(arena.Layers.Canvas);
                //actor.HasShadow = _frames.Frames_Stand.Length > 1;
                if (_frames.Frames_Stand.Length == 1)
                {
                    actor.Shadow.style.Opacity = 0.4;
                }
                actor.AnimationInfo.WalkAnimationInterval = 1000 / 30;
                return(actor);
            };

            var actors = new List <Dude2>
            {
            };

            var selection = from i in actors
                            where i.IsSelected
                            select i;

            arena.ApplySelection +=
                (rect, ev) =>
            {
                if (pending != null)
                {
                    return;
                }

                foreach (var v in actors)
                {
                    v.IsSelected = rect.Contains(v.CurrentLocation.ToInt32());
                }
            };

            var Argh        = new Argh();
            var Affirmative = new Affirmative();
            var ghoullaugh  = new ghoullaugh();
            var sheep       = new sheep();
            var pig         = new pig();
            var click       = new click().AttachToDocument();

            arena.SelectionClick +=
                (p, ev) =>
            {
                if (pending != null)
                {
                    return;
                }

                foreach (var v in selection)
                {
                    if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.ManWithHorns.Frames_Stand[0].Source)
                    {
                        ghoullaugh.play();
                        ghoullaugh = new ghoullaugh();
                    }
                    else if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.ThePig.Frames_Stand[0].Source)
                    {
                        pig.play();
                        pig = new pig();
                    }
                    else if (v.AnimationInfo.Frames_Stand[0].Source == MyFrames.TheSheep.Frames_Stand[0].Source)
                    {
                        sheep.play();
                        sheep = new sheep();
                    }
                    else if (v.AnimationInfo.Frames_Stand[0].Source == Frames.WolfSoldier[0].Source)
                    {
                        Affirmative.play();
                        Affirmative = new Affirmative();
                    }
                    else
                    {
                        Argh.play();
                        Argh = new Argh();
                    }



                    v.WalkTo(p.ToDouble());

                    // move in group formation
                    p.X += 16;
                    p.Y += 16;
                }
            };


            #endregion

            #region tutorial step 4



            #region CreateDialogAt
            var CreateDialogAt =
                new
            {
                //Dialog = default(IHTMLDiv),
                Content = default(IHTMLDiv),
                Width   = default(string)
            }
            .ToFunc(
                (Point pos, string width) =>
            {
                var f = new Form();

                f.Show();

                f.SizeTo(200, 200);


                // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151115/audio
                //f.PopupInsteadOfClosing();

                f.MoveTo(pos.X, pos.Y);
                //f.SizeTo(


                //var dialog = new IHTMLDiv();

                //dialog.style.SetLocation(pos.X, pos.Y);

                //dialog.style.backgroundColor = Color.Gray;
                //dialog.style.padding = "1px";

                //var caption = new IHTMLDiv().AttachTo(dialog);

                //caption.style.backgroundColor = Color.Blue;
                //caption.style.width = width;
                //caption.style.height = "0.5em";
                //caption.style.cursor = IStyle.CursorEnum.move;

                //var drag = new DragHelper(caption);

                //drag.Position = pos;
                //drag.Enabled = true;
                //drag.DragMove +=
                //    delegate
                //    {
                //        dialog.style.SetLocation(drag.Position.X, drag.Position.Y);
                //    };

                var _content = new IHTMLDiv().AttachTo(f.GetHTMLTargetContainer());

                _content.style.textAlign       = IStyle.TextAlignEnum.center;
                _content.style.backgroundColor = Color.White;
                _content.style.padding         = "1px";

                //dialog.AttachToDocument();

                return(new
                {     //Dialog = dialog,
                    Content = _content,
                    Width = width
                });
            }
                );
            #endregion

            #region dialog
            var toolbar = CreateDialogAt(new Point(2, 2), "8em");

            var combo = new IHTMLSelect();
            var build = new IHTMLButton();

            build.style.SetSize(72, 72);
            build.style.padding = "0px";

            var avatar = new IHTMLImage().AttachTo(build);
            var remove = new IHTMLButton("Remove");


            combo.AttachTo(toolbar.Content);
            new IHTMLBreak().AttachTo(toolbar.Content);
            build.AttachTo(toolbar.Content);
            new IHTMLBreak().AttachTo(toolbar.Content);
            remove.AttachTo(toolbar.Content);
            new IHTMLBreak().AttachTo(toolbar.Content);
            #endregion


            #region GetSelectedArsenal
            Func <DudeAnimationInfo> GetSelectedArsenal =
                () =>
            {
                if (arsenal.ContainsKey(combo[combo.selectedIndex].value))
                {
                    return(arsenal[combo[combo.selectedIndex].value]);
                }

                return(null);
            };
            #endregion

            Action Refresh =
                delegate
            {
                var i = GetSelectedArsenal();

                if (i != null)
                {
                    avatar.src = i.Images.Random().src;
                }
            };

            combo.Add(arsenal.Keys.ToArray());
            Refresh();

            combo.onchange +=
                delegate
            {
                Refresh();



                click.play();
                click = new click().AttachToDocument();
            };

            #region pending actor

            arena.MouseMove +=
                p =>
            {
                if (pending == null)
                {
                    return;
                }

                pending.TeleportTo(p.X, p.Y);
            };

            arena.Layers.User.oncontextmenu +=
                e =>
            {
                e.preventDefault();

                if (pending != null)
                {
                    pending.Control.Orphanize();
                    pending = null;
                    arena.ShowSelectionRectangle = true;

                    return;
                }

                actors.ForEach(
                    k => k.IsSelected = false
                    );
            };

            arena.SelectionClick +=
                (p, ev) =>
            {
                if (pending == null)
                {
                    return;
                }

                pending.TeleportTo(p.X, p.Y);

                actors.Add(pending);

                pending.IsHot = false;


                var x = GetSelectedArsenal();
                pending = CreateActor(x,
                                      new Point(
                                          Native.window.Width / 2,
                                          Native.window.Height / 2
                                          )
                                      );

                pending.IsHot = true;


                click.play();
                click = new click().AttachToDocument();
            };

            build.onclick +=
                delegate
            {
                if (pending != null)
                {
                    pending.Control.Orphanize();
                    pending = null;

                    return;
                }

                var x = GetSelectedArsenal();

                pending = CreateActor(x,
                                      new Point(
                                          Native.window.Width / 2,
                                          Native.window.Height / 2
                                          )
                                      );

                pending.IsHot = true;
                arena.ShowSelectionRectangle = false;

                click.play();
                click = new click().AttachToDocument();
            };
            #endregion

            remove.onclick +=
                delegate
            {
                foreach (var v in selection.ToArray())
                {
                    v.Control.Orphanize();
                    actors.Remove(v);
                }


                click.play();
                click = new click().AttachToDocument();
            };

            #endregion

            if (FilterToImpAndSoldier)
            {
            }
            else
            {
                #region step 6

                {
                    var n = "NPC";

                    arsenal.Add(n, MyFrames.NPC3);
                    combo.Add(n);
                }

                #endregion


                {
                    var n = "ManWithHorns";

                    arsenal.Add(n, MyFrames.ManWithHorns);
                    combo.Add(n);
                }
                {
                    var n = "TheSheep";

                    arsenal.Add(n, MyFrames.TheSheep);
                    combo.Add(n);
                }
                {
                    var n = "ThePig";

                    arsenal.Add(n, MyFrames.ThePig);
                    combo.Add(n);
                }

                {
                    var n = "TheCactus";

                    arsenal.Add(n, MyFrames.TheCactus);
                    combo.Add(n);
                }
            }


            if (BeforeAddingDebris != null)
            {
                BeforeAddingDebris(arena.Layers.Canvas);
            }

            3.Times(
                delegate()
            {
                new DebrisImages().Images.ForEach(
                    img => img.AttachTo(arena.Layers.Canvas).style.SetLocation(map.X.Random(), map.Y.Random())
                    );
            }
                );

            16.Times(
                delegate()
            {
                actors.Add(
                    CreateActor(arsenal.Random().Value, new Point(map.X.Random(), map.Y.Random()))
                    );
            }
                );
        }