private int moveLine(Tile t1, Tile t2, Tile t3, Tile t4) { //canGetNext = false; int score = 0; if (t1.Value == 0 && t2.Value == 0 && t3.Value == 0 && t4.Value == 0)//该行全为0直接返回 return 0; //if ((c4.Value == 0 && (c1.Value != 0 || c2.Value != 0 || c3.Value != 0)) || //(c3.Value == 0 && (c1.Value != 0 || c2.Value != 0)) || //(c2.Value == 0 && c1.Value != 0)) // canGetNext = true; Tile[] t = { t1, t2, t3, t4 }; //ArrayList iCubes = new ArrayList(); //for (int i = 0; i < cubes.Length; i++) // if (cubes[i].IValue != 0) // { // iCubes.Add(cubes[i].IValue); // } //for (int i = 0; i < cubes.Length - iCubes.Count; i++) // cubes[i].IValue = 0; //for (int i = 0; i < iCubes.Count; i++) // cubes[i + cubes.Length - iCubes.Count].IValue = (int)iCubes[i]; //选出非0的cube //for (int i = 0; i < iCube.Length; i++) //{ // c[c.Length - 1 - i].Value = iCube[iCube.Length - 1 - i].Value;//将非0的cube放到队尾 // //c[i].Value = iCube[iCube.Count()-1-i]; //} ArrayList iTiles = new ArrayList(); foreach (Tile tile in t) { if (tile.Value != 0) { iTiles.Add(tile.Value); } } for (int i = 0; i < t.Length; i++) { if (iTiles.Count - 1 - i >= 0) { t[t.Length - 1 - i].Value = (int)iTiles[iTiles.Count - 1 - i];//将非0的cube放到队尾 } else { t[t.Length - 1 - i].Value = 0; } //c[i].Value = iCube[iCube.Count()-1-i]; } if (t[2].Value != 0)//如果倒数第二个为0,说明该行只有一个数直接返回 { if (t[3].Value == t[2].Value) { score += 2 * t[3].Value; t[3].Value = 2 * t[3].Value; //canGetNext = true; if (t[1].Value == t[0].Value) { score += 2 * t[1].Value; t[2].Value = 2 * t[1].Value; //if (c[1].Value > 0) canGetNext = true;//??? t[1].Value = 0; t[0].Value = 0; } else { t[2].Value = t[1].Value; t[1].Value = t[0].Value; t[0].Value = 0; } } else { if (t[2].Value == t[1].Value) { score += 2 * t[2].Value; t[2].Value = 2 * t[2].Value; //if (c[1].Value > 0) canGetNext = true; t[1].Value = t[0].Value; t[0].Value = 0; } else { if (t[1].Value == t[0].Value) { score += 2 * t[1].Value; t[1].Value = 2 * t[1].Value; //if (c[0].Value > 0) canGetNext = true; t[0].Value = 0; } } } } return score; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 5 "..\..\..\2048\MainWindow.xaml" ((My2048.MainWindow)(target)).Closing += new System.ComponentModel.CancelEventHandler(this.Window_Closing); #line default #line hidden #line 6 "..\..\..\2048\MainWindow.xaml" ((My2048.MainWindow)(target)).PreviewKeyUp += new System.Windows.Input.KeyEventHandler(this.Window_PreviewKeyUp); #line default #line hidden return; case 2: this.Menu1 = ((System.Windows.Controls.Menu)(target)); return; case 3: this.Save = ((System.Windows.Controls.MenuItem)(target)); #line 16 "..\..\..\2048\MainWindow.xaml" this.Save.Click += new System.Windows.RoutedEventHandler(this.save_Click); #line default #line hidden return; case 4: this.Load = ((System.Windows.Controls.MenuItem)(target)); #line 17 "..\..\..\2048\MainWindow.xaml" this.Load.Click += new System.Windows.RoutedEventHandler(this.load_Click); #line default #line hidden return; case 5: this.Record = ((System.Windows.Controls.MenuItem)(target)); #line 18 "..\..\..\2048\MainWindow.xaml" this.Record.Click += new System.Windows.RoutedEventHandler(this.record_Click); #line default #line hidden return; case 6: this.MainGrid = ((System.Windows.Controls.Grid)(target)); return; case 7: this.B0 = ((My2048.Tile)(target)); return; case 8: this.B1 = ((My2048.Tile)(target)); return; case 9: this.B2 = ((My2048.Tile)(target)); return; case 10: this.B3 = ((My2048.Tile)(target)); return; case 11: this.B4 = ((My2048.Tile)(target)); return; case 12: this.B5 = ((My2048.Tile)(target)); return; case 13: this.B6 = ((My2048.Tile)(target)); return; case 14: this.B7 = ((My2048.Tile)(target)); return; case 15: this.B8 = ((My2048.Tile)(target)); return; case 16: this.B9 = ((My2048.Tile)(target)); return; case 17: this.B10 = ((My2048.Tile)(target)); return; case 18: this.B11 = ((My2048.Tile)(target)); return; case 19: this.B12 = ((My2048.Tile)(target)); return; case 20: this.B13 = ((My2048.Tile)(target)); return; case 21: this.B14 = ((My2048.Tile)(target)); return; case 22: this.B15 = ((My2048.Tile)(target)); return; case 23: this.BtnPlay = ((System.Windows.Controls.Button)(target)); #line 56 "..\..\..\2048\MainWindow.xaml" this.BtnPlay.Click += new System.Windows.RoutedEventHandler(this.btnPlay_Click); #line default #line hidden return; case 24: this.TScore = ((System.Windows.Controls.TextBlock)(target)); return; case 25: this.ButBack = ((System.Windows.Controls.Button)(target)); #line 58 "..\..\..\2048\MainWindow.xaml" this.ButBack.Click += new System.Windows.RoutedEventHandler(this.butBack_Click); #line default #line hidden return; } this._contentLoaded = true; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 5 "..\..\..\MainWindow.xaml" ((My2048.MainWindow)(target)).Closing += new System.ComponentModel.CancelEventHandler(this.Window_Closing); #line default #line hidden #line 6 "..\..\..\MainWindow.xaml" ((My2048.MainWindow)(target)).PreviewKeyUp += new System.Windows.Input.KeyEventHandler(this.Window_PreviewKeyUp); #line default #line hidden return; case 2: this.menu1 = ((System.Windows.Controls.Menu)(target)); return; case 3: this.save = ((System.Windows.Controls.MenuItem)(target)); #line 16 "..\..\..\MainWindow.xaml" this.save.Click += new System.Windows.RoutedEventHandler(this.save_Click); #line default #line hidden return; case 4: this.load = ((System.Windows.Controls.MenuItem)(target)); #line 17 "..\..\..\MainWindow.xaml" this.load.Click += new System.Windows.RoutedEventHandler(this.load_Click); #line default #line hidden return; case 5: this.record = ((System.Windows.Controls.MenuItem)(target)); #line 18 "..\..\..\MainWindow.xaml" this.record.Click += new System.Windows.RoutedEventHandler(this.record_Click); #line default #line hidden return; case 6: this.MainGrid = ((System.Windows.Controls.Grid)(target)); return; case 7: this.b0 = ((My2048.Tile)(target)); return; case 8: this.b1 = ((My2048.Tile)(target)); return; case 9: this.b2 = ((My2048.Tile)(target)); return; case 10: this.b3 = ((My2048.Tile)(target)); return; case 11: this.b4 = ((My2048.Tile)(target)); return; case 12: this.b5 = ((My2048.Tile)(target)); return; case 13: this.b6 = ((My2048.Tile)(target)); return; case 14: this.b7 = ((My2048.Tile)(target)); return; case 15: this.b8 = ((My2048.Tile)(target)); return; case 16: this.b9 = ((My2048.Tile)(target)); return; case 17: this.b10 = ((My2048.Tile)(target)); return; case 18: this.b11 = ((My2048.Tile)(target)); return; case 19: this.b12 = ((My2048.Tile)(target)); return; case 20: this.b13 = ((My2048.Tile)(target)); return; case 21: this.b14 = ((My2048.Tile)(target)); return; case 22: this.b15 = ((My2048.Tile)(target)); return; case 23: this.btnPlay = ((System.Windows.Controls.Button)(target)); #line 56 "..\..\..\MainWindow.xaml" this.btnPlay.Click += new System.Windows.RoutedEventHandler(this.btnPlay_Click); #line default #line hidden return; case 24: this.tScore = ((System.Windows.Controls.TextBlock)(target)); return; case 25: this.butBack = ((System.Windows.Controls.Button)(target)); #line 58 "..\..\..\MainWindow.xaml" this.butBack.Click += new System.Windows.RoutedEventHandler(this.butBack_Click); #line default #line hidden return; } this._contentLoaded = true; }