How to make players interact on php? As an arena, for example, there are browser games in all games.

  • @chops, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky ♦
  • Thanks for the answer! I can not catch the logic, for example, there is a button "Submit a request for a fight", a player appears on the page that submitted it, and there is an opportunity to join him in the fight - that's OK. It is clear that for each battle you need to create an entry in the battle table with the fields id_battle, id_user-1, id_user2, etc. - chops
  • But how to start this fight? Generate some unique link? And how to determine that this link can only be used by these players. There is a thought for the time of the battle to generate some cookies identical for these players and add the same value to the table of the current battle. Plus, it is not very clear how to display the actions of one user on the screen of another, to update data from the database via AJAX every second? - chops
  • A fight is either a page to which both players are transferred (it is possible and automatically), or if they collide on the field, an event when the coordinates of the objects intersect. - Shilgen
  • Thanks for the answer again! The logic begins to emerge in the head. I recently studied php, in this example we are talking about the game "Sea Battle" multiplayer, maybe you should try the interaction of users on something more simple? - chops

1 answer 1

I will try to understand you: a browser game involves storing information about players, a certain card, and, suppose, players interact with each other, with static characters and, possibly, other objects of the virtual world — data is used for this, MySQL database has received the maximum distribution not a panacea.

In the modern approach to web development, Ajax technology is applicable - it will allow you to communicate with the server without reloading the page.

It was an introduction that prepared for the answer itself.

So, suppose: a virtual fight between two players: an entry is created in the battle table with the initial state of the players, the battle begins, strikes the enemy, the application of magic ... - an entry is made in the table "change the player's state during the battle" - we write down all we need the player’s state parameters during a certain battle (looking for how to link tables with keys), at the end of the battle we write the results into the battle table and update the “current warrior status” table (suppose that the player has more than one — then we create a separate table and key You connect them with each other) ...

The role of PHP is to receive POST requests from the client, process them on the server, update the database data, provide the necessary content from the current situation in the game, support the functionality of the site, take account of the local currency, interact with API payment systems ...

PS Php is clearly indicated in the question, but any server-side programming language will cope with this, watch out for the load.

UPD: during the entire use of the site store in the sessions id players, so you will avoid access to the battles to other players. Understand the events in js - click the mouse, press the key ... After each event during the battle for one player, send information about him, record if something has changed (all of a sudden - miss), and update to another once a second, to for example (because the second player can change his parameters), in order to make it imperceptible, do a lengthy animation for 2-3 seconds (while the server updates the information on the monitor screen).