コード例 #1
0
        protected void GamingCore()
        {
            while (!this.isTheGamePlayable())
            {
                //Server.writeMessageForAllPlayer("[Server] Waiting for full team\n");
                Thread.Sleep(1000);
            }

            switch (Server.mainTable.State)
            {
            case GameState.Init:     //Distribution des cards aux players

                bool distribState = this.DistributeCardsForPlayers();

                if (distribState)
                {
                    Server.mainTable.State = GameState.Bet;
                }
                break;

            case GameState.Bet:
                /* All manage in ServerHandler */

                /* Si les paris s'éternise sur plus de 3 tours */
                if (this.TableCycle == 3)
                {
                    Server.mainTable.State = GameState.BetTraitement;
                }
                break;

            case GameState.BetTraitement:
                Team attackingTeam = this.getBestBetTeam(false);
                Team defenseTeam   = this.getBestBetTeam(true);

                defenseTeam.Bet     = 0;
                defenseTeam.Coinche = 0;

                Server.mainTable.Atout = attackingTeam.BetFamily;

                Server.writeMessageForAllPlayer("[Server] Start Game ! Atout is [" +
                                                attackingTeam.BetFamily.ToString() + "]\n");

                Server.mainTable.State = GameState.Pli;
                break;

            case GameState.Waitting:
                break;

            case GameState.Pli:
                if (Server.gameEngigne.PlayerTurn == 3)
                {
                    while (Server.gameEngigne.PlayerTurn != 0)
                    {
                        Thread.Sleep(100);
                    }

                    int sumRoundPoint = Server.mainTable.SumCardDroppedPli;
                    Server.writeMessageForAllPlayer("[Server] Round ended by " + sumRoundPoint + " points \n");
                    Server.mainTable.getTeamOfPlayer(Server.mainTable.WinningCardPlayer.Channel).AddScore(sumRoundPoint);
                    Server.mainTable.SumCardDroppedPli = 0;
                    Server.mainTable.initMidDeck();
                    Server.mainTable.WinningCard       = null;
                    Server.mainTable.WinningCardPlayer = null;

                    if (Tools.CountArray(Server.mainTable.Teams[0].Players1[0].Deck) == 0)
                    {
                        Team attTeam = this.getBestBetTeam(false);
                        Team defTeam = this.getBestBetTeam(true);
                        Server.mainTable.State = GameState.Ended;

                        int scoreAtt = attTeam.Score;
                        int scoreDef = defTeam.Score;

                        int finalAttScore = 0;
                        int finalDefScore = 0;

                        int coincheMultiplicator = attTeam.Coinche > 0 ? attTeam.Coinche : 1;

                        if (scoreAtt >= attTeam.Bet)
                        {
                            Server.writeMessageForAllPlayer("Attacking team succeeded!\n");
                            finalAttScore = scoreAtt + (attTeam.Bet * coincheMultiplicator);
                            finalDefScore = scoreDef;
                        }
                        else
                        {
                            Server.writeMessageForAllPlayer("Attacking team failed!\n");
                            finalDefScore = scoreDef + (attTeam.Bet * coincheMultiplicator);
                        }

                        String messageRoundScore = "Round Score " + finalAttScore.ToString() + " vs "
                                                   + finalDefScore.ToString() + "\n";
                        Server.writeMessageForAllPlayer(messageRoundScore);


                        this.getBestBetTeam(false).GameScore = finalAttScore;
                        this.getBestBetTeam(true).GameScore  = finalDefScore;

                        String messageGameScore = "Game Score "
                                                  + this.getBestBetTeam(false).GameScore.ToString() +
                                                  " vs "
                                                  + this.getBestBetTeam(true).GameScore.ToString() +
                                                  "\n";
                        Server.writeMessageForAllPlayer(messageGameScore);

                        Server.mainTable.State = GameState.Ended;
                    }
                }
                break;

            case GameState.Ended:

                Server.writeMessageForAllPlayer("New round in 3 seconds....");

                Thread.Sleep(3000);

                Server.mainTable.initMainDeck();
                Server.mainTable.initMidDeck();
                this.DistributeCardsForPlayers();

                Server.mainTable.State = GameState.Bet;

                break;

            default:
                break;
            }

            //System.out.println("Game is runnig");
        }