俄羅斯方塊遊戲

using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("RrGame")]
[assembly: AssemblyDescription("俄羅斯遊戲簡單版")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Sirius Studio")]
[assembly: AssemblyProduct("RrGame")]
[assembly: AssemblyCopyright("Sirius")]
[assembly: AssemblyTrademark("RrGame")]
[assembly: AssemblyCulture("")]  
[assembly: AssemblyVersion("06.01.01.01")]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

#region Copyright (c) 2005, By Sirius
/*================================================================
 *
 * Copyright (c) 2005, Sirius, All rights reserved.
 *
 * FileName   : GameMain.cs
 * Author     : sirius
 * CreateDate : 2005/12/12
 * ChangeDate : 2006/01/01 /02 /03
 *
=================================================================*/
#endregion

namespace RrGame
{
 using System;
 using System.Drawing;
 using System.Collections;
 using System.ComponentModel;
 using System.Windows.Forms;
 using System.Runtime.InteropServices;

 /// <summary>
 /// 遊戲主窗體
 /// </summary>
 [Serializable]
 public class GameMain : System.Windows.Forms.Form
 {
  #region 變量【blMain blTemp】
  private int      iNexShapeID;   // 下一個形狀ID
  private int      iNexColorD;    // 下一個顏色ID
  private int      iResult;       // 總得分數
  private int      iDelRows;      // 總消除的行數
  private int      iDelCount;     // 臨時消除的行數
  private int      iToLevel;      // 以幫助提升遊戲級別
  private bool     bFailed;       // 遊戲失敗
  private string   strBackName;   // 背景音樂名
  private Color[,] SiriusC;
  private bool[,]  SiriusB;
  private Block    blMain;        // 遊戲區模塊
  private Block    blTemp;        // 提示區模塊
  private SoundPlayer spReady;    // 準備音樂
  private SoundPlayer spFail;     // 失敗音樂
  private SoundPlayer spWin;      // 贏了音樂
  private SoundPlayer spBack;     // 背景音樂
  private SoundPlayer spDrop;     // 墜落音樂
  private SoundPlayer spEddy;     // 旋轉音樂
  private SoundPlayer spDel;      // 消行音樂
  private SoundList   SL;         // 音樂列表

  private System.Windows.Forms.Button btnPause;
  private System.Windows.Forms.Button btnStop;
  private System.Windows.Forms.Button btnStart;
  private System.Windows.Forms.Button btnSet;
  private System.Windows.Forms.Button btnAbout;
  private System.Windows.Forms.Button btnHelp;
  private System.Windows.Forms.Label lblLevel;
  private System.Windows.Forms.Label lblRowNum;
  private System.Windows.Forms.Label lblSpeed;
  private System.Windows.Forms.Label lblAuthor;
  private System.Windows.Forms.Timer Timer;
  private System.Windows.Forms.TextBox tbxFoucs;
  private System.Windows.Forms.Panel pnlMain;
  private System.Windows.Forms.Panel pnlClew;
  private System.Windows.Forms.MenuItem miBegin;
  private System.Windows.Forms.MenuItem miHelp;
  private System.Windows.Forms.MenuItem menuItem4;
  private System.Windows.Forms.MenuItem miOption;
  private System.Windows.Forms.MenuItem miPause;
  private System.Windows.Forms.MenuItem miStop;
  private System.Windows.Forms.MenuItem menuItem8;
  private System.Windows.Forms.MenuItem miExit;
  private System.Windows.Forms.MenuItem miAbout;
  private System.Windows.Forms.MenuItem miStart;
  private System.Windows.Forms.ContextMenu contextMenu;
  private System.Windows.Forms.MenuItem rMiStart;
  private System.Windows.Forms.MenuItem rMiOption;
  private System.Windows.Forms.MenuItem rMiPause;
  private System.Windows.Forms.MenuItem rMiStop;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.Windows.Forms.MainMenu mainMenu;
  private System.ComponentModel.IContainer components;
  #endregion

  public GameMain()
  {
   InitializeComponent();
  }

  public void GameMain_Load(object sender, System.EventArgs e)
  {
   SaveInit.InitializeGame(this.pnlMain, this);
  }

  public void GameMain_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
  {
   if(this.blMain == null || this.blTemp == null) { return ; }

   if(e.KeyCode == PDefined.KToLeft ) { this.blMain.BlockMove("Left");  }
   if(e.KeyCode == PDefined.KToRight) { this.blMain.BlockMove("Right"); }
   if(e.KeyCode == PDefined.KToDown ) { this.blMain.BlockMove("Down");  }
   if(e.KeyCode == PDefined.KToEddy )
   {
    if(this.spEddy != null) { this.spEddy.Play(); }
    this.blMain.BlockEddy();      
   }
   if(e.KeyCode == PDefined.KSpeedUp)
   {
    if(this.spBack != null) { this.spDrop.Play(); }
    this.blMain.BlockDrop();
   }
  }

  public void pnlClew_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
   if(this.blTemp != null) { this.blTemp.DrawClew(); }
  }

  public void pnlMain_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
   if(this.blMain != null ) { this.blMain.DrawMain();          }
   if(this.bFailed        ) { SaveInit.GameOver(this.pnlMain); }
   if(PDefined.ILevel > 15) { SaveInit.Gamewin(this.pnlMain);  }
  }

  public void Timer_Tick(object sender, System.EventArgs e)
  {
   if(this.iToLevel >= 50)
   {
    this.iToLevel -= 50;
    PDefined.ILevel ++;
   }
   if(PDefined.ILevel > 15)
   {
    if(this.spWin != null) { this.spWin.Play(); }
    this.Timer.Dispose();
    SaveInit.Gamewin(this.pnlMain);
    return ;
   }
   this.Timer.Interval = Arithmetic.ILevel();
   this.lblLevel.Text  = "級別:  " + PDefined.ILevel.ToString();
   this.lblRowNum.Text = "行數:  " + this.iDelRows.ToString();
   this.lblSpeed.Text  = "成績:  " + this.iResult.ToString();

   if((this.blMain != null) && (!this.blMain.BlockMove("Down")))
   {
    this.blMain.SiriusStore();
    this.iDelCount = this.blMain.EraseRows();
    if((this.iDelCount > 0) && (this.spDel != null))
    {
     this.spDel.Play();
    }
    this.iDelRows += this.iDelCount;
    this.iToLevel += this.iDelCount;
    this.iResult  += Arithmetic.DelAcount(this.iDelCount);
    this.InitializeBlock();
   }

   if(this.spBack == null) { return ;            }
   if(!PDefined.BIsMusic ) { this.spBack.Stop(); }
   if((PDefined.BIsMusic ) && (!this.spBack.IsPlaying))
   {
    this.spBack.Play();
   }
  }

  public void btnStart_Click(object sender, System.EventArgs e)
  {
   this.KeyPreview = true;
   this.pnlClew.Invalidate();
   this.pnlMain.Invalidate();
   //
   // 初始化遊戲顯示
   //
   this.lblLevel.Text  = "級別:  " + PDefined.ILevel.ToString();
   this.lblRowNum.Text = "行數:  0";
   this.lblSpeed.Text  = "成績:  0";
   //
   // 初始化遊戲參數
   //
   this.iResult     = 0;
   this.iDelRows    = 0;
   this.bFailed     = false;
   this.iNexShapeID = Block.BShapeID();
   this.iNexColorD  = Block.BColorID();
   this.SiriusB     = new bool[10, 15];
   this.SiriusC     = new Color[10, 15];

   try
   {
    //
    // 初始化播放列表類對象
    //
    this.SL          = new SoundList();
    this.strBackName = SL.GetBack();
    //
    // 初始化播放類對象
    //
    this.spReady = new SoundPlayer("Sounds//Ready.wav", "Ready");
    this.spDrop  = new SoundPlayer("Sounds//Drop.wav",  "Drop" );
    this.spEddy  = new SoundPlayer("Sounds//Eddy.wav",  "Eddy" );
    this.spDel   = new SoundPlayer("Sounds//Del.wav",   "Del"  );
    this.spFail  = new SoundPlayer("Sounds//Fail.wav",  "Fail" );
    this.spWin   = new SoundPlayer("Sounds//Win.wav",   "Win"  );
    this.spBack  = new SoundPlayer("Sounds//Back//" + this.strBackName, "Back");
    //
    // 播放音樂
    //
    if(PDefined.BIsMusic)
    {
     this.spReady.Play();
     this.spBack.Play();
    }
   }
   catch
   {
    MessageBox.Show("音樂播放類或列表類對象初始化出錯!");
   }
   finally
   {
    this.InitializeBlock();   // 構建模塊
    this.Timer.Start();       // 啓動計時器
    this.tbxFoucs.Focus();
   }
  }

  public void btnSet_Click(object sender, System.EventArgs e)
  {
   if(this.Timer.Enabled)
   {
    this.Timer.Stop();
    new GameOption().ShowDialog();
    this.Timer.Start();
   }
   else
   {
    new GameOption().ShowDialog();
   }
   this.tbxFoucs.Focus();
  }

  public void btnPause_Click(object sender, System.EventArgs e)
  {
   if(this.blMain == null || spBack == null) return ;

   if(this.Timer.Enabled)
   {
    if((this.spBack == null) && (this.spBack.IsPlaying))
    { this.spBack.Stop(); }
   }
   else if(spBack != null)
   {
    if((PDefined.BIsMusic) && (!this.spBack.IsPlaying))
    { this.spBack.Play(); }
   }
   this.KeyPreview     = !this.KeyPreview;
   this.Timer.Enabled  = !this.Timer.Enabled;
   this.tbxFoucs.Focus();
  }

  public void btnStop_Click(object sender, System.EventArgs e)
  {
   this.blMain = null;
   this.blTemp = null;
   this.Timer.Dispose();
   this.pnlMain.Invalidate();
   this.pnlClew.Invalidate();

   if((this.spBack != null) && (this.spBack.IsPlaying))
   {
    this.spBack.Stop();
   }
   this.tbxFoucs.Focus();
  }

  public void btnHelp_Click(object sender, System.EventArgs e)
  {
   string sTemp;

   sTemp = "主界面:/n";
   sTemp += "/t單擊開始遊戲正式開始/n";
   sTemp += "/t單擊設置對遊戲環境進行設置/n";
   sTemp += "/t雙擊遊戲區域暫停/n";
   sTemp += "/t遊戲區域支持右鍵菜單/n";
   sTemp += "/t菜單項功能和按鈕功能等效/n/n";
   sTemp += "參數設置界面:/n";
   sTemp += "/t單擊確定,保存當前改動/n";
   sTemp += "/t單擊恢復默認值,恢復遊戲默認設置/n";
   sTemp += "/t單擊取消,退回主界面/n/n";
   sTemp += "附加:/n";
   sTemp += "/t將想加入背景音樂複製到文件夾Sounds/Back下面/t";
   MessageBox.Show(sTemp, "幫助", MessageBoxButtons.OK, MessageBoxIcon.Information);
   this.tbxFoucs.Focus();
  }

  public void btnAbout_Click(object sender, System.EventArgs e)
  {
   string sTemp;

   sTemp = "作者:小陳/n版本:06.01.01.01/n時間:2006年元月/t";
   MessageBox.Show(sTemp, "關於", MessageBoxButtons.OK, MessageBoxIcon.Information);
   this.tbxFoucs.Focus();
  }

  public void lblAuthor_Mouse(object sender, System.EventArgs e)
  {
   if(this.lblAuthor.Text == "作者:sirius")
   {
    this.lblAuthor.Text = "QQ:84211818";
   }
   else
   {
    this.lblAuthor.Text = "作者:sirius";
   }
   this.tbxFoucs.Focus();
  }

  private void miExit_Click(object sender, System.EventArgs e)
  {
   Application.Exit();
  }

  private void InitializeBlock()
  {
   //
   // 創建當前模塊
   //
   this.blMain = new Block(this.pnlMain, 80, 0, 20, this.SiriusB, this.SiriusC);
   if(!this.blMain.BlockCreate(this.iNexShapeID, this.iNexColorD))
   {
    if(this.spFail != null) { this.spFail.Play(); }
    if(this.spBack != null) { this.spBack.Stop(); }

    this.bFailed = true;
    this.blMain  = null;
    this.blTemp  = null;
    this.spBack  = null;
    this.Timer.Stop();
    SaveInit.GameOver(this.pnlMain);
    return ;
   }
   this.blMain.BlockMove("Down");
   //
   // 創建下一個模塊
   //
   iNexShapeID = Block.BShapeID();
   iNexColorD  = Block.BColorID();
   this.pnlClew.Invalidate();
   this.blTemp = new Block(this.pnlClew, 23, 5, 19, this.SiriusB, this.SiriusC);
   this.blTemp.BlockCreate(this.iNexShapeID, this.iNexColorD);
  }

  [STAThread]
  static void Main()
  {
   Application.Run(new GameMain());
  }
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗體設計器生成的代碼
  private void InitializeComponent()
  {
   this.components = new System.ComponentModel.Container();
   this.btnPause = new System.Windows.Forms.Button();
   this.btnStop = new System.Windows.Forms.Button();
   this.btnStart = new System.Windows.Forms.Button();
   this.btnSet = new System.Windows.Forms.Button();
   this.btnAbout = new System.Windows.Forms.Button();
   this.btnHelp = new System.Windows.Forms.Button();
   this.lblLevel = new System.Windows.Forms.Label();
   this.lblRowNum = new System.Windows.Forms.Label();
   this.lblSpeed = new System.Windows.Forms.Label();
   this.lblAuthor = new System.Windows.Forms.Label();
   this.Timer = new System.Windows.Forms.Timer(this.components);
   this.tbxFoucs = new System.Windows.Forms.TextBox();
   this.pnlMain = new System.Windows.Forms.Panel();
   this.contextMenu = new System.Windows.Forms.ContextMenu();
   this.rMiStart = new System.Windows.Forms.MenuItem();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.rMiOption = new System.Windows.Forms.MenuItem();
   this.rMiPause = new System.Windows.Forms.MenuItem();
   this.rMiStop = new System.Windows.Forms.MenuItem();
   this.pnlClew = new System.Windows.Forms.Panel();
   this.mainMenu = new System.Windows.Forms.MainMenu();
   this.miBegin = new System.Windows.Forms.MenuItem();
   this.miStart = new System.Windows.Forms.MenuItem();
   this.menuItem4 = new System.Windows.Forms.MenuItem();
   this.miOption = new System.Windows.Forms.MenuItem();
   this.miPause = new System.Windows.Forms.MenuItem();
   this.miStop = new System.Windows.Forms.MenuItem();
   this.menuItem8 = new System.Windows.Forms.MenuItem();
   this.miExit = new System.Windows.Forms.MenuItem();
   this.miHelp = new System.Windows.Forms.MenuItem();
   this.miAbout = new System.Windows.Forms.MenuItem();
   this.SuspendLayout();
   //
   // btnPause
   //
   this.btnPause.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.btnPause.BackColor = System.Drawing.SystemColors.Control;
   this.btnPause.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnPause.ForeColor = System.Drawing.Color.Black;
   this.btnPause.Location = new System.Drawing.Point(218, 183);
   this.btnPause.Name = "btnPause";
   this.btnPause.Size = new System.Drawing.Size(82, 25);
   this.btnPause.TabIndex = 6;
   this.btnPause.Text = "暫停";
   this.btnPause.Click += new System.EventHandler(this.btnPause_Click);
   //
   // btnStop
   //
   this.btnStop.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.btnStop.BackColor = System.Drawing.SystemColors.Control;
   this.btnStop.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnStop.ForeColor = System.Drawing.Color.Black;
   this.btnStop.Location = new System.Drawing.Point(218, 209);
   this.btnStop.Name = "btnStop";
   this.btnStop.Size = new System.Drawing.Size(82, 25);
   this.btnStop.TabIndex = 7;
   this.btnStop.Text = "停止";
   this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
   //
   // btnStart
   //
   this.btnStart.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.btnStart.BackColor = System.Drawing.SystemColors.Control;
   this.btnStart.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnStart.ForeColor = System.Drawing.Color.Black;
   this.btnStart.Location = new System.Drawing.Point(218, 131);
   this.btnStart.Name = "btnStart";
   this.btnStart.Size = new System.Drawing.Size(82, 25);
   this.btnStart.TabIndex = 4;
   this.btnStart.Text = "開始";
   this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
   //
   // btnSet
   //
   this.btnSet.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.btnSet.BackColor = System.Drawing.SystemColors.Control;
   this.btnSet.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnSet.ForeColor = System.Drawing.Color.Black;
   this.btnSet.Location = new System.Drawing.Point(218, 157);
   this.btnSet.Name = "btnSet";
   this.btnSet.Size = new System.Drawing.Size(82, 25);
   this.btnSet.TabIndex = 5;
   this.btnSet.Text = "設置";
   this.btnSet.Click += new System.EventHandler(this.btnSet_Click);
   //
   // btnAbout
   //
   this.btnAbout.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.btnAbout.BackColor = System.Drawing.SystemColors.Control;
   this.btnAbout.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnAbout.ForeColor = System.Drawing.Color.Black;
   this.btnAbout.Location = new System.Drawing.Point(218, 235);
   this.btnAbout.Name = "btnAbout";
   this.btnAbout.Size = new System.Drawing.Size(82, 25);
   this.btnAbout.TabIndex = 8;
   this.btnAbout.Text = "關於";
   this.btnAbout.Click += new System.EventHandler(this.btnAbout_Click);
   //
   // btnHelp
   //
   this.btnHelp.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.btnHelp.BackColor = System.Drawing.SystemColors.Control;
   this.btnHelp.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnHelp.ForeColor = System.Drawing.Color.Black;
   this.btnHelp.Location = new System.Drawing.Point(218, 261);
   this.btnHelp.Name = "btnHelp";
   this.btnHelp.Size = new System.Drawing.Size(82, 25);
   this.btnHelp.TabIndex = 9;
   this.btnHelp.Text = "幫助";
   this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
   //
   // lblLevel
   //
   this.lblLevel.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.lblLevel.BackColor = System.Drawing.SystemColors.Control;
   this.lblLevel.ForeColor = System.Drawing.Color.Black;
   this.lblLevel.Location = new System.Drawing.Point(214, 63);
   this.lblLevel.Name = "lblLevel";
   this.lblLevel.Size = new System.Drawing.Size(90, 16);
   this.lblLevel.TabIndex = 1;
   this.lblLevel.Text = "級別:";
   this.lblLevel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
   //
   // lblRowNum
   //
   this.lblRowNum.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.lblRowNum.BackColor = System.Drawing.SystemColors.Control;
   this.lblRowNum.ForeColor = System.Drawing.Color.Black;
   this.lblRowNum.Location = new System.Drawing.Point(214, 85);
   this.lblRowNum.Name = "lblRowNum";
   this.lblRowNum.Size = new System.Drawing.Size(90, 16);
   this.lblRowNum.TabIndex = 2;
   this.lblRowNum.Text = "行數:";
   this.lblRowNum.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
   //
   // lblSpeed
   //
   this.lblSpeed.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.lblSpeed.BackColor = System.Drawing.SystemColors.Control;
   this.lblSpeed.ForeColor = System.Drawing.Color.Black;
   this.lblSpeed.Location = new System.Drawing.Point(214, 107);
   this.lblSpeed.Name = "lblSpeed";
   this.lblSpeed.Size = new System.Drawing.Size(90, 16);
   this.lblSpeed.TabIndex = 3;
   this.lblSpeed.Text = "成績:";
   this.lblSpeed.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
   //
   // lblAuthor
   //
   this.lblAuthor.Anchor = System.Windows.Forms.AnchorStyles.Right;
   this.lblAuthor.BackColor = System.Drawing.SystemColors.Control;
   this.lblAuthor.Cursor = System.Windows.Forms.Cursors.Hand;
   this.lblAuthor.ForeColor = System.Drawing.Color.Black;
   this.lblAuthor.Location = new System.Drawing.Point(224, 293);
   this.lblAuthor.Name = "lblAuthor";
   this.lblAuthor.Size = new System.Drawing.Size(90, 16);
   this.lblAuthor.TabIndex = 0;
   this.lblAuthor.Text = "作者:sirius";
   this.lblAuthor.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
   this.lblAuthor.MouseEnter += new System.EventHandler(this.lblAuthor_Mouse);
   this.lblAuthor.MouseLeave += new System.EventHandler(this.lblAuthor_Mouse);
   //
   // Timer
   //
   this.Timer.Interval = 400;
   this.Timer.Tick += new System.EventHandler(this.Timer_Tick);
   //
   // tbxFoucs
   //
   this.tbxFoucs.Location = new System.Drawing.Point(158, 238);
   this.tbxFoucs.Name = "tbxFoucs";
   this.tbxFoucs.Size = new System.Drawing.Size(3, 21);
   this.tbxFoucs.TabIndex = 10;
   this.tbxFoucs.Text = "";
   //
   // pnlMain
   //
   this.pnlMain.BackColor = System.Drawing.Color.LightGray;
   this.pnlMain.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   this.pnlMain.ContextMenu = this.contextMenu;
   this.pnlMain.Location = new System.Drawing.Point(6, 6);
   this.pnlMain.Name = "pnlMain";
   this.pnlMain.Size = new System.Drawing.Size(201, 301);
   this.pnlMain.TabIndex = 11;
   this.pnlMain.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlMain_Paint);
   this.pnlMain.DoubleClick += new System.EventHandler(this.btnPause_Click);
   //
   // contextMenu
   //
   this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                      this.rMiStart,
                      this.menuItem1,
                      this.rMiOption,
                      this.rMiPause,
                      this.rMiStop});
   //
   // rMiStart
   //
   this.rMiStart.Index = 0;
   this.rMiStart.Text = "開始";
   this.rMiStart.Click += new System.EventHandler(this.btnStart_Click);
   //
   // menuItem1
   //
   this.menuItem1.Index = 1;
   this.menuItem1.Text = "-";
   //
   // rMiOption
   //
   this.rMiOption.Index = 2;
   this.rMiOption.Text = "設置";
   this.rMiOption.Click += new System.EventHandler(this.btnSet_Click);
   //
   // rMiPause
   //
   this.rMiPause.Index = 3;
   this.rMiPause.Text = "暫停";
   this.rMiPause.Click += new System.EventHandler(this.btnPause_Click);
   //
   // rMiStop
   //
   this.rMiStop.Index = 4;
   this.rMiStop.Text = "停止";
   this.rMiStop.Click += new System.EventHandler(this.btnStop_Click);
   //
   // pnlClew
   //
   this.pnlClew.BackColor = System.Drawing.Color.LightGray;
   this.pnlClew.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   this.pnlClew.Location = new System.Drawing.Point(214, 6);
   this.pnlClew.Name = "pnlClew";
   this.pnlClew.Size = new System.Drawing.Size(90, 50);
   this.pnlClew.TabIndex = 0;
   this.pnlClew.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlClew_Paint);
   //
   // mainMenu
   //
   this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                      this.miBegin,
                      this.miHelp});
   //
   // miBegin
   //
   this.miBegin.Index = 0;
   this.miBegin.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                     this.miStart,
                     this.menuItem4,
                     this.miOption,
                     this.miPause,
                     this.miStop,
                     this.menuItem8,
                     this.miExit});
   this.miBegin.Text = "遊戲(&G)";
   //
   // miStart
   //
   this.miStart.Index = 0;
   this.miStart.Text = "開始(&B)";
   this.miStart.Click += new System.EventHandler(this.btnStart_Click);
   //
   // menuItem4
   //
   this.menuItem4.Index = 1;
   this.menuItem4.Text = "-";
   //
   // miOption
   //
   this.miOption.Index = 2;
   this.miOption.Text = "設置(&S)";
   this.miOption.Click += new System.EventHandler(this.btnSet_Click);
   //
   // miPause
   //
   this.miPause.Index = 3;
   this.miPause.Text = "暫停(&P)";
   this.miPause.Click += new System.EventHandler(this.btnPause_Click);
   //
   // miStop
   //
   this.miStop.Index = 4;
   this.miStop.Text = "停止(&M)";
   this.miStop.Click += new System.EventHandler(this.btnStop_Click);
   //
   // menuItem8
   //
   this.menuItem8.Index = 5;
   this.menuItem8.Text = "-";
   //
   // miExit
   //
   this.miExit.Index = 6;
   this.miExit.Text = "退出(&X)";
   this.miExit.Click += new System.EventHandler(this.miExit_Click);
   //
   // miHelp
   //
   this.miHelp.Index = 1;
   this.miHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                       this.miAbout});
   this.miHelp.Text = "幫助(&H)";
   //
   // miAbout
   //
   this.miAbout.Index = 0;
   this.miAbout.Text = "關於(&A)";
   this.miAbout.Click += new System.EventHandler(this.btnAbout_Click);
   //
   // GameMain
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.BackColor = System.Drawing.SystemColors.Control;
   this.ClientSize = new System.Drawing.Size(310, 313);
   this.Controls.Add(this.pnlMain);
   this.Controls.Add(this.tbxFoucs);
   this.Controls.Add(this.lblAuthor);
   this.Controls.Add(this.btnStart);
   this.Controls.Add(this.btnSet);
   this.Controls.Add(this.btnPause);
   this.Controls.Add(this.btnStop);
   this.Controls.Add(this.btnAbout);
   this.Controls.Add(this.btnHelp);
   this.Controls.Add(this.lblLevel);
   this.Controls.Add(this.lblRowNum);
   this.Controls.Add(this.lblSpeed);
   this.Controls.Add(this.pnlClew);
   this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
   this.KeyPreview = true;
   this.MaximizeBox = false;
   this.Menu = this.mainMenu;
   this.Name = "GameMain";
   this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
   this.Text = "♂俄羅斯簡單版";
   this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GameMain_KeyDown);
   this.Load += new System.EventHandler(this.GameMain_Load);
   this.ResumeLayout(false);

  }
  #endregion

 }
}
#region Copyright (c) 2005, By Sirius
/*================================================================
 *
 * Copyright (c) 2005, Sirius, All rights reserved.
 *
 * FileName   : GameOption.cs
 * Author     : sirius
 * CreateDate : 2005/12/12
 * ChangeDate : 2006/02 /03
 *
=================================================================*/
#endregion

