Exemple #1
0
        internal ITetromino CreateFromStyle(TetrominoStyle style)
        {
            switch (style)
            {
            case TetrominoStyle.Straight:
                return(new Straight(this.GameBoard));

            case TetrominoStyle.TShaped:
                return(new TShaped(this.GameBoard));

            case TetrominoStyle.LeftZigZag:
                return(new LeftZigZag(this.GameBoard));

            case TetrominoStyle.RightZigZag:
                return(new RightZigZag(this.GameBoard));

            case TetrominoStyle.LShaped:
                return(new LShaped(this.GameBoard));

            case TetrominoStyle.ReverseLShaped:
                return(new ReverseLShaped(this.GameBoard));

            case TetrominoStyle.Block:
            default:
                return(new Block(this.GameBoard));
            }
        }
 public Tetromino CreateFromStyle(TetrominoStyle style, Grid grid)
 {
     return(style switch
     {
         TetrominoStyle.Block => new Block(grid),
         TetrominoStyle.Straight => new Straight(grid),
         TetrominoStyle.TShaped => new TShaped(grid),
         TetrominoStyle.LeftZigZag => new LeftZigZag(grid),
         TetrominoStyle.RightZigZag => new RightZigZag(grid),
         TetrominoStyle.LShaped => new LShaped(grid),
         TetrominoStyle.ReverseLShaped => new ReverseLShaped(grid),
         _ => new Block(grid),
     });
Exemple #3
0
        public async Task Start()
        {
            //set the state to playing
            this.State = GameState.Playing;

            Console.WriteLine("game start");

            //Generate the styles of the first three tetrominos that will be dropped
            NextStyle       = NextTetrominoStyle();
            SecondNextStyle = NextTetrominoStyle(NextStyle);
            ThirdNextStyle  = NextTetrominoStyle(NextStyle, SecondNextStyle);

            //game loop
            while (this.State != GameState.GameOver)
            {
                if (this.State == GameState.Playing)
                {
                    //Create the next tetromino to be dropped from the already-determined nextStyle,
                    //and move the styles "up" in line
                    CurrentTetromino = CreateFromStyle(NextStyle);

                    Console.WriteLine("CurrentTetromino=" + CurrentTetromino.Style);

                    NextStyle       = SecondNextStyle;
                    SecondNextStyle = ThirdNextStyle;
                    ThirdNextStyle  = NextTetrominoStyle(CurrentTetromino.Style, NextStyle, SecondNextStyle);

                    //Update the display
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Game)));

                    //Run the current tetromino until it can't move anymore
                    await RunCurrentTetromino();

                    //If any rows are filled, remove them from the board
                    await ClearCompleteRows();

                    //If the score is high enough, move the user to a new level
                    //LevelChange();

                    //evaluate the gameover condition
                    if (GameBoard.HasAnyTetrominoInRow(GameBoard.Rows - 1))
                    {
                        this.State = GameState.GameOver;
                    }
                }
                //delay
                await Delay(150);
            }
            Console.WriteLine("game over");
        }