Пример #1
0
        public KeyCard(int card_id, int teamFirstToMove, string data_string, int length)
        {
            id          = card_id;
            firstToMove = teamFirstToMove;
            size        = length;

            string[] d = data_string.Split(',');
            for (int i = 0; i < d.Length; i++)
            {
                int       n     = Int32.Parse(d[i].Trim());
                CardColor color = (CardColor)Enum.ToObject(typeof(CardColor), n);
                data.Add(color);
            }
        }
        RevealCardResolutions RevealCard(CardChoice cardChoice) //Reveals the card at the index of the deck
        {
            try
            {
                if (cardChoice == CardChoice.PASS)
                {
                    return(RevealCardResolutions.PASS);
                }

                int index = (int)cardChoice;
                if (deck.Cards[index].State == CardState.Revealed)
                {
                    return(RevealCardResolutions.ALREADY_REVEALED);
                }
                else
                {
                    deck.Cards[index].State = CardState.Revealed;
                    CardColor cardColor = keyCard.data[index];
                    switch (cardColor)
                    {
                    case CardColor.Red:
                        return(RevealCardResolutions.REVEALED_RED_TEAM_CARD);

                    case CardColor.Blue:
                        return(RevealCardResolutions.REVEALED_BLUE_TEAM_CARD);

                    case CardColor.Brown:
                        return(RevealCardResolutions.REVEALED_BROWN_TEAM_CARD);

                    case CardColor.Black:
                        return(RevealCardResolutions.REVEALED_BLACK_TEAM_CARD);

                    default:
                        throw new System.Exception("RevealCardResolutions not implemented: " + cardColor);
                    }
                }
            }
            catch
            {
                return(RevealCardResolutions.ERROR);
            }
        }
        void HandleRevealCardResolution(RevealCardResolutions revealResolution, CardColor teamColor)
        {
            switch (revealResolution)
            {
            case RevealCardResolutions.PASS:
                Debug.Log("Team passed turn");
                if (teamColor == CardColor.Blue)
                {
                    EventManager.onGameStateApiDone.Invoke(GameState.BLUE_TEAM_TURN_END);
                }
                else if (teamColor == CardColor.Red)
                {
                    EventManager.onGameStateApiDone.Invoke(GameState.RED_TEAM_TURN_END);
                }
                else
                {
                    throw new System.InvalidOperationException("A team must be blue or red");
                }
                break;

            case RevealCardResolutions.ALREADY_REVEALED:
                Debug.Log("Ignored Submission. Already revealed card was chosen");
                break;

            case RevealCardResolutions.REVEALED_BLACK_TEAM_CARD:
                Debug.Log("Black card revealed! " + teamColor.ToString() + " team loses the game");
                if (teamColor == CardColor.Blue)
                {
                    EventManager.onGameStateApiDone.Invoke(GameState.RED_TEAM_WINS);
                }
                else if (teamColor == CardColor.Red)
                {
                    EventManager.onGameStateApiDone.Invoke(GameState.BLUE_TEAM_WINS);
                }
                else
                {
                    throw new System.InvalidOperationException("A team must be blue or red");
                }
                break;

            case RevealCardResolutions.REVEALED_BROWN_TEAM_CARD:
                Debug.Log("Brown card revealed! " + teamColor.ToString() + " team loses their turn");
                if (teamColor == CardColor.Blue)
                {
                    EventManager.onGameStateApiDone.Invoke(GameState.BLUE_TEAM_TURN_END);
                }
                else if (teamColor == CardColor.Red)
                {
                    EventManager.onGameStateApiDone.Invoke(GameState.RED_TEAM_TURN_END);
                }
                else
                {
                    throw new System.InvalidOperationException("A team must be blue or red");
                }
                break;

            case RevealCardResolutions.REVEALED_BLUE_TEAM_CARD:
                guessesLeft        -= 1;
                CardsToWinTeamBlue -= 1;
                PrintScore();
                if (CardsToWinTeamBlue == 0)
                {
                    EventManager.onGameStateApiDone.Invoke(GameState.BLUE_TEAM_WINS);
                }
                else
                {
                    if (teamColor == CardColor.Blue)
                    {
                        if (guessesLeft == 0)
                        {
                            EventManager.onGameStateApiDone.Invoke(GameState.BLUE_TEAM_TURN_NO_MORE_GUESSES);
                        }
                        else
                        {
                            Debug.Log("Blue card revealed! Team continues. Guesses left: " + guessesLeft.ToString());
                            EventManager.onGameStateApiDone.Invoke(GameState.BLUE_TEAM_TURN_CONTINUE);
                        }
                    }
                    else if (teamColor == CardColor.Red)
                    {
                        Debug.Log("Blue card revealed! " + teamColor.ToString() + " team loses their turn");
                        EventManager.onGameStateApiDone.Invoke(GameState.RED_TEAM_TURN_END);
                    }
                    else
                    {
                        throw new System.InvalidOperationException("A team must be blue or red");
                    }
                }
                break;



            case RevealCardResolutions.REVEALED_RED_TEAM_CARD:
                guessesLeft       -= 1;
                CardsToWinTeamRed -= 1;
                PrintScore();
                if (CardsToWinTeamRed == 0)
                {
                    EventManager.onGameStateApiDone.Invoke(GameState.RED_TEAM_WINS);
                }
                else
                {
                    if (teamColor == CardColor.Blue)
                    {
                        Debug.Log("Red card revealed! " + teamColor.ToString() + " team loses their turn");
                        EventManager.onGameStateApiDone.Invoke(GameState.BLUE_TEAM_TURN_END);
                    }
                    else if (teamColor == CardColor.Red)
                    {
                        if (guessesLeft == 0)
                        {
                            EventManager.onGameStateApiDone.Invoke(GameState.RED_TEAM_TURN_NO_MORE_GUESSES);
                        }
                        else
                        {
                            Debug.Log("Red card revealed! Team continues. Guesses left: " + guessesLeft.ToString());
                            EventManager.onGameStateApiDone.Invoke(GameState.RED_TEAM_TURN_CONTINUE);
                        }
                    }
                    else
                    {
                        throw new System.InvalidOperationException("A team must be blue or red");
                    }
                }
                break;

            default:
                throw new System.NotImplementedException("RevealCardResolutions not implemented: " + revealResolution.ToString());
            }
        }
 public TeamCardSubmission(CardChoice index, CardColor team)
 {
     cardIndex = index;
     teamColor = team;
 }
