Exemplo n.º 1
0
        /// <summary>
        /// Inserts the Tetromino to the field, and indicates success if it could or couldn't
        /// </summary>
        /// <param name="tetromino">The tetromino to insert</param>
        /// <param name="point">The point (in blocks) on the playfield to insert the tetromino at</param>
        /// <returns>True if the tetromino can be inserted, false otherwise</returns>
        public bool InsertTetrominoAt(Tetromino tetromino, Point point)
        {
            if (IsTetrominoInsertableAt(tetromino, point))
            {
                SetMinos(tetromino, point);
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// A draw method what draws a specific tetromino as if it were in the grid. This is done to reuse code for drawing the individual
        /// Tetromino blocks. This is for a tetromino that is not yet inserted.
        /// </summary>
        /// <param name="batch">The sprite batch instance to draw with</param>
        /// <param name="position">The position (in blocks) of the point on the field to do its initial draw</param>
        /// <param name="tetromino">The tetromino to mock draw in the field</param>
        /// <param name="isGhost">Boolean indicating whether or not to draw the tetromino as a ghost</param>
        public void DrawTetromino(SpriteBatch batch, Point position, Tetromino tetromino, bool isGhost)
        {
            float colorTransparency = isGhost ? GhostTetrominoAlphaFactor : 1.0f;

            for (int i = 0; i < 4; i++)
            {
                Point mino           = tetromino[i];
                Point translatedMino = new Point(position.X + mino.X, position.Y + mino.Y);

                this.DrawMino(batch.GraphicsDevice.Viewport, batch, translatedMino, colorTransparency, tetromino.TetrominoType);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the individual minos of a tetromino to the field. At this point, the Tetromino object is no longer needed.
        /// </summary>
        /// <param name="tetromino">The tetromino being inserted into the field</param>
        /// <param name="insertPosition">The position for the tetromino to be inserted</param>
        private void SetMinos(Tetromino tetromino, Point insertPosition)
        {
            for (int i = 0; i < 4; i++)
            {
                Point minoPosition = tetromino[i];

                Point translatedMino = new Point(insertPosition.X + minoPosition.X, insertPosition.Y + minoPosition.Y);
                fieldLines[translatedMino.Y][translatedMino.X] = tetromino.TetrominoType;

                surfaceHeights[translatedMino.X] = Math.Max(height - translatedMino.Y, surfaceHeights[translatedMino.X]);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks to see if a tetromino can be inserted to the field.
        /// </summary>
        /// <param name="tetromino">The tetromino to check its insertion worthiness</param>
        /// <param name="insertPosition">The position (in blocks) on the field to check the Tetrominos insertion worthiness</param>
        /// <returns>True if the tetromino can be inserted, false otherwise</returns>
        public bool IsTetrominoInsertableAt(Tetromino tetromino, Point insertPosition)
        {
            bool insertable = true;

            for (int i = 0; i < 4; i++)
            {
                Point minoPosition   = tetromino[i];
                Point translatedMino = new Point(insertPosition.X + minoPosition.X, insertPosition.Y + minoPosition.Y);
                insertable &= (IsInBounds(translatedMino) && fieldLines[translatedMino.Y][translatedMino.X] == -1);
            }

            return(insertable);
        }
Exemplo n.º 5
0
 /// <summary>
 /// A draw method what draws a specific tetromino as if it were in the grid. This is done to reuse code for drawing the individual
 /// Tetromino blocks. This is for a tetromino that is not yet inserted.
 /// </summary>
 /// <param name="batch">The sprite batch instance to draw with</param>
 /// <param name="position">The position (in blocks) of the point on the field to do its initial draw</param>
 /// <param name="tetromino">The tetromino to mock draw in the field</param>
 public void DrawTetromino(SpriteBatch batch, Point position, Tetromino tetromino)
 {
     this.DrawTetromino(batch, position, tetromino, false);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Checks to see if a tetromino can be inserted to the field.
 /// </summary>
 /// <param name="tetromino">The tetromino to check its insertion worthiness</param>
 /// <param name="x">The position, in blocks, on the horizontal axis within the play area</param>
 /// <param name="y">The position, in blocks, on the vertical axis within the play area</param>
 /// <returns></returns>
 public bool IsTetrominoInsertableAt(Tetromino tetromino, int x, int y)
 {
     return(IsTetrominoInsertableAt(tetromino, new Point(x, y)));
 }