예제 #1
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Field.Width, Field.Hight);
            // что бы убрать полосы прокрутки
            Console.SetBufferSize(Field.Width, Field.Hight);

            // Field.Width = 20;

            _generator    = new FigureGenerator(Field.Width / 2, 0, Drawer.DEFAULT_SYMBOL);
            currentFigure = _generator.GetNewFigure();
            SetTimer();

            while (true)
            {
                // Если была нажата какая либо клавиша
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    Monitor.Enter(_lockObject);
                    var result = HandleKey(currentFigure, key);
                    ProcessResult(result, ref currentFigure);
                    Monitor.Exit(_lockObject);
                }
            }
        }
예제 #2
0
        private bool IsMoves()
        {
            var figures = FigureGenerator.GetCurrentFigures();

            for (var y = 0; y < Field.Heigh; y++)
            {
                for (var x = 0; x < Field.Width; x++)
                {
                    var cellPos = new Vector2Int(x, y);
                    if (Field.IsCellBusy(cellPos))
                    {
                        continue;
                    }

                    foreach (var f in figures)
                    {
                        if (Field.CanSetFigureToField(f, cellPos))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #3
0
        private static void Init()
        {
            #region console
            Console.ForegroundColor = ConsoleColor.White;
            #endregion // console

            #region game state

            isOver         = false;
            isDrawRequired = true;
            rotateLeft     = false;
            rotateRight    = false;

            #endregion // game state

            #region time
            timeToMove   = 0;
            estimatedFps = 60;
            timePerFrame = 1.0 / estimatedFps;
            timeElapsedSinceLastStatisticsUpdate = 0.0;
            timeToUpdateStatistics   = 0.7;
            timeElapsedSinceLastMove = 0;

            #endregion // time

            #region Game field initialization
            do
            {
                Console.WriteLine("Field Width: ");
            } while (!int.TryParse(Console.ReadLine(), out cupWidth));

            do
            {
                Console.WriteLine("Field Height: ");
            } while (!int.TryParse(Console.ReadLine(), out cupHeight));

            do
            {
                Console.WriteLine("Fall Speed (squares per minute): ");
            } while (!int.TryParse(Console.ReadLine(), out fallSpeed));

            timeToMove = 60.0 / fallSpeed;

            leftMarginWidth = 20;
            field           = new Field(cupWidth, cupHeight, leftMarginWidth);
            #endregion

            #region layout

            Console.CursorVisible = false;
            nextFigureX           = field.Width + 2 + 5;
            nextFigureY           = 1;

            #endregion // layout

            nextFigure          = FigureGenerator.GetRandomFigure(nextFigureX, nextFigureY, leftMarginWidth);
            nextFigure.Stopped += FigureStopped;
            SwapFigures();
        }
예제 #4
0
        private static void SwapFigures()
        {
            currentFigure   = nextFigure;
            currentFigure.X = field.Width / 2;
            currentFigure.Y = 0;

            nextFigure          = FigureGenerator.GetRandomFigure(nextFigureX, nextFigureY, leftMarginWidth);
            nextFigure.Stopped += FigureStopped;
        }
예제 #5
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Field.Width, Field.HEIGHT);
            Console.SetBufferSize(Field.Width, Field.HEIGHT);

            FigureGenerator generator     = new FigureGenerator(20, 0, '*');
            Figure          currentFigure = generator.GetNewFigure();

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    HandleKey(currentFigure, key);
                }
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: Chivirda/Tetris
        static void Main(string[] args)
        {
            Console.SetWindowSize(Field.Width, Field.Height);
            Console.SetBufferSize(Field.Width, Field.Height);

            figureGenerator = new FigureGenerator('#');
            Figure currentFigure = figureGenerator.GetNewFigure();

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    var key    = Console.ReadKey();
                    var result = HandleKey(currentFigure, key.Key);
                    ProcessResult(result, ref currentFigure);
                }
            }
        }
예제 #7
0
        public override void Execute()
        {
            if (Figure == null)
            {
                return;
            }

            Figure.OnDrop();

            if (Field.SetFigure(Figure))
            {
                AudioManager.PlayOnce("Drop");
                FigureGenerator.UseFigure(Figure);
                Figure.Despawn();
            }
            else
            {
                Figure.ReturnToStartPosition();
            }
        }
예제 #8
0
        static void Main(string[] args)
        {
            DrawerProvider.Drawer.InitField();

            generator     = new FigureGenerator(Field.Width / 2, 0);
            currentFigure = generator.GetNewFigure();
            SetTimer();

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    Monitor.Enter(_lockedObject);
                    var result = HandleKey(currentFigure, key.Key);
                    ProcessResult(result, ref currentFigure);
                    Monitor.Exit(_lockedObject);
                }
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Field.Width, Field.Height);
            Console.SetBufferSize(Field.Width, Field.Height);

            generator = new FigureGenerator(Field.Width / 2, 0, Drawer.DEFAULT_SYMBOL);
            Figure currentFigure = generator.GetNewFigure();


            while (true)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    Monitor.Enter(_lockObject);
                    var result = HandleKey(currentFigure, key.Key);
                    ProcessResult(result, ref currentFigure);
                    Monitor.Exit(_lockObject);
                }
            }
        }