Creating a game of ships with C#/ASP.NET
Hi!
I am completely new to ASP.NET and C#, and I have to write a project for a web application that will be a two-player Battleship game. It must use at least two of the following solutions:
• Lock/Mutex (thread synchronization).
• Semaphore (thread synchronization).
• Barrier (thread synchronization).
• Thread pools (thread management).
• Unit tests (minimum 80% code coverage).
• A responsive website that retrieves data using AJAX.
• Client-server communication using WebSocket.
Do you have any ideas on how to approach this, and is there anyone who could help me with this, at least minimally? The deadline is approaching, and unfortunately, I’m feeling increasingly lost with this project.
21 Replies
this is pretty big for a beginner, and you say the time is running low? have u any result yet?
Okay, I didn't specify. I have time for this until the end of the week. I usually coded in Python, but this one has to be in C#/ASP.NET. I also have other possible topics, but the Battleship game seemed relatively simple to me. Does any of the topics below seem simpler to you?
Web applications:
(a) A network-based Battleship game (minimum two players).
(b) An online betting system for races. In the background, the application must "simulate" real horse races, and betting should take place in real-time.
(c) Management of audio taxis, live information on vehicle locations, contact with the vehicle, gathering information about completed rides, etc. In the background, there should be a "simulation" of a vehicle fleet, without a map but with random travel times of the vehicles.
Phenomenon simulations:
(a) A wolf hunting hares grazing in a meadow, each animal is a separate thread.
(b) Any arcade game where opponents are separate threads.
(c) A simulation of several "Roomba" robots cleaning a house/building. Ideally, autonomous but able to communicate with each other.
network based battleship seems the most fun atleast. Do you already have some code? or you at 0% atm?
Im at 0% atm to be honest, just tried to watch some begginers vids about ASP.NET.
so what exactly is your expectation now? get help with the entire project? specific aspects of it? we can help, but i doubt anyone will write it for you.
None of these seem like small beginner projects tbh
No, of course, I wouldn’t even ask for that. I just want to find out which of these topics is the easiest for me as a beginner and what solutions I should use.
all of these are not simple to one sentence answers to "what solution to use"
more like... end of term project for a 2nd course
Unfortunately, my university thinks otherwise. I haven’t touched C#/C++ for 2 years, and now I have this project with such requirements.
• Lock/Mutex (thread synchronization).
• Semaphore (thread synchronization).
• Barrier (thread synchronization).
• Thread pools (thread management).
• Unit tests (minimum 80% code coverage).
• A responsive website that retrieves data using AJAX.
• Client-server communication using WebSocket.
What solutions from this
Well you can create websocket listening with ASP.NET core pretty easily, you gotta keep track of all connected, whether you have multiple rooms of players. earch room gotta probably rely on the same semaphore just for ease of use in a turn based context. then keep the game state on the server and on client modification send updates or state snippets back to clients of the same room/game.
you could pretty much do all communication over websocket, but if you need to throw some ajax into the mix, just do like the username setting at the start of joining a game/room over fetch/ajax.
I need to use 2 of this, not all of this
ah well then use websocket and semphore
it would go hand in hand for your game synchronization in a turn based context, and websocket is for your game communication between server and players
Thanks! There's a lot of work ahead of me, but surly I need to do it
https://learn.microsoft.com/de-de/aspnet/core/fundamentals/websockets?view=aspnetcore-8.0 here is a startup guide on how to get websockets running
WebSockets-Unterstützung in ASP.NET Core
Erfahren Sie, wie Sie mit WebSockets in ASP.NET beginnen.
Some would probably recommend something like SignalR but i never used it so cant recommend it, only raw dogged websockets.
for your general approach to the client handling, for simple purpose, just assign them unique ids, and add them to a dictionary. then their first message should just be hey my name is x, i want to create game or join a game code x, and from there you can sort them into game rooms/lobbies where the actual game logic is running etc etc
as its just a project and not actual production code, dont even bother with scaling that to multiple websocket servers with global house keeping. keep it simple and everything in the memory of that one monolith web app.
simplest for you to get fast at results, instead of sending updates if game state changes, just always sent the full game state to the client, and the client renders the newest state. This makes it harder to transition/animate between different things but thats out of scope anyways.
then every interaction players can make with the game by sending their action to the server, should be inside Semaphore wait and semaphore release, that way u just make sure there are no race conditions in your actual game logic on the server
on the frontend you know enough to get it running?
Yeah, I think so
okay do you need any specific advice on anything atm?
ah i accidently sent the german version, here english: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/websockets?view=aspnetcore-8.0
WebSockets support in ASP.NET Core
Learn how to get started with WebSockets in ASP.NET Core.
I think I'm alright at the moment, thank you for your help
good luck on that task tho