Esempio n. 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();
    }
Esempio n. 2
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();
    }