Example #1
0
        //Checks for any Trias
        private void CheckForTria()
        {
            foreach (Tile tile in CurrentPieces)
            {
                for (int i = -1; i < 2; i++)
                {
                    for (int j = -1; j < 1; j++)
                    {
                        if (i != 0 || j != 0)
                        {
                            Tuple <int, int> position = new Tuple <int, int>(tile.Position.Item1 + i, tile.Position.Item2 + j);
                            int ConsecutivePieces     = 1;

                            while (GetPieceAtPosition(position, CurrentPieces) != null)
                            {
                                position = new Tuple <int, int>(position.Item1 + i, position.Item2 + j);
                                ConsecutivePieces++;
                            }
                            if (ConsecutivePieces == 3)
                            {
                                Tuple <int, int> position1  = new Tuple <int, int>(tile.Position.Item1 - i, tile.Position.Item2 - j);
                                Tuple <int, int> position2  = new Tuple <int, int>(tile.Position.Item1 + (3 * i), tile.Position.Item2 + (3 * j));
                                Tile             t1         = GetPieceAtPosition(position1, AllTiles);
                                Tile             t2         = GetPieceAtPosition(position2, AllTiles);
                                bool             condition1 = (t1 != null && (!t1.IsTaken || t1.PieceColor == CurrentPiece.PieceColor));
                                bool             condition2 = (t2 != null && (!t2.IsTaken || t2.PieceColor == CurrentPiece.PieceColor));

                                if (condition1 && condition2)
                                {
                                    Tria tria = new Tria()
                                    {
                                        StartingPoint = tile.Position,
                                        Direction     = new Tuple <int, int>(i, j)
                                    };

                                    CurrentPlayer.Alerts = $"{CurrentPlayer.Name} has a Tria!";
                                    foreach (Tria t in CurrentPlayer.Trias)
                                    {
                                        if (t.Equals(tria))
                                        {
                                            tria = null;
                                        }
                                    }

                                    if (tria != null)
                                    {
                                        CurrentPlayer.Trias.Add(tria);
                                    }
                                }
                            }

                            if (ConsecutivePieces == 5)
                            {
                                window.GameOver(CurrentPlayer);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public class Tria : Poly { }            // Производный класс

        static void TestAsIs()
        {
            Console.Clear();

            Tria tria  = new Tria();
            Poly poly1 = new Poly(),
                 poly2 = tria;                          // poly2 ссылается на объект производного класса

            Console.WriteLine("\t\tTest 'as' operator");

            Poly p = poly1 as Poly;
            Tria t = poly1 as Tria;             // poly1 ссылается на объект базового класса

            Console.Write(
                "\npoly1 " + (p != null ? "is" : "is not") + " a Poly" +
                "\npoly1 " + (t != null ? "is" : "is not") + " a Tria");

            p = poly2 as Poly;
            t = poly2 as Tria;
            Console.Write(
                "\npoly2 " + (p != null ? "is" : "is not") + " a Poly" +
                "\npoly2 " + (t != null ? "is" : "is not") + " a Tria");

            Console.WriteLine("\n\n\t\tTest 'is' operator");
            Console.Write(
                "\npoly1 " + (poly1 is Poly ? "is" : "is not") + " a Poly" +
                "\npoly1 " + (poly1 is Tria ? "is" : "is not") + " a Tria" +
                "\npoly2 " + (poly2 is Poly ? "is" : "is not") + " a Poly" +
                "\npoly2 " + (poly2 is Tria ? "is" : "is not") + " a Tria");

            Console.WriteLine("\n\t\tPress any key to go to main menu\n");
            Console.ReadKey(true);
        }
Example #3
0
class ShapeFactory {//lsp
    public Shape getShape(int Type, params double[] list)
    {
        Shape shape = null;

        if (Type == 1)
        {
            shape = new Rect(list[0], list[1]);
        }
        else
        {
            shape = new Tria(list[0], list[1], list[2]);
        }
        if (shape.isShape() == false)
        {
            throw (new NotShapeException("Not a Shape"));
        }
        return(shape);
    }
Example #4
0
    static void Main()
    {
        Rect a = new Rect(2.2, 3.3);
        Tria b = new Tria(1, 1, 1.414);

        if (a.getArea() > 0)
        {
            Console.WriteLine(a.getArea());
        }
        else
        {
            Console.WriteLine("Wrong Rect");
        }
        if (b.getArea() > 0)
        {
            Console.WriteLine(b.getArea());
        }
        else
        {
            Console.WriteLine("Wrong Tria");
        }
    }