コード例 #1
0
ファイル: Program.cs プロジェクト: moraispgsi/pacman
        private static void notInstructedClient(string PID, Uri clientURL, List <Uri> serverURLs)
        {
            Hub       hub       = new Hub(serverURLs, clientURL, new SimpleGame());
            Form      form      = new AutomaticStartForm(hub, PID);
            FormStage formStage = null;

            hub.OnStart += (stage) =>
            {
                form.Invoke(new System.Action(() => {
                    form.Hide();
                    formStage = new FormStage(hub, stage);
                    formStage.Show();
                }));
            };

            hub.OnDeath += () =>
            {
                form.Invoke(new System.Action(() =>
                {
                    FormDead f = new FormDead();
                    f.Show();
                }));
            };

            hub.OnGameEnd += (winner) =>
            {
                hub.UnregisterChannel(); //unrigester current channel before creating a new one
                form.Invoke(new System.Action(() =>
                {
                    //MessageBox.Show("END");
                    formStage.Hide();
                    FormEndGame endGame = new FormEndGame(winner);
                    endGame.PID         = PID;
                    endGame.clientURL   = clientURL;
                    endGame.serverURLs  = serverURLs;
                    endGame.Show();
                    //quando um botao for clicado este método tem de ser executado.
                    endGame.OnPlayAgain += (_PID, _clientURL, _serverURLs) =>
                    {
                        notInstructedClient(_PID, _clientURL, _serverURLs);
                    };
                }));
            };

            try
            {
                Application.Run(form);
            }
            catch (InvalidUsernameException exc)
            {
                MessageBox.Show(exc.Message);
                Application.Exit();
            }
        }
コード例 #2
0
        public FormWelcome(Hub hub)
        {
            InitializeComponent();
            this.MaximizeBox        = false; // disable the maximize button
            this.labelError.Visible = false;
            this.textBoxUsername.Select();
            this.hub = hub;

            hub.OnStart += (stage) =>
            {
                Invoke(new System.Action(() =>
                {
                    // TODO: remove this handler of the OnStart event
                    Hide();
                    FormStage formStage = new FormStage(hub, stage);
                    formStage.Show();
                }));
            };
        }