Beispiel #1
0
    /// <summary>
    /// move figure downm generate new one and finish the game
    /// </summary>
    public void MoveFigureDown()
    {
        //move figure down by one
        var isFall = CurrentFigure.MoveDown(GameField);

        if (isFall == false)
        {
            //fill the field with the current figure
            foreach (var point in CurrentFigure.Position)
            {
                GameField[point.Y, point.X] = CurrentFigure.TypeOfCell;
            }

            //check for fill rows
            CheckForFilledRows();

            //change next and current figures, show it
            CurrentFigure = NextFigure;
            CurrentFigure.ChangeFigurePosition += InvokeRefresh;
            NextFigure = FigureGenerator.Generate(_startColumn);

            ChangedNextFigure.Invoke();
            ChangedGameField.Invoke();

            //check for end of game(can't insert figure in game field)
            var isEnd = CurrentFigure.IsCorrect(GameField);
            if (isEnd == false)
            {
                OnEndOfGame.Invoke();
            }
        }

        ChangedGameField.Invoke();
    }
Beispiel #2
0
    //--------------------------------------------------------------------------

    virtual protected void CreateBlock(int xOffset, int yOffset)
    {
        BaseBlock block = FigureGenerator.CreateBlock(GetBlockType());

        block.transform.parent = blockContainer.transform;
        blocks.Add(block);
        block.transform.localPosition = new Vector3(xOffset * TetrisConst.BRICK_SIZE, -yOffset * TetrisConst.BRICK_SIZE);
    }
Beispiel #3
0
    /// <summary>
    /// Start game
    /// </summary>
    public static void Start()
    {
        InitializeStaticComponents();

        Console.Clear();

        ShowStartGameField();

        //generate next figure before start game
        _nextFigure = FigureGenerator.Generate();
        Thread.Sleep(15);//because computer generate two the same figure without it

        //var cancellationTokenSource = MoveByKey();
        var cancellationTokenSource = AutoMoveDown();

        var isExistsDescendingFigure = true;

        while (true)
        {
            //refresh all game field because it can be incorrect print
            // ReFillAllGameField();


            var key = Console.ReadKey().Key;
            //Thread.Sleep(Constants.FigureFallDelay);
            lock (locker)
            {
                //isExistsDescendingFigure = MoveDown();
                isExistsDescendingFigure = Move(key);

                if (isExistsDescendingFigure == false)
                {
                    ResetgameFiledAfterFilledRows();
                    //for correct outfit of game field
                    //RewriteRightBorderGameField();
                    RewriteAllGameField();

                    //exit if imposible insert new figure
                    var isTheEnd = GenerateNewFigures();
                    if (isTheEnd)
                    {
                        //stop task(stop read key keys for move figure)
                        cancellationTokenSource.Cancel();

                        //exit from game
                        Exit.Leave();
                    }

                    //for refresh
                    isExistsDescendingFigure = true;
                }
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// Create first figures couple and show them
    /// </summary>
    public void Start()
    {
        NextFigure = FigureGenerator.Generate(_startColumn);
        Thread.Sleep(25); //because computer generate two the same figure without it
        CurrentFigure = FigureGenerator.Generate(_startColumn);

        CurrentFigure.ChangeFigurePosition += InvokeRefresh;

        //invoke
        ChangedGameField.Invoke();
        ChangedNextFigure.Invoke();
    }
Beispiel #5
0
    //**************************************************************************
    // Spawning

    public void SpawnFigure(System.Type figureType)
    {
        if (!enabled)
        {
            return;
        }

        currentFigure = FigureGenerator.CreateFigure(figureType);
        currentFigure.transform.parent = transform;
        currentFigure.fieldData        = fieldData;
        currentFigure.xPosition        = (int)START_POSITION.x;
        currentFigure.yPosition        = (int)START_POSITION.y;
    }
    //--------------------------------------------------------------------------

    private void CreateFigure(System.Type figureType)
    {
        BaseFigure figure = FigureGenerator.CreateFigure(figureType);

        figure.visualOnly              = true;
        nextFigure                     = figure.gameObject;
        figure.transform.parent        = container;
        figure.transform.localPosition = Vector3.zero;

        if (scoreBonusText.gameObject.activeInHierarchy)
        {
            nextFigure.SetActive(false);
        }
    }
Beispiel #7
0
    /// <summary>
    /// generate new figure insert the one in game and show next figure
    /// </summary>
    /// <returns>true if the figure can not be inserted</returns>
    private static bool GenerateNewFigures()
    {
        CleanAfterDisplayForNextFigure();

        //generate and insert to game current figure
        _currentFigure = _nextFigure;
        _currentFigure.InsertToGame(out bool canBeFilled);

        if (canBeFilled == false)
        {
            return(true);
        }

        //generate and show next figure
        _nextFigure = FigureGenerator.Generate();
        _nextFigure.Show();

        return(false);
    }
Beispiel #8
0
        static void Main(string[] args)
        {
            DrawerProvider.Drawer.InitField();

            var drawer = new ConsoleDrawer();

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

            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);
                }
            }
        }