Exemplo n.º 1
0
 private void InitLayout()
 {
     layout = LayoutRoot.Add(new GridLayout(new GridLayoutOptions()
     {
         Columns = new System.Collections.Generic.List <GridColumnDefinition>()
         {
             new GridColumnDefinition()
             {
                 Width = 40, Type = GridValueType.Pixels
             },
             new GridColumnDefinition()
             {
                 Width = 1, Type = GridValueType.Pixels
             },
             new GridColumnDefinition()
             {
                 Width = 1, Type = GridValueType.RemainderValue
             },
         },
         Rows = new System.Collections.Generic.List <GridRowDefinition>()
         {
             new GridRowDefinition()
             {
                 Height = 1, Type = GridValueType.Percentage
             }
         }
     })).Fill();
     layout.RefreshLayout();
 }
        private async Task OrchestrateServerMode()
        {
            var numPlayers = await PromptForNumberOfPlayers();

            // first initialize the server
            var socketServer = new SocketServerNetworkProvider(8080);
            var server       = new MultiPlayerServer(socketServer);

            await QueueAction(() => LayoutRoot.Add(new MultiPlayerServerInfoControl(server)
            {
                Width = 50
            }).DockToRight().FillVertically()).AsAwaitable();

            this.OnDisposed(server.Dispose);
            var deathmatch = new Deathmatch(new MultiPlayerContestOptions()
            {
                MaxPlayers = numPlayers, Server = server
            });


            deathmatch.OrchestrationFailed.SubscribeOnce((ex) =>
            {
                QueueAction(() =>
                {
                    Dialog.ShowMessage("Fatal error: " + ex.ToString().ToRed()).Then(Cleanup);
                });
            });

            await deathmatch.Start();

            // then connect to it as a client
            await ConnectToRemoteServer(socketServer.ServerInfo);
        }
Exemplo n.º 3
0
 private void InitLayout()
 {
     layout = LayoutRoot.Add(new GridLayout(new GridLayoutOptions()
     {
         Columns = new List <GridColumnDefinition>()
         {
             new GridColumnDefinition()
             {
                 Type = GridValueType.Pixels, Width = 60
             },
             new GridColumnDefinition()
             {
                 Type = GridValueType.RemainderValue, Width = 1
             }
         },
         Rows = new List <GridRowDefinition>()
         {
             new GridRowDefinition()
             {
                 Type = GridValueType.Percentage, Height = 1
             }
         }
     })).Fill();
     layout.RefreshLayout();
 }
Exemplo n.º 4
0
        protected void Initialize()
        {
            this.RequiredSizeMet.SubscribeOnce(() =>
            {
                var introPanel       = new PowerArgsGamesIntro();
                var frameRateControl = LayoutRoot.Add(new FramerateControl(introPanel)
                {
                    ZIndex = 100
                });
                LayoutRoot.Add(introPanel).Play().Then(() => {
                    QueueAction(() =>
                    {
                        LayoutRoot.Controls.Remove(frameRateControl);
                        this.shooterKeys          = new ShooterKeys(() => this.Scene);
                        this.KeyboardInput.KeyMap = this.shooterKeys.ToKeyMap();
                        EnableThemeToggling();
                        LayoutRoot.Add(new HeadsUpDisplay(this, shooterKeys)).CenterHorizontally().DockToBottom();

                        this.Load("IntroCutScene");

                        var requiredSizeCausedPause = false;
                        this.RequiredSizeNotMet.SubscribeForLifetime(() =>
                        {
                            if (Scene.IsRunning)
                            {
                                this.Pause(false);
                                requiredSizeCausedPause = true;
                            }
                            else
                            {
                                requiredSizeCausedPause = false;
                            }
                        }, this);

                        this.RequiredSizeMet.SubscribeForLifetime(() =>
                        {
                            if (requiredSizeCausedPause)
                            {
                                this.Resume();
                            }
                        }, this);

                        Sound.Loop("bgmusicmain").Then(d => bgMusicHandle = d);

                        this.Paused.SubscribeForLifetime(() =>
                        {
                            bgMusicHandle?.Dispose();
                            bgMusicHandle = null;
                        }, this);

                        this.Resumed.SubscribeForLifetime(() =>
                        {
                            Sound.Loop("bgmusicmain").Then(d => bgMusicHandle = d);
                        }, this);
                    });
                });
            });
        }
Exemplo n.º 5
0
 private void InitMinSizeEnforcer()
 {
     LayoutRoot.Add(new MinimumSizeEnforcerPanel(new MinimumSizeEnforcerPanelOptions()
     {
         MinHeight           = 15,
         MinWidth            = 120,
         OnMinimumSizeMet    = () => { },
         OnMinimumSizeNotMet = () => { },
     })).Fill();
 }
