Exemple #1
0
 /// <summary>
 /// Permanently attaches to the game board.
 /// Called when current piece is placed.
 /// </summary>
 /// <param name="b"></param>
 public void Bake(Block b)
 {
     gameBoard[b.Position.X, b.Position.Y] = b;
 }
Exemple #2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    gameBoard[i, j] = new Block(BlockType.None, i, j);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Draws the Ghost Piece.
        /// </summary>
        /// <param name="gameTime">The gameTime.</param>
        /// <param name="sb">The spritebatch.</param>
        public void DrawGhostPiece(GameTime gameTime, SpriteBatch sb)
        {
            Block[] ghostBlock = new Block[4];

            for (int i = 0; i < 4; i++)
                ghostBlock[i] = block[i];

            bool done = false;
            while (!done)
            {

                tempMove[0] = new Point(ghostBlock[0].Position.X, ghostBlock[0].Position.Y + 1);
                tempMove[1] = new Point(ghostBlock[1].Position.X, ghostBlock[1].Position.Y + 1);
                tempMove[2] = new Point(ghostBlock[2].Position.X, ghostBlock[2].Position.Y + 1);
                tempMove[3] = new Point(ghostBlock[3].Position.X, ghostBlock[3].Position.Y + 1);

                if (theBoard.IsMoveValid(tempMove))
                {
                    ghostBlock[0].Position = tempMove[0];
                    ghostBlock[1].Position = tempMove[1];
                    ghostBlock[2].Position = tempMove[2];
                    ghostBlock[3].Position = tempMove[3];
                }
                else done = true;
            }

            foreach (Block b in ghostBlock)
                b.Draw(sb, theBoard.GetTexture(BlockType.None), Color.White, theBoard.Offset, theBoard.Scale);
        }
Exemple #4
0
        /// <summary>
        /// Draws the preview of the next piece.
        /// </summary>
        /// <param name="gameTime">The gameTime.</param>
        /// <param name="sb">The spriteBatch.</param>
        /// <param name="drawLoc">The screen location to draw the next piece at.</param>
        public void drawNextPiece(GameTime gameTime, SpriteBatch sb, Vector2 drawLoc)
        {
            if (Type == BlockType.L) // L Shape
            {
                block[0] = new Block(Type, 1, 2);
                block[1] = new Block(Type, 0, 0);
                block[2] = new Block(Type, 0, 1);
                block[3] = new Block(Type, 0, 2);
            }
            else if (Type == BlockType.J) // J Shape
            {
                block[0] = new Block(Type, 0, 2);
                block[1] = new Block(Type, 1, 0);
                block[2] = new Block(Type, 1, 1);
                block[3] = new Block(Type, 1, 2);
            }
            else if (Type == BlockType.I) // I Shape
            {
                block[0] = new Block(Type, 1, 0);
                block[1] = new Block(Type, 1, 1);
                block[2] = new Block(Type, 1, 2);
                block[3] = new Block(Type, 1, 3);
            }
            else if (Type == BlockType.T) // T Shape
            {
                block[0] = new Block(Type, 0, 0);
                block[1] = new Block(Type, 0, 1);
                block[2] = new Block(Type, 0, 2);
                block[3] = new Block(Type, 1, 1);
            }
            else if (Type == BlockType.S) // S Shape
            {
                block[0] = new Block(Type, 0, 0);
                block[1] = new Block(Type, 0, 1);
                block[2] = new Block(Type, 1, 1);
                block[3] = new Block(Type, 1, 2);
            }
            else if (Type == BlockType.O) // O Shape
            {
                block[0] = new Block(Type, 0, 0);
                block[1] = new Block(Type, 1, 0);
                block[2] = new Block(Type, 0, 1);
                block[3] = new Block(Type, 1, 1);

            }
            else if (Type == BlockType.Z) // Z Shape
            {
                block[0] = new Block(Type, 1, 0);
                block[1] = new Block(Type, 1, 1);
                block[2] = new Block(Type, 0, 1);
                block[3] = new Block(Type, 0, 2);
            }

            foreach (Block b in block)
                b.Draw(sb, theBoard.GetTexture(Type), Color.White, drawLoc, theBoard.Scale);
        }
Exemple #5
0
        /// <summary>
        /// Creates the appropriate shape corresponding to the color.
        /// </summary>
        /// <param name="color">The color of the block.</param>
        public void CreateShape(BlockType color)
        {
            this.Type = color;

            if (color == BlockType.L) // L Shape
            {
                block[0] = new Block(color, 5, 1);
                block[1] = new Block(color, 5, 2);
                block[2] = new Block(color, 4, 2);
                block[3] = new Block(color, 3, 2);
            }
            else if (color == BlockType.J) // J Shape
            {
                block[0] = new Block(color, 3, 1);
                block[1] = new Block(color, 3, 2);
                block[2] = new Block(color, 4, 2);
                block[3] = new Block(color, 5, 2);
            }
            else if (color == BlockType.I) // I Shape
            {
                block[0] = new Block(color, 3, 1);
                block[1] = new Block(color, 4, 1);
                block[2] = new Block(color, 5, 1);
                block[3] = new Block(color, 6, 1);
            }
            else if (color == BlockType.T) // T Shape
            {
                block[0] = new Block(color, 4, 1);
                block[1] = new Block(color, 3, 2);
                block[2] = new Block(color, 4, 2);
                block[3] = new Block(color, 5, 2);

            }
            else if (color == BlockType.S) // S Shape
            {
                block[0] = new Block(color, 5, 1);
                block[1] = new Block(color, 4, 1);
                block[2] = new Block(color, 4, 2);
                block[3] = new Block(color, 3, 2);
            }
            else if (color == BlockType.O) // O Shape
            {
                block[0] = new Block(color, 4, 1);
                block[1] = new Block(color, 5, 1);
                block[2] = new Block(color, 4, 2);
                block[3] = new Block(color, 5, 2);

            }
            else if (color == BlockType.Z) // Z shape
            {
                block[0] = new Block(color, 3, 1);
                block[1] = new Block(color, 4, 1);
                block[2] = new Block(color, 4, 2);
                block[3] = new Block(color, 5, 2);
            }

            tempMove[0] = block[0].Position;
            tempMove[1] = block[1].Position;
            tempMove[2] = block[2].Position;
            tempMove[3] = block[3].Position;

            if (!theBoard.IsMoveValid(tempMove))
                IsGameOver = true;

            HasBlock = true;
        }