S
S
squadbrodyaga2020-11-16 15:49:56
Node.js
squadbrodyaga, 2020-11-16 15:49:56

[Socket.io] How to receive data from two sockets and compare them to each other?

Hello.
In general, I'm doing "Rock, paper, scissors" on Socket.io and I want to learn how to compare
the answers sent by them with each other.

For example, each user has such a menu with a choice of stone, scissors or paper,
and their answers need to be somehow compared with each other, but how? Help me please.
5fb274e7f1129323179225.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twolegs, 2020-11-16
@twolegs

If you are making a game, then make it a rule to keep all the logic on the backend. The client cannot be trusted, so you need to compare on the back, the frontend should only receive the result of the action.

V
VegasChickiChicki, 2020-11-16
@VegasChickiChicki

Well, if you don’t think over some kind of “correct” logic / architecture, then something like this:
Add GameOptions to the room in the database, add the UserValues ​​object to the object, enter user values ​​there, when they change them, initially make them false for example. Next, on the back, when requesting a socket, we check our room, you must specify the room name + username + the value that he chose in the request. We look for a room, check if there is such a user in it, if so, we assign a value and compare it with the second one. Next, we make the answer to the front already with the result of the comparison.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question