Exemplo n.º 6
0
        public GameApp()
        {
            this.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.Escape, null, () =>
            {
                implicitPause = true;
                scenePanel.Scene.Stop();

                Dialog.ConfirmYesOrNo("Are you sure you want to quit?", () =>
                {
                    Stop();
                }, () =>
                {
                    scenePanel.Scene.Start();
                });
            }, this.LifetimeManager);


            var borderPanel = LayoutRoot.Add(new ConsolePanel()
            {
                Background = ConsoleColor.DarkGray, Width = LevelDefinition.Width + 2, Height = LevelDefinition.Height + 2
            }).CenterHorizontally().CenterVertically();

            scenePanel     = borderPanel.Add(new ScenePanel(LevelDefinition.Width, LevelDefinition.Height)).Fill(padding: new Thickness(1, 1, 1, 1));
            InputManager   = new GameInputManager(scenePanel.Scene, this);
            headsUpDisplay = LayoutRoot.Add(new HeadsUpDisplay(this)
            {
                Width = LevelDefinition.Width
            }).DockToBottom().CenterHorizontally();
            LayoutRoot.Add(new FramerateControl(scenePanel.Scene));
            QueueAction(() => { scenePanel.Scene.Start(); });

            GameScene.Started.SubscribeForLifetime(() =>
            {
                SoundEffects.Instance.SoundThread.Start();
                SoundEffects.Instance.PlaySound("music");
            }, this.LifetimeManager);

            scenePanel.Scene.Stopped.SubscribeForLifetime(() =>
            {
                SoundEffects.Instance.SoundThread.Stop();
                if (this.IsRunning && implicitPause == false)
                {
                    QueueAction(() =>
                    {
                        Dialog.ShowMessage("Paused", () => { scenePanel.Scene.Start(); });
                    });
                }
                implicitPause = false;
            }, this.LifetimeManager);
        }
Exemplo n.º 7
0
        private void AssertSizeRequirements(bool initialCheck)
        {
            if (initialCheck)
            {
                if (RequiredWidth.HasValue && this.Bitmap.Console.WindowWidth < RequiredWidth.Value)
                {
                    this.Bitmap.Console.WindowWidth = RequiredWidth.Value;
                    this.Bitmap.Console.BufferWidth = RequiredWidth.Value;
                }

                if (RequiredHeight.HasValue && this.Bitmap.Console.WindowHeight < RequiredHeight.Value)
                {
                    this.Bitmap.Console.WindowHeight = RequiredHeight.Value;
                }
            }

            var currentHeight = ConsoleProvider.Current.WindowHeight;
            var currentWidth  = ConsoleProvider.Current.WindowWidth;
            var tallEnough    = this.RequiredHeight.HasValue == false || currentHeight >= this.RequiredHeight.Value;
            var wideEnough    = this.RequiredWidth.HasValue == false || currentWidth >= this.RequiredWidth.Value;

            if (tallEnough && wideEnough)
            {
                if (tooSmallLifetime != null || initialCheck)
                {
                    tooSmallLifetime?.Dispose();
                    RequiredSizeMet.Fire();
                }
            }

            else if (tooSmallLifetime == null)
            {
                isKeyboardInputEnabled = false;
                RequiredSizeNotMet.Fire();
                tooSmallLifetime = new Lifetime();
                var mask = LayoutRoot.Add(new ConsolePanel()).Fill();
                mask.ZIndex = int.MaxValue;
                mask.Add(new Label()
                {
                    Text = "Increase the console window's size to view the app".ToYellow()
                }).CenterBoth();
                tooSmallLifetime.OnDisposed(() =>
                {
                    isKeyboardInputEnabled = true;
                    LayoutRoot.Controls.Remove(mask);
                    tooSmallLifetime = null;
                });
            }
        }
        private async Task ShowLogo()
        {
            Promise introPromise = null;

            await QueueAction(() =>
            {
                var logo     = LayoutRoot.Add(new PowerArgsGamesIntro()).CenterBoth();
                introPromise = logo.Play();
                introPromise.Then(() =>
                {
                    QueueAction(() => LayoutRoot.Controls.Remove(logo));
                });
            }).AsAwaitable();

            await introPromise.AsAwaitable();
        }
Exemplo n.º 9
0
        private void Link6_Click(object sender, RoutedEventArgs e)
        {
            if (floatChatReal == null)
            {
                initializeFloatChat();
            }
            else if (M.sock.isConnected == false)
            {
                lstOnlineUsers.Items.Clear(); startConnections();
            }
            else
            {
                floatChatReal.Position = new Point(200, 200);
            }


            LayoutRoot.Add(floatChatReal);
            floatChatReal.Show();
            imgBubble.Visibility = System.Windows.Visibility.Collapsed;
        }
