예제 #1
0
        public LandingPage()
        {
            this.InitializeComponent();
            UpdateEnabled();

            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            if (localSettings.Values.TryGetValue(LocalSettingsKeys.GameName, out var gameName))
            {
                GameName.Text = (string)gameName;
                UpdateEnabled();
            }

            connecting = Task.Run(async() =>
            {
                try
                {
                    var handler = await SingleSignalRHandler.GetCreateOrThrow();
                    handler.SetOnClosed(ConnectionLost);
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                        CoreDispatcherPriority.Normal,
                        () =>
                    {
                        LoadingText.Visibility  = Visibility.Collapsed;
                        LoadingSpinner.IsActive = false;
                    });
                }
                catch (Exception ex)
                {
                    await ConnectionLost(ex);
                }
            });
        }
예제 #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);


            Window.Current.CoreWindow.KeyUp += Menu_KeyUp;
            ToggleCurser();

            var gameInfo = (GameInfo)e.Parameter;

            var gameName = gameInfo.gameName;

            var inputs = new MouseKeyboardInputs(lockCurser, playerId);

            game = new Game2();

            zoomer = new MouseZoomer(GameHolder.ActualWidth, GameHolder.ActualHeight, fieldDimensions, (GameState gs) =>
            {
                return(gs.players.Where(x => x.Key == playerId).Select(x => x.Value.PlayerBody.Position)
                       .Union(new[] { gs.GameBall.Posistion })
                       .ToArray());
            });
            //zoomer = new FullField(GameHolder.ActualWidth, GameHolder.ActualHeight, fieldDimensions.xMax / 2.0, fieldDimensions.yMax / 2.0);
            renderGameState = new RenderGameState2(/*Canvas,*/ zoomer, LeftScore, RightScore);

            var signalRHandler = SingleSignalRHandler.GetOrThrow();
            var color          = GetColor();

            signalRHandler.Send(gameName, new AddPlayerEvent(
                                    playerId,
                                    "",
                                    BodyA,
                                    color[0],
                                    color[1],
                                    color[2],
                                    0xff,
                                    color[0],
                                    color[1],
                                    color[2],
                                    new Physics2.Vector(fieldDimensions.xMax / 2.0, fieldDimensions.yMax / 2.0)
                                    ));

            inputs.Init().ContinueWith(_ =>
            {
                signalRHandler.Send(gameName, Inputs(inputs));
            });

            var dontWait = MainLoop(signalRHandler.JoinChannel(new JoinChannel(gameName)));
        }
예제 #3
0
        private void StartOrJoinInner()
        {
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            localSettings.Values[LocalSettingsKeys.GameName] = GameName.Text;
            StartOrJoinButton.IsEnabled = false;
            GameName.IsEnabled          = false;
            var name = GameName.Text;

            Task.Run(async() =>
            {
                try
                {
                    await connecting;
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                        CoreDispatcherPriority.Normal,
                        () =>
                    {
                        LoadingText.Visibility  = Visibility.Visible;
                        LoadingText.Text        = "Starting Game";
                        LoadingSpinner.IsActive = true;
                    });
                    var handler = await SingleSignalRHandler.GetOrThrowAsync();
                    var res     = await handler.Send(new CreateOrJoinGame(name, FieldDimensions.Default));
                    if (res.Is1(out var gameCreated))
                    {
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                            CoreDispatcherPriority.Normal,
                            async() =>
                        {
                            var handler = (await SingleSignalRHandler.GetOrThrowAsync());
                            handler.SetOnClosed(null);
                            handler.ClearCallBacks();
                            this.Frame.Navigate(typeof(OnlineGame), new GameInfo(gameCreated.Id, Mouse.IsChecked.Value ? ControlScheme.SipmleMouse : ControlScheme.MouseAndKeyboard));
                        });
                    }
                    else if (res.Is2(out var joined))
                    {
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                            CoreDispatcherPriority.Normal,
                            async() =>
                        {
                            var handler = (await SingleSignalRHandler.GetOrThrowAsync());
                            handler.SetOnClosed(null);
                            handler.ClearCallBacks();
                            this.Frame.Navigate(typeof(OnlineGame), new GameInfo(joined.Id, Mouse.IsChecked.Value ? ControlScheme.SipmleMouse : ControlScheme.MouseAndKeyboard));
                        });
                    }
                    else if (res.Is3(out var exception))
                    {
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                            CoreDispatcherPriority.Normal,
                            () =>
                        {
                            StartOrJoinButton.IsEnabled = true;
                            GameName.IsEnabled          = true;
                            LoadingText.Text            = exception.Message;
                            LoadingText.Visibility      = Visibility.Visible;
                            LoadingSpinner.IsActive     = false;
                        });
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                catch (Exception ex)
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                        CoreDispatcherPriority.Normal,
                        () =>
                    {
                        StartOrJoinButton.IsEnabled = true;
                        GameName.IsEnabled          = true;
                        LoadingText.Text            = ex.Message;
                        LoadingSpinner.IsActive     = false;
                    });
                }
            });
        }