private void NextStepBtn_Click(object sender, RoutedEventArgs e) { ChangeBtnNewBtn(); Paragraph newparagraph = new Paragraph(); Run newRun = new Run(); newRun.Text = "Ход " + WalksNumber + "\n"; if (WalksNumber % 2 == 0) { newRun.Text += "Белые пропускают ход"; } else { newRun.Text += "Черные пропускают ход"; } WalksNumber++; if (WalksNumber % 2 == 0) { WhoWalks = "Белые"; } else { WhoWalks = "Черные"; } WhoWalksTxt.Text = WhoWalks; WalksNumerTxt.Text = WalksNumber.ToString(); newparagraph.Inlines.Add(newRun); GameLogDocument.Blocks.Add(newparagraph); }
public void TickTimer(object sender, EventArgs e) { Seconds++; if (Seconds == 59) { Seconds = 0; Minutes++; } if (Minutes == 59) { Minutes = 0; Hours++; } if (WalksNumber % 2 == 0) { WhoWalks = "Белые"; } else { WhoWalks = "Черные"; } WhoWalksTxt.Text = WhoWalks; WalksNumerTxt.Text = WalksNumber.ToString(); InfoTimer.Text = string.Format("{0:00}:{1:00}", Hours, Minutes); InfoTimer.ToolTip = string.Format("{0:00}:{1:00}:{2:00}", Hours, Minutes, Seconds); ScoreBlack.Text = User1Quantity.ToString(); ScoreWhite.Text = User2Quantity.ToString(); }
private void Shashka_Click(object sender, RoutedEventArgs e) { if (Shashka1.Content == null) { Shashka1 = (Button)sender; if (WalksNumber % 2 == 0) { if (Shashka1.Background != Brushes.White) { ChangeBtnNewBtn(); return; } } else { if (Shashka1.Background != Brushes.Black) { ChangeBtnNewBtn(); return; } } //Shashka1.Background = Brushes.RoyalBlue; } else { Shashka2 = (Button)sender; Shashka3 = Shashka2; if (Shashka2.Background == Brushes.Black || Shashka2.Background == Brushes.White) { ChangeBtnNewBtn(); return; } var a = Shashka1.Name.ToString().Substring(1); var b = Shashka2.Name.ToString().Substring(1); var a1 = (a[0] - '0'); var a2 = (a[1] - '0'); var b1 = (b[0] - '0'); var b2 = (b[1] - '0'); var f = false; var dvijenie = 0; // 1 - сверху вниз; // 2 - снизу вверх; // 3 - слева направо; // 4 - справа на лево; // 5 - диагональ слева на направо (сверху вниз) // 6 - диагональ справа на лево (снизу вверх) // 7 - диагональ слева на направо (снизу вверх) // 8 - диагональ справа на лево (сверху вниз) #region Вычисление вида движения if (a1 < b1) { dvijenie = 1; } if (a1 > b1) { dvijenie = 2; } if (a2 < b2) { dvijenie = 3; } if (a2 > b2) { dvijenie = 4; } if (a1 < b1 && a2 < b2) { dvijenie = 5; } if (a1 > b1 && a2 > b2) { dvijenie = 6; } if (a1 > b1 && a2 < b2) { dvijenie = 7; } if (a1 < b1 && a2 > b2) { dvijenie = 8; } #endregion // Проверка на то, возможно ли сделать ход switch (dvijenie) { case 1: // 1 - сверху вниз for (int i = 0; i <= 7; i++) { if (f == true) { var ShashkaChanged = FindButton(PlayingField, "N" + i + a2); if (!CheckShashkaChanged(ShashkaChanged)) { ChangeBtnNewBtn(); return; } if (ShashkaChanged.Background != Brushes.White && ShashkaChanged.Background != Brushes.Black) { if (Shashka1 == FindButton(PlayingField, "N" + (i - 1) + a2)) { ChangeBtnNewBtn(); return; } Shashka2 = ShashkaChanged; b = Shashka2.Name.ToString().Substring(1); f = false; break; } } if (a1 == i) { f = true; } } break; case 2: // 2 - снизу вверх for (int i = 7; i >= 0; i--) { if (f == true) { var ShashkaChanged = FindButton(PlayingField, "N" + i + a2); if (!CheckShashkaChanged(ShashkaChanged)) { ChangeBtnNewBtn(); return; } if (ShashkaChanged.Background != Brushes.White && ShashkaChanged.Background != Brushes.Black) { if (Shashka1 == FindButton(PlayingField, "N" + (i + 1) + a2)) { ChangeBtnNewBtn(); return; } if (a2 + 1 == i) { ChangeBtnNewBtn(); return; } Shashka2 = ShashkaChanged; b = Shashka2.Name.ToString().Substring(1); f = false; break; } } if (a1 == i) { f = true; } } break; case 3: // 3 - слева направо for (int i = 0; i <= 7; i++) { if (f == true) { var ShashkaChanged = FindButton(PlayingField, "N" + a1 + i); if (!CheckShashkaChanged(ShashkaChanged)) { ChangeBtnNewBtn(); return; } if (ShashkaChanged.Background != Brushes.White && ShashkaChanged.Background != Brushes.Black) { if (Shashka1 == FindButton(PlayingField, "N" + a1 + (i - 1))) { ChangeBtnNewBtn(); return; } Shashka2 = ShashkaChanged; b = Shashka2.Name.ToString().Substring(1); f = false; break; } } if (a2 == i) { f = true; } } break; case 4: // 4 - справа на лево for (int i = 7; i >= 0; i--) { if (f == true) { var ShashkaChanged = FindButton(PlayingField, "N" + a1 + i); if (!CheckShashkaChanged(ShashkaChanged)) { ChangeBtnNewBtn(); return; } if (ShashkaChanged.Background != Brushes.White && ShashkaChanged.Background != Brushes.Black) { if (Shashka1 == FindButton(PlayingField, "N" + a1 + (i + 1))) { ChangeBtnNewBtn(); return; } Shashka2 = ShashkaChanged; b = Shashka2.Name.ToString().Substring(1); f = false; break; } } if (a2 == i) { f = true; } } break; case 5: // 5 - диагональ слева на направо (сверху вниз) for (int i = 0; i <= 7; i++) { for (int j = 0; j <= 7; j++) { if (a1 == i && a2 == j) { f = true; a1++; a2++; var ShashkaChanged = FindButton(PlayingField, "N" + a1 + a2); if (!CheckShashkaChanged(ShashkaChanged)) { ChangeBtnNewBtn(); return; } if (ShashkaChanged.Background != Brushes.White && ShashkaChanged.Background != Brushes.Black) { if (Shashka1 == FindButton(PlayingField, "N" + (a1 - 1) + (a2 - 1))) { ChangeBtnNewBtn(); return; } Shashka2 = ShashkaChanged; b = Shashka2.Name.ToString().Substring(1); b1 = (b[0] - '0'); b2 = (b[1] - '0'); } } if (b1 == a1 && b2 == a2) { f = false; a1 = -1; a2 = -1; } } } break; case 6: // 6 - диагональ справа на лево (снизу вверх) for (int i = 7; i >= 0; i--) { for (int j = 7; j >= 0; j--) { if (a1 == i && a2 == j) { f = true; a1--; a2--; var ShashkaChanged = FindButton(PlayingField, "N" + a1 + a2); if (!CheckShashkaChanged(ShashkaChanged)) { ChangeBtnNewBtn(); return; } if (ShashkaChanged.Background != Brushes.White && ShashkaChanged.Background != Brushes.Black) { if (Shashka1 == FindButton(PlayingField, "N" + (a1 + 1) + (a2 + 1))) { ChangeBtnNewBtn(); return; } Shashka2 = ShashkaChanged; b = Shashka2.Name.ToString().Substring(1); b1 = (b[0] - '0'); b2 = (b[1] - '0'); } } if (b1 == a1 && b2 == a2) { f = false; a1 = -1; a2 = -1; } } } break; case 7: // 7 - диагональ слева на направо (снизу вверх) for (int i = 7; i >= 0; i--) { for (int j = 0; j <= 7; j++) { if (a1 == i && a2 == j) { f = true; a1--; a2++; var ShashkaChanged = FindButton(PlayingField, "N" + a1 + a2); if (!CheckShashkaChanged(ShashkaChanged)) { ChangeBtnNewBtn(); return; } if (ShashkaChanged.Background != Brushes.White && ShashkaChanged.Background != Brushes.Black) { if (Shashka1 == FindButton(PlayingField, "N" + (a1 + 1) + (a2 - 1))) { ChangeBtnNewBtn(); return; } Shashka2 = ShashkaChanged; b = Shashka2.Name.ToString().Substring(1); b1 = (b[0] - '0'); b2 = (b[1] - '0'); } } if (b1 == a1 && b2 == a2) { f = false; a1 = -1; a2 = -1; } } } break; case 8: // 8 - диагональ справа на лево (сверху вниз) for (int i = 0; i <= 7; i++) { for (int j = 7; j >= 0; j--) { if (a1 == i && a2 == j) { f = true; a1++; a2--; var ShashkaChanged = FindButton(PlayingField, "N" + a1 + a2); if (!CheckShashkaChanged(ShashkaChanged)) { ChangeBtnNewBtn(); return; } if (ShashkaChanged.Background != Brushes.White && ShashkaChanged.Background != Brushes.Black) { if (Shashka1 == FindButton(PlayingField, "N" + (a1 - 1) + (a2 + 1))) { ChangeBtnNewBtn(); return; } Shashka2 = ShashkaChanged; b = Shashka2.Name.ToString().Substring(1); b1 = (b[0] - '0'); b2 = (b[1] - '0'); } } if (b1 == a1 && b2 == a2) { f = false; a1 = -1; a2 = -1; } } } break; default: break; } if (Shashka1.Background == Shashka2.Background || Shashka3 != Shashka2 || f == true) { ChangeBtnNewBtn(); return; } a1 = (a[0] - '0'); a2 = (a[1] - '0'); b1 = (b[0] - '0'); b2 = (b[1] - '0'); f = false; Paragraph newparagraph = new Paragraph(); Run newRun = new Run(); newRun.Text = "Ход " + WalksNumber + "\n"; if (WalksNumber % 2 == 0) { newRun.Text += "Белые делают ход и захватывают поля: "; } else { newRun.Text += "Черные делают ход и захватывают поля: "; } //Зарисовка клеток switch (dvijenie) { case 1: for (int i = 0; i <= 7; i++) { if (a1 == i) { f = true; } if (f == true) { var ShashkaChanged = FindButton(PlayingField, "N" + i + a2); ChangeColorShashka(ShashkaChanged); newRun.Text += ShashkaChanged.Content.ToString() + " "; } if (b1 == i) { f = false; } } break; case 2: for (int i = 7; i >= 0; i--) { if (a1 == i) { f = true; } if (f == true) { var ShashkaChanged = FindButton(PlayingField, "N" + i + a2); ChangeColorShashka(ShashkaChanged); newRun.Text += ShashkaChanged.Content.ToString() + " "; } if (b1 == i) { f = false; } } break; case 3: for (int i = 0; i <= 7; i++) { if (a2 == i) { f = true; } if (f == true) { var ShashkaChanged = FindButton(PlayingField, "N" + a1 + i); ChangeColorShashka(ShashkaChanged); newRun.Text += ShashkaChanged.Content.ToString() + " "; } if (b2 == i) { f = false; } } break; case 4: for (int i = 7; i >= 0; i--) { if (a2 == i) { f = true; } if (f == true) { var ShashkaChanged = FindButton(PlayingField, "N" + a1 + i); ChangeColorShashka(ShashkaChanged); newRun.Text += ShashkaChanged.Content.ToString() + " "; } if (b2 == i) { f = false; } } break; case 5: for (int i = 0; i <= 7; i++) { for (int j = 0; j <= 7; j++) { if (a1 == i && a2 == j) { var ShashkaChanged = FindButton(PlayingField, "N" + i + j); ChangeColorShashka(ShashkaChanged); newRun.Text += ShashkaChanged.Content.ToString() + " "; a1++; a2++; } if (b1 == i && b2 == j) { a1 = -1; a2 = -1; } } } break; case 6: for (int i = 7; i >= 0; i--) { for (int j = 7; j >= 0; j--) { if (a1 == i && a2 == j) { var ShashkaChanged = FindButton(PlayingField, "N" + i + j); ChangeColorShashka(ShashkaChanged); newRun.Text += ShashkaChanged.Content.ToString() + " "; a1--; a2--; } if (b1 == i && b2 == j) { a1 = -1; a2 = -1; } } } break; case 7: for (int i = 7; i >= 0; i--) { for (int j = 0; j <= 7; j++) { if (a1 == i && a2 == j) { var ShashkaChanged = FindButton(PlayingField, "N" + i + j); ChangeColorShashka(ShashkaChanged); newRun.Text += ShashkaChanged.Content.ToString() + " "; a1--; a2++; } if (b1 == i && b2 == j) { a1 = -1; a2 = -1; } } } break; case 8: for (int i = 0; i <= 7; i++) { for (int j = 7; j >= 0; j--) { if (a1 == i && a2 == j) { var ShashkaChanged = FindButton(PlayingField, "N" + i + j); ChangeColorShashka(ShashkaChanged); newRun.Text += ShashkaChanged.Content.ToString() + " "; a1++; a2--; } if (b1 == i && b2 == j) { a1 = -1; a2 = -1; } } } break; default: break; } ChangeBtnNewBtn(); WalksNumber++; if (WalksNumber % 2 == 0) { WhoWalks = "Белые"; } else { WhoWalks = "Черные"; } WhoWalksTxt.Text = WhoWalks; WalksNumerTxt.Text = WalksNumber.ToString(); User1Quantity = 0; User2Quantity = 0; for (int i = 0; i <= 7; i++) { for (int j = 0; j <= 7; j++) { var ShashkaFind = FindButton(PlayingField, "N" + i + j); if (ShashkaFind.Background == Brushes.Black) { User1Quantity++; } if (ShashkaFind.Background == Brushes.White) { User2Quantity++; } } } ScoreBlack.Text = User1Quantity.ToString(); ScoreWhite.Text = User2Quantity.ToString(); newRun.Text += "\nБелых шашек на поле: " + User2Quantity; newRun.Text += "\nЧерных шашек на поле: " + User1Quantity; newRun.Text += "\nВремени с начала игры прошло: " + string.Format("{0:00}:{1:00}:{2:00}", Hours, Minutes, Seconds); newparagraph.Inlines.Add(newRun); GameLogDocument.Blocks.Add(newparagraph); } }
public async void TickTimer(object sender, EventArgs e) { Seconds++; if (Seconds == 59) { Seconds = 0; Minutes++; } if (Minutes == 59) { Minutes = 0; Hours++; } Core.db = new MainEntities(); OnLineGames Gamesdb = await Core.db.OnLineGames.FindAsync(CurrentGame.ID); if (CurrentGame != Gamesdb) { CurrentGame = Gamesdb; if (CurrentGame.StatusID == 3) { Timer.Stop(); var H = Hours * 60 * 60; var M = Minutes * 60; var S = Seconds + M + H; try { var ThisUserInGame = await Core.db.UsersInOnLineGame.FindAsync(ThisUser.ID); ThisUserInGame.StatusID = 3; // Работа со статистикой и рекордами осталась await Core.db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } if (WalksNumber % 2 != 0 && ThisUser.StatusID == 2) { MessageBox.Show("Ваш противник сдался\nВаши очки: " + User2Quantity * S, "Вы выиграли!", MessageBoxButton.OK, MessageBoxImage.Information); } else if (WalksNumber % 2 == 0 && ThisUser.StatusID == 1) { MessageBox.Show("Ваш противник сдался\nВаши очки: " + User1Quantity * S, "Вы выиграли!", MessageBoxButton.OK, MessageBoxImage.Information); } foreach (Window item in Application.Current.Windows) { if (item.Name == "LogGameWindow") { this.Close(); return; } } string str = Gamesdb.GameLog; Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(str); GameLogDocument = new FlowDocument(); GameLogDocument.Blocks.Add(paragraph); var newGameLogDocument = GameLogDocument; GameLogWindow window = new GameLogWindow(newGameLogDocument); window.Show(); this.Close(); } var CurrentLocationOfChekersStr = String.Empty; var GameLogText = new TextRange(GameLogDocument.ContentStart, GameLogDocument.ContentEnd); foreach (var item in CurrentGameArea) { CurrentLocationOfChekersStr += item + " "; } if (/*Gamesdb.GameLog != GameLogText.Text && */ Gamesdb.LocationOfCheckers != String.Empty && Gamesdb.LocationOfCheckers != CurrentLocationOfChekersStr) { string[] words = CurrentGame.LocationOfCheckers.Split(new char[] { ' ' }); var a = 0; User1Quantity = 0; User2Quantity = 0; PlayingField.Children.RemoveRange(0, PlayingField.Children.Count); for (int i = 0; i <= 7; i++) { StackPanel newStackpanel = new StackPanel(); newStackpanel.Orientation = Orientation.Horizontal; newStackpanel.Name = "N" + i; PlayingField.Children.Add(newStackpanel); for (int j = 0; j <= 7; j++) { CurrentGameArea[i, j] = words[a]; Button NewBtn = new Button(); NewBtn.Name = "N" + i + j; NewBtn.Content = "" + m[j] + (i + 1); NewBtn.Style = this.TryFindResource("Shashka") as Style; if (CurrentGameArea[i, j].ToString()[0] == 'W') { User2Quantity++; NewBtn.Background = Brushes.White; NewBtn.Foreground = Brushes.White; } if (CurrentGameArea[i, j].ToString()[0] == 'B') { User1Quantity++; NewBtn.Background = Brushes.Black; NewBtn.Foreground = Brushes.Black; } NewBtn.Click += Shashka_Click; NewBtn.MouseEnter += Shashka_MouseEnter; NewBtn.MouseLeave += Shashka_MouseLeave; newStackpanel.Children.Add(NewBtn); a++; } } string str = Gamesdb.GameLog; Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(str); GameLogDocument = new FlowDocument(); GameLogDocument.Blocks.Add(paragraph); WalksNumber++; } } this.Title = "Игра против пользователя с ником " + EnemyLogin; if (WalksNumber % 2 != 0 && ThisUser.StatusID == 1) { this.Title += " (Ваш ход)"; } else if (WalksNumber % 2 == 0 && ThisUser.StatusID == 2) { this.Title += " (Ваш ход)"; } else { this.Title += " (Ход противника)"; } if (WalksNumber % 2 == 0) { WhoWalks = "Белые"; } else { WhoWalks = "Черные"; } WhoWalksTxt.Text = WhoWalks; WalksNumerTxt.Text = WalksNumber.ToString(); InfoTimer.Text = string.Format("{0:00}:{1:00}", Hours, Minutes); InfoTimer.ToolTip = string.Format("{0:00}:{1:00}:{2:00}", Hours, Minutes, Seconds); ScoreBlack.Text = User1Quantity.ToString(); ScoreWhite.Text = User2Quantity.ToString(); }