/// <summary> /// return true if is a valid hand and is greater than lastHand /// return false if not valid /// </summary> /// <param name="cards"></param> /// <returns></returns> public bool PlayHand(List <Card> cards, Hand lastHand) { Hand hand; try { hand = new Hand(cards); } catch (Exception e) { BackToFront.CreateErrorMessage(_client, "Hand is not valid"); return(false); } if (hand.CompareHand(lastHand)) { foreach (var card in cards) { _cardsInHand.Remove(card); } BackToFront.HandIsValidBackend(_client); return(true); } BackToFront.CreateErrorMessage(_client, "Hand is not greater than the previous one"); return(false); }
public void ReturnTribute(Player p, int returnNumber) { bool valid = false; while (!valid) { BackToFront.AskReturnTributeBackend(_client); var userReturn = PlayerHubTempData.returnCards; if (userReturn.Count != returnNumber) { BackToFront.CreateErrorMessage(_client, "Tribute Return Not Valid"); } else { BackToFront.ReturnIsValidBackend(_client); valid = true; } } foreach (var card in PlayerHubTempData.returnCards) { this._cardsInHand.Remove(card); } p.AddCards(PlayerHubTempData.returnCards); p.OrganizeHand(); PlayerHubTempData.returnCards = new List <Card> { }; }
// return true if go public, otherwise not. // if one player has two ace, no solution now public async Task AceGoPublic() { if (IsBlackAce) { await BackToFront.AskAceGoPublicBackend(_client); IsBlackAcePublic = PlayerHubTempData.aceGoPublic; PlayerHubTempData.aceGoPublic = false; } }
public async void StartGameBackend() { if (Room.activeRoom.CanStartGame()) { Console.WriteLine("can start game"); // await here? BackToFront.clients = Clients; BackToFront.NotifyOthersBackend(); // no need to wait here? Room.activeRoom.StartGame(); Console.WriteLine("finish start game"); } else { await Clients.Caller.SendAsync("showErrorMessage", "Cannot start the game!"); } }
private void reInital() { BackToFront.ResetState(); foreach (var p in playerList) { p.ClearCard(); } stillPlay = new List <Player> { }; for (int i = 0; i < playerList.Count; i++) { if (playerList[i].IsBlackAce) { dealerIndex = i; playerIndex = i; break; } } }
/// <summary> /// main process /// </summary> public async Task GameProcess() { int roundNumber = 1; while (true) { if (roundNumber != 1) { SetTributeList(); } foreach (var p in playerList) { p.clearAce(); } InitCardList(); SendCurrentCardListBackend(); await Task.Delay(5000); if (roundNumber != 1) { // alert user that we sill start to pay tribute foreach (var p in playerList) { p.PaytributeBegin(finishOrder); } await Task.Delay(2000); PayTribute(); SendCurrentCardListBackend(); ReturnTribute(); } isGameStarted = true; finishOrder = new List <Player> { }; // init tributeList PlayerHubTempData.returnCards = new List <Card> { }; stillPlay = playerList.Select(x => x).ToList(); PlayerHubTempData.userHand = new List <Card> { }; await AceGoPublic(); while (isGameStarted) // skip means hand are empty { ShowCurrentPlayerTurn(); await AskForPlay(); SendCurrentCardListBackend(); checkEnded(); playerIndex = (playerIndex + 1) % playerList.Count; while (playerList[playerIndex].isFinished() && isGameStarted == true) { playerIndex = (playerIndex + 1) % playerList.Count; } } reInital(); await Room.AskPlayOneMoreRound(); if (!toPlayOneMoreRound()) { BackToFront.BreakGameBackend(); break; } PlayerHubTempData.playOneMoreRound = true; roundNumber += 1; ClearLastHandBackend(); } }
public static async Task AskPlayOneMoreRound() { await BackToFront.AskPlayOneMoreRoundBackend(); }
public void showAceIdPlayerListBackend() { BackToFront.showAceIdPlayerListBackend(Context.ConnectionId); }
public void GameOverBackend(string message) { BackToFront.CreateErrorMessage(_client, message); }
public void PaytributeBegin(List <Player> finishOrder) { var list = finishOrder.Select(o => o.Name).ToList(); BackToFront.CreateErrorMessage(_client, String.Join("<- ", list.ToArray())); }
public void PlayerListUpdateBackend(List <Card> userHand) { BackToFront.PlayerListUpdateBackend(userHand, this.ConnectionId, CardCount); }
public void ShowCurrentPlayerTurn(int currentPlayerIndex) { BackToFront.ShowCurrentPlayerTurnBackend(currentPlayerIndex, _client); }
public void SendCurrentCardListBackend() { BackToFront.SendCurrentCardListBackend(_client, _cardsInHand); }
public async Task GetPlayerHand() { await BackToFront.AskForPlayBackend(_client); }