欢迎来到三一文库! | 帮助中心 三一文库31doc.com 一个上传文档投稿赚钱的网站
三一文库
全部分类
  • 研究报告>
  • 工作总结>
  • 合同范本>
  • 心得体会>
  • 工作报告>
  • 党团相关>
  • 幼儿/小学教育>
  • 高等教育>
  • 经济/贸易/财会>
  • 建筑/环境>
  • 金融/证券>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 三一文库 > 资源分类 > DOCX文档下载  

    C++俄罗斯方块代码.docx

    • 资源ID:5013993       资源大小:87.91KB        全文页数:55页
    • 资源格式: DOCX        下载积分:8
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录   微博登录  
    二维码
    微信扫一扫登录
    下载资源需要8
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C++俄罗斯方块代码.docx

    Block.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Windows.Forms;namespace Tetris / <summary> / 砖Á?块¨¦的Ì?类¤¨¤ / </summary> class Block protected Point structArr;/储ä¡é存ä?砖Á?块¨¦组Á¨¦成¨¦信?息¡é的Ì?坐Á?标À¨º数ºy组Á¨¦ protected int _xPos;/研D究?砖Á?块¨¦顶£¤点Ì?所¨´在¨²游®?戏¡¤界?面?的Ì?x坐Á?标À¨º protected int _yPos;/研D究?砖Á?块¨¦顶£¤点Ì?所¨´在¨²游®?戏¡¤界?面?的Ì?y坐Á?标À¨º protected Color _blockColor;/砖Á?块¨¦的Ì?颜?色¦? protected Color _disapperColor;/擦¨¢出?颜?色¦? protected int rectPix;/每?个?单Ì£¤元a格?的Ì?像?素? public Block()/默?认¨?构1造¨¬函¡¥数ºy,ê?声¦¨´明¡Â此ä?函¡¥数ºy是º?为a了¢?子Á¨®类¤¨¤能¨¹顺3利¤?创ä¡ä建¡§ / <summary> Block类¤¨¤的Ì?构1造¨¬函¡¥数ºy的Ì?介¨¦绍¦¨¹ / Block类¤¨¤的Ì?构1造¨¬函¡¥数ºy / </summary> / <param name="sa">储ä¡é存ä?砖Á?块¨¦各¡Â点Ì?的Ì?Point类¤¨¤</param> / <param name="bColor">砖Á?块¨¦颜?色¦?</param> / <param name="dColor">擦¨¢出?颜?色¦?</param> / <param name="pix">砖Á?块¨¦像?素?</param> public Block(Point sa,Color bColor,Color dColor,int pix) _blockColor = bColor; _disapperColor = dColor; rectPix = pix; structArr = sa; public Point thisint index get return structArrindex; #region 成¨¦员¡À变À?量¢?相¨¤应®|属º?性? public int Lengce get return structArr.Length; public int xPos get return _xPos; set _xPos = value; public int yPos get return _yPos; set _yPos = value; public Color BlockColor get return _blockColor; #endregion public void DeasilRotate()/顺3时º¡À针?旋y转Áa int temp; for(int i=0;i<structArr.Length;+i) temp = structArri.X; structArri.X = structArri.Y; structArri.Y = -temp; public void ContraRotate()/逆?时º¡À针?旋y转Áa int temp; for (int i = 0; i < structArr.Length; +i) temp = structArri.X; structArri.X = -structArri.Y; structArri.Y = temp; private Rectangle PointToRect(Point p) return new Rectangle(_xPos + p.X) * rectPix + 1, (_yPos - p.Y) * rectPix + 1, rectPix - 2, rectPix - 2); / <summary> / 在¨²指?定¡§画-板ã?下?绘?制?砖Á?块¨¦ / </summary> / <param name="gp">一°?个?用®?于®¨²绘?制?的Ì?Graphics对?象¨®</param> public virtual void Paint (Graphics gp) SolidBrush sb = new SolidBrush(_blockColor); foreach(Point p in structArr) lock(gp)/线?程¨¬锁? gp.FillRectangle(sb, PointToRect(p); public void erase(Graphics gp)/擦¨¢除y矩?形? SolidBrush sb = new SolidBrush(_disapperColor); foreach (Point p in structArr) lock (gp) gp.FillRectangle(sb, PointToRect(p); BlockGroup.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Collections;namespace Tetris / <summary> / 用®?于®¨²砖Á?块¨¦生¦¨²产¨²的Ì?类¤¨¤ / </summary> class BlockGroup private InfoArr info;/存ä?放¤?所¨´有®D砖Á?块¨¦样¨´式º?信?息¡é private Color disapperColor;/背À3景¡ã色¦? private int rectPix;/单Ì£¤元a格?像?素? public BlockGroup()/构1造¨¬函¡¥数ºy Config config = new Config(); config.LoadFromXmlFile(); /info = new InfoArr(); info = config.Info; disapperColor = config.BackColor; rectPix = config.RectPix; public Block GetAblock()/从䨮砖Á?块¨¦中D随?机¨²抽¨¦取¨?一°?个?砖Á?块¨¦样¨´式º?并¡é返¤¦Ì回? Random rd = new Random();/声¦¨´明¡Â一°?个?产¨²生¦¨²随?机¨²数ºy的Ì?类¤¨¤ int keyOrder = rd.Next(0, info.Lenth);/产¨²生¦¨²一°?个?随?机¨²数ºy(.Next(0,3)产¨²生¦¨²的Ì?是º?0,1,2) BitArray ba = infokeyOrder.Id;/抽¨¦取¨?的Ì?砖Á?块¨¦样¨´式º?赋3给?BitArray类¤¨¤的Ì?对?象¨®ba int strNum = 0;/确¨¡¤定¡§这a个?砖Á?块¨¦样¨´式º?中D被À?填¬?充?的Ì?方¤?块¨¦样¨´式º? foreach(bool b in ba)/即¡ä需¨¨要°a确¨¡¤定¡§Point数ºy组Á¨¦的Ì?长¡è度¨¨ if(b) strNum+; /*创ä¡ä建¡§一°?个?Point数ºy组Á¨¦并¡é确¨¡¤定¡§其?长¡è度¨¨,以°?创ä¡ä建¡§新?的Ì?Block*/ Point structArr = new PointstrNum; int k = 0; for(int j=0;j<ba.Length;+j)/循-环¡¤给?Point数ºy组Á¨¦StructArr赋3坐Á?标À¨º值¦Ì if(baj) structArrk.X = j % 5 - 2; structArrk.Y = 2 - j / 5; +k; /*创ä¡ä建¡§新?砖Á?块¨¦并¡é返¤¦Ì回?*/ return new Block(structArr, infokeyOrder.BColor, disapperColor, rectPix); BlockInfo.cs:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections;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() 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(); BlockSet.xml:<?xml version="1.0" encoding="utf-8" ?> <blockset> <Type> <ID>0000001100011000000000000</ID> <Color>-65536</Color> </Type> <Type> <ID>0000000100001000010000100</ID> <Color>-16711936</Color> </Type> <Type> <ID>0000000000011100010000000</ID> <Color>-8323073</Color> </Type> <Type> <ID>0000000100001100001000000</ID> <Color>-16776961</Color> </Type> <Type> <ID>0000000100011000100000000</ID> <Color>-32704</Color> </Type> <Type> <ID>0000000000001100010000100</ID> <Color>-32513</Color> </Type> <Type> <ID>0000000000011000010000100</ID> <Color>-8372160</Color> </Type> <Key> <DownKey>83</DownKey> <DropKey>16</DropKey> <MoveLeftKey>65</MoveLeftKey> <MoveRightKey>68</MoveRightKey> <DeasilRotateKey>32</DeasilRotateKey> <ContraRotateKey>87</ContraRotateKey> </Key> <Surface> <CoorWidth>15</CoorWidth> <CoorHeight>25</CoorHeight> <RectPix>20</RectPix> <BackColor>-16777216</BackColor> </Surface></blockset>Config.cs: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;using System.IO;using System.Reflection;using System.Collections;using System.Xml;namespace Tetris class Config #region 私?有®D变À?量¢?及¡ã相¨¤应®|属º?性? private Keys _downKey; public Keys DownKey get return _downKey; set _downKey = value; private Keys _dropKey; public Keys DropKey get return _dropKey; set _dropKey = value; private Keys _moveLeftKey; public Keys MoveLeftKey get return _moveLeftKey; set _moveLeftKey = value; private Keys _moveRightKey; public Keys MoveRightKey get return _moveRightKey; set _moveRightKey = value; private Keys _deasilRotateKey; public Keys DeasilRotateKey get return _deasilRotateKey; set _deasilRotateKey = value; private Keys _contraRotateKey; public Keys ContraRotateKey get return _contraRotateKey; set _contraRotateKey = value; private int _coorWidth; public int CoorWidth get return _coorWidth; set if (value >= 10 && value <= 50) _coorWidth = value; private int _coorHeight; public int CoorHeight get return _coorHeight; set if (value >= 15 && value <= 50) _coorHeight = value; private int _rectPix; public int RectPix get return _rectPix; set if (value >= 10 && value <= 30) _rectPix = value; private Color _backColor; public Color BackColor get return _backColor; set _backColor = value; private InfoArr info = new InfoArr(); public InfoArr Info getreturn info; setinfo=value; #endregion #region 从䨮Xml中D读¨¢取¨?信?息¡é public void LoadFromXmlFile() XmlTextReader reader; if(File.Exists("BlockSet.xml") reader = new XmlTextReader("BlockSet.xml"); else Assembly asm = Assembly.GetExecutingAssembly(); Stream sm = asm.GetManifestResourceStream("Tetris.BlockSet.xml"); reader = new XmlTextReader(sm); string key = "" try while (reader.Read() if(reader.NodeType=XmlNodeType.Element) if (reader.Name = "ID") key = reader.ReadElementString().Trim(); info.Add(key, ""); else if (reader.Name = "Color") infokey = 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 = "CoorHeight") _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(),"Error"); finally if (reader != null) reader.Close(); #endregion #region 把ã?设¦¨¨置?保À¡ê存ä?成¨¦Xml信?息¡é public void SaveToXmlFile() XmlDocument doc = new XmlDocument();/在¨²内¨²存ä?中D创ä¡ä建¡§xml文?件t doc.LoadXml("<BlockSet></BlockSet>");/在¨²内¨²存ä?中D载?入¨?<BlockSet></BlockSet>中D的Ì?内¨²容¨Y XmlNode root = doc.SelectSingleNode("BlockSet");/创ä¡ä建¡§BlockSet的Ì?根¨´结¨¢点Ì? for(int i = 0; i<Info.Lenth;i+)/用®?循-环¡¤创ä¡ä建¡§每?一°?个?<Type></Type>砖Á?块¨¦样¨´式º?结¨¢点Ì? XmlElement xmlType = doc.CreateElement("Type");/创ä¡ä建¡§<Type></Type>结¨¢点Ì? XmlElement xmlID = doc.CreateElement("ID");/创ä¡ä建¡§<ID></ID>结¨¢点Ì? /*在¨²<ID></ID>结¨¢点Ì?中D添¬¨ª加¨®信?息¡é,把ã?ArriList类¤¨¤Infoi(Object类¤¨¤)

    注意事项

    本文(C++俄罗斯方块代码.docx)为本站会员(西安人)主动上传,三一文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    经营许可证编号:宁ICP备18001539号-1

    三一文库
    收起
    展开