private async Task UpdateGameScore(CancellationToken ct) { try { if (!ct.IsCancellationRequested) { if (PlayersHandTotal > DealersHandTotal) { PlayerGameScore++; PlayerScoreText = "Players score: " + PlayerGameScore.ToString(); ConvoText = "Players hand wins."; } else if (PlayersHandTotal < DealersHandTotal) { DealerGameScore++; DealerScoreText = "Dealers score: " + DealerGameScore.ToString(); ConvoText = "Dealers hand wins."; } else if (PlayersHandTotal == DealersHandTotal) { DealerGameScore++; ConvoText = "Draw, points go to dealer."; } await Task.Delay(2000, ct); await CheckIfGameContinues(ct); } } catch (OperationCanceledException) { } }
private void GameStart() { Deck = new PlayingCardDeck(); Deck.Shuffle(); PlayersHandTotal = 0; PlayersHand.Clear(); DealersHandTotal = 0; DealersHand.Clear(); ButtonsEnabled = true; PlayerScoreText = "Players score: " + PlayerGameScore.ToString(); DealerScoreText = "Dealers score: " + DealerGameScore.ToString(); PlayersHand.Add(Deck.RemoveTopCard()); DealersHand.Add(Deck.RemoveTopCard()); PlayersHand.Add(Deck.RemoveTopCard()); DealersHand.Add(Deck.RemoveTopCard()); DealersHandTotalText = "Dealers hand total: " + DealersHandTotal; OnPropertyChanged(nameof(PlayersHand)); PlayersHandTotal = UpdateScore(PlayersHand); PlayersHandTotalText = "Players hand total: " + PlayersHandTotal.ToString(); ConvoText = "Players turn"; }
public void ResetGame() { DealersHandTotalText = string.Empty; PlayersHandTotalText = string.Empty; ConvoText = string.Empty; DealerGameScore = 0; PlayerGameScore = 0; DealerScoreText = "Dealers score: " + DealerGameScore.ToString(); PlayerScoreText = "Players score: " + PlayerGameScore.ToString(); }
public void printReport() { Debug.Log("Uploading Report"); report.reportsSentCount++; if (report.reportsSentCount == 1) { report.setFirstPostDateTime(System.DateTime.UtcNow); } PlayerGameScore playerGameScore = new PlayerGameScore(); playerGameScore.Complete = (int)report.getPercentage(); playerGameScore.CreatedBy = (Toolbox.ExternalHandler.Model.GetGameId()).ToString(); playerGameScore.CreatedDate = report.GetFirstPostDateTime(); playerGameScore.Duration = (int)report.getPlaytime(); playerGameScore.GameId = Toolbox.ExternalHandler.Model.GetGameId(); playerGameScore.IncorrectAttempts = report.getIncorrectAttempts(); playerGameScore.InstanceId = 0; playerGameScore.IsInAccessibilityMode = Toolbox.GameManager.accessibilityCheck; playerGameScore.ModifiedBy = (Toolbox.ExternalHandler.Model.GetGameId()).ToString(); playerGameScore.ModifiedDate = System.DateTime.UtcNow; playerGameScore.PlayType = GetGameType(); //playerGameScore.Responsiveness = report.getResponsiveness();//Previous Logic playerGameScore.Responsiveness = null; //Because Game_4 Fundraiser has No responsiveness playerGameScore.StudentId = Toolbox.ExternalHandler.Model.GetStudentId(); playerGameScore.Timestamp = report.getDatetime(); //print("Percentage completed in game:" + playerGameScore.Complete); //print("Game Created By :" + playerGameScore.CreatedBy); //print("Game Created date :" + playerGameScore.CreatedDate); //print("Total time played is: " + playerGameScore.Duration); //print("Game Id is : " + playerGameScore.GameId); //print("Total Incorrect Attempts : " + playerGameScore.IncorrectAttempts); //print("Instance Id Of the game : " + playerGameScore.InstanceId); //print("InAccessibilityMode Of the game : " + playerGameScore.IsInAccessibilityMode); //print("Game Modified By : " + playerGameScore.ModifiedBy); //print("Game Modified Date : " + playerGameScore.ModifiedDate); //print("Game play type : " + playerGameScore.PlayType); //print("Total number of interaction in game (responsiveness):" + playerGameScore.Responsiveness); //print("Student Id in Game :" + playerGameScore.StudentId); //print("Date and time is: " + playerGameScore.Timestamp); string JsonString = JsonConvert.SerializeObject(playerGameScore); Debug.Log(JsonString); string Url = Toolbox.ExternalHandler.baseURL + "api/PlayerScoreApi/SavePlayerScore"; Debug.Log("URl used for posting : " + Url); RestAPIHandler.Instance.StartCoroutine(RestAPIHandler.Instance.PostRequest(Url, JsonString)); }
private void SetWinnerText() { LabelEndGamePoints.Text = $"Players score: {PlayerGameScore.ToString()} Dealers score: {DealerGameScore.ToString()}"; if (PlayerGameScore > DealerGameScore) { LabelWinnerText.Text = "Player wins!"; } else { LabelWinnerText.Text = "Dealer wins!"; } }