Exemple #1
0
 public Piece()
 {
     for (int counter = 0; counter < blocks.Length; counter++ )
     {
         blocks[counter] = new Block(pieceType, this);
     }
 }
Exemple #2
0
        public void Draw()
        {
            ((Game1)gameTab.Game).spriteBatch.Draw(nextFigureTexture, position, Color.White);

            for (int i = 0; i < Constants.FIGUREMAXSIZE; i++)
                for (int j = 0; j < Constants.FIGUREMAXSIZE; j++)
                {
                    Texture2D activeBlock;
                    Color color;
                    if ((i < figure.GetLength(0)) && (j < figure.GetLength(1)))
                    {
                        activeBlock = figure[i, j].blockTexture;
                        color = figure[i, j].color;
                    }
                    else
                    {
                        activeBlock = new Block().blockTexture;
                        color = Block.blankColor;
                    }

                    ((Game1)gameTab.Game).spriteBatch.Draw(activeBlock,
                         position + new Vector2(i * Constants.BLOCKPIXELSIZE + 1, j * Constants.BLOCKPIXELSIZE + 1),
                         null,
                         color,
                         0, Vector2.Zero,
                         1,
                         SpriteEffects.None, 1);
                }
        }
Exemple #3
0
 public Level(IServiceProvider serviceProvider)
 {
     content = new ContentManager(serviceProvider, "Content");
     tetrisWell = new TetrisWell(this);
     block = new Block(this, tetrisWell.WellPosition);
     wellMatrix = tetrisWell.wellMatrix;
     LoadContent();
 }
		void ICmpInitializable.OnShutdown(Component.ShutdownContext context)
		{
			if (context == ShutdownContext.Deactivate)
			{
				blocks.Remove(this);
				if (activeBlock == this) activeBlock = null;
			}
		}
		void ICmpInitializable.OnInit(Component.InitContext context)
		{
			if (context == InitContext.Activate)
			{
				blocks.Add(this);
				activeBlock = this;
			}
		}
Exemple #6
0
 public Board()
 {
     this.rowsCompleted = 0;
     this.currentLevel = 1;
     this.score = 0;
     this.currentBlock = new Block();
     this.coord = new Coordinate(0, 0);
     this.colorCodeBoard();
 }
Exemple #7
0
 public void Clear()
 {
     for(int i=0;i<board.GetLength(0);i++)
     {
         for(int j=0;j<board.GetLength(1);j++)
         {
             board[i, j] = new Block(false, Color.Empty);
         }
     }
 }
Exemple #8
0
 public Piece(BlockType pieceType)
 {
     for (int counter = 0; counter < blocks.Length; counter++ )
     {
         blocks[counter] = new Block(pieceType, this);
     }
     this.pieceType = pieceType;
     //When a new piece object is created, the piece is placed at the starting position
     switch(pieceType)
     {
         case BlockType.I:
             blocks[0] = new Block(pieceType, new Point(Board.leftBorder + 3, Board.topBorder - 1), this);
             blocks[1] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 1), this);
             blocks[2] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 1), this);
             blocks[3] = new Block(pieceType, new Point(Board.leftBorder + 6, Board.topBorder - 1), this);
             break;
         case BlockType.J:
             blocks[0] = new Block(pieceType, new Point(Board.leftBorder + 3, Board.topBorder - 2), this);
             blocks[1] = new Block(pieceType, new Point(Board.leftBorder + 3, Board.topBorder - 1), this);
             blocks[2] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 1), this);
             blocks[3] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 1), this);
             break;
         case BlockType.L:
             blocks[0] = new Block(pieceType, new Point(Board.leftBorder + 3, Board.topBorder - 1), this);
             blocks[1] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 1), this);
             blocks[2] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 1), this);
             blocks[3] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 2), this);
             break;
         case BlockType.O:
             blocks[0] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 1), this);
             blocks[1] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 2), this);
             blocks[2] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 1), this);
             blocks[3] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 2), this);
             break;
         case BlockType.S:
             blocks[0] = new Block(pieceType, new Point(Board.leftBorder + 3, Board.topBorder - 1), this);
             blocks[1] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 1), this);
             blocks[2] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 2), this);
             blocks[3] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 2), this);
             break;
         case BlockType.T:
             blocks[0] = new Block(pieceType, new Point(Board.leftBorder + 3, Board.topBorder - 1), this);
             blocks[1] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 1), this);
             blocks[2] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 2), this);
             blocks[3] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 1), this);
             break;
         case BlockType.Z:
             blocks[0] = new Block(pieceType, new Point(Board.leftBorder + 3, Board.topBorder - 2), this);
             blocks[1] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 2), this);
             blocks[2] = new Block(pieceType, new Point(Board.leftBorder + 4, Board.topBorder - 1), this);
             blocks[3] = new Block(pieceType, new Point(Board.leftBorder + 5, Board.topBorder - 1), this);
             break;
     }
 }
		void ICmpUpdatable.OnUpdate()
		{
			if (activeBlock != this) return;
			if ((this.timeFirstContact != 0.0f && Time.GameTimer - this.timeFirstContact > 750.0f) || this.GameObj.Transform.Vel.Length <= 0.1f)
			{
				activeBlock = null;
				DualityApp.Sound.PlaySound(GameRes.Data.Sound.BlockDrop_Sound);

				float angleDistFromIdeal = MathF.CircularDist(0.0f, this.GameObj.Transform.Angle, 0.0f, MathF.PiOver2);
				float angleDistTolerance = MathF.Pi * 0.1f;
				GameController.Instance.Score += MathF.RoundToInt(50.0f * (1.0f - MathF.Clamp(angleDistFromIdeal / angleDistTolerance, 0.0f, 1.0f)));
			}
		}
