예제 #1
0
        static void Main(string[] args)
        {
            iIOmethod ioMethod = new ConsoleIO();

            Console.WriteLine("1. Circle");
            iFigureFactory factory = new CircleFactory(ioMethod);
            iFigure        fig     = factory.create();

            Console.WriteLine("Circle square = " + fig.getSquare());

            Console.WriteLine("2. Triangle");
            factory = new TriangleFactory(ioMethod);
            fig     = factory.create();
            Console.WriteLine("Triangle square = " + fig.getSquare());
            Triangle triangle = fig as Triangle;

            if (triangle != null)
            {
                Console.WriteLine("Is this a right triangle? " + (triangle.isRightAngle() ? "Yes!!" : "No!"));
            }


            Console.WriteLine();
            Console.WriteLine("Happy end! Press a key..");
            Console.ReadKey();
        }
예제 #2
0
 public void StartGame()
 {
     ClearField();
     NextFigure    = builder.BuildRandom();
     CurrentFigure = builder.BuildRandom();
     Cells         = AttemptFigure(CurrentFigure.Cells, StaticCells);
     StateHasChanged();
     // timer.Start();
 }
예제 #3
0
        public iFigure BuildRandom()
        {
            int rnd = new Random().Next(0, 4);

            switch (rnd)
            {
            case 0: Figure = new BoxFigure(cellSize);   break;

            case 1: Figure = new StickFigure(cellSize); break;

            case 2: Figure = new CornLFigure(cellSize); break;

            case 3: Figure = new CornRFigure(cellSize); break;

            case 4: Figure = new CapFigure(cellSize);   break;

            default: break;
            }
            return(Figure);
        }
예제 #4
0
        /// <summary>
        /// true - success
        /// false - end game
        /// </summary>
        /// <param name="figure"></param>
        /// <returns></returns>
        public bool FreeFall(iFigure figure)
        {
            var movedFig = CurrentFigure.Move(0, 1);

            if (IsFigureInButtom(movedFig) || IsCollisionOldCells(movedFig, StaticCells)) //on floor
            {
                StaticCells   = AttemptFigure(CurrentFigure.Cells, StaticCells);          //объединение фигуры и поля
                CurrentFigure = NextFigure;
                NextFigure    = builder.BuildRandom();
                Cells         = AttemptFigure(CurrentFigure.Cells, StaticCells);
                if (IsCollisionOldCells(CurrentFigure.Cells, StaticCells))
                {
                    timer.Stop();
                    return(false); //Game over
                }
            }
            else
            {
                CurrentFigure.Cells = movedFig;//отображаем сдвинутую фигуру
                Cells = AttemptFigure(CurrentFigure.Cells, StaticCells);
            }
            return(true);
        }
예제 #5
0
 public void DrawFigure(iFigure figure)
 {
 }