Online game - 1 vs 1 (IONIC 3 & ANGULAR 5) [closed]

0

Could someone give me some guidance on how to play online from my application?

I've been looking for things but I can not find something with which to consider something similar or something that comes close to what I want to do.

Basically it is a button that I want you to detect if someone is connected and to search among all the available users at that moment I that are not in game, and from there to do everything related to the games.

I have some points that above all are the ones I doubt most ...

- How do I detect if a user is active in my application? -How to detect if the user has disconnected in my application? -How do you get a button to search for an online game, with the users that are available? - How to contemplate that if a player is in game already so that, it does not appear in several games? (Although I think it's easier, if I manage to do all the steps above)

If someone can guide me a little I would be very helpful ... (My final goal is also to be able to upload the game created to Play Store), although I do not know if that will serve as useful information to help me

Thanks in advance!

    
asked by Daniel 16.04.2018 в 21:43
source

1 answer

1

in your db you could add a field: connected giving a 1 if it is connected and a 0 if not, the same, in the same field if the user is playing you place a 2 therefore if the connected user == 1 is possible Look for another game ... you know disconnected or playing. make a query to the db and know all those who have been connected == 1, that is in my case I would use ajax but all have their techniques, for example I do not work with angle 5 there must be a way, also in react there is another way ... therefore each time a user searches for a game you would have to do an asynchronic function using ajax to make a query on the bd and bring back the result of who is connected and who is not.

In my case the ajax json.html is already the complete list of all the users with the query already made that brings a table with which connected = 1 and you make an append to some div like this:

AJAX

   $("#buscarUsers").on("click", function() {
      var formData = new FormData();
      $.ajax({
        type: "POST",
        url: "api/buscar_usuarios",
        contentType: false,
        processData: false,
        data: formData,
        success: function(json) {
          if (json.success == 1) {
          $('#algundiv').append(json.html);
          } else {
            msg_box_alert(json.success, "Error", json.message);
          }
        },
        error: function(xhr, status) {
          msg_box_alert(99, "Error", xhr.responseText);
        }
      });
    });
    
answered by 16.04.2018 / 22:15
source