Exemple #10
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch = new SpriteBatch(GraphicsDevice);
     texture = new Texture2D(GraphicsDevice, 1, 1);
     texture.SetData(new Color[] { Color.White });
     squareRect = new Rectangle(780, 460, 20, 20);
     Block b = new Block(0, 1);
     Static.game = this;
     Static.spritebatch = spriteBatch;
     Block.texture = texture;
     this.Components.Add(b);
 }
        public Block Clone()
        {
            var result = new Block(blockPositionX, blockPositionY, new int[blockCols, blockRows]);

            for (int indexRows = 0; indexRows < blockRows; indexRows++)
            {
                for (int indexCols = 0; indexCols < blockCols; indexCols++)
                {
                    result[indexCols, indexRows] = this[indexCols, indexRows];
                }
            }

            return result;
        }
Exemple #12
0
        public void GenerateRandom()
        {
            Color color = Color.White;

            int rng = new Random().Next(0, 4); //MEER SHAPES AH MATTIE
            if (rng == 0) //Vierkant
            {
                blocks = new Block[2, 2];
                blocks[0, 0] = new Block();
                blocks[0, 1] = new Block();
                blocks[1, 0] = new Block();
                blocks[1, 1] = new Block();

                color = Color.Red;
            }
            else if (rng == 1) //L 1
            {
                blocks = new Block[2, 3];
                blocks[1, 0] = new Block();
                blocks[1, 1] = new Block();
                blocks[1, 2] = new Block();
                blocks[0, 2] = new Block();

                color = Color.Green;
            }
            else if (rng == 2) //L 2
            {
                blocks = new Block[2, 3];
                blocks[0, 0] = new Block();
                blocks[0, 1] = new Block();
                blocks[0, 2] = new Block();
                blocks[1, 2] = new Block();

                color = Color.Blue;
            }
            else if (rng == 3) //I
            {
                blocks = new Block[1, 4];
                blocks[0, 0] = new Block();
                blocks[0, 1] = new Block();
                blocks[0, 2] = new Block();
                blocks[0, 3] = new Block();

                color = Color.Cyan;
            }

            foreach (Block block in blocks)
                if (block != null)
                    block.color = color;
        }