namespace RrGame
{
 using System;
 using System.Drawing;
 using System.Collections;
 using System.ComponentModel;
 using System.Windows.Forms;

 /// <summary>
 /// Setting 的摘要說明。
 /// </summary>
 public class GameOption : System.Windows.Forms.Form
 {
  #region ControlVariables
  private System.Windows.Forms.GroupBox groupBox1;
  private System.Windows.Forms.GroupBox groupBox2;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Label label3;
  private System.Windows.Forms.Label label4;
  private System.Windows.Forms.Label label5;
  private System.Windows.Forms.Label label11;
  private System.Windows.Forms.Button btnOk;
  private System.Windows.Forms.Button btnCancel;
  private System.Windows.Forms.Button btnDefault;
  private System.Windows.Forms.TextBox tbxRight;
  private System.Windows.Forms.TextBox tbxEddy;
  private System.Windows.Forms.TextBox tbxDown;
  private System.Windows.Forms.TextBox tbxLeft;
  private System.Windows.Forms.TextBox tbxDrop;
  private System.Windows.Forms.CheckBox ckxMusic;
  private System.Windows.Forms.ComboBox cbxLevel;
  private System.ComponentModel.Container components = null;
  #endregion

  public GameOption()
  {
   InitializeComponent();
  }

  private void GameOption_Load(object sender, System.EventArgs e)
  {
   this.ckxMusic.Checked = PDefined.BIsMusic;
   this.cbxLevel.Text    = PDefined.ILevel.ToString();
   this.tbxLeft.Text     = PDefined.KToLeft.ToString();
   this.tbxRight.Text    = PDefined.KToRight.ToString();
   this.tbxDown.Text     = PDefined.KToDown.ToString();
   this.tbxEddy.Text     = PDefined.KToEddy.ToString();
   this.tbxDrop.Text     = PDefined.KSpeedUp.ToString();
   SaveInit.PMemoryDispose(this);
  }

