public void TaskOnClick() { ApiClientScript.modell = HttpQueryManager.GetCardsForPlayers(InfoFromAnotherScena.CountUser); ApiClientScript.CurrentUserId = ApiClientScript.modell.users.First(a => a.is_connected).user_id; ApiClientScript.SessionId = ApiClientScript.modell.id; SceneManager.LoadScene("SampleScene"); }
// Start is called before the first frame update void Start() { // кидаем запрос в апишку var sessions = HttpQueryManager.GetSessions(); InternalManager.SetSessionsInfo(canvas, play, gameName, userCount, sessions.data, scrollbar); Buttons.ForEach(a => { a.onClick.AddListener(TaskOnClick); }); }
/// <summary> /// сдаться /// </summary> public void TaskOnLose() { ApiClientScript.IsTryToStayAlive = false; ApiClientScript.GameModel .Users.First(a => a.UserId == ApiClientScript.CurrentUserId) .CardsModel.ForEach(a => { Destroy(a.Card.gameObject); }); ApiClientScript.GameModel.Users.First(a => a.UserId == ApiClientScript.CurrentUserId).CardsModel.Clear(); ApiClientScript.modell = HttpQueryManager.DeleteUserFromGame(); MessageManager.TurnOffElements(ok, message, panel, lose, fail); MessageManager.TurnOffButtons(cansel, toSbros, take, go, fail); }
// Start is called before the first frame update void Start() { goOut.onClick.AddListener(GoOutTaskOnClick); modell = HttpQueryManager.GetCurrentPack(SessionId); if (CurrentUserId == -1) { CurrentUserId = modell?.users?.FirstOrDefault(a => !a.is_connected)?.user_id ?? 0; modell = HttpQueryManager.ActivateUser(CurrentUserId, SessionId); } SelectedCardsIds = modell.selected_cards_ids.ToList(); SetSceneElements(modell); buff = 110; }
public void TaskOnClick() { try { var sessionIdString = EventSystem.current.currentSelectedGameObject.name; Int32.TryParse(sessionIdString, out var sessionId); ApiClientScript.SessionId = sessionId; ApiClientScript.modell = HttpQueryManager.GetCurrentPack(sessionId); if (ApiClientScript.modell.users.Any(a => !a.is_connected)) { SceneManager.LoadScene("SampleScene"); } } catch (Exception ex) { Debug.Log(ex.Message); } }
public void CancelShag() { try { if (ApiClientScript.IsBlocked) { return; } go.interactable = true; // получаем данные с апишки var data = HttpQueryManager.CanselShag(); var information = Manager.GetInfoAboutPlayers(data); if (information == null || information.RealUser == null) { return; } ApiClientScript.GameModel .Users.First(a => a.UserId == ApiClientScript.CurrentUserId) .CardsModel.ForEach(a => { Destroy(a.Card.gameObject); }); ApiClientScript.GameModel.Users.First(a => a.UserId == ApiClientScript.CurrentUserId).CardsModel.Clear(); ApiClientScript.SelectedCardsIds.Clear(); ApiClientScript.GameModel.Users.First(a => a.UserId == ApiClientScript.CurrentUserId).CardsModel = information.RealUser.CardsModel; InternalManager.SetRealUserCardsTwo(main, mainTwoRow, information.RealUser.CardsModel, selectedCard); } catch (Exception ex) { Debug.Log("CancelShag" + ex.Message); MessageManager.ErrorMessage(ok, lose, message, panel, $" Произошла внутренняя \n ошибка, " + $"\n попробуйте еще раз!" + $" {ex.Message}", Assets.Enums.TypeNotificationEnum.Error); } }
public void TaskOnClick() { try { if (!string.IsNullOrEmpty(ApiClientScript.SelectedCard)) { Int32.TryParse(ApiClientScript.SelectedCard, out var num); ApiClientScript.modell = HttpQueryManager.DoShag(num); ApiClientScript.SelectedCardsIds = ApiClientScript.modell.selected_cards_ids.ToList(); ApiClientScript.buff = 110; ApiClientScript.SelectedCard = ""; } } catch (Exception ex) { Debug.Log(ex.Message); MessageManager.ErrorMessage(ok, lose, message, panel, $" Произошла внутренняя \n ошибка, " + $"\n попробуйте еще раз! " + $"{ex.Message}", Assets.Enums.TypeNotificationEnum.Error); } }
public void TaskOnClick() { if (ApiClientScript.IsBlocked) { return; } var userId = ApiClientScript.GameModel .Users.First(a => a.UserId == ApiClientScript.CurrentUserId).UserId; if (ApiClientScript.GameModel.Users.First(a => a.UserId == userId).CountCards < 12) { ApiClientScript.modell = HttpQueryManager.GetCardsFromPack(1, userId, ApiClientScript.SessionId); var information = Manager.GetInfoAboutPlayers(ApiClientScript.modell); if (information == null || information.RealUser == null) { MessageManager.ErrorMessage(ok, lose, message, panel, $" Произошла внутренняя \n ошибка, " + $"\n попробуйте еще раз!", Assets.Enums.TypeNotificationEnum.Error); return; } ApiClientScript.GameModel .Users.First(a => a.UserId == userId) .CardsModel.ForEach(a => { Destroy(a.Card.gameObject); }); ApiClientScript.GameModel.Users.First(a => a.UserId == userId).CardsModel.Clear(); ApiClientScript.GameModel.Users.First(a => a.UserId == userId).CardsModel = information.RealUser.CardsModel; ApiClientScript.GameModel.Users.First(a => a.UserId == userId).CountCards = information.RealUser.CardsModel.Count(); InternalManager.SetRealUserCardsTwo(main, mainTwoRow, information.RealUser.CardsModel, selectedCard); if (information.RealUser.IsLoser) { ApiClientScript.IsTryToStayAlive = false; MessageManager.ErrorMessage(ok, lose, message, panel, $" Вы проиграли!", Assets.Enums.TypeNotificationEnum.Boomb, cansel, toSbros, take, go ); ApiClientScript.IsBlocked = true; } else { ApiClientScript.modell = HttpQueryManager.ChangeActiveUser(ApiClientScript.SessionId); ApiClientScript.buff = 110; } koloda.text = "Колода: " + ApiClientScript.modell.pack.count; sbros.text = "Сброс: " + ApiClientScript.modell.sbros.count; } }
// Update is called once per frame void Update() { buff++; if (buff == 120) { GameModel .Users.First(a => a.UserId == CurrentUserId) .CardsModel.ForEach(a => { Destroy(a.Card.gameObject); }); GameModel? .Users?.Where(a => a.UserId != CurrentUserId && !a.IsConnected) .ToList()? .ForEach(usr => { usr?.CardsModel?.ForEach(a => { if (a?.Card?.gameObject != null) { Destroy(a.Card.gameObject); } }); }); if (SelectedCardsTransformList.Any()) { SelectedCardsTransformList.ForEach(a => { if (a?.gameObject != null) { Destroy(a.gameObject); } }); SelectedCardsTransformList.Clear(); } modell = HttpQueryManager.GetCurrentPack(SessionId); SelectedCardsIds = modell.selected_cards_ids.ToList(); SetSceneElements(modell); if (modell.users.Any(a => !a.is_connected && !a.loser)) { infoText.text = "Ждем игроков..."; infoText.gameObject.SetActive(true); IsBlocked = true; } else { if (modell.users.First(a => a.user_id == CurrentUserId).winner) { MessageManager.ErrorMessage(ok, lose, message, panel, $" Вы победили!", TypeNotificationEnum.Win, cansel, toSbros, take, go); IsBlocked = true; HttpQueryManager.DeleteSession(); return; } IsBlocked = false; if (modell.users.First(a => a.user_id == CurrentUserId).is_active_user) { infoText.text = "Ваш ход"; infoText.gameObject.SetActive(true); if (modell.users.First(a => a.user_id == CurrentUserId).loser&& !IsTryToStayAlive) { MessageManager.ErrorMessage(ok, lose, message, panel, $" Вы проиграли!", TypeNotificationEnum.Boomb, cansel, toSbros, take, go); return; } } else { infoText.gameObject.SetActive(false); IsBlocked = true; goOut.gameObject.SetActive(true); } } buff = 0; } if (Input.GetMouseButtonDown(0) && !IsBlocked) { Vector2 cubeRay = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D cubeHit = Physics2D.Raycast(cubeRay, Vector2.zero); if (cubeHit) { if (SelectedCard == cubeHit.collider.name) { SelectedCard = ""; var card = GameModel .Users .First(a => a.UserId == CurrentUserId) .CardsModel .First(a => a.CardNumber.ToString() == cubeHit.collider.name).Card; card.transform.GetComponent <SpriteRenderer>().color = new Color(1F, 1F, 1F, 1); } else { if (string.IsNullOrEmpty(SelectedCard)) { SelectedCard = cubeHit.collider.name; var card = GameModel .Users .First(a => a.UserId == CurrentUserId) .CardsModel .First(a => a.CardNumber.ToString() == cubeHit.collider.name).Card; card.transform.GetComponent <SpriteRenderer>().color = new Color(0.2F, 0.3F, 0.4F, 0.5F); } } } } }
public void GoOutTaskOnClick() { HttpQueryManager.DeleteUserFromGame(); SceneManager.LoadScene("Start"); }
public void TaskOnClick() { try { if (ApiClientScript.IsBlocked) { return; } var userId = ApiClientScript.GameModel.Users.First(user => user.UserId == ApiClientScript.CurrentUserId).UserId; if (ApiClientScript.GameModel.Users.First(a => a.UserId == userId).CountCards <= 0) { MessageManager.ErrorMessage(ok, lose, message, panel, $" Произошла внутренняя \n ошибка, " + $"\n попробуйте еще раз!", Assets.Enums.TypeNotificationEnum.Error); return; } if (ApiClientScript.SelectedCardsIds.Count != 0) { var finResult = HttpQueryManager.FinishShag(); var data = finResult.Data; if (!finResult.StatusShag) { MessageManager.ErrorMessage(ok, lose, message, panel, $" Нельзя использовать карту!", Assets.Enums.TypeNotificationEnum.Error); return; } data = HttpQueryManager.PutCardsInSbros(); var information = Manager.GetInfoAboutPlayers(data); if (information == null || information.RealUser == null) { MessageManager.ErrorMessage(ok, lose, message, panel, $" Произошла внутренняя \n ошибка, " + $"\n попробуйте еще раз!", Assets.Enums.TypeNotificationEnum.Error); return; } ApiClientScript.GameModel .Users.First(a => a.UserId == userId) .CardsModel.ForEach(a => { Destroy(a.Card.gameObject); }); ApiClientScript.GameModel.Users.First(a => a.UserId == userId).CardsModel.Clear(); ApiClientScript.GameModel.Users.First(a => a.UserId == userId).CardsModel = information.RealUser.CardsModel; ApiClientScript.GameModel.Users.First(a => a.UserId == userId).CountCards = information.RealUser.CardsModel.Count(); InternalManager.SetRealUserCardsTwo(realPlayer, realPlayerTwoRow, information.RealUser.CardsModel, selectedCard); ApiClientScript.SelectedCard = ""; ApiClientScript.SelectedCardsIds.Clear(); koloda.text = "Колода: " + data.pack.count; sbros.text = "Сброс: " + data.sbros.count; go.interactable = true; } } catch (Exception ex) { Debug.Log(ex.Message); MessageManager.ErrorMessage(ok, lose, message, panel, $" Произошла внутренняя \n ошибка, " + $"\n попробуйте еще раз! " + $"{ ex.Message}", Assets.Enums.TypeNotificationEnum.Error); } }