Exemplo n.º 1
0
 void OnGUI()
 {
     if (instances.Count > 0 && instances[0].Controller.DataLoaded)
     {
         return;
     }
     GUILayout.BeginHorizontal();
     if (instances.Count < 4 && GUILayout.Button("Run test"))
     {
         GotoView("lobby");
         Co.YieldWhileTrue(() => { return(!ClientsConnected()); }, () => {
             instances[0].Dispatcher.ScheduleMessage("RunTest");
         });
     }
     if (instances.Count < 4 && GUILayout.Button("Add player"))
     {
         AddPlayer();
     }
     if (instances.Count == 0)
     {
         GUILayout.Label(" OR: skip to view: ");
         gotoView = GUILayout.TextField(gotoView, 25, GUILayout.Width(50));
         if (gotoView != "" && ValidView(gotoView))
         {
             if (GUILayout.Button("Go"))
             {
                 GotoView(gotoView);
             }
         }
     }
     GUILayout.EndHorizontal();
 }
Exemplo n.º 2
0
 void OnSetDeck(NetMessage msg)
 {
     // Wait a frame to ensure that DeckManager sets the deck before referencing it
     Co.WaitForFixedUpdate(() => {
         Game.Dispatcher.ScheduleMessage("StartGame");
         Co.YieldWhileTrue(() => { return(!Game.Controller.DataLoaded); }, () => {
             AllGotoView("roles");
         });
     });
 }
Exemplo n.º 3
0
        void Start()
        {
            debug.gameObject.SetActive(
                        #if SHOW_DEBUG_INFO
                true);
            Co.YieldWhileTrue(() => { return(Parent == null); }, () => {
                debug.Init(Game);
            });
                        #else
                false);
                        #endif

                        #if UNITY_EDITOR
            debug.gameObject.SetActive(enableEditorDebugging);
            Co.YieldWhileTrue(() => { return(Parent == null); }, () => {
                debug.Init(Game);
            });

            if (Parent == null)
            {
                gameObject.SetActive(false);
            }
                        #endif
        }
Exemplo n.º 4
0
    void GotoView(string id)
    {
        // Skip ahead to the view with the given id
        // This must be called *before* any players have been added - it "fakes" a game playthrough
        // (only for testing purposes)

        bool beforeLobby  = id == "start" || id == "hostjoin";
        bool beforeDeck   = beforeLobby || id == "lobby" || id == "games";
        bool beforeBio    = beforeDeck || id == "roles" || id == "pot";
        bool beforeWinner = beforeBio || id == "agenda" || id == "question" || id == "think_instructions" || id == "think" || id == "pitch_instructions" || id == "pitch" || id == "extra_time" || id == "deliberate_instructions" || id == "deliberate" || id == "extra_time_deliberate" || id == "decide";
        bool deck         = id == "deck";

        // Create host
        AddPlayer();

        if (beforeLobby)
        {
            instances[0].Views.Goto(id);
            for (int i = 1; i < 3; i++)
            {
                AddPlayer();
                instances[i].Views.Goto(id);
            }
            return;
        }

        instances[0].StartGame();
        instances[0].Multiplayer.HostGame((ResponseType res) => {
            if (res != ResponseType.Success)
            {
                Debug.LogWarning("Failed to run test because the host name is already being used by another open room.");
                return;
            }

            // Move the host to the view
            if (deck)
            {
                instances[0].Views.Goto("deck");
            }
            else if (beforeDeck)
            {
                instances[0].Views.Goto(id);
            }

            string hostName = instances[0].Name;
            string roomId   = instances[0].Multiplayer.RoomId;

            // Create the other players
            for (int i = 1; i < 3; i++)
            {
                AddPlayer();
                GameInstance gi = instances[i];

                gi.Multiplayer.JoinGame(hostName, roomId, (ResponseType response) => {
                    gi.StartGame();
                });
            }
        });


        // WARNING: js-style callback hell approaching
        // Wait for clients to connect
        Co.YieldWhileTrue(() => { return(!ClientsConnected()); }, () => {
            if (deck)
            {
                instances[0].Views.AllGoto("deck");
            }
            else if (!beforeDeck)
            {
                instances[0].Dispatcher.AddListener("SetDeck", (NetMessage msg) => {
                    Co.WaitForFixedUpdate(() => {
                        // Once the deck has been set, start the game
                        instances[0].Dispatcher.ScheduleMessage("StartGame");

                        // Once the data has loaded, send all players to the supplied view
                        Co.YieldWhileTrue(() => { return(instances.Find(x => !x.Controller.DataLoaded) != null); }, () => {
                            // If the view happens at or after the winner screen, choose a winner
                            if (!beforeWinner)
                            {
                                string winner = System.Array.Find(instances[0].Controller.Roles, x => x.Title != "Decider").PlayerName;
                                for (int i = 0; i < instances.Count; i++)
                                {
                                    instances[i].Controller.SetWinner(winner);
                                }
                            }

                            instances[0].Views.AllGoto(id);

                            // If the view comes after the pot screen, set the scores
                            if (!beforeBio)
                            {
                                for (int i = 0; i < instances.Count; i++)
                                {
                                    instances[i].Score.FillPot();
                                    instances[i].Score.AddRoundStartScores();
                                }
                            }
                        });
                    });
                });

                // Set the default deck
                instances[0].Dispatcher.ScheduleMessage("SetDeck", "Civic");
            }
        });
    }
Exemplo n.º 5
0
    void GotoView(NetMessage msg)
    {
        Co.YieldWhileTrue(() => { return(Animating); }, () => {
            Co.WaitForSeconds(0.5f, () => {
                switch (msg.str1)
                {
                case "deck":
                    if (Hosting)
                    {
                        PressRadioButton("deck_list", "Civic");
                    }
                    break;

                case "pot":
                case "bio":
                case "agenda":
                case "question":
                case "think_instructions":
                case "pitch_instructions":
                case "deliberate_instructions":
                case "winner":
                case "agenda_item_accept":
                case "agenda_item_reject":
                case "scoreboard":
                    PressNext();
                    break;

                case "roles":
                    if (IsDecider)
                    {
                        PressButton("play");
                    }
                    break;

                case "think":
                    if (IsDecider)
                    {
                        PressTimerButton();
                    }
                    break;

                case "pitch":
                    if (IsDecider)
                    {
                        PressTimerButton();
                    }
                    else
                    {
                        Co.YieldWhileTrue(() => { return(Game.Views.CurrView != "extra_time"); }, () => {
                            GotoView(NetMessage.Create("GotoView", "extra_time"));
                        });
                    }
                    break;

                case "extra_time":
                case "extra_time_deliberate":
                    PressButton("decline");
                    break;

                case "deliberate":
                    if (IsDecider)
                    {
                        PressTimerButton();
                    }
                    else
                    {
                        Co.YieldWhileTrue(() => { return(Game.Views.CurrView != "extra_time_deliberate"); }, () => {
                            GotoView(NetMessage.Create("GotoView", "extra_time_deliberate"));
                        });
                    }
                    break;

                case "decide":
                    if (IsDecider)
                    {
                        PressListButton("peer_list", Game.Controller.PeerNames[0]);
                        PressButton("confirm");
                    }
                    break;

                case "agenda_item":
                    if (IsDecider)
                    {
                        bool accept = Random.value > 0.5f;
                        if (accept)
                        {
                            PressButton("accept");
                        }
                        else
                        {
                            PressButton("reject");
                        }
                    }
                    break;
                }
            });
        });
    }