Exemplo n.º 10
0
    protected override async Task Startup()
    {
        InitPause();
        var random = new Random(100);

        var camera = LayoutRoot.Add(new Camera()
        {
            BigBounds = new RectF(0, 0, 400, 400)
        }).Fill();

        camera.CameraLocation = camera.BigBounds.Center.ToRect(camera.Width, camera.Height).TopLeft;

        FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.W, null, () => DefaultColliderGroup.SpeedRatio = DefaultColliderGroup.SpeedRatio + .1f, this);
        FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.S, null, () => DefaultColliderGroup.SpeedRatio = Math.Max(0, DefaultColliderGroup.SpeedRatio - .1f), this);

        while (true)
        {
            var left = camera.Add(new ConsoleControl()
            {
                Width      = 5,
                Height     = 2,
                X          = ConsoleMath.Round(camera.BigBounds.Center.Left - 50),
                Y          = ConsoleMath.Round(camera.BigBounds.Center.Top),
                Background = new RGB((byte)random.Next(60, 120), (byte)random.Next(60, 120), (byte)random.Next(60, 120))
            });

            var right = camera.Add(new ConsoleControl()
            {
                Width      = 5,
                Height     = 2,
                X          = ConsoleMath.Round(camera.BigBounds.Center.Left + 50),
                Y          = ConsoleMath.Round(camera.BigBounds.Center.Top),
                Background = new RGB((byte)random.Next(60, 120), (byte)random.Next(60, 120), (byte)random.Next(60, 120))
            });

            await Task.WhenAll(left.FadeIn(delayProvider: DelayProvider), right.FadeIn(delayProvider: DelayProvider));

            var leftV = new Velocity2(left, DefaultColliderGroup)
            {
                Bounce = true
            };
            leftV.Speed = 90;
            leftV.Angle = Angle.Right;

            var rightV = new Velocity2(right, DefaultColliderGroup)
            {
                Bounce = true
            };
            rightV.Speed = 10;
            rightV.Angle = Angle.Left;

            FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.UpArrow, null, () =>
            {
                leftV.SpeedRatio = leftV.SpeedRatio + .1f;
            }, this);

            FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.DownArrow, null, () =>
            {
                leftV.SpeedRatio = Math.Max(0, leftV.SpeedRatio - .1f);
            }, this);

            await TaskEx.WhenAny(PauseManager.Delay(5000), leftV.ImpactOccurred.CreateNextFireTask());

            await Task.WhenAll(left.FadeOut(duration: 2000, delayProvider: DelayProvider), right.FadeOut(duration: 2000, delayProvider: DelayProvider));

            left.Dispose();
            right.Dispose();
        }
        camera.BigBounds = default;
    }
Exemplo n.º 11
0
        public LevelBuilder()
        {
            Cursor    = new Cursor();
            UndoStack = new UndoRedoStack();
            var topPanel = LayoutRoot.Add(new ConsolePanel()
            {
                Background = System.ConsoleColor.Black
            }).Fill(padding: new Thickness(0, 0, 0, 6));
            var botPanel = LayoutRoot.Add(new ConsolePanel()
            {
                Height = 6, Background = System.ConsoleColor.DarkRed
            }).DockToBottom().FillHoriontally();

            var borderPanel = topPanel.Add(new ConsolePanel()
            {
                Background = ConsoleColor.DarkGray, Width = LevelDefinition.Width + 2, Height = LevelDefinition.Height + 2
            }).CenterHorizontally().CenterVertically();

            ScenePanel = borderPanel.Add(new ScenePanel(LevelDefinition.Width, LevelDefinition.Height)).Fill(padding: new Thickness(1, 1, 1, 1));

            var sceneFPSLabel = LayoutRoot.Add(new Label()
            {
                Text = "".ToConsoleString()
            }).FillHoriontally();
            var renderFPSLabel = LayoutRoot.Add(new Label()
            {
                Y = 1, Text = "".ToConsoleString()
            }).FillHoriontally();
            var paintFPSLabel = LayoutRoot.Add(new Label()
            {
                Y = 2, Text = "".ToConsoleString()
            }).FillHoriontally();

            LifetimeManager.Manage(SetInterval(() =>
            {
                sceneFPSLabel.Text  = $"{ScenePanel.Scene.FPS} scene frames per second".ToCyan();
                renderFPSLabel.Text = $"{FPS} render frames per second".ToCyan();
                paintFPSLabel.Text  = $"{PPS} paint frames per second".ToCyan();
            }, TimeSpan.FromSeconds(1)));



            QueueAction(() =>
            {
                if (this.LevelId != null)
                {
                    LoadLevel(this.LevelId);
                }
                else
                {
                    CurrentLevelDefinition = new LevelDefinition();
                }

                PreviewScene.Start();
                SetupCursorKeyInput();
                SetupDropKeyInput();
                SetupSaveKeyInput();
            });

            PreviewScene.QueueAction(() =>
            {
                Cursor.Bounds.Resize(ScenePanel.PixelSize);
                PreviewScene.Add(Cursor);
            });
        }