Last night, all sleepy I made the third session of my "Chill & Python" live in youtube.
It is a space where I just chill out, put some music and code without any pressure or stress, just for the sake of it.
While doing this I decided to make a roguelike game that works on any console.
What is new since last time? I changed who is responsable for what. Sometimes is difficult to establish responsabilities between classes.
Now, the room class does not have enemies, but positions.
import random
class Room:
def __init__(self, name, description, enemies) -> None:
self.name = name
self.description = description
self.room_arch = [[0]*78 for _ in range(21)]
self.room_architecture()
def describe_room(self):
return {'name':self.name, 'description': self.description}
def room_architecture(self):
for i in range(0,21):
for j in range(0,78): #Hardcoded values, for now it will be ok...
self.room_arch[i][j]= random.randint(0,1) #for now, 2 values will be ok. 0 = empty, 1 = wall
This is the first step on creating dungeons, the most simply way to put stuff in the "room". Just random 0 and 1. If 0, then put an empty space, if 1, put a wall in the form of a #.
Now, enemies are not part of the room, enemies are enemies and we will see some day how to make that work, but for now, I can create an enemy in the principal file and give it a position in x and y. I also have a symbol and a code to send it.
import random
class Enemies:
def __init__(self, name, strength, defense, life, posx,posy,symbol):
self.name = name
self.strenght = strength
self.defense = defense
self.posx = posx
self.posy = posy
self.life = life
self.symbol = symbol
def initial_place(self, room):
found = False
while not found:
self.posx = random.randint(0,77)
self.posy = random.randint(0,21)
if room.room_arch[self.posy][self.posx] in [0]:
found = True
#TODO: the enemies should move every turn.
def move_enemy(self, room):
move = random.randint(1,4)
if move == 1:
if self.posx>1 and room.room_arch[self.posy][self.posx-1] in [0]:
self.posx -=1
if move == 2:
if self.posx>1 and room.room_arch[self.posy][self.posx+1] in [0]:
self.posx +=1
if move == 3:
if self.posx>1 and room.room_arch[self.posy-1][self.posx] in [0]:
self.posy -=1
if move == 4:
if self.posx>1 and room.room_arch[self.posy+1][self.posx] in [0]:
self.posy+=1
As you can see, not only the position but the movement is part of the enemy now. With that it is easier to manage all what happens in the game. Responsabilities are better now.
This is something terrible but is just basecode...
room.room_arch[enemy.posy][enemy.posx] = 0 #THE MOST HARDCODED THING ON EARTH
enemy.move_enemy(room)
room.room_arch[enemy.posy][enemy.posx] = enemy.symbol #Better...
Also sent the code of the user (2) to the room class Now it contains all the info of what is inside.
https://github.com/Draculinio/ChillGame
To be continued...
Top comments (0)