예제 #1
0
        void _menuWindow_BtnStart_Pressed(object sender, EventArgs e)
        {
            if (this._connection.State != ConnectionState.Connected)
            {
                MessageScene msg = new MessageScene();
                msg.SetText("Отсутствует подключение к серверу");
                this._gui.Screen.Desktop.Children.Add(msg);
                msg.BringToFront();
                return;
            }

            this._gui.Screen.Desktop.Children.Remove(this._gameWindow);

            Tuple <string, string, char> gameData = this._proxy.Call(s => s.CreateNewGame());

            if (string.IsNullOrWhiteSpace(gameData.Item1))
            {
                MessageScene msg;
                if (string.IsNullOrWhiteSpace(gameData.Item2))
                {
                    msg = new MessageScene();
                    msg.SetText("На сервере нет пользователей,\nчтобы с вами сыграть");
                }
                else
                {
                    msg = new MessageScene();
                    msg.SetText("Не удалось создать игру\nс игроком [" + gameData.Item2 + "]");
                }
                this._gui.Screen.Desktop.Children.Add(msg);
                msg.BringToFront();
                return;
            }

            if (string.IsNullOrWhiteSpace(gameData.Item2))
            {
                MessageScene msg = new MessageScene();
                msg.SetText("Не удалось получить\nимя противника в игре [" + gameData.Item1 + "]");
                this._gui.Screen.Desktop.Children.Add(msg);
                msg.BringToFront();
                return;
            }

            this.CurrentGameId    = gameData.Item1;
            this.CurrentEnemyNick = gameData.Item2;
            this.ShowGameWindow(gameData.Item3, true);
        }
예제 #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Perform second-stage initialization
            this._gui.Initialize();

            this._menuWindow = new MenuScene();
            this._menuWindow.BtnStart.Pressed    += _menuWindow_BtnStart_Pressed;
            this._menuWindow.BtnSaveNick.Pressed += (sender, e) =>
            {
                if (this._connection.State != ConnectionState.Connected)
                {
                    MessageScene msg = new MessageScene();
                    msg.SetText("Отсутствует подключение к серверу");
                    this._gui.Screen.Desktop.Children.Add(msg);
                    msg.BringToFront();
                    return;
                }

                if (!this._menuWindow.IsValidNick())
                {
                    MessageScene msg = new MessageScene();
                    msg.SetText(
                        "Имя игрока должно состоять из\nлатинских букв и цифр\nи иметь длину от 3 до 100 символов");
                    this._gui.Screen.Desktop.Children.Add(msg);
                    msg.BringToFront();
                    return;
                }

                this._proxy.Call(s => s.Connect(this._menuWindow.TbNickName.Text));
            };
            this._gui.Screen.Desktop.Children.Add(this._menuWindow);
            this._gui.Screen.FocusChanged += this._menuWindow.OnFocusChanged;
            this._menuWindow.BringToFront();

            //MessageScene msg = new MessageScene("fadggsgfsdhfdhdfhjsgjsjksksgkgksfkgg4234235623664");
            //this._gui.Screen.Desktop.Children.Add(msg);
            //msg.BringToFront();
            Task.Run(async() => await this._connection.Start());
        }
예제 #3
0
        public Game1()
        {
            // сначала наследуемые
            this.Window.AllowUserResizing  = true;
            this.Window.AllowAltF4         = true;
            this.Window.ClientSizeChanged += this.Window_ClientSizeChanged;
            this.IsMouseVisible            = true;
            this.Content.RootDirectory     = "Content";

            // объявленные нами
            this._graphicsDeviceManager = new GraphicsDeviceManager(this);
            this._backgroundColor       = Color.CornflowerBlue;
            this._inputManager          = new InputListenerComponent(this);

            // Then, we create GUI.
            this._inputService = new GuiInputService(_inputManager);
            this._gui          = new GuiManager(this.Services, this._inputService);

            // Create a GUI screen and attach it as a default to GuiManager.
            // That screen will also act as a root parent for every other control that we create.
            this._gui.Screen = new GuiScreen(1280, 1024);
            this._gui.Screen.Desktop.Bounds = new UniRectangle(
                new UniScalar(0f, 0),
                new UniScalar(0f, 0),
                new UniScalar(1f, 0),
                new UniScalar(1f, 0));

            /*BoxingViewportAdapter viewportAdapter =
             *  new BoxingViewportAdapter(this.Window, this.GraphicsDevice, 800, 480);
             * this._camera = new Camera2D(viewportAdapter);*/

            this._connection = new HubConnection("http://localhost:8080/signalr");
            this._connection.DeadlockErrorTimeout    = TimeSpan.FromSeconds(15);
            this._connection.TransportConnectTimeout = TimeSpan.FromSeconds(15);

            this._proxy = this._connection.CreateHubProxy("GlobalHub")
                          .AsHubProxy <IServerContract, IClientContract>();
            this._proxy.SubscribeOn <string>(
                c => c.OnShowMessage,
                s =>
            {
                MessageScene msg = new MessageScene();
                msg.SetText(s);
                this._gui.Screen.Desktop.Children.Add(msg);
                msg.BringToFront();
            });

            this._proxy.SubscribeOn <char>(
                c => c.OnCanDoStep,
                ch => this._gameWindow.AddNewChar(ch));

            this._proxy.SubscribeOn <string, string, char>(
                c => c.OnGameStarted,
                (gameId, enemyNick, startChar) =>
            {
                this.CurrentGameId    = gameId;
                this.CurrentEnemyNick = enemyNick;
                this.ShowGameWindow(startChar, false);
            });

            this._proxy.SubscribeOn <string, string>(
                c => c.OnGameFinished,
                (result, reason) =>
            {
                MessageScene msg = new MessageScene();
                msg.SetText(result + ":\n" + reason);
                this._gui.Screen.Desktop.Children.Add(msg);
                msg.BringToFront();
                this._gameWindow?.Close();
            });
        }