⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 block.cs

📁 这个程序是基于c#平台的俄罗斯方框游戏。拿来共享。要求加分哦!
💻 CS
📖 第 1 页 / 共 2 页
字号:
				// Returns the value in the blockType attribute.
				return blockType;
			}

			set
			{
				// Creates a new shape.
				Brick[,] shape;

				// Tests if the current block type is "Undefined".
				if (blockType == BlockType.Undefined)
				{
					// Current block type is "Undefined".
					// Sets the 
					blockType = value;

					// Checks for the new block type.
					switch(blockType)
					{
						case BlockType.Straight:
							// Block type is "Straight".
							// Sets the Width, Height, Top and Left properties.
							this.Width = 4;
							this.Height = 1;
							this.Top = 0;
							this.Left = 3;
							// Creates the new shape for this block.
							shape = new Brick[this.Width, this.Height];
							shape[0, 0].Filled = true;
							shape[1, 0].Filled = true;
							shape[2, 0].Filled = true;
							shape[3, 0].Filled = true;
							// Creates the images for this block.
							shape[0, 0].BrickImage = blockImage13;
							shape[1, 0].BrickImage = blockImage14;
							shape[2, 0].BrickImage = blockImage13;
							shape[3, 0].BrickImage = blockImage14;
							// Sets the Shape property to the new shape created.
							this.Shape = shape;
							break;

						case BlockType.Rectangle:
							// Block type is "Rectangle".
							// Sets the Width, Height, Top and Left properties.
							this.Width = 2;
							this.Height = 2;
							this.Top = 0;
							this.Left = 4;
							// Creates the new shape for this block.
							shape = new Brick[this.Width, this.Height];
							shape[0, 0].Filled = true;
							shape[0, 1].Filled = true;
							shape[1, 0].Filled = true;
							shape[1, 1].Filled = true;
							// Creates the images for this block.
							shape[0, 0].BrickImage = blockImage05;
							shape[0, 1].BrickImage = blockImage06;
							shape[1, 0].BrickImage = blockImage06;
							shape[1, 1].BrickImage = blockImage05;
							// Sets the Shape property to the new shape created.
							this.Shape = shape;
							break;

						case BlockType.CornerLeft:
							// Block type is "CornerLeft".
							// Sets the Width, Height, Top and Left properties.
							this.Width = 3;
							this.Height = 2;
							this.Top = 0;
							this.Left = 4;
							// Creates the new shape for this block.
							shape = new Brick[this.Width, this.Height];
							shape[0, 0].Filled = true;
							shape[1, 0].Filled = true;
							shape[2, 0].Filled = true;
							shape[0, 1].Filled = true;
							shape[1, 1].Filled = false;
							shape[2, 1].Filled = false;
							// Creates the images for this block.
							shape[0, 0].BrickImage = blockImage08;
							shape[1, 0].BrickImage = blockImage07;
							shape[2, 0].BrickImage = blockImage08;
							shape[0, 1].BrickImage = blockImage07;
							// Sets the Shape property to the new shape created.
							this.Shape = shape;
							break;

						case BlockType.CornerRight:
							// Block type is "CornerRight".
							// Sets the Width, Height, Top and Left properties.
							this.Width = 3;
							this.Height = 2;
							this.Top = 0;
							this.Left = 4;
							// Creates the new shape for this block.
							shape = new Brick[this.Width, this.Height];
							shape[0, 0].Filled = true;
							shape[1, 0].Filled = true;
							shape[2, 0].Filled = true;
							shape[0, 1].Filled = false;
							shape[1, 1].Filled = false;
							shape[2, 1].Filled = true;
							// Creates the images for this block.
							shape[0, 0].BrickImage = blockImage11;
							shape[1, 0].BrickImage = blockImage12;
							shape[2, 0].BrickImage = blockImage11;
							shape[2, 1].BrickImage = blockImage12;
							// Sets the Shape property to the new shape created.
							this.Shape = shape;
							break;

						case BlockType.Cross:
							// Block type is "Cross".
							// Sets the Width, Height, Top and Left properties.
							this.Width = 3;
							this.Height = 2;
							this.Top = 0;
							this.Left = 4;
							// Creates the new shape for this block.
							shape = new Brick[this.Width, this.Height];
							shape[0, 0].Filled = true;
							shape[1, 0].Filled = true;
							shape[2, 0].Filled = true;
							shape[0, 1].Filled = false;
							shape[1, 1].Filled = true;
							shape[2, 1].Filled = false;
							// Creates the images for this block.
							shape[0, 0].BrickImage = blockImage04;
							shape[1, 0].BrickImage = blockImage03;
							shape[2, 0].BrickImage = blockImage04;
							shape[1, 1].BrickImage = blockImage03;
							// Sets the Shape property to the new shape created.
							this.Shape = shape;
							break;

						case BlockType.Zigzag1:
							// Block type is "Zigzag1".
							// Sets the Width, Height, Top and Left properties.
							this.Width = 2;
							this.Height = 3;
							this.Top = 0;
							this.Left = 4;
							// Creates the new shape for this block.
							shape = new Brick[this.Width, this.Height];
							shape[0, 0].Filled = false;
							shape[1, 0].Filled = true;
							shape[0, 1].Filled = true;
							shape[1, 1].Filled = true;
							shape[0, 2].Filled = true;
							shape[1, 2].Filled = false;
							// Creates the images for this block.
							shape[1, 0].BrickImage = blockImage10;
							shape[0, 1].BrickImage = blockImage10;
							shape[1, 1].BrickImage = blockImage09;
							shape[0, 2].BrickImage = blockImage09;
							// Sets the Shape property to the new shape created.
							this.Shape = shape;
							break;

						case BlockType.Zigzag2:
							// Block type is "Zigzag2".
							// Sets the Width, Height, Top and Left properties.
							this.Width = 2;
							this.Height = 3;
							this.Top = 0;
							this.Left = 4;
							// Creates the new shape for this block.
							shape = new Brick[this.Width, this.Height];
							shape[0, 0].Filled = true;
							shape[1, 0].Filled = false;
							shape[0, 1].Filled = true;
							shape[1, 1].Filled = true;
							shape[0, 2].Filled = false;
							shape[1, 2].Filled = true;
							// Creates the images for this block.
							shape[0, 0].BrickImage = blockImage02;
							shape[0, 1].BrickImage = blockImage01;
							shape[1, 1].BrickImage = blockImage02;
							shape[1, 2].BrickImage = blockImage01;
							// Sets the Shape property to the new shape created.
							this.Shape = shape;
							break;
					}
				}
				else
				{
					// Current block type is not Undefined.
					// Throws an argument exception with the error.
					throw new ArgumentException("The property BlockType can't be changed once defined for the first time.");
				}
			}
		}

		/// <summary>
		/// Method that draws the block in a surface.
		/// </summary>
		/// <param name="drawingSurface">The graphics surface where the block will be drawn.</param>
		public void Draw(Graphics drawingSurface)
		{
			// Runs through the block Width.
			for(int i = 0; i < this.Width; i++)
			{
				// Runs through the block Height.
				for(int j = 0; j < this.Height; j++)
				{
					// Checks if the current brick of the block is set to be solid.
					if (this.Shape[i, j].Filled == true)
					{
						// Current brick of the block is set to be solid.
						// Creates a rectangle in the right position of this brick.
						Rectangle rect = new Rectangle((this.Left + i) * Game.BlockImageWidth, (this.Top + j) * Game.BlockImageHeight, Game.BlockImageWidth, Game.BlockImageHeight);
						// Draws the block image in the just created rectangle.
						drawingSurface.DrawImage(this.Shape[i, j].BrickImage, rect);
					}
				}
			}
		}

		/// <summary>
		/// Method that rotates the block.
		/// </summary>
		/// <param name="clockwise">True if the block will be rotated clockwise, false if counterclockwise.</param>
		public void Rotate(bool clockwise)
		{
			short newWidth = 0;
			short newHeight = 0;
			Brick[,] newShape;

			// Inverts the width with the height.
			newWidth = this.Height;
			newHeight = this.Width;
			// Creates a new shape with the new width and height.
			newShape = new Brick[newWidth, newHeight];

			// Checks if the block must be rotated clockwise or counterclockwise.
			if(clockwise)
			{
				// The block must be rotated clockwise.
				// Tests if the block can be rotated clockwise, according to its position in the play field.
				if (((this.Left + newWidth) <= Game.PlayingFieldWidth) && ((this.Top + newHeight) < Game.PlayingFieldHeight))
				{
					// The block can be rotated.
					// Populates the new shape by rotating the old shape.
					for(int i = 0; i < this.Width; i++)
					{
						for(int j = 0; j < this.Height; j++)
						{
							newShape[((this.Height - 1) - j), i] = this.Shape[i, j];
						}
					}

					// Puts the new values in the current block.
					this.Width = newWidth;
					this.Height = newHeight;
					this.Shape = newShape;
				}
			}
			else
			{
				// The block must be rotated counterclockwise.
				// Tests if the block can be rotated counterclockwise, according to its position in the play field.
				if (((this.Left + newWidth) <= Game.PlayingFieldWidth) && ((this.Top + newHeight) < Game.PlayingFieldHeight))
				{
					// The block can be rotated.
					// Populates the new shape by rotating the old shape.
					for(int i = 0; i < this.Width; i++)
					{
						for(int j = 0; j < this.Height; j++)
						{
							newShape[j, ((this.Width - 1) - i)] = this.Shape[i, j];
						}
					}
					// Puts the new values in the current block.
					this.Width = newWidth;
					this.Height = newHeight;
					this.Shape = newShape;
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -