俄罗斯方块代码.docx
- 文档编号:8204394
- 上传时间:2023-01-29
- 格式:DOCX
- 页数:40
- 大小:27.08KB
俄罗斯方块代码.docx
《俄罗斯方块代码.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块代码.docx(40页珍藏版)》请在冰豆网上搜索。
俄罗斯方块代码
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Windows.Forms;
namespaceTetris
{
staticclassProgram
{
///
///应用程序的主入口点。
///
[STAThread]
staticvoidMain()
{//程序从这里开始
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new策略());
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingTetris.logic;
namespaceTetris
{
publicpartialclass策略:
Form
{
privateGamePalettem_GamePalette;
public策略()
{
InitializeComponent();//显示的属性pbmainpalettepbnextpaletteformmain的属性
}//Application.Run(newFormMain());FormMain_ShownpbNextPalette_PaintpbMainPalette_Paint
privatevoidpbMainPalette_Paint(objectsender,PaintEventArgse)
{
if(m_GamePalette!
=null)
{
m_GamePalette.PaintPalette(e.Graphics);//背景设定为灰色
}
}
privatevoidpbNextPalette_Paint(objectsender,PaintEventArgse)
{
if(m_GamePalette!
=null)
m_GamePalette.PaintNext(e.Graphics);//一开始就有一些图像信息如背景位图
}
privatevoid策略_KeyDown(objectsender,KeyEventArgse)
{
if(e.KeyCode==Keys.F2)
{
if(m_GamePalette!
=null)
{
m_GamePalette.m_Score=0;
m_GamePalette.Close();
m_GamePalette=null;
}
TemplateArrayarray=newTemplateArray();//privateArrayListm_List=newArrayList();//m_List为一个动态数组
array.Add("0000001000011100000000000",Color.FromArgb(-128));//get{returnm_List.Count;}
array.Add("0000000000111100000000000",Color.FromArgb(-65536));//m_List.Add(newBrickTemplate(code,color))
array.Add("0000000110011000000000000",Color.FromArgb(-16711936));//array含有m_list与Count信息地址(public)
array.Add("0000000100011100000000000",Color.FromArgb(-4144960));
array.Add("0000000100011000100000000",Color.FromArgb(-16776961));
array.Add("0000000000011100100000000",Color.FromArgb(-65281));
array.Add("0000001000011000110000000",Color.FromArgb(-8323073));
m_GamePalette=newGamePalette(//publicGamePalette()
15,
25,
array,
20,
Color.Black,
pbMainPalette.CreateGraphics(),
pbNextPalette.CreateGraphics(),
pictureBox1.CreateGraphics(),
0,
Color.White,
false);
m_GamePalette.PaintScore();
m_GamePalette.InitRandomBrick();
m_GamePalette.Start();
}
else
{
if(m_GamePalette==null||m_GamePalette.IsGameover)
return;
if(e.KeyCode==Keys.F3)
{
if(m_GamePalette.IsRunning)m_GamePalette.Pause();
else
m_GamePalette.Resume();
}
elseif(e.KeyCode==Keys.Left)
m_GamePalette.MoveLeft();
elseif(e.KeyCode==Keys.Right)
m_GamePalette.MoveRight();
elseif(e.KeyCode==Keys.Down)
m_GamePalette.DropDown();
elseif(e.KeyCode==Keys.Up)
m_GamePalette.ContraRotate();
elseif(e.KeyCode==Keys.Space)
m_GamePalette.ContraRotate();
}
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
m_GamePalette.ContraRotate();
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
m_GamePalette.MoveLeft();
}
privatevoidbutton3_Click(objectsender,EventArgse)
{
m_GamePalette.MoveRight();
}
privatevoidbutton4_Click(objectsender,EventArgse)
{
m_GamePalette.MoveDown();
}
privatevoidbutton5_Click(objectsender,EventArgse)
{
}
privatevoid策略_Shown(objectsender,EventArgse)
{
}
privatevoidpictureBox1_Paint(objectsender,PaintEventArgse)
{
{
if(m_GamePalette!
=null)
m_GamePalette.PaintScore();//一开始就有一些图像信息如背景位图
}
}
namespaceTetris
{
partialclass策略
{
///
///必需的设计器变量。
///
privateSystem.ComponentModel.IContainercomponents=null;
///
///清理所有正在使用的资源。
///
///
protectedoverridevoidDispose(booldisposing)
{
if(disposing&&(components!
=null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#regionWindows窗体设计器生成的代码
///
///设计器支持所需的方法-不要
///使用代码编辑器修改此方法的内容。
///
privatevoidInitializeComponent()
{
System.ComponentModel.ComponentResourceManagerresources=newSystem.ComponentModel.ComponentResourceManager(typeof(策略));
this.pbMainPalette=newSystem.Windows.Forms.PictureBox();
this.pbNextPalette=newSystem.Windows.Forms.PictureBox();
this.pictureBox1=newSystem.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pbMainPalette)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbNextPalette)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
//pbMainPalette
//
this.pbMainPalette.Image=((System.Drawing.Image)(resources.GetObject("pbMainPalette.Image")));
this.pbMainPalette.Location=newSystem.Drawing.Point(0,0);
this.pbMainPalette.Name="pbMainPalette";
this.pbMainPalette.Size=newSystem.Drawing.Size(300,500);
this.pbMainPalette.TabIndex=0;
this.pbMainPalette.TabStop=false;
this.pbMainPalette.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.pbMainPalette_Paint);
//
//pbNextPalette
//
this.pbNextPalette.Image=((System.Drawing.Image)(resources.GetObject("pbNextPalette.Image")));
this.pbNextPalette.Location=newSystem.Drawing.Point(306,12);
this.pbNextPalette.Name="pbNextPalette";
this.pbNextPalette.Size=newSystem.Drawing.Size(100,100);
this.pbNextPalette.TabIndex=1;
this.pbNextPalette.TabStop=false;
this.pbNextPalette.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.pbNextPalette_Paint);
//
//pictureBox1
//
this.pictureBox1.Image=((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location=newSystem.Drawing.Point(306,133);
this.pictureBox1.Name="pictureBox1";
this.pictureBox1.Size=newSystem.Drawing.Size(100,150);
this.pictureBox1.TabIndex=2;
this.pictureBox1.TabStop=false;
this.pictureBox1.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
//
//策略
//
this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,12F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=newSystem.Drawing.Size(410,507);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.pbNextPalette);
this.Controls.Add(this.pbMainPalette);
this.KeyPreview=true;
this.Name="策略";
this.Text="策略";
this.Shown+=newSystem.EventHandler(this.策略_Shown);
this.KeyDown+=newSystem.Windows.Forms.KeyEventHandler(this.策略_KeyDown);
((System.ComponentModel.ISupportInitialize)(this.pbMainPalette)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pbNextPalette)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
privateSystem.Windows.Forms.PictureBoxpbMainPalette;
privateSystem.Windows.Forms.PictureBoxpbNextPalette;
privateSystem.Windows.Forms.PictureBoxpictureBox1;
}
}
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
//砖块列表信息类d
namespaceTetris.logic
{
classTemplateArray//定义了Add函数与Clear函数管理木块增减
{
privateArrayListm_List=newArrayList();//创建m_List为一个动态数组
//获取砖块末班数
publicintCount
{
get{returnm_List.Count;}
}
//获取砖块模板index下标return砖块模具
publicBrickTemplatethis[intindex]//BrickTemplate//砖块样色信息模板类(砖块样式编码,样色)BrickTemplate为格式
{
get{return(BrickTemplate)m_List[index];}//返回m_List[index]下的(砖块样式编码,样色)m-list的元素下都有m-codem-color
}
//添加新砖块模板砖块样式编码颜色
publicvoidAdd(stringcode,Colorcolor)
{
m_List.Add(newBrickTemplate(code,color));//接着执行BrickTemplate执行m_Code=code;m_Color=color;返回form1把m-Codem-Color的地址送给m-list
}//完毕后Code=m_CodeCode可改m-Code不能改
//清空砖块模板
publicvoidClear()
{
m_List.Clear();
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceTetris.logic
{
classBrickTemplate//砖块样色信息模板类(砖块样式编码,样色)
{
privatestringm_Code;
privateColorm_Color;
//构造砖块信息code砖块编码字符串color砖块
publicBrickTemplate(stringcode,Colorcolor)
{
if(code==null||code.Length!
=25||color==Color.Empty)
{thrownewFormatException("zhuankuaiyangshixinxicuowu!
");}
m_Code=code;
m_Color=color;
}//返回后清空
//获取砖块样式编码
publicstringCode//使得外部变量Code与私有变量m_Code相等
{
get{returnm_Code;}//使用BrickTemplate函数是已经赋值了的m_Code(=code);
}
//获取砖块颜色
publicColorColor////使得外部变量Color与m_Color私有变量相等
{
get{returnm_Color;}
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceTetris.logic
{
classBrick//构造砖块
{
privatePoint[]m_Points;//zuobiaoprivate组织防止其它调用
privateintm_X;//zhongdianzuobiao
privateintm_Y;
publicColorm_Color;//zhuankuaiyanse
privateColorm_BgColor;//beijingyanse
privateintm_BlockSize;//danyuangexiangse
privateSolidBrushm_Brush;//单色画笔,用来填充
//
//单点放大成矩形
privateRectanglePointToRect(Pointp)//由坐标返回:
坐标,宽长四要素
{
Rectangler=newRectangle((X+m_X+p.X)*m_BlockSize+1,//xRectangle贮存(坐标x,坐标y,宽,高)
(Y+m_Y+p.Y)*m_BlockSize+1,//ym_XY使Y从变化到heigh-2最后一行矮一点?
不Y在m_Runbrick=-y时已经被改变
m_BlockSize-2,//width因为单位格稍小
m_BlockSize-2);//height
returnr;//中点在(x+m_x,y+m_y)
}
//构造砖块:
sa砖块样式color砖块颜色bgcolor砖块背景颜色size砖块单位大小
publicBrick(Point[]sa,Colorcolor,ColorbgColor,intsize)//Brick(样式,砖颜色,背景颜色,大小)
{
m_Color=color;
m_BgColor=bgColor;//赋值给privateRectanglePointToRect(Pointp)在显示时使用(返回r值时使用)
m_Bloc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 俄罗斯方块 代码