俄罗斯方块之四 运动块的绘制实现
来源:互联网 发布:房屋中介软件哪个好 编辑:程序博客网 时间:2024/06/12 00:09
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Drawing.Drawing2D;namespace Els{ class Block { //定义类的属性: Random ran = new Random(); //随机数对象 BlockType typeId; //枚举类型变量type private int[,] currentShapes; //当前形状的二维数组,具体到是哪个具体的俄罗斯方块 protected int left, top; //block的位置 protected int colorIndex; //随机俄罗斯方块的颜色; public const int SquareSize = 16; // 单个方块长宽为16像素 /// <summary> /// 定义块的构造方法 /// </summary> public Block() { typeId = (BlockType)ran.Next(4); //需要强制转化一下,随机产生一个俄罗斯方块 this.currentShapes = ShapeTable.getShape(typeId, ran.Next(0, 5)); top = 0; left = 64; //当前块panel的一半 this.colorIndex = ran.Next(1, 9); //可以暂时省略该代码; } /// <summary> /// /// </summary> /// <param name="g"></param> public void DrawSmall(Graphics g) { int left = 3 - currentShapes.GetLength(1) / 2+1; int top = 3 - currentShapes.GetLength(0) / 2+1; //上面两行代码,定位居左和居中的位置; Image img = System.Drawing.Image.FromFile("img/"+colorIndex+".jpg"); //拆分成一个类,存放了8个颜色的俄罗斯方块的路径; for (int y = 0; y < this.currentShapes.GetLength(0); y++) { for (int x = 0; x < this.currentShapes.GetLength(1); x++) { //如果判断二维数组的单元格值是1,则,构造一个矩形,在指定位置,长度; if (this.currentShapes[y, x] == 1) { Rectangle rec = new Rectangle((left + x) * SquareSize, (top + y) * SquareSize, SquareSize, SquareSize); g.DrawImage(img, rec); } } } } }}
可以实现暂时绘制简单图形,复杂图形还没有做,以及运动轨迹的实现还没有实现。
0 0
- 俄罗斯方块之四 运动块的绘制实现
- Java开发的游戏之四 俄罗斯方块 完整源代码
- 俄罗斯方块中方块的旋转变形
- 俄罗斯方块的接口实现
- 俄罗斯方块的简单实现
- MFC实现的俄罗斯方块
- C# 俄罗斯方块的实现
- C实现的俄罗斯方块
- 俄罗斯方块的实现
- 俄罗斯方块java的实现
- 俄罗斯方块的源码实现
- 俄罗斯方块的 C++实现
- 俄罗斯方块的源码实现
- 实现俄罗斯方块的下落
- 类的成员之四:代码块
- 用H5 canvas实现唯美渐变色块的绘制
- 粗糙的iOS笔记四之绘制
- iOS 之地图上绘制运动轨迹
- Boost库命名规则
- TCP套接字与UDP套接字编程
- 弹性正碰演示系统
- hibernate 笔记之api详解
- ref和out
- 俄罗斯方块之四 运动块的绘制实现
- 利用数列对应的生成函数求解数列的通项式
- 跟小博老师一起学习数据库 ——大数据
- BZOJ 1486: [HNOI2009]最小圈 01分数规划+SPFA判环
- LeetCode 290. Word Pattern 双map *****
- 1.oracle账户创建、权限控制
- gcc 的执行过程详解 预处理 编译 汇编 链接
- 社会心理现象0.0
- LeetCode刷题(C++)——Remove Element(Easy)