Exemple #13
0
        /// <summary>
        ///     This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (GameBoard.GameOver)
            {
                _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                _spriteBatch.DrawString(_scoreFont, "Game over :-(", new Vector2(300.0f, 20.0f), Color.LightGreen,
                    0,
                    _scoreFont.MeasureString("Game over :-(")/2, 1.0f, SpriteEffects.None, 0.5f);
                const string output1 = "Score:";
                var output2 = GameBoard.Instance.Score + "";
                _spriteBatch.DrawString(_scoreFont, output1, new Vector2(300.0f, 40.0f), Color.LightGreen, 0,
                    _scoreFont.MeasureString(output1) / 2, 1.0f, SpriteEffects.None, 0.5f);
                _spriteBatch.DrawString(_scoreFont, output2, new Vector2(300.0f, 60.0f), Color.LightGreen, 0,
                    _scoreFont.MeasureString(output2) / 2, 1.0f, SpriteEffects.None, 0.5f);
                _spriteBatch.End();
            }
            else
            {
                GraphicsDevice.Clear(Color.White);

                _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                _spriteBatch.Draw(_background, Vector2.Zero, Color.White);
                const string output1 = "Score:";
                var output2 = GameBoard.Instance.Score + "";
                _spriteBatch.DrawString(_scoreFont, output1, new Vector2(380.0f, 20.0f), Color.LightGreen, 0,
                    _scoreFont.MeasureString(output1) / 2, 1.0f, SpriteEffects.None, 0.5f);
                _spriteBatch.DrawString(_scoreFont, output2, new Vector2(380.0f, 40.0f), Color.LightGreen, 0,
                    _scoreFont.MeasureString(output2) / 2, 1.0f, SpriteEffects.None, 0.5f);

                if (_fallingBlock == null)
                    _fallingBlock = _blockFactory.GenerateBlock();
                foreach (var square in _fallingBlock.Squares)
                {
                    _spriteBatch.Draw(square.Texture, square.Position, Color.White);
                }
                foreach (var square in GameBoard.Instance.Board)
                {
                    if (square != null)
                        _spriteBatch.Draw(square.Texture, square.Position, Color.White);
                }
                _spriteBatch.End();
            }

            base.Draw(gameTime);
        }
Exemple #14
0
        public Block[,] getTurned()
        {
            Point[,] positions = new Point[figure.GetLength(0), figure.GetLength(1)];
            int offset = (int)Math.Floor((float)figure.GetLength(0) / 2);

            for (int i = 0; i < figure.GetLength(0); i++)
                for (int j = 0; j < figure.GetLength(1); j++)
                {
                    positions[i, j] = new Point(i, j);

                    positions[i, j].X -= offset;
                    positions[i, j].Y -= offset;

                    if ((figure.GetLength(0) % 2) == 0)
                    {
                        if (positions[i, j].X >= 0)
                            positions[i, j].X++;
                        if (positions[i, j].Y >= 0)
                            positions[i, j].Y++;
                    }

                    positions[i, j] = new Point(positions[i, j].Y, -positions[i, j].X);

                    positions[i, j].X += offset;
                    positions[i, j].Y += offset;

                    if ((figure.GetLength(0) % 2) == 0)
                    {
                        if (positions[i, j].X >= offset)
                            positions[i, j].X--;
                        if (positions[i, j].Y >= offset)
                            positions[i, j].Y--;
                    }
                }

            Block[,] newFigure = new Block[figure.GetLength(0), figure.GetLength(1)];

            for (int i = 0; i < figure.GetLength(0); i++)
                for (int j = 0; j < figure.GetLength(1); j++)
                    newFigure[i, j] = figure[positions[i, j].X, positions[i, j].Y];

            return newFigure;
        }
Exemple #15
0
        public Game()
        {
            InitializeComponent();

            // Applying the settings to the WinForm window
            ClientSize = new Size(colWidth * columns, rowHeight * rows);
            BackColor = backColor;
            timer.Interval = updateTime;
            timer.Start();
            fastTimer.Start();

            Color randomColor = Color.FromArgb(randomizer.Next(105) + 150,
                        randomizer.Next(105) + 150,
                        randomizer.Next(105) + 50);

            newWorld = new World(Controls, backColor, rows, columns, colWidth, rowHeight);
            block = new Block((BlockType)(randomizer.Next((int)BlockType.count)),
                CreateRandomBlockColor(), newWorld, backColor);
        }
Exemple #16
0
        public static Block operator +(Block a, Block b)
        {
            int rows, cols, x, y;

            //// get Uperr left cordinate
            if (a.blockPositionX < b.blockPositionX) x = a.blockPositionX;
            else x = b.blockPositionX;
            if (a.blockPositionY < b.blockPositionY) y = a.blockPositionY;
            else y = b.blockPositionY;

            //// size of new Block
            if (a.blockRows + a.blockPositionY > b.blockRows + b.blockPositionY)
                rows = a.blockRows + a.blockPositionY - y;
            else rows = b.blockRows + b.blockPositionY - y;
            if (a.blockCols + a.blockPositionX > b.blockCols + b.blockPositionX)
                cols = a.blockCols + a.blockPositionX - x;
            else cols = b.blockCols + b.blockPositionX - x;

            Block result = new Block(x, y, new int[cols, rows]);

            for (int r = b.blockPositionY; r < b.blockRows + b.blockPositionY; r++)
            {
                for (int c = b.blockPositionX; c < b.blockCols + b.blockPositionX; c++)
                {
                    if (b[c - b.blockPositionX, r - b.blockPositionY] != 0)
                        result[c - result.blockPositionX, r - result.blockPositionY] = b[c - b.blockPositionX, r - b.blockPositionY];
                }
            }

            for (int r = a.blockPositionY; r < a.blockRows + a.blockPositionY; r++)
            {
                for (int c = a.blockPositionX; c < a.blockCols + a.blockPositionX; c++)
                {
                    if (a[c - a.blockPositionX, r - a.blockPositionY] != 0)
                        result[c - result.blockPositionX, r - result.blockPositionY] = a[c - a.blockPositionX, r - a.blockPositionY];
                }
            }
            return result;
        }
