Ejemplo n.º 1
0
 protected override bool Resolve(Trouble trouble)
 {
     if (trouble.Difficulty % 2 == 1)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
        public void SupportTrouble(Trouble trouble)
        {
            /*递归*/

            //if (Resolve(trouble))
            //{
            //    Done(trouble);
            //}
            //else if(Next != null)
            //{
            //    Next.SupportTrouble(trouble);
            //}
            //else
            //{
            //    Fail(trouble);
            //}


            /*迭代*/
            Support current = this;

            do
            {
                if (current.Resolve(trouble))
                {
                    current.Done(trouble);
                    break;
                }
                else if (current.Next != null)
                {
                    current = current.Next;
                }
                else
                {
                    current.Fail(trouble);
                    break;
                }
            } while (true);
        }
Ejemplo n.º 3
0
 protected void Fail(Trouble trouble)
 {
     Console.WriteLine(trouble.ToString() + " cannot be resolved.");
 }
Ejemplo n.º 4
0
 protected void Done(Trouble trouble)
 {
     Console.WriteLine(trouble.ToString() + " is resolved by " + ToString() + ".");
 }
Ejemplo n.º 5
0
 protected abstract bool Resolve(Trouble trouble);
Ejemplo n.º 6
0
 protected override bool Resolve(Trouble trouble)
 {
     return(false);
 }