1、 Form private GamePalette m_GamePalette; public 策略() InitializeComponent();/显示的属性pbmainpalette pbnextpalette formmain的属性 / Application.Run(new FormMain(); FormMain_Shown pbNextPalette_Paint pbMainPalette_Paint private void pbMainPalette_Paint(object sender,PaintEventArgs e) if (m_GamePalette != null
2、) m_GamePalette.PaintPalette(e.Graphics);/背景设定为灰色 private void pbNextPalette_Paint(object sender,PaintEventArgs e) if(m_GamePalette!=null) m_GamePalette.PaintNext(e.Graphics); /一开始就有一些图像信息如背景位图 private void 策略_KeyDown(object sender, KeyEventArgs e) if (e.KeyCode = Keys.F2) m_GamePalette.m_Score = 0;
3、 m_GamePalette.Close(); m_GamePalette = null; TemplateArray array = new TemplateArray(); /private ArrayList m_List = new ArrayList();/m_List 为一个动态数组 array.Add(0000001000011100000000000, Color.FromArgb(-128); /get return m_List.Count;0000000000111100000000000, Color.FromArgb(-65536);/ m_List.Add(new
4、BrickTemplate(code,color)0000000110011000000000000, Color.FromArgb(-16711936);/array 含有m_list与Count信息地址 (public)0000000100011100000000000, Color.FromArgb(-4144960);0000000100011000100000000, Color.FromArgb(-16776961);0000000000011100100000000, Color.FromArgb(-65281);0000001000011000110000000, Color.
5、FromArgb(-8323073); m_GamePalette = new GamePalette( / public GamePalette() 15, 25, array, 20, Color.Black, pbMainPalette.CreateGraphics(), pbNextPalette.CreateGraphics(), pictureBox1.CreateGraphics(), 0, Color.White, false); m_GamePalette.PaintScore(); m_GamePalette.InitRandomBrick(); m_GamePalette
6、.Start(); else if (m_GamePalette = null | m_GamePalette.IsGameover) return; if (e.KeyCode = Keys.F3) if (m_GamePalette.IsRunning) m_GamePalette.Pause(); m_GamePalette.Resume(); else if (e.KeyCode = Keys.Left) m_GamePalette.MoveLeft(); else if (e.KeyCode = Keys.Right) m_GamePalette.MoveRight(); else
7、if (e.KeyCode = Keys.Down) m_GamePalette.DropDown(); else if (e.KeyCode = Keys.Up) m_GamePalette.ContraRotate(); else if (e.KeyCode = Keys.Space) private void button1_Click(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e) private void button3_Click(object sender, Ev
8、entArgs e) private void button4_Click(object sender, EventArgs e) m_GamePalette.MoveDown(); private void button5_Click(object sender, EventArgs e) private void 策略_Shown(object sender, EventArgs e) private void pictureBox1_Paint(object sender, PaintEventArgs e) partial class 策略 / 必需的设计器变量。 private Sy
9、stem.ComponentModel.IContainer components = null; / 清理所有正在使用的资源。param name=disposing如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) if (disposing & (components != null) components.Dispose(); base.Dispose(disposing); #region Windows 窗体设计器生成的代码 / 设计器支持所需的方法 - 不要 / 使用代码编辑器修改
10、此方法的内容。 private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(策略); this.pbMainPalette = new System.Windows.Forms.PictureBox(); this.pbNextPalette = new System.Windows.Forms.PictureBox(); this.pictureBox
11、1 = new System.Windows.Forms.PictureBox(); (System.ComponentModel.ISupportInitialize)(this.pbMainPalette).BeginInit(); (System.ComponentModel.ISupportInitialize)(this.pbNextPalette).BeginInit(); (System.ComponentModel.ISupportInitialize)(this.pictureBox1).BeginInit(); this.SuspendLayout(); / / pbMai
12、nPalette this.pbMainPalette.Image = (System.Drawing.Image)(resources.GetObject(pbMainPalette.Image); this.pbMainPalette.Location = new System.Drawing.Point(0, 0); this.pbMainPalette.Name = pbMainPalette; this.pbMainPalette.Size = new System.Drawing.Size(300, 500); this.pbMainPalette.TabIndex = 0; th
13、is.pbMainPalette.TabStop = false; this.pbMainPalette.Paint += new System.Windows.Forms.PaintEventHandler(this.pbMainPalette_Paint); / pbNextPalette this.pbNextPalette.Image = (System.Drawing.Image)(resources.GetObject(pbNextPalette.Image this.pbNextPalette.Location = new System.Drawing.Point(306, 12
14、); this.pbNextPalette.Name = pbNextPalette this.pbNextPalette.Size = new System.Drawing.Size(100, 100); this.pbNextPalette.TabIndex = 1; this.pbNextPalette.TabStop = false; this.pbNextPalette.Paint += new System.Windows.Forms.PaintEventHandler(this.pbNextPalette_Paint); / pictureBox1 this.pictureBox
15、1.Image = (System.Drawing.Image)(resources.GetObject(pictureBox1.Image this.pictureBox1.Location = new System.Drawing.Point(306, 133); this.pictureBox1.Name = pictureBox1 this.pictureBox1.Size = new System.Drawing.Size(100, 150); this.pictureBox1.TabIndex = 2; this.pictureBox1.TabStop = false; this.
16、pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); / 策略 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(410, 507); this.Controls.Add(this.pictur
17、eBox1); this.Controls.Add(this.pbNextPalette); this.Controls.Add(this.pbMainPalette); this.KeyPreview = true; this.Name = 策略 this.Text = this.Shown += new System.EventHandler(this.策略_Shown); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.策略_KeyDown); (System.ComponentModel.ISupportIni
18、tialize)(this.pbMainPalette).EndInit(); (System.ComponentModel.ISupportInitialize)(this.pbNextPalette).EndInit(); (System.ComponentModel.ISupportInitialize)(this.pictureBox1).EndInit(); this.ResumeLayout(false); #endregion private System.Windows.Forms.PictureBox pbMainPalette; private System.Windows
19、.Forms.PictureBox pbNextPalette; private System.Windows.Forms.PictureBox pictureBox1;using System.Collections;/砖块列表信息类dnamespace Tetris.logic class TemplateArray /定义了Add函数与Clear函数管理木块增减 private ArrayList m_List = new ArrayList();/创建m_List 为一个动态数组 /获取砖块末班数 public int Count get return m_List.Count; /获
20、取砖块模板 index 下标 return 砖块模具 public BrickTemplate thisint index /BrickTemplate /砖块样色信息模板类(砖块样式编码,样色) BrickTemplate为格式 get return (BrickTemplate)m_Listindex; /返回m_Listindex下的(砖块样式编码,样色)m-list的元素下都有m-code m-color /添加新砖块模板 砖块样式编码 颜色 public void Add(string code,Color color) m_List.Add(new BrickTemplate(co
21、de,color);/接着执行BrickTemplate 执行m_Code =code; m_Color =color; 返回form1 把m-Code m-Color的地址送给m-list /完毕后Code=m_Code Code 可改m-Code不能改 /清空砖块模板 public void Clear() m_List.Clear(); class BrickTemplate /砖块样色信息模板类(砖块样式编码,样色) private string m_Code; private Color m_Color; /构造砖块信息 code砖块编码字符串 color 砖块 public Bri
22、ckTemplate(string code, Color color) if(code=null | code.Length !=25| color = Color.Empty) throw new FormatException(zhuankuai yangshi xinxi cuowu!); m_Code =code; /返回后清空 /获取砖块样式编码 public string Code /使得外部变量Code与私有变量m_Code相等 get return m_Code; /使用BrickTemplate函数是已经赋值了的m_Code (=code); /获取砖块颜色 public
23、Color Color / /使得外部变量Color与m_Color私有变量相等 get return m_Color; class Brick /构造砖块 private Point m_Points;/zuobiao private组织防止其它调用 private int m_X; /zhongdian zuobiao private int m_Y; public Color m_Color; /zhuankuai yanse private Color m_BgColor; /beijing yanse private int m_BlockSize; /danyuange xiang
24、se private SolidBrush m_Brush; /单色画笔,用来填充 /单点放大成矩形 private Rectangle PointToRect(Point p) /由坐标返回:坐标,宽长 四要素 Rectangle r = new Rectangle(X+m_X+p.X)*m_BlockSize+1,/ x Rectangle贮存(坐标x,坐标y,宽,高) (Y+m_Y+p.Y)*m_BlockSize+1,/y m_XY使Y从变化到heigh-2 最后一行矮一点?不Y在m_Runbrick=-y时已经被改变 m_BlockSize-2, / width 因为单位格稍小 m_BlockSize-2); /height return r; /中点在(x+m_x,y+m_y) /构造砖块:sa 砖块样式 color 砖块颜色 bgcolor 砖块背景颜色size 砖块单位大小 public Brick(Point sa, Color color, Color bgColor, int size)/Brick(样式,砖颜色,背景颜色,大小) m_Color = color; m_BgColor = bgColor; /赋值给private Rectangle PointToRect(Point p)在显示时使用(返回值时使用) m_Bloc
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1