  private void tbxSet_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
  {
   if((e.KeyValue >= 32 && e.KeyValue <= 40)
    || (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 <= 192)
    || (e.KeyValue >= 219 && e.KeyValue <= 222))
   {
    ((TextBox)sender).Text = e.KeyCode.ToString();
   }
  }

  private void btnDefault_Click(object sender, System.EventArgs e)
  {
   this.ckxMusic.Checked = true;
   this.cbxLevel.Text    = "1";
   this.tbxLeft.Text     = Keys.Left.ToString();
   this.tbxRight.Text    = Keys.Right.ToString();
   this.tbxDown.Text     = Keys.Down.ToString();
   this.tbxEddy.Text     = Keys.Up.ToString();
   this.tbxDrop.Text     = Keys.Space.ToString();
  }

  private void btnOk_Click(object sender, System.EventArgs e)
  {
   KeysConverter  kc;
   kc = new KeysConverter();

   try
   {
    PDefined.BIsMusic   = this.ckxMusic.Checked;
    PDefined.ILevel     = int.Parse(this.cbxLevel.Text);
    PDefined.KToLeft    = (Keys)(kc.ConvertFromString(this.tbxLeft.Text));
    PDefined.KToRight   = (Keys)(kc.ConvertFromString(this.tbxRight.Text));
    PDefined.KToDown    = (Keys)(kc.ConvertFromString(this.tbxDown.Text));
    PDefined.KToEddy    = (Keys)(kc.ConvertFromString(this.tbxEddy.Text));
    PDefined.KSpeedUp   = (Keys)(kc.ConvertFromString(this.tbxDrop.Text));
   }
   finally
   {
    SaveInit.SaveSetting();
    this.Close();
   }
  }

  private void btnCancel_Click(object sender, System.EventArgs e)
  {
   this.Close();
  }