Пример #5
0
 private void ReloadGameState()
 {
     Task.Run(() =>
     {
         GameState gameState = new GameState();
         try
         {
             gameState = StreamHelper.Communicate <GameState>(user.clientStream, RequestCodes.GAME_STATE);
         }
         catch (IOException)
         {
             try
             {
                 Invoke((MethodInvoker) delegate
                 {
                     Utils.ConnectionAbortMessageBox();
                     Close();
                 });
             }
             catch { }
         }
         if (gameState.winner != CardType.NONE)
         {
             GameUpdates_Timer.Enabled = false;
             Utils.RtlMessageBox("המשחק הסתיים! הקבוצה ה" + (gameState.winner == CardType.RED ? "אדומה" : "כחולה") + " ניצחה!", "סוף המשחק", MessageBoxIcon.Information);
             Game_Panel.Enabled = false;
         }
         else if (gameState.deleted)
         {
             GameUpdates_Timer.Enabled = false;
             MessageBox.Show("המשחק נמחק");
             Game_Panel.Enabled = false;
         }
         try
         {
             Invoke((MethodInvoker) delegate
             {
                 if (gameState.turn == CardType.RED)
                 {
                     CurrTurn_Label.Text      = "אדום";
                     CurrTurn_Label.ForeColor = CardColor.REVEALED_RED;
                 }
                 else
                 {
                     CurrTurn_Label.Text      = "כחול";
                     CurrTurn_Label.ForeColor = CardColor.REVEALED_BLUE;
                 }
                 CurrWord_Label.Text   = Utils.Base64Decode(gameState.curr_word);
                 CurrAmount_Label.Text = gameState.curr_revealed.ToString() + "/" + gameState.curr_cards.ToString();
                 for (int r = 0; r < gameState.board.Count; r++)
                 {
                     for (int c = 0; c < gameState.board[r].Count; c++)
                     {
                         board[r][c].Text      = Utils.Base64Decode(gameState.board[r][c].word);
                         board[r][c].revealed  = gameState.board[r][c].revealed;
                         board[r][c].BackColor = CardColor.GetColor(gameState.board[r][c].type, gameState.board[r][c].revealed);
                     }
                 }
                 CurrWord_TextBox.Visible         = gameState.turn == team && gameState.curr_word == "" && manager;
                 CurrWord_Label.Visible           = !CurrWord_TextBox.Visible;
                 CurrAmount_NumericUpDown.Visible = CurrWord_TextBox.Visible;
                 CurrAmount_Label.Visible         = !CurrAmount_NumericUpDown.Visible;
                 SendWord_Button.Visible          = CurrWord_TextBox.Visible;
                 GuessWord_Panel.Visible          = gameState.turn == team && gameState.curr_word != "" && !manager;
                 if (!CurrWord_TextBox.Visible)
                 {
                     CurrWord_TextBox.Text          = "";
                     CurrAmount_NumericUpDown.Value = 1;
                 }
             });
         }
         catch { }
     });
 }
Пример #6
0
 public Clue(CardColor color, string w, int clue_count)
 {
     team   = color;
     word   = w;
     number = clue_count;
 }