public void Notification(BinaryReader binaryReader) { string code = binaryReader.ReadString(); if (code == "1-11") { IsVisibleGame = true; IsVisibleSpinner = false; OpponentName = binaryReader.ReadString(); FirstGamerSymbol = binaryReader.ReadString(); if (FirstGamerSymbol == "X") { IsEnable = true; SecondGamerSymbol = "0"; GameInformation = FIRST_PLAYER_TURN; } else { IsEnable = false; SecondGamerSymbol = "X"; GameInformation = SECOND_PLAYER_TURN + OpponentName; } TextNotification = $"Вы играете за {FirstGamerSymbol}"; ShowNotificationAsync(); } else if (code == "2-11") { Application.Current.Dispatcher.Invoke(() => { IsVisibleSpinner = false; var gameDialogViewModel = new GameDialogViewModel("Соперник не найден! Хотите сыгарть с компьютером?"); var gameDialogView = new GameDialogView(gameDialogViewModel); gameDialogView.ShowDialog(); if (gameDialogViewModel.UserResponse == "Да") { IsVisibleGame = true; OpponentName = "Компьютер"; _delegateMove = MoveForGameWithComputer; _gameLogic = new GameLogic(this); FirstGamerSymbol = _gameLogic.GamerSymbol; SecondGamerSymbol = _gameLogic.ComputerSymbol; TextNotification = $"Вы играете за {FirstGamerSymbol}"; ShowNotificationAsync(); if (FirstGamerSymbol == "X") { IsEnable = true; GameInformation = FIRST_PLAYER_TURN; } else { GameInformation = "Ожидание хода от компьютера"; } _delegateMove = MoveForGameWithComputer; } else { Condition = "Collapsed"; } }, DispatcherPriority.Background); } else if (code == "11-0") { SetSymbolInPlayingField(SecondGamerSymbol, binaryReader.ReadString(), false); IsEnable = true; GameInformation = FIRST_PLAYER_TURN; } else if (code == "11-1") { Application.Current.Dispatcher.Invoke(async() => { GameInformation = FIRST_PLAYER_WIN; string[] positions = binaryReader.ReadString().Split('-'); SetSymbolInPlayingField(FirstGamerSymbol, positions[0], true, "#00FF7F"); await Task.Delay(528); SetSymbolInPlayingField(FirstGamerSymbol, positions[1], true, "#00FF7F"); await Task.Delay(528); SetSymbolInPlayingField(FirstGamerSymbol, positions[2], true, "#00FF7F"); IsVisibleCancel = true; }, DispatcherPriority.Background); } else if (code == "11-2") { Application.Current.Dispatcher.Invoke(async() => { GameInformation = SECOND_PLAYER_WIN; string[] positions = binaryReader.ReadString().Split('-'); SetSymbolInPlayingField(SecondGamerSymbol, positions[0], true, "#FA8072"); await Task.Delay(528); SetSymbolInPlayingField(SecondGamerSymbol, positions[1], true, "#FA8072"); await Task.Delay(528); SetSymbolInPlayingField(SecondGamerSymbol, positions[2], true, "#FA8072"); IsVisibleCancel = true; }, DispatcherPriority.Background); } else if (code == "11-3") { Application.Current.Dispatcher.Invoke(() => { GameInformation = DRAW; SetSymbolInPlayingField(SecondGamerSymbol, binaryReader.ReadString(), false); IsVisibleCancel = true; }, DispatcherPriority.Background); } else if (code == "11-4") { Application.Current.Dispatcher.Invoke(() => { GameInformation = OpponentName + SECOND_PLAYER_GIVE_UP; IsVisibleCancel = true; }, DispatcherPriority.Background); } else if (code == "29") { NotificationTranslator.GetEnteringUserNotification(binaryReader.ReadString(), "Information"); } else if (code == "30") { NotificationTranslator.PlaySoundNotificationAsync(); NotificationTranslator.GetNewMessageNotification(binaryReader.ReadString()); } else if (code == "40") { NotificationTranslator.RewriteDataNotification("Имя пользователя изменено!", "Success"); Name = binaryReader.ReadString(); } else if (code == "41") { NotificationTranslator.RewriteDataNotification("Имя пользователя не изменено! Пользователь с таким именем уже зарегистрирован!", "Error"); } else if (code == "42") { NotificationTranslator.RewriteDataNotification("Логин пользователя изменён!", "Success"); UserContainer.Login = binaryReader.ReadString(); } else if (code == "43") { NotificationTranslator.RewriteDataNotification("Логин пользователя не изменён! Пользователь с таким логином уже зарегистрирован!", "Error"); } }
public GameDialogView(GameDialogViewModel gameDialogViewModel) { InitializeComponent(); DataContext = gameDialogViewModel; }