  /// <summary>
  /// 清理所有正在使用的資源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if(components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗體設計器生成的代碼
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void InitializeComponent()
  {
   this.groupBox1 = new System.Windows.Forms.GroupBox();
   this.tbxRight = new System.Windows.Forms.TextBox();
   this.label1 = new System.Windows.Forms.Label();
   this.label2 = new System.Windows.Forms.Label();
   this.label3 = new System.Windows.Forms.Label();
   this.label4 = new System.Windows.Forms.Label();
   this.label5 = new System.Windows.Forms.Label();
   this.tbxEddy = new System.Windows.Forms.TextBox();
   this.tbxDown = new System.Windows.Forms.TextBox();
   this.tbxLeft = new System.Windows.Forms.TextBox();
   this.tbxDrop = new System.Windows.Forms.TextBox();
   this.groupBox2 = new System.Windows.Forms.GroupBox();
   this.cbxLevel = new System.Windows.Forms.ComboBox();
   this.ckxMusic = new System.Windows.Forms.CheckBox();
   this.label11 = new System.Windows.Forms.Label();
   this.btnOk = new System.Windows.Forms.Button();
   this.btnCancel = new System.Windows.Forms.Button();
   this.btnDefault = new System.Windows.Forms.Button();
   this.groupBox1.SuspendLayout();
   this.groupBox2.SuspendLayout();
   this.SuspendLayout();
   //
   // groupBox1
   //
   this.groupBox1.Controls.Add(this.tbxRight);
   this.groupBox1.Controls.Add(this.label1);
   this.groupBox1.Controls.Add(this.label2);
   this.groupBox1.Controls.Add(this.label3);
   this.groupBox1.Controls.Add(this.label4);
   this.groupBox1.Controls.Add(this.label5);
   this.groupBox1.Controls.Add(this.tbxEddy);
   this.groupBox1.Controls.Add(this.tbxDown);
   this.groupBox1.Controls.Add(this.tbxLeft);
   this.groupBox1.Controls.Add(this.tbxDrop);
   this.groupBox1.Location = new System.Drawing.Point(12, 10);
   this.groupBox1.Name = "groupBox1";
   this.groupBox1.Size = new System.Drawing.Size(148, 136);
   this.groupBox1.TabIndex = 0;
   this.groupBox1.TabStop = false;
   this.groupBox1.Text = "鍵盤設置";
   //
   // tbxRight
   //
   this.tbxRight.BackColor = System.Drawing.SystemColors.Control;
   this.tbxRight.ImeMode = System.Windows.Forms.ImeMode.NoControl;
   this.tbxRight.Location = new System.Drawing.Point(54, 22);
   this.tbxRight.Name = "tbxRight";
   this.tbxRight.ReadOnly = true;
   this.tbxRight.Size = new System.Drawing.Size(76, 21);
   this.tbxRight.TabIndex = 2;
   this.tbxRight.Text = "";
   this.tbxRight.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
   this.tbxRight.WordWrap = false;
   this.tbxRight.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbxSet_KeyDown);
   //
   // label1
   //
   this.label1.BackColor = System.Drawing.SystemColors.Control;
   this.label1.Location = new System.Drawing.Point(12, 24);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(40, 14);
   this.label1.TabIndex = 0;
   this.label1.Text = "右移:";
   this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label2
   //
   this.label2.BackColor = System.Drawing.SystemColors.Control;
   this.label2.Location = new System.Drawing.Point(12, 44);
   this.label2.Name = "label2";
   this.label2.Size = new System.Drawing.Size(40, 14);
   this.label2.TabIndex = 0;
   this.label2.Text = "左移:";
   this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label3
   //
   this.label3.BackColor = System.Drawing.SystemColors.Control;
   this.label3.Location = new System.Drawing.Point(12, 84);
   this.label3.Name = "label3";
   this.label3.Size = new System.Drawing.Size(40, 14);
   this.label3.TabIndex = 0;
   this.label3.Text = "旋轉:";
   this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label4
   //
   this.label4.BackColor = System.Drawing.SystemColors.Control;
   this.label4.Location = new System.Drawing.Point(12, 64);
   this.label4.Name = "label4";
   this.label4.Size = new System.Drawing.Size(40, 14);
   this.label4.TabIndex = 0;
   this.label4.Text = "下移:";
   this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label5
   //
   this.label5.BackColor = System.Drawing.SystemColors.Control;
   this.label5.Location = new System.Drawing.Point(12, 104);
   this.label5.Name = "label5";
   this.label5.Size = new System.Drawing.Size(40, 14);
   this.label5.TabIndex = 0;
   this.label5.Text = "墜落:";
   this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // tbxEddy
   //
   this.tbxEddy.BackColor = System.Drawing.SystemColors.Control;
   this.tbxEddy.ImeMode = System.Windows.Forms.ImeMode.NoControl;
   this.tbxEddy.Location = new System.Drawing.Point(54, 82);
   this.tbxEddy.Name = "tbxEddy";
   this.tbxEddy.ReadOnly = true;
   this.tbxEddy.Size = new System.Drawing.Size(76, 21);
   this.tbxEddy.TabIndex = 2;
   this.tbxEddy.Text = "";
   this.tbxEddy.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
   this.tbxEddy.WordWrap = false;
   this.tbxEddy.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbxSet_KeyDown);
   //
   // tbxDown
   //
   this.tbxDown.BackColor = System.Drawing.SystemColors.Control;
   this.tbxDown.ImeMode = System.Windows.Forms.ImeMode.NoControl;
   this.tbxDown.Location = new System.Drawing.Point(54, 62);
   this.tbxDown.Name = "tbxDown";
   this.tbxDown.ReadOnly = true;
   this.tbxDown.Size = new System.Drawing.Size(76, 21);
   this.tbxDown.TabIndex = 2;
   this.tbxDown.Text = "";
   this.tbxDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
   this.tbxDown.WordWrap = false;
   this.tbxDown.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbxSet_KeyDown);
   //
   // tbxLeft
   //
   this.tbxLeft.BackColor = System.Drawing.SystemColors.Control;
   this.tbxLeft.ImeMode = System.Windows.Forms.ImeMode.NoControl;
   this.tbxLeft.Location = new System.Drawing.Point(54, 42);
   this.tbxLeft.Name = "tbxLeft";
   this.tbxLeft.ReadOnly = true;
   this.tbxLeft.Size = new System.Drawing.Size(76, 21);
   this.tbxLeft.TabIndex = 2;
   this.tbxLeft.Text = "";
   this.tbxLeft.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
   this.tbxLeft.WordWrap = false;
   this.tbxLeft.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbxSet_KeyDown);
   //
   // tbxDrop
   //
   this.tbxDrop.BackColor = System.Drawing.SystemColors.Control;
   this.tbxDrop.ImeMode = System.Windows.Forms.ImeMode.NoControl;
   this.tbxDrop.Location = new System.Drawing.Point(54, 102);
   this.tbxDrop.Name = "tbxDrop";
   this.tbxDrop.ReadOnly = true;
   this.tbxDrop.Size = new System.Drawing.Size(76, 21);
   this.tbxDrop.TabIndex = 2;
   this.tbxDrop.Text = "";
   this.tbxDrop.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
   this.tbxDrop.WordWrap = false;
   this.tbxDrop.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbxSet_KeyDown);
   //
   // groupBox2
   //
   this.groupBox2.Controls.Add(this.cbxLevel);
   this.groupBox2.Controls.Add(this.ckxMusic);
   this.groupBox2.Controls.Add(this.label11);
   this.groupBox2.Location = new System.Drawing.Point(168, 10);
   this.groupBox2.Name = "groupBox2";
   this.groupBox2.Size = new System.Drawing.Size(160, 76);
   this.groupBox2.TabIndex = 1;
   this.groupBox2.TabStop = false;
   this.groupBox2.Text = "環境設置";
   //
   // cbxLevel
   //
   this.cbxLevel.BackColor = System.Drawing.SystemColors.Control;
   this.cbxLevel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
   this.cbxLevel.Items.AddRange(new object[] {
                "1",
                "2",
                "3",
                "4",
                "5",
                "6",
                "7",
                "8",
                "9",
                "10",
                "11",
                "12",
                "13",
                "14",
                "15"});
   this.cbxLevel.Location = new System.Drawing.Point(70, 18);
   this.cbxLevel.MaxDropDownItems = 10;
   this.cbxLevel.Name = "cbxLevel";
   this.cbxLevel.Size = new System.Drawing.Size(78, 20);
   this.cbxLevel.TabIndex = 2;
   //
   // ckxMusic
   //
   this.ckxMusic.Location = new System.Drawing.Point(14, 46);
   this.ckxMusic.Name = "ckxMusic";
   this.ckxMusic.Size = new System.Drawing.Size(50, 18);
   this.ckxMusic.TabIndex = 1;
   this.ckxMusic.Text = "音效";
   //
   // label11
   //
   this.label11.BackColor = System.Drawing.SystemColors.Control;
   this.label11.Location = new System.Drawing.Point(10, 22);
   this.label11.Name = "label11";
   this.label11.Size = new System.Drawing.Size(60, 14);
   this.label11.TabIndex = 0;
   this.label11.Text = "遊戲級別:";
   this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // btnOk
   //
   this.btnOk.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
   this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.System;
   this.btnOk.Location = new System.Drawing.Point(168, 120);
   this.btnOk.Name = "btnOk";
   this.btnOk.Size = new System.Drawing.Size(77, 26);
   this.btnOk.TabIndex = 4;
   this.btnOk.Text = "確定";
   this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
   //
   // btnCancel
   //
   this.btnCancel.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
   this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
   this.btnCancel.Location = new System.Drawing.Point(250, 120);
   this.btnCancel.Name = "btnCancel";
   this.btnCancel.Size = new System.Drawing.Size(77, 26);
   this.btnCancel.TabIndex = 5;
   this.btnCancel.Text = "取消";
   this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
   //
   // btnDefault
   //
   this.btnDefault.Cursor = System.Windows.Forms.Cursors.Hand;
   this.btnDefault.FlatStyle = System.Windows.Forms.FlatStyle.System;
   this.btnDefault.Location = new System.Drawing.Point(168, 90);
   this.btnDefault.Name = "btnDefault";
   this.btnDefault.Size = new System.Drawing.Size(159, 26);
   this.btnDefault.TabIndex = 3;
   this.btnDefault.Text = "恢復默認值";
   this.btnDefault.Click += new System.EventHandler(this.btnDefault_Click);
   //
   // GameOption
   //
   this.AcceptButton = this.btnOk;
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.BackColor = System.Drawing.SystemColors.Control;
   this.CancelButton = this.btnCancel;
   this.ClientSize = new System.Drawing.Size(342, 158);
   this.Controls.Add(this.btnOk);
   this.Controls.Add(this.groupBox2);
   this.Controls.Add(this.groupBox1);
   this.Controls.Add(this.btnCancel);
   this.Controls.Add(this.btnDefault);
   this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
   this.KeyPreview = true;
   this.MaximizeBox = false;
   this.MinimizeBox = false;
   this.Name = "GameOption";
   this.ShowInTaskbar = false;
   this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
   this.Text = "遊戲參數設置";
   this.Load += new System.EventHandler(this.GameOption_Load);
   this.groupBox1.ResumeLayout(false);
   this.groupBox2.ResumeLayout(false);
   this.ResumeLayout(false);

  }
  #endregion
 }
}
#region Copyright (c) 2005, By Sirius
/*================================================================
 *
 * Copyright (c) 2005, Sirius, All rights reserved.
 *
 * FileName   : Block.cs
 * Author     : sirius
 * CreateDate : 2005/12/12
 * ChangeDate : 2005/12/13 /14 /15  2006/01/01 02/ 03/ 19/ 20/
 *
=================================================================*/
#endregion

