俄罗斯方块之四 运动块的绘制实现
生活随笔
收集整理的這篇文章主要介紹了
俄罗斯方块之四 运动块的绘制实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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; //枚舉類型變量typeprivate 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);}}}}}
}
可以實現暫時繪制簡單圖形,復雜圖形還沒有做,以及運動軌跡的實現還沒有實現。
視頻課:https://edu.csdn.net/course/play/8034
視頻:https://edu.csdn.net/course/detail/27107
?
?
總結
以上是生活随笔為你收集整理的俄罗斯方块之四 运动块的绘制实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ssm整合之六 时间日期装换
- 下一篇: android 十八 蓝牙及Wi-Fi