Exemple #1
0
    /// <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);
    }
Exemple #2
0
    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> {
        };
    }
Exemple #3
0
    // 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;
        }
    }
Exemple #4
0
 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!");
     }
 }
Exemple #5
0
    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;
            }
        }
    }
Exemple #6
0
    /// <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();
        }
    }
Exemple #7
0
 public static async Task AskPlayOneMoreRound()
 {
     await BackToFront.AskPlayOneMoreRoundBackend();
 }
Exemple #8
0
 public void showAceIdPlayerListBackend()
 {
     BackToFront.showAceIdPlayerListBackend(Context.ConnectionId);
 }
Exemple #9
0
 public void GameOverBackend(string message)
 {
     BackToFront.CreateErrorMessage(_client, message);
 }
Exemple #10
0
    public void PaytributeBegin(List <Player> finishOrder)
    {
        var list = finishOrder.Select(o => o.Name).ToList();

        BackToFront.CreateErrorMessage(_client, String.Join("<- ", list.ToArray()));
    }
Exemple #11
0
 public void PlayerListUpdateBackend(List <Card> userHand)
 {
     BackToFront.PlayerListUpdateBackend(userHand, this.ConnectionId, CardCount);
 }
Exemple #12
0
 public void ShowCurrentPlayerTurn(int currentPlayerIndex)
 {
     BackToFront.ShowCurrentPlayerTurnBackend(currentPlayerIndex, _client);
 }
Exemple #13
0
 public void SendCurrentCardListBackend()
 {
     BackToFront.SendCurrentCardListBackend(_client, _cardsInHand);
 }
Exemple #14
0
 public async Task GetPlayerHand()
 {
     await BackToFront.AskForPlayBackend(_client);
 }