namespace RrGame
{
 using System;
 using System.Drawing;          //
 using System.Windows.Forms;    //

 /// <summary>
 /// 模塊類
 /// </summary>
 public class Block
 {
  private Control     bOwner;          // 模塊擁有者
  private int         bx;              // 方塊的橫座標
  private int         by;              // 方塊的縱座標
  private int         bUnitPix;        // 方塊大小(像素)
  private int         bShapeID;        // 模塊的形狀ID
  private int         bQuadrantID;     // 模塊所在象限ID
  private Color       bColor;          // 模塊對象的顏色
  private bool[,]     SiriusB;
  private Color[,]    SiriusC;
  private Rectangle[] bRects;          // 四個方塊框架對象

  public Block( Control bOwner, int LeftBorder, int BottomBorder,
   int bUnitPix, bool[,] bol, Color[,] col )
  {
   this.bOwner   = bOwner;
   this.bx       = LeftBorder;
   this.by       = BottomBorder;
   this.bUnitPix = bUnitPix;
   this.SiriusB  = bol;
   this.SiriusC  = col;
   this.bRects   = new Rectangle[4];
  }

  #region 繪製方塊
  /// <summary>
  /// 繪製方塊單個方塊
  /// </summary>
  private void BlockDraw( Rectangle rect )
  {
   int x, y;

   x = rect.X / this.bUnitPix;
   y = rect.Y / this.bUnitPix;
   this.BlockDraw(x, y, this.bColor);
  }

  /// <summary>
  /// 繪製方塊單個方塊
  /// </summary>
  /// <param name="x">要繪製的方塊左上角橫座標</param>
  /// <param name="y">要繪製的方塊左上角縱座標</param>
  /// <param name="color">填充方塊的顏色</param>
  private void BlockDraw( int x, int y, Color color )
  {
   Point      ptTemp;
   Pen        pTemp;
   SolidBrush sbTempM;

   ptTemp  = new Point(this.bUnitPix * x, this.bUnitPix * y);
   pTemp   = new Pen(Color.Gray,1);
   sbTempM = new SolidBrush(color);
   this.BlockDraw(ptTemp, this.bUnitPix, pTemp, sbTempM);
  }

  /// <summary>
  /// 繪製方塊單個方塊
  /// </summary>
  /// <param name="pt">頂點</param>
  /// <param name="unitPix">模塊像素</param>
  /// <param name="pen">模塊邊框畫筆</param>
  /// <param name="sbrush">模塊中心畫刷</param>
  private void BlockDraw( Point pt, int unitPix, Pen pen, SolidBrush sbrush )
  {
   Graphics   graTemp;
   SolidBrush sbTempB;

   sbTempB = new SolidBrush(Color.White);
   graTemp = this.bOwner.CreateGraphics();

   graTemp.FillRectangle(sbTempB, pt.X + 1, pt.Y + 1, unitPix - 1, unitPix - 1);
   graTemp.FillRectangle(sbrush, pt.X + 3, pt.Y + 3, unitPix - 3, unitPix - 3);
   graTemp.DrawRectangle(pen, pt.X, pt.Y, unitPix, unitPix);
  }

  /// <summary>
  /// 重繪提示區域
  /// </summary>
  internal void DrawClew()
  {
   for(int i = 0; i < this.bRects.Length; i ++)
   {
    this.BlockDraw(this.bRects[i]);
   }
  }

  /// <summary>
  /// 重繪遊戲區域
  /// </summary>
  internal void DrawMain()
  {
   for(int i = 0; i < this.bRects.Length; i ++)
   {
    this.BlockDraw(this.bRects[i]);
   }

   for(int i = this.SiriusB.GetLength(0) - 1; i >= 0; i --)
   {
    for(int j = this.SiriusB.GetLength(1) - 1; j >= 0; j --)
    {
     if(this.SiriusB[i, j])
     {
      this.BlockDraw(i, j, this.SiriusC[i,j]);
     }
    }
   }
  }
  #endregion

  #region 撤消模塊
  /// <summary>
  /// 使模塊區域無效
  /// </summary>
  internal void EraseBlocks()
  {
   Rectangle rectTemp;
   foreach(Rectangle rect in this.bRects)
   {
    rectTemp = new Rectangle(rect.X, rect.Y, bUnitPix + 1, bUnitPix + 1);
    this.bOwner.Invalidate(rectTemp);
   }
  }

  /// <summary>
  /// 消行
  /// </summary>
  internal int EraseRows()
  {
   int   delCount = 0;
   int[] delRows  = { -1, -1, -1, -1 };

   // ======================================================== 判斷
   for(int i = 0; i < this.bRects.Length; i ++)
   {
    int x = 0;
    int y = this.Y(i);
    
    for(x = 0; x < this.SiriusB.GetLength(0); x ++)
    {
     if(!this.SiriusB[x, y]) break;
    }
    if(x == this.SiriusB.GetLength(0))
    {
     delRows[i] = y;
    }
   }
   // ======================================================== 排序
   for(int i = 0; i < delRows.Length; i ++)
   {
    for(int j = i + 1; j < delRows.Length; j ++)
    {
     if(delRows[i] > delRows[j])
     {
      int iTemp;
      iTemp      = delRows[i];
      delRows[i] = delRows[j];
      delRows[j] = iTemp;
     }
    }
   }
   // ======================================================== 過濾
   for(int i = 0; i < delRows.Length; i ++)
   {
    for(int j = i + 1; j < delRows.Length; j ++)
    {
     if(delRows[i] == delRows[j])
     {
      delRows[i] = -1;
     }
    }
   }
   // ======================================================== 記數
   for(int i = 0; i < delRows.Length; i ++)
   {
    if(delRows[i] != -1) { delCount ++; }
   }
   // ======================================================== 存儲
   for(int i = 0; i < delRows.Length; i ++)
   {
    for(int y = delRows[i]; y > 0; y --)
    {
     for(int x = 0; x < this.SiriusB.GetLength(0); x ++)
     {
      this.SiriusB[x, y] = this.SiriusB[x, y - 1];
      this.SiriusC[x, y] = this.SiriusC[x, y - 1];
     }
    }
   }
   this.bOwner.Invalidate();
   return delCount;
  }
  #endregion

  #region SiriusStore
  internal void SiriusStore()
  {
   int x = 0;
   int y = 0;

   for(int i = 0; i < this.bRects.Length; i ++)
   {
    x = this.X(i);
    y = this.Y(i);
    this.SiriusB[x, y] = true;
    this.SiriusC[x, y] = this.bColor;
   }
  }
  #endregion

  #region 模塊動作
  /// <summary>
  /// 模塊移動
  /// </summary>
  internal bool BlockMove( string direction )
  {
   if(!this.CanMove(direction)) { return false; }

   int offx = 0;
   int offy = 0;
   switch(direction)
   {
    case "Left" : offx = -this.bUnitPix; break;
    case "Right": offx = this.bUnitPix;  break;
    case "Down" : offy = this.bUnitPix;  break;
    default     :                        break;
   }

   this.EraseBlocks();
   for(int i = 0; i < this.bRects.Length; i ++)
   {
    this.bRects[i].Offset(offx, offy);
   }
   return true;
  }

  /// <summary>
  /// 加速下落
  /// </summary>
  internal void BlockDrop()
  {
   while(this.CanMove("Down"))
   {
    this.BlockMove("Down");
   }
  }

