Exemple #1
0
        // action methods
        private void DoActionSetToTop()
        {
            Debug.Assert(this.State == TetrisState.AtTop);

            // create new tetrimino
            this.curr = this.AttachTetrimino();

            if (this.curr.CanSetToTop())
            {
                this.curr.SetToTop();
                this.State = TetrisState.Normal;
            }
            else
            {
                this.State = TetrisState.GameOver;
            }
        }
Exemple #2
0
        // tetrimino management
        private ITetrimino AttachTetrimino()
        {
            // choose tetrimino by random
            int which = this.random.Next() % MaxTetriminos;

            // or do not :-) choose tetrimino by random (just for testing)
            which = this.testTetriCounter++;

            if (which % MaxTetriminos == 0)
            {
                this.curr = new Tetrimino_I(this.board);
            }
            else if (which % MaxTetriminos == 1)
            {
                this.curr = new Tetrimino_J(this.board);
            }
            else if (which % MaxTetriminos == 2)
            {
                this.curr = new Tetrimino_L(this.board);
            }
            else if (which % MaxTetriminos == 3)
            {
                this.curr = new Tetrimino_O(this.board);
            }
            else if (which % MaxTetriminos == 4)
            {
                this.curr = new Tetrimino_S(this.board);
            }
            else if (which % MaxTetriminos == 5)
            {
                this.curr = new Tetrimino_T(this.board);
            }
            else if (which % MaxTetriminos == 6)
            {
                this.curr = new Tetrimino_Z(this.board);
            }

            return(this.curr);
        }
Exemple #3
0
 private void DetachTetrimino()
 {
     this.curr = null;
 }
        private static IReadOnlyList <MemoizedBlock> GetMemoizedBlocksForTetriminoNode(TetriminoNode node,
                                                                                       ITetrimino tetrimino)
        {
            var memoizedBlocks = new List <MemoizedBlock>();

            foreach (var block in tetrimino.Blocks)
            {
                var newBlock = new MemoizedBlock
                {
                    Position = block.Position,
                    FilledBy = block.FilledBy,
                    Owner    = node
                };
                memoizedBlocks.Add(newBlock);
            }

            return(memoizedBlocks);
        }