循-环·给?
Point数簓组哩truArr赋3坐?
标括?
值μ
{
if(ba[j])
{
structArr[k].X=j/5-2;
structArr[k].Y=2-j%5;
k++;
}
}
//创洹?
建¨一?
个?
新?
的?
砖?
块é并¢返う?
回?
returnnewBlock(structArr,info[KeyOrder].BColor,disapperColor,rectPix);
}
}
}
BlockInfo类
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Collections;
usingSystem.Drawing;
namespaceTetris
{
classBlockInfo
{
privateBitArray_id;//存?
放?
砖?
块é样ù式?
信?
息¢
privateColor_bColor;//存?
放?
颜?
色?
信?
息¢
publicBlockInfo(BitArrayid,ColorbColor)//构1造ì函ˉ数簓,?
给?
私?
有瓺变?
量?
赋3值μ
{
_id=id;
_bColor=bColor;
}
publicBitArrayID
{
get
{
return_id;
}
set
{
_id=value;
}
}
publicColorBColor
{
get
{
return_bColor;
}
set
{
_bColor=value;
}
}
publicstringGetIdStr()
{
StringBuilders=newStringBuilder(25);
foreach(boolbin_id)
{
s.Append(b?
"1":
"0");
}
returns.ToString();
}
publicstringGetColorStr()
{
returnConvert.ToString(_bColor.ToArgb());
}
}
}
Config类
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Drawing;
usingSystem.Xml;
usingSystem.IO;
usingSystem.Reflection;
namespaceTetris
{
classConfig
{
privateKeys_downKey;//向ò下?
键ü
privateKeys_dropKey;//丢a下?
键ü
privateKeys_moveLeftKey;//向ò左哩?
键ü
privateKeys_moveRightKey;//向ò右?
键ü
privateKeys_deasilRotateKey;//顺3时骸?
针?
旋y转羇键ü
privateKeys_contraRotateKey;//逆?
时骸?
针?
旋y转羇键ü
privateint_coorWidth;//水?
平?
格?
子哩?
数簓
privateint_coorHeight;//垂?
直±格?
子哩?
数簓
privateint_rectPix;//方?
块é像?
素?
privateColor_backColor;//背?
景°色?
privateInfoArrinfo=newInfoArr();//砖?
块é信?
息¢集ˉ合?
#region私?
有瓺变?
量?
相à应畖属?
性?
publicKeysDownKey//向ò下?
键ü
{
get
{
return_downKey;
}
set
{
_downKey=value;
}
}
publicKeysDropKey//抛×下?
键ü
{
get
{
return_dropKey;
}
set
{
_dropKey=value;
}
}
publicKeysMoveLeftKey//向ò左哩?
键ü
{
get
{
return_moveLeftKey;
}
set
{
_moveLeftKey=value;
}
}
publicKeysMoveRightKey//向ò右?
键ü
{
get
{
return_moveRightKey;
}
set
{
_moveRightKey=value;
}
}
publicKeysDeasilRotateKey//顺3时骸?
针?
旋y转羇键ü
{
get
{
return_deasilRotateKey;
}
set
{
_deasilRotateKey=value;
}
}
publicKeysContraRotateKey//逆?
时骸?
针?
旋y转羇键ü
{
get
{
return_contraRotateKey;
}
set
{
_contraRotateKey=value;
}
}
publicintCoorWidth//水?
平?
格?
子哩?
长¤
{
get
{
return_coorWidth;
}
set
{
if(value>=10&&value<=50)
{
_coorWidth=value;
}
}
}
publicintCoorHeight//垂?
直±格?
子哩?
长¤
{
get
{
return_coorHeight;
}
set
{
if(value>=15&&value<=50)
{
_coorHeight=value;
}
}
}
publicintRectPix//方?
块é像?
素?
{
get
{
return_rectPix;
}
set
{
if(value>=10&&value<=30)
{
_rectPix=value;
}
}
}
publicColorBackColor//背?
景°色?
{
get
{
return_backColor;
}
set
{
_backColor=value;
}
}
publicInfoArrInfo//砖?
块é信?
息¢集ˉ合?
{
get
{
returninfo;
}
set
{
info=value;
}
}
#endregion
publicvoidLoadFromXmlFile()//从洙?
Xml中D读á取?
信?
息¢
{
XmlTextReaderreader;
if(File.Exists("BlockSet.xml"))
{//优?
先è读á取?
外猘部?
BloackSet并¢把?
信?
息¢写′入?
blockInfo内ú
reader=newXmlTextReader("BlockSet.xml");
}
else
{//如?
果?
外猘部?
资哩?
源′不?
存?
在ú,?
则ò从洙?
嵌?
入?
资哩?
源′读á取?
BlockSet文?
件t
Assemblyasm=Assembly.GetExecutingAssembly();
Streamsm=asm.GetManifestResourceStream("Tetris.BlockSet.xml");
reader=newXmlTextReader(sm);
}
stringkey="";
try
{
while(reader.Read())//读á取?
Xml文?
件t
{
if(reader.NodeType==XmlNodeType.Element)
{
if(reader.Name=="ID")
{
key=reader.ReadElementString().Trim();
info.Add(key,"");
}
elseif(reader.Name=="Color")
{
info[key]=reader.ReadElementString().Trim();
}
elseif(reader.Name=="DropKey")
{
_dropKey=(Keys)Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="DownKey")
{
_downKey=(Keys)Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="MoveLeftKey")
{
_moveLeftKey=(Keys)Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="MoveRightKey")
{
_moveRightKey=(Keys)Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="DeasilRotateKey")
{
_deasilRotateKey=(Keys)Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="ContraRotateKey")
{
_contraRotateKey=(Keys)Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="CoorWidth")
{
_coorWidth=Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="CoorHeight")
{
_coorHeight=Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="RectPix")
{
_rectPix=Convert.ToInt32(reader.ReadElementString().Trim());
}
elseif(reader.Name=="BackColor")
{
_backColor=Color.FromArgb(Convert.ToInt32(reader.ReadElementString().Trim()));
}
}
}
}
catch(Exceptionex)
{
MessageBox.Show(ex.ToString());
}
finally
{
if(reader!
=null)
{
reader.Close();
}
}
}
publicvoidSaveToXmlFile()//把?
信?
息¢保馈?
存?
为axml文?
件t
{
XmlDocumentdoc=newXmlDocument();
doc.LoadXml("");
XmlNoderoot=doc.SelectSingleNode("BlockSet");
//写′砖?
块é信?
息¢
for(inti=0;i{
XmlElementxelType=doc.CreateElement("Type");
XmlElementxelID=doc.CreateElement("ID");
xelID.InnerText=((BlockInfo)info[i]).GetIdStr();
xelType.AppendChild(xelID);
XmlElementxelColor=doc.CreateElement("Color");
xelColor.InnerText=((BlockInfo)info[i]).GetColorStr();
xelType.AppendChild(xelColor);
root.AppendChild(xelType);
}
//写′快ì捷Y键ü
XmlElementxelKey=doc.CreateElement("Key");
XmlElementxelDownKey=doc.CreateElement("DownKey");
xelDownKey.InnerText=Convert.ToInt32(_downKey).ToString();
xelKey.AppendChild(xelDownKey);
XmlElementxelDropKey=doc.CreateElement("DropKey");
xelDropKey.InnerText=Convert.ToInt32(_dropKey).ToString();
xelKey.AppendChild(x