  /// <summary>
  /// 模塊旋轉
  /// </summary>
  internal void BlockEddy()
  {
   int     iTemp;
   Point[] ptTemp;

   iTemp = 0;
   ptTemp = new Point[4];

   for(int i = 0; i< this.bRects.Length; i ++)
   {
    ptTemp[i].X = this.bRects[i].Location.X;
    ptTemp[i].Y = this.bRects[i].Location.Y;
   }
   // ================================================================ “——”型
   if(this.bQuadrantID == 21)
   {
    ptTemp[0].Offset(this.bUnitPix * 2, -this.bUnitPix * 2);
    ptTemp[1].Offset(this.bUnitPix, -this.bUnitPix);
    ptTemp[3].Offset(-this.bUnitPix, this.bUnitPix);
    iTemp = 22;
   }
   if(this.bQuadrantID == 22)    // “——”型
   {
    ptTemp[0].Offset(-this.bUnitPix * 2, this.bUnitPix * 2);
    ptTemp[1].Offset(-this.bUnitPix, this.bUnitPix);
    ptTemp[3].Offset(this.bUnitPix, -this.bUnitPix);
    iTemp = 21;
   }
   // ================================================================ “Z”型
   if(this.bQuadrantID == 31)
   {
    ptTemp[0].Offset(this.bUnitPix * 2, 0);
    ptTemp[1].Offset(this.bUnitPix, this.bUnitPix);
    ptTemp[3].Offset(-this.bUnitPix, this.bUnitPix);
    iTemp = 32;
   }
   if(this.bQuadrantID == 32)    // “Z”型
   {
    ptTemp[0].Offset(-this.bUnitPix * 2, 0);
    ptTemp[1].Offset(-this.bUnitPix, -this.bUnitPix);
    ptTemp[3].Offset(this.bUnitPix, -this.bUnitPix);
    iTemp =31;
   }
   // ================================================================ 倒“Z”型
   if(this.bQuadrantID == 41)   
   {
    ptTemp[0].Offset(0, this.bUnitPix);
    ptTemp[1].Offset(-this.bUnitPix, 0);
    ptTemp[2].Offset(this.bUnitPix, 0);
    ptTemp[3].Offset(this.bUnitPix * 2, this.bUnitPix);
    iTemp =42;
   }
   if(this.bQuadrantID == 42)    // 倒“Z”型
   {
    ptTemp[0].Offset(0, -this.bUnitPix);
    ptTemp[1].Offset(this.bUnitPix, 0);
    ptTemp[2].Offset(-this.bUnitPix, 0);
    ptTemp[3].Offset(-this.bUnitPix * 2, -this.bUnitPix);
    iTemp =41;
   }
   // ================================================================ 倒“土”型
   if(this.bQuadrantID == 51)
   {
    ptTemp[0].Offset(this.bUnitPix, -this.bUnitPix);
    ptTemp[1].Offset(-this.bUnitPix, this.bUnitPix);
    ptTemp[3].Offset(-this.bUnitPix, -this.bUnitPix);
    iTemp = 52;
   }
   if(this.bQuadrantID == 52)    // 倒“土”型
   {
    ptTemp[0].Offset(this.bUnitPix, this.bUnitPix);
    ptTemp[1].Offset(-this.bUnitPix, -this.bUnitPix);
    ptTemp[3].Offset(this.bUnitPix, -this.bUnitPix);
    iTemp = 53;
   }
   if(this.bQuadrantID == 53)    // 倒“土”型
   {
    ptTemp[0].Offset(-this.bUnitPix, this.bUnitPix);
    ptTemp[1].Offset(this.bUnitPix, -this.bUnitPix);
    ptTemp[3].Offset(this.bUnitPix, this.bUnitPix);
    iTemp = 54;
   }
   if(this.bQuadrantID == 54)    // 倒“土”型
   {
    ptTemp[0].Offset(-this.bUnitPix, -this.bUnitPix);
    ptTemp[1].Offset(this.bUnitPix, this.bUnitPix);
    ptTemp[3].Offset(-this.bUnitPix, this.bUnitPix);
    iTemp = 51;
   }
   // ================================================================ “L”型
   if(this.bQuadrantID == 61)
   {
    ptTemp[0].Offset(this.bUnitPix, -this.bUnitPix);
    ptTemp[1].Offset(-this.bUnitPix, this.bUnitPix);
    ptTemp[3].Offset(0, -2 * this.bUnitPix);
    iTemp = 62;
   }
   if(this.bQuadrantID == 62)    // “L”型
   {
    ptTemp[0].Offset(this.bUnitPix, this.bUnitPix);
    ptTemp[1].Offset(-this.bUnitPix, -this.bUnitPix);
    ptTemp[3].Offset(this.bUnitPix * 2, 0);
    iTemp = 63;
   }

   if(this.bQuadrantID == 63)    // “L”型
   {
     ptTemp[0].Offset(-this.bUnitPix, this.bUnitPix);
    ptTemp[1].Offset(this.bUnitPix, -this.bUnitPix);
    ptTemp[3].Offset(0, this.bUnitPix * 2);
    iTemp = 64;
   }
   if(this.bQuadrantID == 64)    // “L”型
   {
     ptTemp[0].Offset(-this.bUnitPix, -this.bUnitPix);
    ptTemp[1].Offset(this.bUnitPix, this.bUnitPix);
    ptTemp[3].Offset(-this.bUnitPix * 2, 0);
    iTemp = 61;
   }
   // ================================================================ 倒“L”型
   if(this.bQuadrantID == 71)
   {
     ptTemp[0].Offset(this.bUnitPix, -this.bUnitPix);
    ptTemp[1].Offset(-this.bUnitPix, this.bUnitPix);
    ptTemp[3].Offset(-this.bUnitPix * 2, 0);
    iTemp = 72;
   }

   if(this.bQuadrantID == 72)    // 倒“L”型
   {
    ptTemp[0].Offset(this.bUnitPix, this.bUnitPix);
    ptTemp[1].Offset(-this.bUnitPix, -this.bUnitPix);
    ptTemp[3].Offset(0, -this.bUnitPix * 2);
    iTemp = 73;
   }
   if(this.bQuadrantID == 73)    // 倒“L”型
   {
    ptTemp[0].Offset(-this.bUnitPix, this.bUnitPix);
    ptTemp[1].Offset(this.bUnitPix, -this.bUnitPix);
    ptTemp[3].Offset(this.bUnitPix * 2, 0);
    iTemp = 74;
   }
   if(this.bQuadrantID == 74)    // 倒“L”型
   {
    ptTemp[0].Offset(-this.bUnitPix, -this.bUnitPix);
    ptTemp[1].Offset(this.bUnitPix, this.bUnitPix);
    ptTemp[3].Offset(0, this.bUnitPix * 2);
    iTemp = 71;
   }

   if(this.CanEddy(ptTemp))
   {
    this.bQuadrantID = iTemp;
    this.EraseBlocks();
    for(int i = 0; i < this.bRects.Length; i ++)
    {
     this.bRects[i].X = ptTemp[i].X;
     this.bRects[i].Y = ptTemp[i].Y;
    }
   }
  }
  #endregion

  #region 動作判斷
  /// <summary>
  /// 模塊是否能移動
  /// </summary>
  private bool CanMove( string direction )
  {
   bool isMove = true;
   for(int i = 0; i < this.bRects.Length; i ++)
   {
    if(direction == "Down")
    {
     if((Y(i) >= 14) || (this.SiriusB[X(i), Y(i) + 1]))
     { isMove = false; }
    }
    if(direction == "Left")
    {
     if((X(i) <= 0) || (this.SiriusB[X(i) - 1, Y(i)]))
     { isMove = false; }
    }
    if(direction == "Right")
    {
     if((X(i) >= 9) || (this.SiriusB[X(i) + 1, Y(i)]))
     { isMove = false; }
    }
   }
   return isMove;
  }

  /// <summary>
  /// 模塊能否旋轉
  /// </summary>
  /// <param name="pos">四個方快的頂點</param>
  private bool CanEddy( Point[] pos )
  {
   bool isEddy = true;
   for(int i = 0; i < pos.Length; i ++)
   {
    if((pos[i].X < 0) || (pos[i].X + bUnitPix > BOWNERMAXX))
    { isEddy = false; }

    if((pos[i].Y < 0) || (pos[i].Y + bUnitPix > BOWNERMAXY))
    { isEddy = false; }

    if(this.SiriusB[this.X(i), this.Y(i)])
    { isEddy = false; }
   }
   return isEddy;
  }
  #endregion

  #region 生成模塊
  /// <summary>
  /// 生成模塊形狀ID
  /// </summary>
  /// <returns></returns>
  internal static int BShapeID()
  {
   return new Random().Next(1, 8);
  }

  /// <summary>
  /// 生成四方塊組合的模塊
  /// </summary>
  /// <param name="ShapeID">形狀ID</param>
  /// <param name="ColorID">顏色ID</param>
  /// <returns>是否能生成</returns>
  internal bool BlockCreate( int ShapeID, int ColorID )
  {
   Point[] posTemp;
   Graphics graTemp;
   Pen pTemp;
   SolidBrush sbTemp;

   posTemp    = new Point[4];
   posTemp[0] = new Point(this.bx, this.by);
   graTemp    = this.bOwner.CreateGraphics();
   pTemp      = new Pen(Color.Gray, 1);
   sbTemp     = new SolidBrush(this.BlockColor(ColorID));
   this.bShapeID    = ShapeID;
   this.bQuadrantID = this.bShapeID * 10 + 1;

   switch(this.bShapeID)
   {
    case 1:    //“田”型
     posTemp[1] = new Point(this.bx + bUnitPix, this.by);
     posTemp[2] = new Point(this.bx, this.by + bUnitPix);
     posTemp[3] = new Point(this.bx + bUnitPix, this.by + bUnitPix);
     break;

    case 2:    //“——”型
     posTemp[0] = new Point(this.bx - bUnitPix, this.by);
     posTemp[1] = new Point(this.bx, this.by);
     posTemp[2] = new Point(this.bx + bUnitPix, this.by);
     posTemp[3] = new Point(this.bx + bUnitPix * 2, this.by);
     break;

    case 3:   //“Z”型
     posTemp[1] = new Point(this.bx + bUnitPix, this.by);
     posTemp[2] = new Point(this.bx + bUnitPix, this.by + bUnitPix);
     posTemp[3] = new Point(this.bx + bUnitPix * 2, this.by + bUnitPix);
     break;

    case 4:   //倒“Z”型
     posTemp[0] = new Point(this.bx + bUnitPix, this.by);
     posTemp[1] = new Point(this.bx + bUnitPix * 2, this.by);
     posTemp[2] = new Point(this.bx + bUnitPix, this.by + bUnitPix);
     posTemp[3] = new Point(this.bx, this.by + bUnitPix);
     break;

    case 5:   //倒“土”型
     posTemp[1] = new Point(this.bx + bUnitPix * 2, this.by);
     posTemp[2] = new Point(this.bx + bUnitPix, this.by);
     posTemp[3] = new Point(this.bx + bUnitPix, this.by + bUnitPix);
     break;

    case 6:    //“L”型
     posTemp[1] = new Point(this.bx + bUnitPix * 2, this.by);
     posTemp[2] = new Point(this.bx + bUnitPix, this.by);
     posTemp[3] = new Point(this.bx, this.by + bUnitPix);
     break;

    case 7:   //倒“L”型
     posTemp[1] = new Point(this.bx + bUnitPix * 2, this.by);
     posTemp[2] = new Point(this.bx + bUnitPix, this.by);
     posTemp[3] = new Point(this.bx + bUnitPix * 2, this.by + bUnitPix);
     break;

    default: break;
   }

   for(int i = 0; i < posTemp.Length; i ++)
   {
    int x = posTemp[i].X / this.bUnitPix;
    int y = posTemp[i].Y / this.bUnitPix;

    if(this.SiriusB[x, y]) { return false; }
   }
   for(int i = 0; i < posTemp.Length; i ++)
   {
    this.BlockDraw(posTemp[i], this.bUnitPix, pTemp, sbTemp);
    this.bRects[i] = new Rectangle(posTemp[i], new Size(bUnitPix, bUnitPix));
   }
   return true;
  }
  #endregion

