Ejemplo n.º 1
0
 public static void Link(Pice pice1, LinkDirectory directory, Pice pice2)
 {
     // set pice1
     {
         var info = new Linking();
         info.directory = directory;
         info.pice      = pice2;
         pice1.linkingList.Add(info);
         if (pice1.linkingList.Count == 1)
         {
             pice1.FlashAsLink();
         }
     }
     // set pice2
     {
         var info = new Linking();
         info.directory = LinkDirectoryUtil.Reverse(directory);
         info.pice      = pice1;
         pice2.linkingList.Add(info);
         if (pice2.linkingList.Count == 1)
         {
             pice2.FlashAsLink();
         }
     }
 }
Ejemplo n.º 2
0
    public static void TryLink(Pice pice1, LinkDirectory directory, Pice pice2)
    {
        // 如果任一 pice 不在 board 上,则不予处理
        if (pice1.owner != PiceOwner.Board || pice2.owner != PiceOwner.Board)
        {
            return;
        }

        // 如果 pice1 的指定方向上已经连结,则不予处理
        var alreadyLinked = false;

        pice1.linkingList.ForEach(info => {
            if (info.directory == directory)
            {
                alreadyLinked = true;
            }
        });
        if (alreadyLinked)
        {
            return;
        }

        // 连接两个 pice
        Link(pice1, directory, pice2);
    }
Ejemplo n.º 3
0
    public static LinkDirectory Reverse(LinkDirectory directory)
    {
        switch (directory)
        {
        case LinkDirectory.Left:
            return(LinkDirectory.Right);

        case LinkDirectory.Right:
            return(LinkDirectory.Left);

        case LinkDirectory.Top:
            return(LinkDirectory.Bottom);

        case LinkDirectory.Bottom:
            return(LinkDirectory.Top);

        default:
            throw new Exception("unsupport directory: " + directory);
        }
    }