Exemple #17
0
        static Block Rotate(Block inp)
        {
            if (inp.blockCols != inp.blockRows) // If it's The O-Tetrimino there's no sence in rotating it
            {
                inp.Clear();
                Block newBlock = inp.Rotate();

                if (Block.OverlapBlocks(newBlock, bigBlock))
                {
                    inp.Print();
                    return inp;
                }
                else
                {
                    newBlock.Print();
                    Sounds.SFX(Sounds.SoundEffects.Rotate);
                    return newBlock;
                }
            }
            return inp;
        }
Exemple #18
0
 static void Gameover(Block inp)
 {
     if (Block.OverlapBlocks(inp, bigBlock) == true)
     {
         if (bigBlock.blockRows == Console.WindowHeight)
         {
             Console.BackgroundColor = ConsoleColor.Red;
             Sounds.SFX(Sounds.SoundEffects.GameOver);
             PrintOnPosition(12, 12, "Game Over!");
             Thread.Sleep(2000);
             Main();
         }
     }
 }
Exemple #19
0
 static void Drop(int playerNumber)
 {
     if (numberOfPlayers == 2)
     {
         if (brickPlayer[playerNumber].blockPositionY > brickPlayer[Math.Abs(playerNumber - 1)].blockPositionY)
         {
             while (Block.OverlapBlocks(brickPlayer[playerNumber], bigBlock) == false)
             {
                 score += level * 2; // Bonus score
                 brickPlayer[playerNumber].blockPositionY++;
                 if (Block.OverlapBlocks(brickPlayer[playerNumber], bigBlock) == true)
                 {
                     brickPlayer[playerNumber].blockPositionY--;
                     bigBlock = bigBlock + brickPlayer[playerNumber];
                     brickPlayer[playerNumber] = nextBrick;
                     brickPlayer[playerNumber].blockPositionX = playerPos[playerNumber];
                     brickPlayer[playerNumber].Print();
                     CheckForCompleteLines();
                     nextBrick = GenerateRandomBlock(playerPos[0]);
                     Sounds.SFX(Sounds.SoundEffects.Drop);
                     PrintNextBrick();
                     bigBlock.SetColor(15);
                     bigBlock.Print();
                     return;
                 }
                 else
                 {
                     brickPlayer[playerNumber].blockPositionY--;
                     brickPlayer[playerNumber].Clear();
                     brickPlayer[playerNumber].blockPositionY++;
                     brickPlayer[playerNumber].Print();
                 }
             }
         }
         else if (brickPlayer[playerNumber].blockPositionX > brickPlayer[Math.Abs(playerNumber - 1)].blockPositionX + brickPlayer[Math.Abs(playerNumber - 1)].blockCols - 1 || brickPlayer[playerNumber].blockPositionX + brickPlayer[playerNumber].blockCols - 1 < brickPlayer[Math.Abs(playerNumber - 1)].blockPositionX)
             while (Block.OverlapBlocks(brickPlayer[playerNumber], bigBlock) == false)
             {
                 score += level * 2; // Bonus score
                 brickPlayer[playerNumber].blockPositionY++;
                 if (Block.OverlapBlocks(brickPlayer[playerNumber], bigBlock) == true)
                 {
                     brickPlayer[playerNumber].blockPositionY--;
                     bigBlock = bigBlock + brickPlayer[playerNumber];
                     brickPlayer[playerNumber] = nextBrick;
                     brickPlayer[playerNumber].blockPositionX = playerPos[playerNumber];
                     brickPlayer[playerNumber].Print();
                     CheckForCompleteLines();
                     nextBrick = GenerateRandomBlock(playerPos[0]);
                     Sounds.SFX(Sounds.SoundEffects.Drop);
                     PrintNextBrick();
                     bigBlock.SetColor(15);
                     bigBlock.Print();
                     return;
                 }
                 else
                 {
                     brickPlayer[playerNumber].blockPositionY--;
                     brickPlayer[playerNumber].Clear();
                     brickPlayer[playerNumber].blockPositionY++;
                     brickPlayer[playerNumber].Print();
                 }
             }
     }
     else
     {
         while (Block.OverlapBlocks(brickPlayer[playerNumber], bigBlock) == false)
         {
             score += level * 2; // Bonus score
             brickPlayer[playerNumber].blockPositionY++;
             if (Block.OverlapBlocks(brickPlayer[playerNumber], bigBlock) == true)
             {
                 brickPlayer[playerNumber].blockPositionY--;
                 bigBlock = bigBlock + brickPlayer[playerNumber];
                 brickPlayer[playerNumber] = nextBrick;
                 brickPlayer[playerNumber].blockPositionX = playerPos[playerNumber];
                 brickPlayer[playerNumber].Print();
                 CheckForCompleteLines();
                 nextBrick = GenerateRandomBlock(playerPos[0]);
                 Sounds.SFX(Sounds.SoundEffects.Drop);
                 PrintNextBrick();
                 bigBlock.SetColor(15);
                 bigBlock.Print();
                 return;
             }
             else
             {
                 brickPlayer[playerNumber].blockPositionY--;
                 brickPlayer[playerNumber].Clear();
                 brickPlayer[playerNumber].blockPositionY++;
                 brickPlayer[playerNumber].Print();
             }
         }
     }
 }
