C
C#2y ago
Milenov

❔ Creating a multiplayer Snake game WPF, Blazor, SignalR

Hello guys! I'm in a hole and can't seem to do anything right at the time and since i don't have much more time, i'm asking for some help with this. Please take a look at the code and i'll get you on my ideas. https://github.com/rmilenov/Snake.git
GitHub
GitHub - rmilenov/Snake
Contribute to rmilenov/Snake development by creating an account on GitHub.
41 Replies
Milenov
MilenovOP2y ago
So basically the game is running well for a single player. It still need a decent menu a Multiplayer Class and finally a Server to handle the communication between the client. Prefferably launched on an actual WebServer not locally
RiA
RiA2y ago
it's too big a question to ask. i can summarize your possible approach to a few points. 1. set up a server that can correlate all the player's positions and actions 2. set up a communication system (SignalR or something, maybe even code your own) 3. change any method that makes updates to the players in the game to one that can receive input from the server.
Insire
Insire2y ago
so, you basically are trying to recruit ppl for your project?
Milenov
MilenovOP2y ago
I'm asking for a fresh set of eyes cause i can't seem to get what to do next i have a major block in my head
Insire
Insire2y ago
since this is going to be multiplayer, you are going to rewrite the entire thing anyway the game logic has to run on your server and not a client the client just renders the data received from the server and sends its input to the server also, you most likely have to figure out a way to enable clients/player to find a match - or even the server so, now is probably a good time to take a break and a step back and figure out what things/workflows/user stories you need and how you are going to implement them
Milenov
MilenovOP2y ago
did you had a look on what i have so far ?
Insire
Insire2y ago
briefly
Milenov
MilenovOP2y ago
ok well it's my first so advanced project i didn't have anything to do with networking in code until i got this so basically you think i should get models and control on the server?
Insire
Insire2y ago
yes, because the alternative would be to have that on each client and how are you going to synchronize that? is everyone going to wait for the slowest network connection? what if a player disconnects?
Milenov
MilenovOP2y ago
well it is pretty simple game i think i would only need to pass the snake array
Insire
Insire2y ago
it doesnt matter what you need to pass what if you got 5 players with 5 different arrays? who is right?
Milenov
MilenovOP2y ago
i will only allow 2 so the network speed shouldn't be an issue but you're wright it only seems logical to have it on the server
Insire
Insire2y ago
the amount doesnt matter, its more than 1
Milenov
MilenovOP2y ago
ok starting small first step should be to get the server up and running and connect a single client
Insire
Insire2y ago
well, you should think about what to use for what
Milenov
MilenovOP2y ago
Blazor should to the trick right ?
Insire
Insire2y ago
blazor is web dev you got a wpf app there so not web dev
Milenov
MilenovOP2y ago
please excuse my ignorance i'm really new to this 🙂
Insire
Insire2y ago
not sure what your plan there is
Milenov
MilenovOP2y ago
what would you suggest ?
Insire
Insire2y ago
decide on one not both
Milenov
MilenovOP2y ago
wpf definitely
Insire
Insire2y ago
if you want your server to use c#, then asp.net core will be your server framework and then you get to decide how to communicate with that, http/rest requests and/or something real time communication like signalr or grpc
Milenov
MilenovOP2y ago
i would think SignalR should suffice
Insire
Insire2y ago
in any case, you are going to need error handling
Milenov
MilenovOP2y ago
if it's good for a chat programm should be enought for my purpose as well
Insire
Insire2y ago
and fault tollerance/retry logic and as i mentioned before, you will have to figure out how your clients will find the server and find a game session and if you ever want to actually release this project, how ppl are going to get a server. will you provide one? will they need to setup one? will a player/client be a server and so on
Milenov
MilenovOP2y ago
well i'm thinking my own server and the player is a client the server will be hardcoded for the purpose of the project
Insire
Insire2y ago
then you need some hosting somewhere
Milenov
MilenovOP2y ago
but i can test it on virtual maschine on my own pc right ?
Insire
Insire2y ago
i mean sure, but you will encounter an entirely different case of problems, once the server is deployed the kind you'll never get on a local machine
Milenov
MilenovOP2y ago
Makes sence How about Docker?
Insire
Insire2y ago
thats a nice to have, doesnt change the fundamental problem
Milenov
MilenovOP2y ago
I‘ll google around for hosting when i get home Do you have the time to kind of tutor me about it?
Insire
Insire2y ago
i dont tutor if you got questions that google cant answer, you'll get plenty of help around here, if you show what you got troubles with
Milenov
MilenovOP2y ago
Will do 🙂 @RiA do you have some thoughts for me as well 🙂
RiA
RiA2y ago
i suppose you can set up a temporary system that delays all requests sent by (n + random) ms, to simulate network latency and jitter same for the recieve side
Milenov
MilenovOP2y ago
damn the glitch in my head ist massive i suppose i need to start from scratch i'm taking the MVVM Pattern Models: Snake, Grid, Food,Images, Sound Views:Singleplayer, Multiplayer, MainMenu ViewModels: GameState,Direction, Position That would be the Main project I'm not sure about the server. it should initialize the multiplayer. So one Listener always open. If a player starts a multiplayer another listener starts connects to the client creating a multiplayer and waits for another client connection. So the other client needs to be able to select the created game once 2 players are connected the created game ist no longer visible for other clients and the two players are connected p2p does it make sence that way?
Uchuu
Uchuu2y ago
Server: This is where your snake array actually lives. All actual game mechanics should be calculated here. In my opinion, the server should not know the client exists. Client: This is where your players play the game. All the client does is sends data to the server and receives data from the server. In my opinion, the client should not know that the server exists. API: This is the layer that connects the server and the client and is generally an abstraction over your server's chosen connectivity choice, whether it be a web API or real-time framework like GRPC. This is how you will ensure the client and the server don't exactly know about each other, but can be trusted to communicate in a standard way. You do not need to think about an exact schematic for every specific function of how this will work just yet. I strongly recommend you have these three concepts in mind and just start programming!
Insire
Insire2y ago
and ignore MVVM for now, you can refactor later, once your code works
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server