  #region 生成顏色
  /// <summary>
  ///  生成模塊顏色ID
  /// </summary>
  internal static int BColorID()
  {
   return new Random().Next(10);
  }

  /// <summary>
  /// 生成方塊的顏色值
  /// </summary>
  /// <param name="ColorID">顏色ID</param>
  internal Color BlockColor( int ColorID )
  {
   switch(ColorID)
   {
    case 0:  this.bColor = System.Drawing.Color.Red;              break;
    case 1:  this.bColor = System.Drawing.Color.Black;            break;
    case 2:  this.bColor = System.Drawing.Color.DarkViolet;       break;
    case 3:  this.bColor = System.Drawing.Color.Magenta;          break;
    case 4:  this.bColor = System.Drawing.Color.MediumBlue;       break;
    case 5:  this.bColor = System.Drawing.Color.MediumSeaGreen;   break;
    case 6:  this.bColor = System.Drawing.Color.Olive;            break;
    case 7:  this.bColor = System.Drawing.Color.DarkGoldenrod;    break;
    case 8:  this.bColor = System.Drawing.Color.Brown;            break;
    case 9:  this.bColor = System.Drawing.Color.Pink;             break;
    default: this.bColor = System.Drawing.Color.SaddleBrown;      break;
   }
   return this.bColor;
  }
  #endregion

  #region 獲取模塊所屬控件邊界值
  /// <summary>
  /// 右邊界值
  /// </summary>
  private int BOWNERMAXX
  {
   get { return this.bOwner.Size.Width; }
  }

  /// <summary>
  /// 垂直邊界值
  /// </summary>
  private int BOWNERMAXY
  {
   get { return this.bOwner.Size.Height; }
  }
  #endregion

  #region 獲取方塊在Sirius中的橫縱座標
  /// <summary>
  /// 獲取方塊在Sirius中的X座標
  /// </summary>
  /// <param name="index">方塊ID</param>
  private int X( int index )
  {
   return this.bRects[index].X / this.bUnitPix;
  }

  /// <summary>
  /// 獲取方塊在Sirius中的Y座標
  /// </summary>
  /// <param name="index">方塊ID</param>
  private int Y( int index )
  {
   return this.bRects[index].Y / this.bUnitPix;
  }
  #endregion
 }
}
#region Copyright (c) 2005, By Sirius
/*================================================================
 *
 * Copyright (c) 2005, Sirius, All rights reserved.
 *
 * FileName   : BPara.cs
 * Author     : sirius
 * CreateDate : 2005/12/12
 * ChangeDate : 2005/12/13 2006/01/01 /02 /03
 *
=================================================================*/
#endregion

namespace RrGame
{
 using System;
 using System.Windows.Forms;

 /// <summary>
 /// 當前參數類
 /// </summary>
 class PDefined
 {
  internal static int  ILevel;        // 遊戲級別
  internal static bool BIsMusic;      // 是否有背景音樂
  internal static Keys KToLeft;       // 向左控制鍵
  internal static Keys KToRight;      // 向右控制鍵
  internal static Keys KToDown;       // 向下控制鍵
  internal static Keys KSpeedUp;      // 加速控制鍵
  internal static Keys KToEddy;       // 旋轉控制鍵
 }

 /// <summary>
 /// 算法類
 /// </summary>
 public class Arithmetic
 {
  /// <summary>
  /// 計時器間隔
  /// </summary>
  /// <returns></returns>
  public static int ILevel()
  {
   int intervalTemp = 500;
   switch(PDefined.ILevel)
   {
    case 1:  intervalTemp = 490; break;
    case 2:  intervalTemp = 440; break;
    case 3:  intervalTemp = 390; break;
    case 4:  intervalTemp = 340; break;
    case 5:  intervalTemp = 290; break;
    case 6:  intervalTemp = 240; break;
    case 7:  intervalTemp = 210; break;
    case 8:  intervalTemp = 180; break;
    case 9:  intervalTemp = 150; break;
    case 10: intervalTemp = 120; break;
    case 11: intervalTemp = 100; break;
    case 12: intervalTemp = 80;  break;
    case 13: intervalTemp = 50;  break;
    case 14: intervalTemp = 30;  break;
    case 15: intervalTemp = 20;  break;
    default:                     break;
   }
   return intervalTemp;
  }

  /// <summary>
  /// 消行得分
  /// </summary>
  /// <param name="delRows"></param>
  /// <returns></returns>
  public static int DelAcount(int delRows)
  {
   int acount = 0;
   switch(delRows)
   {
    case 1:  acount = 1; break;
    case 2:  acount = 3; break;
    case 3:  acount = 5; break;
    case 4:  acount = 8; break;
    default: acount = 0; break;
   }
   return acount;
  }
 }
}
#region Copyright (c) 2005, By Sirius
/*================================================================
 *
 * Copyright (c) 2005, Sirius, All rights reserved.
 *
 * FileName   : BSoundPlay.cs
 * Author     : sirius
 * CreateDate : 2005/12/12
 * ChangeDate : 2006/01/02 /03 /04
 *
=================================================================*/
#endregion

namespace RrGame
{
 using System;
 using System.IO;
 using System.Text;
 using System.Collections;
 using System.Windows.Forms;
 using System.Runtime.InteropServices;

 /// <summary>
 /// 名稱:音樂播放類
 /// 功能:播放音樂
 /// 作者:小陳
 /// </summary>
 public class SoundPlayer
 {
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
  private string mciStatus = "" ;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
  private string shortFileName = "" ;
  
  [DllImport("winmm.dll",EntryPoint="mciSendString",SetLastError=true, CharSet=CharSet.Auto)]
  private static extern long mciSendString(
   string lpstrCommand,
   string lpstrReturnString,
   long uReturnLength,
   long hwndCallback
   );

  [DllImport("kernel32.dll",SetLastError=true, CharSet = CharSet.Auto)]
  public static extern int GetShortPathName (
   string lpszLongPath,
   string shortFile,
   int cchBuffer
   );

  private string File;
  private string Alias;
  private string status;

  /// <summary>
  /// 初始化參數
  /// </summary>
  /// <param name="strFileName">音樂文件名</param>
  /// <param name="strAliasName">別名</param>
  public SoundPlayer(string strFileName, string strAliasName)
  {
   this.status = "close";
   this.Alias  = strAliasName;
   this.File   = this.LongNameToShortName(strFileName);
  }

  #region 名稱處理
  /// <summary>
  ///
  /// </summary>
  /// <param name="strFileName"></param>
  /// <returns></returns>
  private string LongNameToShortName(string strFileName)
  {
   this.shortFileName = this.shortFileName.PadLeft(260, Convert.ToChar(" "));
   GetShortPathName(strFileName, shortFileName, shortFileName.Length);
   return this.NameTrim(shortFileName);
  }

  /// <summary>
  /// 過濾字符串內空格
  /// </summary>
  /// <param name="name">需要過濾的字符串</param>
  /// <returns>沒有空格的字符串</returns>
  private string NameTrim(string name)
  {
   if(name.Length < 1) return "";
   name = name.Trim();
   name = name.Substring(0, name.Length - 1);
   return name;
  }
  #endregion

  #region 播放控制
  /// <summary>
  /// 播放音樂
  /// </summary>
  /// <returns></returns>
  public bool Play()
  {
   bool rValue;
   long lRet;

   try
   {
    this.Stop();
    lRet = mciSendString("open " + this.File + " alias " + this.Alias, "", 0, 0);
    lRet = mciSendString("play " + this.Alias, "", 0, 0);
    rValue = (lRet == 0);
    this.status = "play";
   }
   catch(Exception)
   {
    return false;
   }
   return true;
  }

  /// <summary>
  /// 停止播放
  /// </summary>
  public bool Stop()
  {
   long lRet;
   try
   {
    lRet = mciSendString("stop " + Alias, "", 0, 0);
    lRet = mciSendString("close " + Alias, "", 0, 0);
    status = "stop";
    return true;
   }
   catch(Exception)
   {
    return false;
   }
  }

  /// <summary>
  /// 關閉所有
  /// </summary>
  public void CloseAudio()
  {
   mciSendString("close all", "", 0, 0);
   this.status = "close";
  }
  #endregion

  /// <summary>
  /// 判斷聲音文件是否在播放
  /// </summary>
  /// <returns>是否正在播放</returns>
  public bool IsPlaying
  {
   get
   {
    if(this.status != "play")
    { return false; }

    this.mciStatus = "";
    this.mciStatus = this.mciStatus.PadLeft(128, Convert.ToChar(" "));
    mciSendString("status " + this.Alias + " mode", this.mciStatus, 128, 0);

    return this.mciStatus.Substring(0, 7).ToLower() == "playing".ToLower();
   }
  }

  /// <summary>
  /// 音樂名
  /// </summary>
  public string FileName
  {
   get { return this.File; }
   set { this.File = this.LongNameToShortName(value); }
  }

  /// <summary>
  /// 別名
  /// </summary>
  public string AliasName
  {
   get { return this.Alias; }
  }
 }

