Building a web game
Posted by BigTimberFGC@reddit | Python | View on Reddit | 19 comments
Hey everyone, I'm a physical game developer looking to port our card game to a website format. I know surface level python and Javascript, but was wondering what the recommended framework would be for getting started.
This will be my first proper app, so any tips in any direction is appreciated!
Python-ModTeam@reddit
Hi there, from the /r/Python mods.
We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.
The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.
On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.
Warm regards, and best of luck with your Pythoneering!
Trang0ul@reddit
Make sure all the actions are performed server-side, and the front-end is just a dumb client. Otherwise expect rampant cheating.
AlSweigart@reddit
Also keep in mind what information you're sending to clients. Even if the client can't dictate, say, the playing cards that are in their hand, if you send out the data for everyone's playing cards, they'll be able to cheat and view that data even if the client program only shows them their own cards.
SwampFalc@reddit
Or embrace it, depends on the game.
Trang0ul@reddit
That's another valid option, but it should be the developer's conscious decision rather than negligence/laziness. In case of most web games, it's sadly the latter...
Savings-Most-3995@reddit
abbit hole I needed today
snugar_i@reddit
You can get away with JavaScript/TypeScript both on the frontend and the backend, if you don't want to split your attention between two languages.
Otherwise, if you want more useful advice, you should provide a bit more information - what do you want to build? What is the physical card game?
BigTimberFGC@reddit (OP)
It's a trading card game. Think Magic: The Gathering, Pokémon, Yugioh, etc.
Will have complex interactions and gameplay mechanics that all have nuances and would require a very robust foundation.
Would also need a database of some variety to handle card creation, user accounts, inventory, achievements, currency, etc
snugar_i@reddit
You'll definitely want to have all game logic on the server and the client be "dumb". The real challenge is then to make the game feel responsive enough and not like Magic Arena with its "Waiting for server", "Connection lost" and other BS.
Also try to separate the game logic from the rest so that it's easier to test and change.
Nater5000@reddit
This is a very broad question, and I concur with u/nicholashairs that you should probably ask r/learnpython
But, generally speaking, how you approach this will depend a lot on the scope of the project. Based on what you said, your best bet is to start with something pretty simple/low-level, get a working prototype in order, then re-evaluate your options and start-over with what you've learned.
If that seems reasonable, then my suggestion would be to focus on a building a basic REST API which handles the game interactions then build a front-end which basically works more like a website rather than a game. You may not be able to build the kind of game you're targeting, but this approach will let you touch everything, get a lay of the land, and operate fast enough that you can toss the whole thing and focus on the more complex technologies you may need to actually build your game.
In Python, you could do this with something like FastAPI. You'd need to back this with some sort of database, like Postgres (although a very simple prototype may just use SQLite). You'd likely want to use SQLAlchemy as an ORM to handle the database interactions. Ideally, you'd also use Pydantic for data modeling, but that might be overkill at this point. Your goal would be to build a backend that is logical, scalable, and can be operated against entirely programmatically.
From there, the front-end is just an interface for the backend. I'd pick the simplest front-end framework you're willing to use and just go nuts with it. I'm partial to React (which isn't particularly simple), but there's a lot of good, modern options you can choose from. I'd avoid building things without this kind of framework. It's possible (and not too hard), but it quickly becomes unwieldy, so it's just worth doing it "right" from the start. Similarly, I'd avoid using JS game framework to start (like Phaser), since that it a whole other ball game.
Again, start simple, and just make something that resembles the kind of game you want to make. Don't try to force the technology to do stuff it isn't designed to do. Instead, just keep moving forward until you're satisfied with it and restart. Luckily, card games are usually simple enough that the approach I described should get you pretty far (i.e., turned based, simple interfaces, etc.).
Once you have that in-place, you can start exploring more complex stuff that may be required to actually build the game you want. This will likely lead you to exploring websockets (which FastAPI can still help you with), different kinds of databases like NoSQL such as MongoDB or even in-memory key-value databases like Redis, more appropriate front-end libraries (like Phaser), etc. You might even decide to move into a more proper game engine like Godot (which I'd recommend) which can still interact with a Python backend if you decide that's an appropriate approach.
BigTimberFGC@reddit (OP)
I'm glad you went in depth on this, thank you! I will be researching this today
wh33t@reddit
I suggest Godot.
KitAndKat@reddit
More than half the world is on phones, not lap/desktops, these days, so if your game has any chance of fitting onto a smaller screen, you should think in terms of a cross-platform tool. I used Flutter for a game. It uses Dart as the language. I have a C++/Python background, but it was not hard to pick up. The weirdest thing is that the language and the UI are intertwined; it's kinda neat once you grok it.
nicholashairs@reddit
You'll likely be better off asking in r/learnpython 🙂
BigTimberFGC@reddit (OP)
Will do! Thanks
Fluid_Opportunity161@reddit
For a web game, I think Python really isn't the right choice here in most cases. Will the game logic run entirely on the client or does it require a server?
sys_exit_0@reddit
Game or web3game ?
riklaunim@reddit
The key question will be the UI. Simple card game visuals can easily be done with rather simple CSS/JS while anything much more fancy would require some more complex animations, maybe a canvas or more. Then actual game apps can be run via web browser using webassembly and/or porting to webGL/webGPU
HoneydewPretty1712@reddit
I know a lot of people here aren't too fond of this, but if I were you I'd go with Claude Code. With it you can put together a prototype in hours — a couple of days at most — and keep building on it from there. I recently did this with remakes of two of my old games. One was originally written in Python, the other in Haxe. Now they're both written in TypeScript, which I don't know — https://caterpillar.games. The fact that you've done programming before will really help you when it comes to framing the tasks.