Exemple #20
0
        static void Down(int playerNumber)
        {
            brickPlayer[playerNumber].blockPositionY++;

            if (numberOfPlayers == 2 && Block.OverlapBlocks(brickPlayer[1], brickPlayer[0]))
            {
                brickPlayer[playerNumber].blockPositionY--;
            }
            else if (Block.OverlapBlocks(brickPlayer[playerNumber], bigBlock))
            {
                brickPlayer[playerNumber].blockPositionY--;
                bigBlock = bigBlock + brickPlayer[playerNumber];
                brickPlayer[playerNumber] = nextBrick.Clone();
                brickPlayer[playerNumber].blockPositionX = playerPos[playerNumber];
                brickPlayer[playerNumber].Print();
                CheckForCompleteLines();
                nextBrick = GenerateRandomBlock(playerPos[playerNumber]);
                PrintNextBrick();
                bigBlock.SetColor(15);
                bigBlock.Print();
            }
            else
            {
                brickPlayer[playerNumber].blockPositionY--;
                brickPlayer[playerNumber].Clear();
                Sounds.SFX(Sounds.SoundEffects.Move);
                brickPlayer[playerNumber].blockPositionY++;
                brickPlayer[playerNumber].Print();
            }
        }
Exemple #21
0
        private bool isCollide(Block[,] figure, Vector2 position)
        {
            for (int i = 0; i < figure.GetLength(0); i++)
                for (int j = 0; j < figure.GetLength(1); j++)
                {
                    Block check;
                    if (((position.X + i) < 0) || ((position.X + i) >= field.GetLength(0)) || ((position.Y + j) >= field.GetLength(1)))
                        check = new Block(0);
                    else if ((position.Y + j) < 0)
                        check = new Block();
                    else
                        check = field[(int)position.X + i, (int)position.Y + j];

                    if (figure[i, j].isFill && check.isFill)
                        return true;
                }

            return false;
        }
Exemple #22
0
 private void FixFigure(Block[,] figure, Vector2 position)
 {
     for (int i = 0; i < figure.GetLength(0); i++)
         for (int j = 0; j < figure.GetLength(1); j++)
             if (figure[i, j].isFill)
                 if ((int)position.Y + j >= 0)
                     field[(int)position.X + i, (int)position.Y + j] = new Block(figure[i, j].hue);
                 else
                 {
                     ((Game1)gameTab.Game).ChangeState(Game1.GameStates.End);
                     return;
                 }
 }
Exemple #23
0
        void deleteLine(int index)
        {
            for (int i = 0; i < field.GetLength(0); i++)
            {
                for (int j = index; j > 0; j--)
                    field[i, j] = field[i, j - 1];

                field[i, 0] = new Block();
            }
        }
Exemple #24
0
        public static Block[,] getBlinkArray(Vector2 size)
        {
            if ((size.X < 1) || (size.Y < 1))
                return null;

            Block[,] result = new Block[(int)size.X, (int)size.Y];
            for (int i = 0; i < size.X; i++)
                for (int j = 0; j < size.Y; j++)
                    result[i, j] = new Block();

            return result;
        }
