为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

俄罗斯方块游戏论文

2011-09-06 42页 doc 528KB 82阅读

用户头像

is_115930

暂无简介

举报
俄罗斯方块游戏论文毕业设计用纸 中文摘要 随着现代社会生活节奏的不断加快,软件的开发周期要求越来越短,这就要求有一种简单易开发的语言工具出现,而C#的出现正好适应了这种要求。 C#是微软公司为Visual Studio开发平台推出的一种简洁、安全的面向对象的编程语言,开发人员可以通过它编写在.NET Framework上运行的各种安全可靠的应用程序,例如控制台应用程序、WinForms应用程序和Web应用程序等。由于C#简单易学,而且可以跨平台使用,因此它正在成为程序开发人员使用的主流编程语言。 本论文主要是用C#语言和ASP.NET技术编写一...
俄罗斯方块游戏论文
毕业用纸 中文摘要 随着现代社会生活节奏的不断加快,软件的开发周期要求越来越短,这就要求有一种简单易开发的语言工具出现,而C#的出现正好适应了这种要求。 C#是微软公司为Visual Studio开发平台推出的一种简洁、安全的面向对象的编程语言,开发人员可以通过它编写在.NET Framework上运行的各种安全可靠的应用程序,例如控制台应用程序、WinForms应用程序和Web应用程序等。由于C#简单易学,而且可以跨平台使用,因此它正在成为程序开发人员使用的主流编程语言。 本论文主要是用C#语言和ASP.NET技术编写一个在.NET Framework上运行的俄罗斯方块小游戏。 关键词:C#,ASP.NET,.NET Framework,软件开发,俄罗斯方块 ABSTRACT With the pace of modern life continues to accelerate, increasing demands of software development cycle is short, which requires a simple and easy development of language tools appear, and C # just to adapt to the emergence of such a request. C # is Microsoft's Visual Studio development platform for the launch of a simple, secure object-oriented programming language, developers can write in it. NET Framework to run on a variety of safe and reliable applications, such as a console application , WinForms applications, and Web applications and so on. Since C # is easy to learn, and can cross-platform, so it is becoming the mainstream application developers to use programming language. This thesis is ASP.NET C # language and a technical writing. NET Framework run on Tetris game. Keywords:C#,ASP.NET,.NET Framework,software development,Tetris game 目 录 引言 —————————————————————————————3 一、配置窗体的实现——————————————————————3 (一)砖块样式配置窗体的实现 ——————————————————3 【一】生成方块的网格矩阵的实现———————————————————5 【二】屏幕像素值与数组下标值转换的实现———————————————6 【三】添删改方块样式的按钮的实现——————————————————8 参数配置窗体的实现 ————————————————————12 【一】快捷键设置方法的实现—————————————————————12 【二】砖块信息存放的实现——————————————————————16 【三】专门配置类的实现———————————————————————20 二、游戏主窗体的实现—————————————————————25 (一)砖块信息类的实现——————————————————————25 【一】砖块基类与生产类的实现 ————————————————————25 (二)砖块画布类的实现—————————————————————————30 【一】砖块移动的实现 ————————————————————————30 (三)主窗体按钮的实现——————————————————————38 【一】主窗体按钮的实现 ———————————————————————38 结束语 —————————————————————————————41 致谢 —————————————————————————————41 参考文献—————————————————————————————42 引言 在写此论文之前,我们恰好学完了C#语言程序设计这门课程。所以我决定用C#语言开发一个俄罗斯方块小游戏,来进一步掌握C#语言的语法,并通过此论文地编写,对什么是程序开发、如何进行程序开发有一个更新的认识,更明确的定位。之所以选择俄罗斯方块这个游戏,是因为我们大家对这个游戏的规则都很熟悉,并且代码的实现也不是很难。以一个来月的时间来写这篇论文正好合适。当然,我这个游戏只是刚好能实现基本的功能而已,仅凭我一个人的力量是不可能做出一个完美的游戏的。但是,我这个游戏却不乏自己的个性,就是能自定义方块的样式。尽管如此,如果大家有相关语言基础,完全可以在此游戏基础上添加和完善更多功能。 配置窗体的实现 参数配置窗体主要是实现游戏砖块的配置及游戏环境的设置,在这个窗体中,用户可以来设置自己的喜欢的快捷键和游戏环境并保存设置以供下次使用,下面我们来慢慢实现。 、砖块样式配置窗体的实现 此窗体主要是实现砖块的生成、砖块的增删改以及砖块信息的保存。在此窗体中,用户还可以保存对配置窗体的修改和退出配置窗体,其图如下所示: 图 1 砖块样式配置窗体示意图 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Tetris { public partial class FrmConfig : Form { public FrmConfig() { InitializeComponent(); } private bool[,] struArr = new bool[5, 5];//声明数组,存放方块信息 private Color blockColor = Color.Red; //声明颜色类型变量并赋值为红色 private Config config = new Config();//声明一个config类 【一】生成方块的网格矩阵的实现 我们希望用户点击矩阵生成方块样式,因此我们需要生成一个5x5的矩阵,当用户单击某个方块时该方块就变色,单击两次则变回背景色,用户通过单击不同方块来创建不同样式和不同颜色的方块。当然,想要不同砖块能设置不同颜色,我们需要一个颜色对话框。所以,这个矩阵的样式如下: 图1-1 方块构成示意图 //lblMode_Paint事件,绘画出网格并实现给方块上色 private void lblMode_Paint(object sender, PaintEventArgs e) { Graphics gp = e.Graphics; //声明画板 gp.Clear(Color.Black); //清空画板时背景色为黑色 Pen p = new Pen(Color.White); //定义画笔,颜色为白色 for (int i = 31; i < 155; i = i + 31) //画横线 gp.DrawLine(p, 1, i, 155, i); for (int i = 31; i < 155; i = i + 31) //画竖线 gp.DrawLine(p, i, 1, i, 155); SolidBrush s = new SolidBrush(blockColor); //定义一个刷子,颜色为上面定义的红色,用来填充矩阵中的方块 for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { if (struArr[x, y]) //判断方格是否选中,选中则上色 { gp.FillRectangle(s, 31 * x + 1, 31 * y + 1, 30, 30); } } } } 【二】屏幕像素值与数组下标值转换的实现 而为了方便给方块上色,我们将声明一个bool类型的二维数组,其可以将屏幕像素转换为数组下标值,其对应关系如下图,同时它也是以上代码中画线函数的原型。 图1-2 屏幕像素值示意图 图1-3 数组下标值示意图 //鼠标单击事件,给选中的方块上色,双击还原 private void lblMode_MouseClick(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) //判断是否点击左键 return; int xPos, yPos; //定义数组下标 xPos = e.X / 31; yPos = e.Y / 31; //屏幕的像素值转换为数组的下标值 struArr[xPos, yPos] = !struArr[xPos, yPos]; bool b = struArr[xPos, yPos]; //定义bool值b来保存方块信息 Graphics gp = lblMode.CreateGraphics(); SolidBrush s = new SolidBrush(b ? blockColor : Color.Black); //根据值b给刷子s赋值上颜色 gp.FillRectangle(s, 31 * xPos + 1, 31 * yPos + 1, 30, 30); //给方块上色 gp.Dispose(); } //lblColor_Click事件,设置并保存方块颜色 private void lblColor_Click(object sender, EventArgs e) { colorDialog1.ShowDialog(); // 打开颜色对话框 blockColor = colorDialog1.Color; //把我们选中的颜色赋值给私有变量blockColor lblColor.BackColor = colorDialog1.Color; //选中颜色显示在方框中 lblMode.Invalidate(); //使重画 } 【三】添加方框样式的按钮的实现 如何保存这些方块样式的信息呢,考虑到这些方块信息将要以文件的方式保存在磁盘里面,用户就可以设置一次下次还可继续用这些方块信息,而且我们也希望这种信息是比较直观的,所以我们将使用字符串的方式来存储方块信息。我们看,这样一个方块存储后的信息是这个样子,没有设置的地方为0,设置的地方就为1,如图: 图1-4 砖块信息示意图 //砖块添加事件的实现 private void btnAdd_Click(object sender, EventArgs e) { bool isEmpty = false;//判断查找图案是否为空 foreach (bool i in struArr) { if (i) { isEmpty = true; break; } } if (!isEmpty) { MessageBox.Show("图案为空,请先用鼠标 点击左边窗口绘制图案!", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } StringBuilder sb = new StringBuilder(25); foreach (bool i in struArr) { sb.Append(i ? "1" : "0"); } string blockString = sb.ToString(); //再检查是否有重复的图案 foreach (ListViewItem item in lsvBlockSet.Items) { if (item.SubItems[0].Text == blockString) { MessageBox.Show("该图案已经存在!", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } //把新砖块图案信息进listviewitem。 ListViewItem myItem = new ListViewItem(); myItem = lsvBlockSet.Items.Add(blockString); myItem.SubItems.Add(Convert.ToString(blockColor.ToArgb())); //使用listview保存砖块信息,使砖块图案信息与代码信息一一对应的实现。其中用到一个转换方法,就是将字符串转换为二维数组,这个转换函数的模型如下图所示: 图1-4 转换函数模型示意图 Private void lsvBlockSet_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (e.IsSelected) //判断是否选中,避免重复执行事件。 { blockColor = Color.FromArgb(int.Parse(e.Item.SubItems[1].Text)); lblColor.BackColor = blockColor; string s = e.Item.SubItems[0].Text; //取砖块样式信息。 for (int i = 0; i < s.Length; i++)//字符串信息转换为二维数组 { struArr[i / 5, i % 5] = (s[i] == '1') ? true : false; } lblMode.Invalidate(); //使重画。这里可以使编码信息和砖块样式对应起来。 drawIt();//调用画事件,给方块上色 } } private void drawIt() //画方块函数的实现 { for (int xPos = 0; xPos < 5; xPos++) for (int yPos = 0; yPos < 5; yPos++) { bool b = struArr[xPos, yPos]; Graphics gp = lblMode.CreateGraphics(); SolidBrush s = new SolidBrush(b ? blockColor : Color.Black); gp.FillRectangle(s, 31 * xPos + 1, 31 * yPos + 1, 30, 30); gp.Dispose(); } } //删除砖块样式按键的实现。 private void btnDel_Click(object sender, EventArgs e) { if (lsvBlockSet.SelectedItems.Count == 0) //判断是否有项目选中,没有则显示信息。 { MessageBox.Show("请在右边窗口 选择一个条目进行删除!", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } lsvBlockSet.Items.Remove(lsvBlockSet.SelectedItems[0]); //每次只能选中一个项目。 btnClear.PerformClick();//执行清空事件。 } //清空砖块样式按键的实现。 private void btnClear_Click(object sender, EventArgs e) { for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { struArr[x, y] = false; } } lblMode.Invalidate(); //将数组清空再强制重画就可以清空画板。 } //修改砖块样式按键的实现。 private void btnUpdata_Click(object sender, EventArgs e) { if (lsvBlockSet.SelectedItems.Count == 0)//判断是否有项目选中 { MessageBox.Show("请在右边窗口选择 一个条目进行修改!", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool isEmpty = false;//判断图案是否为空 foreach (bool i in struArr) { if (i) { isEmpty = true; break; } } if (!isEmpty)//为空则显示提示信息。 { MessageBox.Show("图案为空,请先在左边 窗口绘制图案再进行修改!", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } StringBuilder sb = new StringBuilder(25); foreach (bool i in struArr) { sb.Append(i ? "1" : "0"); } lsvBlockSet.SelectedItems[0].SubItems[0].Text = sb.ToString(); //改变样式信息 svBlockSet.SelectedItems[0].SubItems[1].Text= Convert.ToString(blockColor.ToArgb());//改变颜色信息 } 、砖块样式配置窗体的实现 参数配置窗体主要是实现对热键的设置,如快捷键的设置和程序环境的设置。其窗体样式如下图所示: 图 2 参数配置窗体示意图 【一】快捷键设置方法的实现。 在设计窗口中,选中全部textbox,双击生成一个KeyDown事件,这样所有的textbox都会全部使用这个事件。设置热键是通过按这个热键来直接进行设置的,比如说向左你按了个A键那么A就会记录在向左这个TEXTBOX里了。而其中又不可以设置相同的值,例如,如果在向右TEXTBOX中再输入个A,则向左的TEXTBOX中的值就会清空。 private void txtContra_KeyDown(object sender, KeyEventArgs e) { //排除一些不适合的热键。 if ((e.KeyValue >= 33 && e.KeyValue <= 36) || (e.KeyValue >= 45 && e.KeyValue <= 46) || (e.KeyValue >= 48 && e.KeyValue <= 57) || (e.KeyValue >= 65 && e.KeyValue <= 90) || (e.KeyValue >= 96 && e.KeyValue <= 107) || (e.KeyValue >= 109 && e.KeyValue <= 111) || (e.KeyValue >= 186 && e.KeyValue <= 182) || (e.KeyValue >= 219 && e.KeyValue <= 222)) { //检查是否存在冲突的快捷键 foreach (Control c in gbKeySet.Controls) { Control TempC = c as TextBox;//强制类型转换。 if (TempC != null && ((TextBox)TempC).Text != "") { if (((int)((TextBox)TempC).Tag) == e.KeyValue) { ((TextBox)TempC).Text = ""; ((TextBox)TempC).Tag = Keys.None; } } } ((TextBox)sender).Text = e.KeyCode.ToString(); ((TextBox)sender).Tag = (Keys)e.KeyValue; } } //设置背景色的实现。 private void lblBackColor_Click(object sender, EventArgs e) { colorDialog1.ShowDialog(); blockColor = colorDialog1.Color; lblBackColor.BackColor = colorDialog1.Color; } //保存设置的按键的实现 private void btnSave_Click(object sender, EventArgs e) { InfoArr info = new InfoArr(); foreach (ListViewItem item in lsvBlockSet.Items) //从lsvBlockSet内读取砖块信息,并存入info内 { info.Add(item.SubItems[0].Text, item.SubItems[1].Text); } config.Info = info; //把info赋给config对象的Info属性 config.DownKey = (Keys)txtDown.Tag; config.DropKey = (Keys)txtDrop.Tag; config.MoveLeftKey = (Keys)txtLeft.Tag; config.MoveRightKey = (Keys)txtRight.Tag; config.DeasilRotateKey = (Keys)txtDeasil.Tag; config.ContraRotateKey = (Keys)txtContra.Tag; config.CoorWidth = int.Parse(txtCoorWidth.Text); config.CoorHight = int.Parse(txtCoorHeight.Text); config.RectPix = int.Parse(txtRectPix.Text); config.BackColor = lblBackColor.BackColor; config.SaveToXmlFile();//保存为xml文件 } private void btnClose_Click(object sender, EventArgs e)//退出按键 { this.Close(); } //配置窗体加载时,调用config类设置窗体类的实现 private void FrmConfig_Load(object sender, EventArgs e) { config.LoadFromXmlFile();读取xml文件 InfoArr info = config.Info; //读砖块信息 ListViewItem myItem = new ListViewItem(); for (int i = 0; i < info.Length; i++) { myItem = lsvBlockSet.Items.Add(info[i].GetIdStr()); myItem.SubItems.Add(info[i].GetColorStr()); } //读快捷键 txtDown.Text = ((Keys)config.DownKey).ToString(); txtDown.Tag = config.DownKey; txtDrop.Text = ((Keys)config.DropKey).ToString(); txtDrop.Tag = config.DropKey; txtLeft.Text = ((Keys)config.MoveLeftKey).ToString(); txtLeft.Tag = config.MoveLeftKey; txtRight.Text = ((Keys)config.MoveRightKey).ToString(); txtRight.Tag = config.MoveRightKey; txtDeasil.Text = ((Keys)config.DeasilRotateKey).ToString(); txtDeasil.Tag = config.DeasilRotateKey; txtContra.Text = ((Keys)config.ContraRotateKey).ToString(); txtContra.Tag = config.ContraRotateKey; txtCoorWidth.Text = config.CoorWidth.ToString(); txtCoorHeight.Text = config.CoorHight.ToString(); txtRectPix.Text = config.RectPix.ToString(); lblBackColor.BackColor = config.BackColor; } } } 【二】砖块信息存放的实现 为了防止用户设置的信息随着游戏窗体的关闭而消失,我们需要想个办法把用户的配置信息保存在硬盘里,以备用户再次使用时调用。信息存放在硬盘的方法有好几种,但基于游戏的信息量不是很大,且xml比较流行和容易实现,用记事本都可以打开编辑,因此这里我们选择用xml文件来保存信息。 //默认砖块样式信息,为方便看出方块形状,我们用以下这种方式排版 00000 01100 01100 00000 00000 -65536 00000 00000 11110 00000 00000 -16711936 00000 00000 00110 00100 00100 -8323073 00100 00100 00110 00000 00000 -16776961 00000 00100 00110 00100 00000 -32704 00000 00100 00110 00010 00000 -32513 00010 00010 00010 00010 00000 -8372160 //默认快捷键的信息 83 88 65 68 99 97 //默认程序环境的信息 15 25 20 -16777216 //砖块信息类的实现:砖块信息我们是保存好了,但我们还得想办想去操作它啊。怎样来操作呢,首先我要考虑在内存中怎样存放砖块样式信息,也就是要寻找一种比较合适的数据结构,而考虑到C#中不支持动态数组,所以只能自己编写一个类来存储管理这些信息了。 using System; using System.Collections; using System.Linq; using System.Text; using System.Drawing; namespace Tetris { class BlockInfo { private BitArray _id; private Color _bColor; //声明两变量分别存放砖块样式和颜色 public BlockInfo (BitArray id,Color bColor) //声明一个构造函数 { _id =id ; _bColor =bColor; } public BitArray ID //添加两个属性 { get {return _id;} set {_id =value ;} } public Color BColor { get {return _bColor;} set {_bColor =value ;} } public string GetIdStr( ) //将Id 转换为字符串的值再返回 { StringBuilder s =new StringBuilder (25); foreach (bool b in _id ) {s.Append (b ?"1":"0");} return s.ToString (); } public string GetColorStr() //颜色值转换为字符串再返回 {return Convert .ToString (_bColor.ToArgb());} } } //砖块数组类:以上砖块信息类只适合存放一块砖块的信息,而我们需要存放多块砖块的信息,因此我还得在砖块信息类的基础上再添加一个类来存放多个砖块,就是砖块数组类。 using System; using System.Collections; using System.Windows.Forms; using System.Linq; using System.Text; using System.Drawing; namespace Tetris { class InfoArr { private ArrayList info = new ArrayList(); private int _length = 0; //定义一个数组来存放砖块信息 public int Length //添加一个属性 { get { return _length; } } public BlockInfo this[int index] //索引器,根据下标,返回一个BlockInfo { get { return (BlockInfo)info[index]; } } public string this[string id] //索引器,根据一个字符串的id值下标,给相应id的颜色赋值 { set { if (value == "") { return; } for (int i = 0; i < info.Count; i++) { if (((BlockInfo)info[i]).GetIdStr() == id) { try { ((BlockInfo)info[i]).BColor = Color.FromArgb(Convert.ToInt32(value)); } catch (System .FormatException ) { MessageBox.Show("颜色信息有误!请删除 BlockSet.xml文件,并重新启动程序", "错误信息", MessageBoxButtons.OK,MessageBoxIcon.Error); } } } } } private BitArray StrToBit(string id) //把字符串转换为BitArray { if (id.Length != 25) { throw new System.FormatException("砖块样式不合法! 请删除BlockSet.xml文件,并重新启动程序"); } BitArray ba = new BitArray(25); for (int i = 0; i < 25; i++) { ba[i] = (id[i] == '0') ? false : true; } return ba; } public void Add(BitArray id,Color bColor)添加一个砖块信息 { if (id.Length != 25) { throw new System.FormatException("砖块样式不合法! 请删除BlockSet.xml文件,并重新启动程序"); } info.Add(new BlockInfo(id, bColor)); //给动态数组info添加一个砖块信息 _length++; //长度加1 } public void Add(string id, string bColor)//把字符串转换为颜色类 { Color temp; if (!(bColor == "")) { temp = Color.FromArgb(Convert.ToInt32(bColor)); } else { temp = Color.Empty; } info.Add(new BlockInfo(StrToBit(id), temp)); //把字符串转换为BitArray类 _length++; } } } 【三】专门配置类的实现 至此,前期的铺垫工作已经做完了,我们终于可以去实现访问xml类了。在此我们添加一个新类来专门用来配置。有这个方法,我们可以很好地读取和保存XML文件。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Windows .Forms ; using System.Collections ; using System.Xml ; using System.IO; using System.Reflection; namespace Tetris { class Config { private Keys _downKey;//定义快捷键及程序环境设置键 private Keys _dropKey; private Keys _moveLeftKey; private Keys _moveRightKey; private Keys _deasilRotateKey; private Keys _contraRotateKey; private int _coorWidth; private int _coorHeight; private int _rectPix; private Color _backColor; private InfoArr info = new InfoArr(); public Keys DownKey//分别为每个变量添加属性 { get { return _downKey; } set { _downKey = value; } } public Keys DropKey { get { return _dropKey; } set { _dropKey = value; } } public Keys MoveLeftKey { get { return _moveLeftKey; } set { _moveLeftKey = value; } } public Keys MoveRightKey { get { return _moveRightKey; } set { _moveRightKey = value; } } public Keys DeasilRotateKey { get { return _deasilRotateKey; } set { _deasilRotateKey = value; } } public Keys ContraRotateKey { get { return _contraRotateKey; } set { _contraRotateKey = value; } } public int CoorWidth { get { return _coorWidth; }//限制水平格子数 set { if (value >= 10 && value <= 50) _coorWidth =value; } } public int CoorHight { get { return _coorHeight; }//限制垂直格子数 set { if (value >= 15 &&value <= 50) _coorHeight =value; } } public int RectPix { get { return _rectPix; }//限制方块像素值 set { if (value >= 10 && value <= 30) _rectPix =value; } } public Color BackColor { get { return _backColor; } set { _backColor = value; } } public InfoArr Info { get { return info; } set { info = value; } } //此处我们把BlockSet.xml文件做为嵌入的资源,它会嵌入进程序的exe文件中,因此会有两个BlockSet.xml文件,一个存放在本地硬盘,一个就是嵌入的资源。 public void LoadFromXmlFile() { XmlTextReader reader; if (File.Exists("BlockSet.xml")) //优先读取外部BlockSet.xml文件并把信息写入blockInfo内 { reader = new XmlTextReader("BlockSet.xml"); } else {//如果BlockSet.xml不存在,则从嵌入资源内读取BlockSet.xml Assembly asm = Assembly.GetExecutingAssembly(); Stream sm = asm.GetManifestResourceStream("Tetris.BlockSet.xml"); reader = new XmlTextReader(sm); } string key = ""; try { //若发生异常则显示给用户 while (reader.Read()) //循环读取xml文件,读出所有标志分别赋给变量 { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "ID") { key = reader.ReadElementString().Trim(); info.Add(key, ""); } else if (reader.Name == "Color") { info[key] = reader.ReadElementString().Trim(); } else if (reader.Name == "DownKey") { _downKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim()); } else if (reader.Name == "DropKey") { _dropKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim()); } else if (reader.Name == "MoveLeftKey") { _moveLeftKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim()); } else if (reader.Name == "MoveRightKey") { _moveRightKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim()); } else if (reader.Name == "DeasilRotateKey") { _deasilRotateKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim()); } else if (reader.Name == "ContraRotateKey") { _contraRotateKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim()); } else if (reader.Name == "CoorWidth") { _coorWidth = Convert.ToInt32(reader.ReadElementString().Trim()); } else if (reader.Name == "CoorHight") { _coorHeight = Convert.ToInt32(reader.ReadElementString().Trim()); } else if (reader.Name == "RectPix") { _rectPix = Convert.ToInt32(reader.ReadElementString().Trim()); else if (reader.Name == "BackColor") { _backColor = Color.FromArgb(Convert.ToInt32(reader.ReadElementString().Trim())); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //Finally无论是否异常都释放 { if (reader != null) reader.Close(); } } public void SaveToXmlFile()//把信息保存为xml文件 { XmlDocument doc = new XmlDocument(); doc.LoadXml(""); XmlNode root = doc.SelectSingleNode("BlockSet");//写砖块信息 for (int i = 0; i < info.Length; i++)//写砖块信息 { XmlElement xelType = doc.CreateElement("Type"); XmlElement xelID = doc.CreateElement("ID"); xelID .InnerText =((BlockInfo )info [i]).GetIdStr(); xelType.AppendChild(xelID); XmlElement xelColor = doc.CreateElement("Color"); xelColor.InnerText = ((BlockInfo)info[i]).GetColorStr(); xelType.AppendChild(xelColor); root.AppendChild(xelType); } XmlElement xelKey = doc.CreateElement("Key"); XmlElement xelDownKey = doc.CreateElement("DownKey"); xelDownKey.InnerText = Convert.ToInt32(_downKey).ToString(); xelKey.AppendChild(xelDownKey); XmlElement xelDropKey = doc.CreateElement("DropKey"); xelDropKey.InnerText = Convert.ToInt32(_dropKey).ToString(); xelKey.AppendChild(xelDropKey); XmlElement xelMoveLeftKey = doc.CreateElement("MoveLeftKey"); xelMoveLeftKey.InnerText = Convert.ToInt32(_moveLeftKey).ToString(); xelKey.AppendChild(xelMoveLeftKey); XmlElement xelMoveRightKey = doc.CreateElement("MoveRightKey"); xelMoveRightKey.InnerText = Convert.ToInt32(_moveRightKey).ToString(); xelKey.AppendChild(xelMoveRightKey); XmlElement xelDeasilRotateKey = doc.CreateElement("DeasilRotateKey"); xelDeasilRotateKey.InnerText = Convert.ToInt32(_deasilRotateKey).ToString(); xelKey.AppendChild(xelDeasilRotateKey); XmlElement xelContraRotateKey = doc.CreateElement("ContraRotateKey"); xelContraRotateKey.InnerText = Convert.ToInt32(_contraRotateKey).ToString(); xelKey.AppendChild(xelContraRotateKey); root.AppendChild(xelKey); //写界面信息 XmlElement xelSurface = doc.CreateElement("Surface"); XmlElement xelCoorWidth = doc.CreateElement("CoorWidth"); xelCoorWidth.InnerText = _coorWidth.ToString(); xelSurface.AppendChild(xelCoorWidth); XmlElement xelCoorHight = doc.CreateElement("CoorHight"); xe
/
本文档为【俄罗斯方块游戏论文】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索