 /// <summary>
 /// 名稱:音樂播放列表類
 /// 功能:存儲播放列表
 /// 作者:小陳
 /// </summary>
 public class SoundList
 {
  private ArrayList list;     // 音樂列表

  public SoundList()
  {
   this.Initalize();
  }

  /// <summary>
  /// 初始化音樂列表
  /// </summary>
  private void Initalize()
  {
   string musicPath;
   this.list  = new ArrayList(0);
   musicPath  = Application.StartupPath + "//Sounds//Back";

   try
   {
    this.list.AddRange(Directory.GetFiles(musicPath));
   }
   catch
   {
    PDefined.BIsMusic = false;
    MessageBox.Show("背景音樂文件丟失!", "錯誤");
   }
  }

  /// <summary>
  /// 生成背景音樂
  /// </summary>
  public string GetBack()
  {
   Random rdTemp;
   int    backID;
   string musicName;

   rdTemp    = new Random();
   backID    = rdTemp.Next(this.list.Count);
   musicName = this.list[backID].ToString();
   musicName = musicName.Substring(musicName.LastIndexOf("//") + 1);
   return musicName;
  }

/*  #region 操作列表
  /// <summary>
  /// 添加背景音樂
  /// </summary>
  /// <param name="musicName"></param>
  public void AddMusic(string musicName)
  {
   try   { this.list.Add(musicName); }
   catch { }
  }

  /// <summary>
  /// 刪除背景音樂
  /// </summary>
  /// <param name="musicName"></param>
  public void DelMusic(string musicName)
  {
   try   { this.list.Remove(musicName); }
   catch { }
  }
  #endregion

  /// <summary>
  /// 音樂列表屬性
  /// </summary>
  public ArrayList List
  {
   get { return this.list; }
  }
*/ 
 }
}
#region Copyright (c) 2005, By Sirius
/*================================================================
 *
 * Copyright (c) 2005, Sirius, All rights reserved.
 *
 * FileName   : BSaveInit.cs
 * Author     : sirius
 * CreateDate : 2005/12/12
 * ChangeDate : 2005/12/14 2006/01/03
 *
=================================================================*/
#endregion

namespace RrGame
{
 using System;
 using System.Xml;
 using System.Drawing;
 using System.Windows.Forms;

 /// <summary>
 /// 保存和初始化遊戲設置類
 /// </summary>
 public class SaveInit
 {
  /// <summary>
  /// 保存遊戲設置
  /// </summary>
  public static void SaveSetting()
  {
   try
   {
    string         fileName;
    XmlDocument    xmlDoc;
    XmlDeclaration xmlDec;
    XmlElement     xmlEltSetting,  xmlEltKeys;
    XmlElement     xmlEltLevel, xmlEltIsMusic;
    XmlElement     xmlKeyToLeft, xmlKeyToRight, xmlKeyToDown;
    XmlElement     xmlKeyToEddy, xmlKeyToSpeedUp, xmlEltRoot;
    KeysConverter  keyCvt;
    
    xmlDoc = new XmlDocument();
    keyCvt = new KeysConverter();

    fileName        = Application.StartupPath + "//Configure.sirius";
    xmlDec          = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null);
    xmlEltSetting   = xmlDoc.CreateElement("Settings");
    xmlEltLevel     = xmlDoc.CreateElement("Level");
    xmlEltIsMusic   = xmlDoc.CreateElement("IsMusice");
    xmlEltKeys      = xmlDoc.CreateElement("Keys");
    xmlKeyToLeft    = xmlDoc.CreateElement("Key");
    xmlKeyToRight   = xmlDoc.CreateElement("Key");
    xmlKeyToDown    = xmlDoc.CreateElement("Key");
    xmlKeyToEddy    = xmlDoc.CreateElement("Key");
    xmlKeyToSpeedUp = xmlDoc.CreateElement("Key");

    xmlEltLevel.InnerText     = PDefined.ILevel.ToString();
    xmlEltIsMusic.InnerText   = PDefined.BIsMusic.ToString();
    xmlKeyToLeft.InnerText    = keyCvt.ConvertToString(PDefined.KToLeft);
    xmlKeyToRight.InnerText   = keyCvt.ConvertToString(PDefined.KToRight);
    xmlKeyToDown.InnerText    = keyCvt.ConvertToString(PDefined.KToDown);
    xmlKeyToEddy.InnerText    = keyCvt.ConvertToString(PDefined.KToEddy);
    xmlKeyToSpeedUp.InnerText = keyCvt.ConvertToString(PDefined.KSpeedUp);

    xmlDoc.AppendChild(xmlEltSetting);
    xmlEltSetting.AppendChild(xmlEltLevel);
    xmlEltSetting.AppendChild(xmlEltIsMusic);
    xmlEltSetting.AppendChild(xmlEltKeys);

    xmlEltKeys.AppendChild(xmlKeyToLeft);
    xmlEltKeys.AppendChild(xmlKeyToRight);
    xmlEltKeys.AppendChild(xmlKeyToDown);
    xmlEltKeys.AppendChild(xmlKeyToEddy);
    xmlEltKeys.AppendChild(xmlKeyToSpeedUp);

    xmlEltRoot = xmlDoc.DocumentElement;
    xmlDoc.InsertBefore(xmlDec, xmlEltRoot); 
    xmlDoc.Save(fileName);
   }
   catch(Exception exp)
   {
    MessageBox.Show(exp.Message);
   }
  }

  /// <summary>
  /// 初始化遊戲參數
  /// </summary>
  /// <param name="panel">遊戲區</param>
  /// <param name="form">panel所在窗體</param>
  public static void InitializeGame(Panel panel, Form form)
  {
   try
   {
    string        fileName;
    KeysConverter kc;
    XmlDocument   xmlDoc;
    XmlNodeList   nodes;

    fileName = Application.StartupPath + "//Configure.sirius";
    kc       = new KeysConverter();
    xmlDoc   = new XmlDocument();
    xmlDoc.Load(fileName);
    nodes    = xmlDoc.DocumentElement.ChildNodes;

    PDefined.ILevel     = Convert.ToInt32(nodes[0].InnerText);
    PDefined.BIsMusic   = Convert.ToBoolean(nodes[1].InnerText);
    PDefined.KToLeft    = (Keys)(kc.ConvertFromString(nodes[2].ChildNodes[0].InnerText));
    PDefined.KToRight   = (Keys)(kc.ConvertFromString(nodes[2].ChildNodes[1].InnerText));
    PDefined.KToDown    = (Keys)(kc.ConvertFromString(nodes[2].ChildNodes[2].InnerText));
    PDefined.KToEddy    = (Keys)(kc.ConvertFromString(nodes[2].ChildNodes[3].InnerText));
    PDefined.KSpeedUp   = (Keys)(kc.ConvertFromString(nodes[2].ChildNodes[4].InnerText));
   }
   catch
   {
    PDefined.ILevel     = 1;             // 遊戲級別
    PDefined.BIsMusic   = true;          // 是否有背景音樂
    PDefined.KToLeft    = Keys.Left;     // 向左控制鍵
    PDefined.KToRight   = Keys.Right;    // 向右控制鍵
    PDefined.KToDown    = Keys.Down;     // 向下控制鍵
    PDefined.KToEddy    = Keys.Up;       // 旋轉控制鍵
    PDefined.KSpeedUp   = Keys.Space;    // 加速控制鍵
      }
   finally
   {
    SaveInit.PMemoryDispose(form);
   }
  }

  /// <summary>
  /// 遊戲通關
  /// </summary>
  /// <param name="bOwner">通關消息顯示所屬控件</param>
  public static void Gamewin(Control bOwner)
  {
   Pen  pTemp;
   Font ft1Temp;
   Font ft2Temp;
   SolidBrush sbTempB;
   SolidBrush sbTempM;
   Graphics   graTemp;

   pTemp   = new Pen(Color.Green);
   ft1Temp = new Font("Arial Black",13f);
   ft2Temp = new Font("宋體",10f);
   sbTempB = new SolidBrush(Color.Lime);
   sbTempM = new SolidBrush(Color.LimeGreen);
   graTemp = bOwner.CreateGraphics();
   graTemp.DrawRectangle(pTemp, 30, 50, 130, 70);
   graTemp.FillRectangle(sbTempB, 30, 50, 130, 70);
   graTemp.DrawRectangle(pTemp, 35, 55, 120, 60);
   graTemp.FillRectangle(sbTempM, 36, 56, 120, 60);
   graTemp.DrawString("congratulate", ft1Temp, new SolidBrush(Color.Red), 35, 60);
   graTemp.DrawString("再接再厲", ft2Temp, new SolidBrush(Color.Red), 70, 90);
  }

  /// <summary>
  /// 遊戲失敗
  /// </summary>
  /// <param name="bOwner">失敗消息顯示所屬控件</param>
  public static void GameOver(Control bOwner)
  {
   Pen  pTemp;
   Font ft1Temp;
   Font ft2Temp;
   SolidBrush sbTempB;
   SolidBrush sbTempM;
   Graphics   graTemp;

   pTemp   = new Pen(Color.Green);
   ft1Temp = new Font("Arial Black",13f);
   ft2Temp = new Font("宋體",10f);
   sbTempB = new SolidBrush(Color.Lime);
   sbTempM = new SolidBrush(Color.LimeGreen);
   graTemp = bOwner.CreateGraphics();
   graTemp.DrawRectangle(pTemp, 30, 50, 130, 70);
   graTemp.FillRectangle(sbTempB, 30, 50, 130, 70);
   graTemp.DrawRectangle(pTemp, 35, 55, 120, 60);
   graTemp.FillRectangle(sbTempM, 36, 56, 120, 60);
   graTemp.DrawString("Game Over", ft1Temp, new SolidBrush(Color.Red), 40, 60);
   graTemp.DrawString("繼續努力", ft2Temp, new SolidBrush(Color.Red), 70, 90);
  }

  internal static void PMemoryDispose(Form form)
  {
   form.WindowState = FormWindowState.Minimized;
   form.WindowState = FormWindowState.Normal;
  }
 }
}
 

發佈了15 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章