毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

C语言俄罗斯方块程序设计 第3页

更新时间:2010-3-5:  来源:毕业论文
C语言俄罗斯方块程序设计 第3页
using System;
using System.Drawing;

namespace AnotherBlock
{
 /// <summary>
 /// Summary description for Blocks.
 /// </summary>
 public class Blocks
 {
  private short width;
  private short height;
  private bool[,] shape;
  private short top;
  private short left;
  private BlockTypes blockType = BlockTypes.undefined;

  Image basicBlockImage = Image.FromFile("images/block.gif");

  private const int blockImageWidth = 10;
  private const int blockImageHeight = 10;

  public Blocks(BlockTypes blockType)
  {
   this.BlockType = blockType;
  }

  public Blocks()
  {
   Random randomGenerator = new Random();
   BlockTypes randomBlockType = (BlockTypes)(randomGenerator.Next(1, 8));

   this.BlockType = randomBlockType;
  }

  public short Top
  {
   get
   {
    return top;
   }

   set
   {
    if ((value > -1) && (value < 21))
    {
     top = value;
     if (top == 0)
     {
      top = 1;
     }
    }
    else
    {
     throw new ArgumentException("Property Top must be between 1 and 20.");
    }
   }
  }

  public short Left
  {
   get
   {
    return left;
   }

   set
   {
    if ((value > -1) && (value < 10))
    {
     left = value;
    }
    else
    {
     throw new ArgumentException("Property Left must be between 0 and 9.");
    }
   }
  }

  public short Width
  {
   get
   {
    return width;
   }

   set
   {
    if ((value > 0) && (value < 5))
    {
     width = value;
    }
    else
    {
     throw new ArgumentException("Propert Width must be between 1 and 4.");
    }
   }
  }

  public short Height
  {
   get
   {
    return height;
   }

   set
   {
    if ((value > 0) && (value < 5))
    {
     height = value;
    }
    else
    {
     throw new ArgumentException("Property Height must be between 1 and 4.");
    }
   }
  }

  public bool[,] Shape
  {
   get
   {
    return shape;
   }

   set
   {
    if (value.Length == width * height)
    {
     shape = value;
    }
    else
    {
     throw new InvalidOperationException("Specified index length does not match block dimensions.");
    }
   }
  }

  public BlockTypes BlockType
  {
   get
   {
    return blockType;
   }

   set
   {
    bool[,] shape;

    if (blockType == BlockTypes.undefined)
    {
     blockType = value;

     switch(blockType)
     {
      case BlockTypes.straight:
       this.Width = 1;
       this.Height = 4;
       this.Top = 0;
       this.Left = 5;
       shape = new bool[this.Width, this.Height];
       shape[0, 0] = true;
       shape[0, 1] = true;
       shape[0, 2] = true;
       shape[0, 3] = true;
       this.Shape = shape;
       break;

      case BlockTypes.rectangle:
       this.Width = 2;
       this.Height = 2;
       this.Top = 0;
       this.Left = 4;
       shape = new bool[this.Width, this.Height];
       shape[0, 0] = true;
       shape[0, 1] = true;
       shape[1, 0] = true;
       shape[1, 1] = true;
       this.Shape = shape;
       break;

      case BlockTypes.cornerleft:
       this.Width = 3;
       this.Height = 2;
       this.Top = 0;
       this.Left = 4;
       shape = new bool[this.Width, this.Height];
       shape[0, 0] = true;
       shape[1, 0] = true;
       shape[2, 0] = true;
       shape[0, 1] = true;
       shape[1, 1] = false;
       shape[2, 1] = false;
       this.Shape = shape;
       break;

      case BlockTypes.cornerright:
       this.Width = 3;
       this.Height = 2;
       this.Top = 0;
       this.Left = 4;
       shape = new bool[this.Width, this.Height];
       shape[0, 0] = true;
       shape[1, 0] = true;
       shape[2, 0] = true;
       shape[0, 1] = false;
       shape[1, 1] = false;
       shape[2, 1] = true;
       this.Shape = shape;
       break;

      case BlockTypes.cross:
       this.Width = 3;
       this.Height = 2;
       this.Top = 0;
       this.Left = 4;
       shape = new bool[this.Width, this.Height];
       shape[0, 0] = true;
       shape[1, 0] = true;
       shape[2, 0] = true;
       shape[0, 1] = false;
       shape[1, 1] = true;
       shape[2, 1] = false;
       this.Shape = shape;
       break;

      case BlockTypes.zigzag1:
       this.Width = 2;
       this.Height = 3;
       this.Top = 0;
       this.Left = 4;
       shape = new bool[this.Width, this.Height];
       shape[0, 0] = false;
       shape[1, 0] = true;
       shape[0, 1] = true;
       shape[1, 1] = true;
       shape[0, 2] = true;
       shape[1, 2] = false;
       this.Shape = shape;
       break;

      case BlockTypes.zigzag2:
       this.Width = 2;
       this.Height = 3;
       this.Top = 0;
       this.Left = 4;
       shape = new bool[this.Width, this.Height];
       shape[0, 0] = true;
       shape[1, 0] = false;
       shape[0, 1] = true;
       shape[1, 1] = true;
       shape[0, 2] = false;
       shape[1, 2] = true;
       this.Shape = shape;
       break;
     }
    }
    else
    {
     throw new InvalidOperationException("The property BlockType can't be changed once defined the first time.");
    }
   }
  }

  public void Draw(Graphics drawingSurface)
  {
   for(int i = 0; i < this.Width; i++)
   {
    for(int j = 0; j < this.Height; j++)
    {
     if (this.Shape[i, j] == true)
     {
      Rectangle rect = new Rectangle((this.Left + i) * blockImageWidth, (this.Top + j) * blockImageHeight, blockImageWidth, blockImageHeight);
      drawingSurface.DrawImage(basicBlockImage, rect);

上一页  [1] [2] [3] 

C语言俄罗斯方块程序设计 第3页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。