コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: akaxiaok/MyGame
 /// <summary>
 /// 移动一行操作
 /// </summary>
 /// <param name="block1"></param>
 /// <param name="block2"></param>
 /// <param name="block3"></param>
 /// <param name="block4"></param>
 /// <param name="canGetNext">是否能获取下一个</param>
 /// <returns></returns>
 private int MoveLine(Blocks block1, Blocks block2, Blocks block3, Blocks block4, out bool canGetNext)
 {
     canGetNext = false;
     int score = 0;
     if (block1.IValue == 0 && block2.IValue == 0 && block3.IValue == 0 && block4.IValue == 0)
         return 0;
     if ((block4.IValue == 0 && (block1.IValue != 0 || block2.IValue != 0 || block3.IValue != 0)) ||
         (block3.IValue == 0 && (block1.IValue != 0 || block2.IValue != 0)) ||
         (block2.IValue == 0 && block1.IValue != 0)
         )
         canGetNext = true;
     Blocks[] Blockss = { block1, block2, block3, block4 }; 
     
     ArrayList iBlockes = new ArrayList();//存储不为0的方块
     for (int i = 0; i < Blockss.Length; i++)
         if (Blockss[i].IValue != 0)
         {
             iBlockes.Add(Blockss[i].IValue);
         }
     for (int i = 0; i < Blockss.Length - iBlockes.Count; i++)
         Blockss[i].IValue = 0;
     for (int i = 0; i < iBlockes.Count; i++)
         Blockss[i + Blockss.Length - iBlockes.Count].IValue = (int)iBlockes[i];
     //如果等于0,说明该行只有一个非0的数,则不需要再移动和累加分值了。
     if (Blockss[2].IValue != 0)
     {
         if (Blockss[3].IValue == Blockss[2].IValue)
         {
             score += 2 * Blockss[3].IValue;
             Blockss[3].IValue = 2 * Blockss[3].IValue;
             canGetNext = true;
             if (Blockss[1].IValue == Blockss[0].IValue)
             {
                 score += 2 * Blockss[1].IValue;
                 Blockss[2].IValue = 2 * Blockss[1].IValue;
                 if (Blockss[1].IValue > 0) canGetNext = true;
                 Blockss[1].IValue = 0;
                 Blockss[0].IValue = 0;
             }
             else
             {
                 Blockss[2].IValue = Blockss[1].IValue;
                 Blockss[1].IValue = Blockss[0].IValue; ;
                 Blockss[0].IValue = 0;
             }
         }
         else
         {
             if (Blockss[2].IValue == Blockss[1].IValue)
             {
                 score += 2 * Blockss[2].IValue;
                 Blockss[2].IValue = 2 * Blockss[2].IValue;
                 if (Blockss[1].IValue > 0) canGetNext = true;
                 Blockss[1].IValue = Blockss[0].IValue; ;
                 Blockss[0].IValue = 0;
             }
             else
             {
                 if (Blockss[1].IValue == Blockss[0].IValue)
                 {
                     score += 2 * Blockss[1].IValue;
                     Blockss[1].IValue = 2 * Blockss[1].IValue;
                     if (Blockss[0].IValue > 0) canGetNext = true;
                     Blockss[0].IValue = 0;
                 }
             }
         }
     }
     return score;
 }
コード例 #2
0
ファイル: MainWindow.g.i.cs プロジェクト: akaxiaok/MyGame
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     
     #line 5 "..\..\..\MainWindow.xaml"
     ((Game1024.MainWindow)(target)).Closing += new System.ComponentModel.CancelEventHandler(this.Window_Closing);
     
     #line default
     #line hidden
     
     #line 6 "..\..\..\MainWindow.xaml"
     ((Game1024.MainWindow)(target)).PreviewKeyDown += new System.Windows.Input.KeyEventHandler(this.Window_PreviewKeyDown);
     
     #line default
     #line hidden
     return;
     case 2:
     
     #line 13 "..\..\..\MainWindow.xaml"
     ((System.Windows.Controls.Border)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Border_MouseDown);
     
     #line default
     #line hidden
     
     #line 13 "..\..\..\MainWindow.xaml"
     ((System.Windows.Controls.Border)(target)).MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.Border_MouseUp);
     
     #line default
     #line hidden
     return;
     case 3:
     this.MainGrid = ((System.Windows.Controls.Grid)(target));
     return;
     case 4:
     this.b1 = ((Game1024.UControl.Blocks)(target));
     return;
     case 5:
     this.b2 = ((Game1024.UControl.Blocks)(target));
     return;
     case 6:
     this.b3 = ((Game1024.UControl.Blocks)(target));
     return;
     case 7:
     this.b4 = ((Game1024.UControl.Blocks)(target));
     return;
     case 8:
     this.b5 = ((Game1024.UControl.Blocks)(target));
     return;
     case 9:
     this.b6 = ((Game1024.UControl.Blocks)(target));
     return;
     case 10:
     this.b7 = ((Game1024.UControl.Blocks)(target));
     return;
     case 11:
     this.b8 = ((Game1024.UControl.Blocks)(target));
     return;
     case 12:
     this.b9 = ((Game1024.UControl.Blocks)(target));
     return;
     case 13:
     this.b10 = ((Game1024.UControl.Blocks)(target));
     return;
     case 14:
     this.b11 = ((Game1024.UControl.Blocks)(target));
     return;
     case 15:
     this.b12 = ((Game1024.UControl.Blocks)(target));
     return;
     case 16:
     this.b13 = ((Game1024.UControl.Blocks)(target));
     return;
     case 17:
     this.b14 = ((Game1024.UControl.Blocks)(target));
     return;
     case 18:
     this.b15 = ((Game1024.UControl.Blocks)(target));
     return;
     case 19:
     this.b16 = ((Game1024.UControl.Blocks)(target));
     return;
     case 20:
     this.btn_play = ((System.Windows.Controls.Button)(target));
     
     #line 46 "..\..\..\MainWindow.xaml"
     this.btn_play.Click += new System.Windows.RoutedEventHandler(this.btn_play_Click);
     
     #line default
     #line hidden
     return;
     case 21:
     this.t_Score = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 22:
     this.btn_back = ((System.Windows.Controls.Button)(target));
     
     #line 48 "..\..\..\MainWindow.xaml"
     this.btn_back.Click += new System.Windows.RoutedEventHandler(this.btn_back_Click);
     
     #line default
     #line hidden
     return;
     }
     this._contentLoaded = true;
 }