This content originally appeared on DEV Community and was authored by Draculinio
A couple of days ago I was bored at home, nothing to do, so, I decided to stream in my youtube channel, just chill, some soft music and random code, no camera, no comments, just chill & python.
This is the stream:
But as soon as I started coding I realized that I wanted to do a game. And not any game. Lately I was playing a lot of ADOM, and was asking myself I would be able to do something like that, but in old school mode, to play this in the console (does not matter if it is windows or linux) like in the old and original Rogue or the old versions of ADOM
Another thing that I have to mention about this is that I am a devote Pythonist. My mantra is "Python is love and love is Python"
With that in mind I started to code while listening to cool and relaxing music live on youtube.
Some rules here:
- I will keep on coding without a real plan or schedule. I have A LOT of work in real life, a family and other hobbies.
- I love old school games, so I will attach the idea of ADOM, Rogue or Angband.
- Permadeath. YES, it is important and will be like that.
- About randomly generated dungeons: I think that there should be both things. Random dungeons and fixed ones.
As for the libraries, I know that there are some cool things like tcod but I will go with the old and lovely curses. I know that the libraries for windows and linux are different, but they are very similar so I only need to verify which os I am using.
First, I started by creating a character class:
import random
class Character:
def __init__(self, name, creature):
self.name = name
self.creature = creature #let's start with human or elf.
self.strength = 0
self.defense = 0
self.gold = 0
self.room = ''
def char_creator(self):
str_mod = {'h':5, 'e':3}
def_mod = {'h':4, 'e':3}
self.strength = random.randint(1,6) + str_mod[self.creature]
self.defense = random.randint(1,6) + def_mod[self.creature]
def char_info(self):
creatures = {'h':'Human', 'e':'Elf'} #maybe this may die.
return {'name': self.name, 'creature': creatures[self.creature], 'strength': self.strength, 'defense': self.defense}
Here I have a couple of questions.
- Should the player generator be part of the character class? for now, yes, will see. -** The player should know in which room he is? Or the room should contain the character, or both? This is a BIG BIG question**
Then, I created a first version of the enemy class (all this was in 2 hours in a live stream, don't ask for speed.
class Enemies:
def __init__(self, name, strength, defense):
self.name = name
self.strenght = strength
self.defense = defense
MY biggest question here for the future is if the character and enemies should be classes that inherit from a base class. I don't know.
Finaly, I made a room class:
import random
from enemies import Enemies
class Room:
def __init__(self, name, description, enemies) -> None:
self.name = name
self.description = description
#what kind of monsters can appear?
self.possible_enemies = enemies #this will have a list of possible monsters that can appear in a room
self.enemies = [] #this is getting weird...
def describe_room(self):
#TODO: show monsters in a better way
enemies = ''
for i in self.enemies:
enemies += i.name+' '
return {'name':self.name, 'description': self.description, 'enemies': enemies}
def create_enemies(self):
#we will do something better than this in the near future...
for i in self.possible_enemies:
#if random.randint(1,2) == 1: #a coin flip for appearance
if i == 'rat':
self.enemies.append(Enemies('Rat', 2,2))
Here a lot of magic will happen. For now, it is just a placement of the base code. But the room has a title, a description and some monsters that appear randomly.
The principal with the main loop is just putting all together and a little main loop with a couple of commands (I will change the commands with key presses soon)
from character import Character
from room import Room
import curses
screen = curses.initscr()
screen.addstr(0,20,'---GAMEEEEEE---')
screen.addstr(2,0,'Enter a name: ')
name = screen.getstr().decode('utf-8') #here it is XD
screen.refresh()
creature_type = ''
while creature_type not in ['h','e']:
screen.addstr(3,0,'What kind of creature do you want to be? (H-Human/E-Elf): ')
creature_type = screen.getkey().lower()
p = Character(name, creature_type)
p.char_creator()
room = Room('Inside your house', 'This is your house',['rat'])
room.create_enemies()
#For now, let's write here, in the future we will do it better
p.room = room
screen.erase()
screen.addstr(3,0,'Hello,'+p.char_info()['name']+' you are a ' +p.char_info()['creature'])
screen.refresh()
#we need a main loop...
command = ''
while command != 'exit':
screen.addstr(1,0,p.char_info()['name'])
screen.addstr(5,0, p.room.describe_room()['name'])
screen.addstr(20,0, 'Command: ')
command = screen.getstr().decode('utf-8')
screen.erase()
#for now I will write some simple commands here, and then I will move them
if command.lower() == 'describe':
screen.addstr(8,0, 'Description: '+p.room.describe_room()['description'])
screen.addstr(10,0, 'Enemies: '+p.room.describe_room()['enemies'])
if command.lower() == 'stats':
screen.addstr(8,0, 'Your stats: STR: '+ str(p.char_info()['strength'])+ ' DEF: '+str(p.char_info()['defense']))
curses.endwin()
print('Thank you for playing!')
I know that the actual code is TERRIBLE but, it was 2 hours of chill out and non stressful coding, and this will continue in that way.
If you want to see the repo: https://github.com/Draculinio/ChillGame
The second stream? Soon enough I wish.
This content originally appeared on DEV Community and was authored by Draculinio
Draculinio | Sciencx (2024-07-23T21:25:58+00:00) Making a Roguelike while chillin out part I. Retrieved from https://www.scien.cx/2024/07/23/making-a-roguelike-while-chillin-out-part-i/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.