示例#1
0
文件: Card.cs 项目: owogames/ruetobas
        public static int CheckPlacement(int x, int y, int ID, int rot)
        {
            if (Logic.cards[ID].cardType != CardType.Tunnel)
            {
                return(4);
            }
            if (x < 1 || x > 17 || y < 1 || y > 13)
            {
                return(-1);
            }
            if (Logic.cards[Logic.map[x, y].ID].cardType != CardType.Empty)
            {
                return(3);
            }

            Point[] placements     = { new Point(0, -1), new Point(1, 0), new Point(0, 1), new Point(-1, 0) };
            bool    any_valid_card = false;
            Tunnel  center         = (Tunnel)Logic.cards[ID];

            for (int i = 0; i < 4; i++)
            {
                PlacedCard current = Logic.map[x + placements[i].X, y + placements[i].Y];
                if (current.ID == 45 || current.ID == 0)
                {
                    continue;
                }
                else
                {
                    Tunnel currentTL = (Tunnel)Logic.cards[current.ID];
                    if (center.GetEntrance(i + rot * 2) != currentTL.GetEntrance(i + (current.rotation - 1) * 2))
                    {
                        return(2);
                    }
                    else if (center.GetEntrance(i + rot * 2) && reach[x + placements[i].X, y + placements[i].Y, (i + 2) % 4])
                    {
                        any_valid_card = true;
                    }
                }
            }
            //    0       0
            //  3 C 1 - 3 T 1  //no rotation
            //    2       2

            if (any_valid_card == false)
            {
                return(1);
            }
            return(0);
            //0 - OK
            //1 - karta musi mieć połączenie z początkiem
            //2 - tunele wychodzące z karty muszą pasować do sąsiednich kart
            //3 - karta musi być położona na pustym polu
            //4 - karta musi tunelem
        }
示例#2
0
文件: Card.cs 项目: owogames/ruetobas
        public static Card ParseString(string line, int ID) //linijka z pliku oraz numer linijki (czyli numer karty)
        {
            string[] words = line.Split(' ');
            int      size  = words.Length;

            if (words[0] == "T")
            {
                TunnelObject objekt = (TunnelObject)int.Parse(words[size - 1]);
                Tunnel       output = new Tunnel(Logic.cardTexture[ID], ID, objekt);
                for (int i = 0; i < 4; i++)
                {
                    output.entrance[i] = Convert.ToBoolean(int.Parse(words[i + 1]));
                }
                for (int i = 0; i < 16; i++)
                {
                    output.graph[i / 4, i % 4] = Convert.ToBoolean(int.Parse(words[i + 5]));
                }
                return(output);
            }
            else if (words[0] == "B")
            {
                BuffCard output = new BuffCard(Logic.cardTexture[ID], ID, (Buff)int.Parse(words[1]));
                return(output);
            }
            else if (words[0] == "D")
            {
                DebuffCard output = new DebuffCard(Logic.cardTexture[ID], ID, (Buff)int.Parse(words[1]), (Buff)int.Parse(words[2]));
                return(output);
            }
            else if (words[0] == "M")
            {
                MapCard output = new MapCard(Logic.cardTexture[ID], ID);
                return(output);
            }
            else if (words[0] == "C")
            {
                RemoveCard output = new RemoveCard(Logic.cardTexture[ID], ID);
                return(output);
            }
            return(null);
        }
示例#3
0
文件: Card.cs 项目: owogames/ruetobas
        public static void RecalculateReach()
        {
            Queue <Tuple <int, int, int> > q = new Queue <Tuple <int, int, int> >();

            q.Enqueue(new Tuple <int, int, int>(5, 7, 0));
            for (int i = 0; i < 19; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    for (int ij = 0; ij < 4; ij++)
                    {
                        reach[i, j, ij] = false;
                    }
                }
            }
            reach[5, 7, 0] = true;

            while (q.Count > 0)
            {
                Tuple <int, int, int> T = q.Dequeue();
                int x = T.Item1;
                int y = T.Item2;
                int e = T.Item3;
                if (x <= 0)
                {
                    continue;
                }
                if (x >= 18)
                {
                    continue;
                }
                if (y <= 0)
                {
                    continue;
                }
                if (y >= 14)
                {
                    continue;
                }
                Tunnel t1 = (Tunnel)Logic.cards[Logic.map[x, y].ID];
                bool   r1 = (Logic.map[x, y].rotation == 1);
                for (int i = 0; i < 4; i++)
                {
                    if (t1.IsConnected(i, e, r1) && !reach[x, y, i])
                    {
                        reach[x, y, i] = true;
                        q.Enqueue(new Tuple <int, int, int>(x, y, i));
                    }
                }

                int        xn       = e == 0 ? x : (e == 1 ? x + 1 : (e == 2 ? x : x - 1));
                int        yn       = e == 0 ? y - 1 : (e == 1 ? y : (e == 2 ? y + 1 : y));
                PlacedCard neighbor = Logic.map[xn, yn];
                Tunnel     t2       = (Tunnel)Logic.cards[neighbor.ID];
                bool       r2       = (neighbor.rotation == 1);
                if (t1.GetEntrance(e, r1) && t2.GetEntrance(e + 2, r2) && !reach[xn, yn, (e + 2) % 4])
                {
                    reach[xn, yn, (e + 2) % 4] = true;
                    q.Enqueue(new Tuple <int, int, int>(xn, yn, (e + 2) % 4));
                }
            }

            /*for (int j = 1; j <= 13; j++)
             * {
             *  for (int i = 1; i <= 17; i++)
             *  {
             *      for (int ij = 0; ij < 4; ij++)
             *          Console.Write(Convert.ToInt32(reach[i, j, ij]));
             *      Console.Write(" ");
             *  }
             *  Console.WriteLine();
             * }*/
        }