コード例 #1
0
ファイル: Game_Pregame.cs プロジェクト: Rafa652/GameChannel
 private void PregamePart(Player p, bool newTurn)
 {
     if (Players.Count == 0) {
         // Stop if there are 0 players remaining
         EndGameNotEnough();
     }
 }
コード例 #2
0
ファイル: Game_Pregame.cs プロジェクト: Rafa652/GameChannel
 private void PregameInput(Player p, string line)
 {
     // Only '@begin' is recognized at this point
     if (line.ToLower() == "@begin") {
         if (Players.Count < 3) {
             SendOut(Messages.PregameNotEnough);
         } else {
             SetTopic(Messages.Topic);
             PWSetup();
         }
     }
 }
コード例 #3
0
ファイル: Game_PickWhite.cs プロジェクト: Rafa652/GameChannel
        private void PWPart(Player p, bool newTurn)
        {
            if (Players.Count < 3) {
                EndGameNotEnough();
                return;
            }

            if (!newTurn) {
                // Check if no more responses needed to continue
                if (TS != TickState.LastWhiteWait && Players.GetNeedResponseList().Count == 0) {
                    SetTimeout(TickState.LastWhiteWait, PWInputLastTime);
                }
            } else {
                // Reset
                PWSetup(false); // AdvanceTurn was already called
            }
        }
コード例 #4
0
ファイル: Game_PickBlack.cs プロジェクト: Rafa652/GameChannel
        private void PBInput(Player p, string line)
        {
            if (p != Players.CardCzar) return;

            HashSet<int> responseIndex = GetChoiceList(line);
            if (responseIndex == null) {
                // Don't say anything - this returns null even when the line didn't start with "p"
                return;
            }

            if (responseIndex.Count != 1) {
                SendOut(Players.CardCzar + ": " + Messages.PBCommandBadAmount);
                return;
            }

            int pick = responseIndex.ToArray()[0] - 1;
            if (pick >= Players.GetResponseCount() || pick < 0) {
                SendOut(Players.CardCzar + ": " + Messages.PBCommandOutOfRange);
                return;
            }

            // Give points
            Player winner = Players.GetResponse(pick).Item1;
            winner.Points++;
            SendOut(String.Format(Messages.PBCommand, p, winner));
            ShowScores();

            // Check if someone has won the game
            if (EndingPoints != -1) {
                if (winner.Points >= EndingPoints) {
                    SendOut(String.Format(Messages.GameWin, winner, winner.Points));
                    // TODO later: report win to GameChannel
                    PrepareEndGame();
                    return;
                }
            }

            // Next turn
            PWSetup();
        }
コード例 #5
0
ファイル: Game_PickWhite.cs プロジェクト: Rafa652/GameChannel
        private void PWInput(Player p, string line)
        {
            HashSet<int> responseIndex = GetChoiceList(line);
            if (responseIndex == null) {
                // Don't say anything - this returns null even when the line didn't start with "p"
                return;
            }

            if (p == Players.CardCzar) {
                SendOut(p.Name + ": " + Messages.PWCzar);
                return;
            }

            if (responseIndex.Count != TopCard.Blanks) {
                SendOut(p + ": " + String.Format(Messages.PWCommandBadAmount, TopCard.Blanks));
                return;
            }

            if (responseIndex.Any(r => r > 10 || r < 1)) {
                SendOut(p + ": " + Messages.PWCommandOutOfRange);
                return;
            }

            // Turn int array into card array
            int[] cardindex = responseIndex.ToArray();
            Card[] response = new Card[responseIndex.Count];
            for (int i = 0; i < cardindex.Length; i++) {
                response[i] = p.Hand[cardindex[i] - 1];
            }

            bool changed = Players.AddResponse(p, response);
            SendOut(p + ": " + (changed ? Messages.PWCommandShift : Messages.PWCommandSet));

            // Check if the game can move on
            if (Players.GetNeedResponseList().Count == 0) {
                SetTimeout(TickState.LastWhiteWait, PWInputLastTime);
            }
        }
コード例 #6
0
ファイル: Game_PickBlack.cs プロジェクト: Rafa652/GameChannel
        private void PBPart(Player p, bool newTurn)
        {
            if (Players.Count < 3) {
                EndGameNotEnough();
                return;
            }

            if (newTurn) {
                // Czar has left.
                if (Presenting) {
                    Presenting = false;
                    SendOut(Messages.PBDisplayAbort);
                }
                PWSetup(false);
            } else {
                // Player has left - must present again due to changed indexes
                SendOut(Messages.PBDisplayReset);
                Players.ShuffleResponses();
                Presenting = true;
                PresentingIndex = 0;
                SetTimeout(TickState.InactiveWarn1, TicksPerSecond);
            }
        }
コード例 #7
0
ファイル: Game.cs プロジェクト: Rafa652/GameChannel
        // Sends a player their hand
        private void SendCards(Player p)
        {
            // Due to very long white cards, multiple lines will have to be sent out to the players
            // to display all their 10 cards. They need to be split.
            const int MsgLen = 470;

            StringBuilder line = new StringBuilder();
            for (int i = 0; i < p.Hand.Count; i++) {
                string next = (i + 1) + ". " + p.Hand[i].ToString() + "\u000f ";
                if (next.Length + line.Length > MsgLen) {
                    // Outgoing line is now long enough - send it out
                    SendOut(p.Name, line.ToString());
                    line.Clear();
                }
                line.Append(next);
            }

            // Send out the last remaining value
            if (line.Length > 0) {
                SendOut(p.Name, line.ToString());
            }
        }