Exemplo n.º 1
0
        public LoadingPage(int width, int height, int bomb, GraphicalPage prevPage) : this()
        {
            _prevPage = prevPage;

            Task.Run(() =>
            {
                // host - only host is able to customize the game
                var queue = GetQueue();
                int id    = GetCurrentGlobalGameID();
                var text  = _drawingObjects[0] = new Button($"Your game id is: {id}")
                {
                    HorizontalAlign = 0.05f,
                    VerticalAlign   = 0.05f,
                    BorderColor     = Constants.BACKGROUND_COLOR
                };

                text.AlignHorizontally();
                text.AlignVertically();

                // get settings and also upload new settings too
                queue.Add(id);

                GameSettings settings = new GameSettings(width, height, bomb, id);
                Upload(queue, id, settings.ToJsonString());
                _settings = settings;
            });
        }
Exemplo n.º 2
0
 /// <summary>
 /// Get multiplayer page but must be awaited because the main thread must not be blocked
 /// when multiplayer page is processing in this method
 /// </summary>
 /// <param name="mainMenuPage">Exit page from multiplayer page</param>
 /// <param name="role">Role of multiplayer connection</param>
 /// <returns>New multiplayer page</returns>
 public async Task <MultiplayerPage> GetMultiplayerPage(GraphicalPage mainMenuPage, MultiplayerRole role)
 => await Task.Run(() =>
 {
     while (_settings == null)
     {
     }
     var page = new MultiplayerPage(_settings)
     {
         PreviousPage = mainMenuPage
     };
     page.CreateConnection(role);
     return(page);
 });
Exemplo n.º 3
0
        public LoadingPage(GraphicalPage prevPage) : this()
        {
            _prevPage = prevPage;

            // guest
            Task.Run(() =>
            {
                var queue = GetQueue();
                if (queue.Count == 0)
                {
                    DisplayErrorMessage("There is currently no game queued. Please try again!");
                    return;
                }

                var randIdTask = GetRandomGameIDFromQueue(queue);
                randIdTask.Wait();
                int id = randIdTask.Result;

                var text = _drawingObjects[0] = new Button($"Your game id is: {id}")
                {
                    HorizontalAlign = 0.05f,
                    VerticalAlign   = 0.05f,
                    BorderColor     = Constants.BACKGROUND_COLOR
                };
                text.AlignHorizontally();
                text.AlignVertically();

                Upload(queue);

                // get the game information
                var task = Firebase.Get($"{Constants.GAMENAME}{id}/settings");
                if (!task.Wait(Constants.TIMEOUT))
                {
                    DisplayErrorMessage("Connection timed out. Please try again later!");
                }

                _settings = new GameSettings(task.Result, id);
            });
        }