コード例 #1
0
        // c'tor
        public TetrisModelImpl()
        {
            Debug.WriteLine("c'tor TetrisModel");

            this.random = new Random();

            this.testTetriCounter = 0;

            this.board = new TetrisBoard(this.NumRows, this.NumColumns);
            this.board.BoardChanged   += this.TetrisBoard_Changed;
            this.board.LinesCompleted += this.TetrisBoard_LinesCompleted;

            this.state     = TetrisState.Idle;
            this.gameState = GameState.GameIdle;

            this.viewCellList = new ViewCellList();

            // initialize score management
            this.level = 1;
            this.lines = 0;
            this.score = 0;

            // setup timer
            this.timerMode              = TimerMode.Normal;
            this.maxIntervalCounter     = MaxIntervalCounter;
            this.currentIntervalCounter = 0;
        }
コード例 #2
0
        public void MoveNonEmptyRowsDown()
        {
            ViewCellList list = new ViewCellList();

            // compute number of complete rows - beginning from the bottom
            int completeRows = 0;

            for (int row = this.numRows - 1; row >= 0; row--)
            {
                if (this.IsRowComplete(row))
                {
                    completeRows++;
                }
                else
                {
                    break;
                }
            }

            // calculate number of rows to move
            int startRow = this.numRows - 1;

            while (!this.IsRowEmpty(startRow))
            {
                startRow--;
            }

            for (int i = this.numRows - 2; i >= startRow; i--)
            {
                this.CopySingleRow(list, i);
            }

            this.OnBoardChanged(list);
            this.OnLinesCompleted(completeRows);
        }
コード例 #3
0
        // public interface
        public void Clear()
        {
            // reset internal state of board
            for (int i = 0; i < this.numRows; i++)
            {
                for (int j = 0; j < this.numColumns; j++)
                {
                    this.board[i, j].Color = CellColor.LightGray;
                    this.board[i, j].State = CellState.Free;
                }
            }

            // update view
            ViewCellList list = new ViewCellList();

            for (int i = 0; i < this.numRows; i++)
            {
                for (int j = 0; j < this.numColumns; j++)
                {
                    ViewCell cell = new ViewCell();
                    cell.Color = CellColor.LightGray;
                    cell.Point = new CellPoint()
                    {
                        X = j, Y = i
                    };
                    list.Add(cell);
                }
            }
            this.OnBoardChanged(list);
        }
コード例 #4
0
 private void OnBoardChanged(ViewCellList list)
 {
     if (this.BoardChanged != null)
     {
         this.BoardChanged.Invoke(list);
     }
 }
コード例 #5
0
ファイル: Tetrimino.cs プロジェクト: peterloos/Xamarin_Tetris
        // public interface (movement specific methods)
        public void SetToTop()
        {
            this.Set();

            ViewCellList list = new ViewCellList();

            this.UpdateModifiedCellList(list, this.color);
            this.board.PostChanges(list);
        }
コード例 #6
0
ファイル: Tetrimino.cs プロジェクト: peterloos/Xamarin_Tetris
        public void Rotate()
        {
            ViewCellList list = new ViewCellList();

            this.Delete();
            this.UpdateModifiedCellList(list, CellColor.LightGray);
            this.RotateTetrimino();
            this.Set();
            this.UpdateModifiedCellList(list, this.color);
            this.board.PostChanges(list);
        }
コード例 #7
0
ファイル: Tetrimino.cs プロジェクト: peterloos/Xamarin_Tetris
        public void MoveRight()
        {
            ViewCellList list = new ViewCellList();

            this.Delete();
            this.UpdateModifiedCellList(list, CellColor.LightGray);
            this.MoveAnchorRight();
            this.Set();
            this.UpdateModifiedCellList(list, this.color);
            this.board.PostChanges(list);
        }
コード例 #8
0
ファイル: Tetrimino.cs プロジェクト: peterloos/Xamarin_Tetris
        public bool MoveDown()
        {
            if (!this.CanMoveDown())
            {
                return(false);
            }

            ViewCellList list = new ViewCellList();

            this.Delete();
            this.UpdateModifiedCellList(list, CellColor.LightGray);
            this.MoveAnchorDown();
            this.Set();
            this.UpdateModifiedCellList(list, this.color);
            this.board.PostChanges(list);

            return(true);
        }
コード例 #9
0
 public override void UpdateModifiedCellList(ViewCellList list, CellColor color)
 {
     list.Add(new ViewCell(color, new CellPoint()
     {
         X = this.anchorPoint.X, Y = this.anchorPoint.Y
     }));
     list.Add(new ViewCell(color, new CellPoint()
     {
         X = this.anchorPoint.X + 1, Y = this.anchorPoint.Y
     }));
     list.Add(new ViewCell(color, new CellPoint()
     {
         X = this.anchorPoint.X, Y = this.anchorPoint.Y + 1
     }));
     list.Add(new ViewCell(color, new CellPoint()
     {
         X = this.anchorPoint.X + 1, Y = this.anchorPoint.Y + 1
     }));
 }
コード例 #10
0
        private void CopySingleRow(ViewCellList list, int row)
        {
            for (int j = 0; j < this.numColumns; j++)
            {
                // create cell to update view
                ViewCell cell = new ViewCell();
                cell.Color = this.board[row, j].Color;
                cell.Point = new CellPoint()
                {
                    X = j, Y = row + 1
                };
                list.Add(cell);

                // finally copy block one row down ...
                // Note: TetrisCell is a 'struct', so '=' works fine --
                // In case of a reference type: Clone needed (deep copy) !!!
                this.board[row + 1, j] = this.board[row, j];
            }
        }
コード例 #11
0
 // private helper methods
 private void TetrisBoard_Changed(ViewCellList list)
 {
     this.BoardStateChanges = list;
 }
コード例 #12
0
ファイル: Tetrimino.cs プロジェクト: peterloos/Xamarin_Tetris
 public abstract void UpdateModifiedCellList(ViewCellList list, CellColor color);
コード例 #13
0
 public override void UpdateModifiedCellList(ViewCellList list, CellColor color)
 {
     if (this.rotation == RotationAngle.Degrees_0)
     {
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X - 1, Y = this.anchorPoint.Y + 1
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X, Y = this.anchorPoint.Y + 1
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X, Y = this.anchorPoint.Y
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X + 1, Y = this.anchorPoint.Y
         }));
     }
     else if (this.rotation == RotationAngle.Degrees_90)
     {
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X - 1, Y = this.anchorPoint.Y - 1
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X - 1, Y = this.anchorPoint.Y
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X, Y = this.anchorPoint.Y
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X, Y = this.anchorPoint.Y + 1
         }));
     }
     else if (this.rotation == RotationAngle.Degrees_180)
     {
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X - 1, Y = this.anchorPoint.Y
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X, Y = this.anchorPoint.Y
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X, Y = this.anchorPoint.Y - 1
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X + 1, Y = this.anchorPoint.Y - 1
         }));
     }
     else if (this.rotation == RotationAngle.Degrees_270)
     {
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X, Y = this.anchorPoint.Y - 1
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X, Y = this.anchorPoint.Y
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X + 1, Y = this.anchorPoint.Y
         }));
         list.Add(new ViewCell(color, new CellPoint()
         {
             X = this.anchorPoint.X + 1, Y = this.anchorPoint.Y + 1
         }));
     }
 }
コード例 #14
0
 public void PostChanges(ViewCellList list)
 {
     this.OnBoardChanged(list);
 }