Skip to content
Sign upLog in
← Back to Community

Python Console Game Template

Profile icon
Zimonze

This is a template for a simple console game in Python. It's best played using the repl.run link. The game might not work properly in this post.

The game is grid-based and every character represents one space. The player can be controlled using the arrow keys, and objects that the player can interact with can be placed on grid squares.

If you have any questions, you can ask me in the comments. This is my first post on Repl Talk, hopefully it's good.

Voters
Profile icon
KanishkThummala
Profile icon
Timgb11
Profile icon
WhoIsMatt
Profile icon
frissyn
Profile icon
Roar123
Profile icon
NarwhalFanatic
Profile icon
CodingCactus
Profile icon
AmazingMech2418
Profile icon
noodles37
Profile icon
python9160
Comments
hotnewtop
Profile icon
GregorySullivan

Thanks, I like it. I am searching for the Python console game template online and I am so glad I found your post. It is simple and easy to use. I want to make a casino game. I have also found a website with the help of this https://casinosanalyzer.com/online-casinos/best-payout link where I found an online real money game to get some idea. Now, I can easily make an online casino game.

Profile icon
Timgb11

Wow amazin! really good job

Profile icon
noodles37

u can put this is 'Share' forum. pretty cool tho!

Profile icon
CodingCactus

hi, cool. Please could you explain to me how you are detecting the key presses, I'm working on ASCII games (here and here) but I'm unsure about how to detect a key press.

Profile icon
Zimonze

@CodingCactus
I'm using sys.stdin to get input. If you have tty.setraw(sys.stdin), then ord(sys.stdin.read(1)) will give you a code as an integer that tells you what key is pressed. Arrow keys are slightly more complicated, since they're a sequence of 3 codes. I first learned this from here, but it's not a proper guide so I suggest looking into better documentation.

Profile icon
lynnlo

@Zimonze
@CodingCactus

You can also use bytes.decode(msvcrt.getch()) from the msvcrt lib.

It also easier because you can compare it to ascii characters.

a = bytes.decode(msvcrt.getch()) if a == 'w': #do something
Profile icon
CodingCactus

@tharlynnhtetong
ok, cool

Profile icon
JakubSkop

I prefer readchar

@CodingCactus