Exemple #25
0
    public bool IsMoveValid(int dx, int dy, int dr)
    {
      Block temp = new Block(m_theGame);

      temp.Clone(m_theGame.CurrentBlock);
      temp.X += dx;
      temp.Y += dy;
      temp.Rotation = (temp.Rotation + 4 + dr) % 4;

      // get coordinates
      float[] x = new float[4];
      float[] y = new float[4];

      temp.ToVirtualCoordinates(ref x, ref y);

      // validate...
      for (int i = 0; i < 4; i++)
      {
        // out of horizontal border
        if (x[i] < 0 || x[i] >= Game.Width)
        {
          return false;
        }

        // out of vertical border
        if (y[i] < 0)
        {
          return false;
        }

        if (y[i] >= Game.Height)
        {
          return true;
        }

        // on another block
        if (m_theGame.Block[(int)x[i], (int)y[i]] != 0)
        {
          return false;
        }
      }

      // indicate success
      return true;
    }
Exemple #26
0
 public void Clone(Block src)
 {
   y_start = src.y_start;
   m_nX = src.m_nX;
   m_nY = src.m_nY;
   m_nFreefalls = src.m_nFreefalls;
   m_nRotation = src.m_nRotation;
   m_nData = src.m_nData;
   m_nColor = src.m_nColor;
 }
Exemple #27
0
    public void Start()
    {
      m_blockCurrent = new Block(this);
      m_blockCurrent.Create();

      m_blockNext = new Block(this);
      m_blockNext.Create();

      while (m_blockNext.ColorIndex == m_blockCurrent.ColorIndex)
      {
        // same block, keep trying until our current and next blocks are
        // different - saw too many instances where the two blocks at the
        // start of a game are the same.
        Thread.Sleep(100);
        m_blockNext.Create();
      }

      // shift the current block into the playing area
      m_blockCurrent.Y -= 5;

      m_nScore = 0;
      m_nLines = 0;
      m_nLevel = 0;

      // clear the board
      for (int x = 0; x < Width; x++)
      {
        for (int y = 0; y < Height; y++)
        {
          m_nBlock[x, y] = 0;
        }
      }

      m_nState = State.Running;
    }
Exemple #28
0
        private static void SetGameField()
        {
            Console.BackgroundColor = (ConsoleColor)0;
            Console.ForegroundColor = (ConsoleColor)15;
            Console.Clear();
            Console.Title = "Console Tetris";
            Console.WindowHeight = 25;
            Console.WindowWidth = 51;
            Console.BufferHeight = Console.WindowHeight;
            Console.BufferWidth = Console.WindowWidth;
            Console.CursorVisible = false;
            PrintInfoScreen();

            bigBlock = new Block(0, 0, new int[16, 25]);

            for (int i = 0; i < 25; i++)
            {
                bigBlock[0, i] = 15;
                bigBlock[15, i] = 15;
            }
            for (int i = 0; i < 16; i++)
            {
                bigBlock[i, 24] = 15;
            }

            bigBlock.Print();
        }
Exemple #29
0
 private static void SetInitialGameParams()
 {
     score = 0;
     level = 1;
     millisecond = 0;
     countPrint = 0;
     SetGameField();
     brickPlayer[0] = GenerateRandomBlock(playerPos[0]);
     if (numberOfPlayers == 2) brickPlayer[1] = GenerateRandomBlock(playerPos[1]);
     nextBrick = GenerateRandomBlock(playerPos[0]);
     PrintNextBrick();
     brickPlayer[0].Print();
     if (numberOfPlayers == 2) brickPlayer[0].Print();
     millisecond = DateTime.Now.Millisecond;
     PrintStatus();
     Thread.Sleep(1);
 }
Exemple #30
0
    private void RenderBlock(float timePassed, Block block, int nHint)
    {
      if (block != null)
      {
        float[] x = new float[4];
        float[] y = new float[4];

        // get coordinates
        block.ToCoordinates(ref x, ref y);

        if (Environment.TickCount - m_nLastBlockTick < 600 && nHint == 0)
        {
          nHint = 3;
        }

        for (int nBlock = 0; nBlock < 4; nBlock++)
        {
          m_pHost.OnRenderBlock(timePassed, x[nBlock], Height - y[nBlock], block.Color, nHint);
        }
      }
    }