Lol DM that code was terrible.
Here is the most updated version of that text RPG I was making, and had to postpone due to personal reasons:
import random
MAP1 = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
[1, 7, 0, 0, 0, 2, 1, 6, 1, 3],
[1, 1, 2, 0, 0, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 0, 0, 2, 0, 1, 3],
[1, 0, 1, 1, 0, 0, 1, 0, 1, 3],
[1, 0, 0, 0, 0, 0, 0, 0, 1, 3],
[1, 0, 0, 2, 1, 0, 1, 1, 1, 3],
[1, 2, 0, 7, 1, 0, 0, 5, 1, 3],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 3]
]
MAP2 = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 3],
[1, 7, 0, 0, 0, 2, 1, 6, 1, 3],
[1, 1, 2, 0, 0, 0, 1, 0, 1, 3],
[1, 0, 1, 0, 0, 0, 2, 0, 1, 3],
[1, 0, 1, 1, 0, 0, 1, 0, 1, 3],
[1, 0, 0, 0, 0, 0, 0, 0, 1, 3],
[1, 0, 0, 2, 1, 0, 1, 1, 1, 3],
[1, 2, 0, 7, 1, 0, 0, 5, 1, 3],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 3]
]
class gameField:
def __init__(self, mapData=[0]):
self.mapData = mapData
self.string = ''
self.blocks = []
for i in range(len(self.mapData)):
for j in range(len(self.mapData[i])):
if self.mapData[i][j] == 2:
r = random.randrange(0, 4)+1
if r == 1:
self.blocks.append(' v ')
if r == 2:
self.blocks.append(' x ')
if r == 3:
self.blocks.append(' ^ ')
if r == 4:
self.blocks.append(' * ')
if r == 5:
self.blocks.append(' ~ ')
class character:
def __init__(self, x=0, y=0, field=None, startwep=None):
self.crds = [x, y] #crds = coordinates
self.x = self.crds[0]
self.y = self.crds[1]
self.field = field #This links the current playing field with the character. The purpose was to make is easy to manipulate the player's coordinates in reference to the current game field. field would be an instance of the gameField class.
self.inventory = {'Slot1':None, 'Slot2':None, 'Slot3':None, 'Equipped':None, 'Gold':0,}
self.hp = 100
self.inventory['Equipped'] = startwep
def __str__(self):
s = ''
r = 0
for i in range(len(self.field.mapData)):
for j in range(len(self.field.mapData[i])):
if self.field.mapData[i][j] == 4:
self.field.mapData[i][j] = 0
self.field.mapData[self.y][self.x] = 4
for i in range(len(self.field.mapData)):
for j in range(len(self.field.mapData[i])):
if self.field.mapData[i][j] == 0:
s += ' '
elif self.field.mapData[i][j] == 1:
s += ' / '
elif self.field.mapData[i][j] == 2:
r += 1
s += self.field.blocks[r-1]
elif self.field.mapData[i][j] == 3:
s += '\n'
elif self.field.mapData[i][j] == 4:
s += ' O '
elif self.field.mapData[i][j] == 5:
s += ' S '
elif self.field.mapData[i][j] == 6:
s += '[/]'
elif self.field.mapData[i][j] == 7:
s += '{"}'
elif self.field.mapData[i][j] == 8:
s += '{_}'
self.field.string = s
return self.field.string
def isValidMove(self, move):
'''This method just checks to see if a desired move is valid.
The coordinates must be referenced backwards due to the way I use
lists of lists to store coordinates. It would actually be more
efficient if I converted the lists to tuples after instantiation.
Oh well.'''
if move == 'a':
if self.field.mapData[self.y][self.x - 1] != 0:
return False
if move == 'a':
if self.field.mapData[self.y][self.x - 1] == 0:
return True
if move == 'w':
if self.field.mapData[self.y - 1][self.x] != 0:
return False
if move == 'w':
if self.field.mapData[self.y - 1][self.x] == 0:
return True
if move == 's':
if self.field.mapData[self.y + 1][self.x] != 0:
return False
if move == 's':
if self.field.mapData[self.y + 1][self.x] == 0:
return True
if move == 'd':
if self.field.mapData[self.y][self.x + 1] != 0:
return False
if move == 'd':
if self.field.mapData[self.y][self.x + 1] == 0:
return True
class item:
def __init__(self, name='', drange=[1, 4], itype='', price=0):
self.name = name
self.drange = drange
self.itype = itype
self.price = price
def attackRoll(self):
#Ranges in the if comparisons are for hit/miss.
#Ranges of drange[0]-[1] are for the weapon's damage ranges.
if self.itype == 'Small':
if random.randrange(1, 12) > 1:
return random.randrange(self.drange[0], self.drange[1]+1)
else:
return 0
if self.itype == 'Medium':
if random.randrange(1, 9) > 1:
return random.randrange(self.drange[0], self.drange[1]+1)
else:
return 0
if self.itype == 'Large':
if random.randrange(1, 5) > 1:
return random.randrange(self.drange[0], self.drange[1]+1)
else:
return 0
class monster:
def __init__(self, name='', size=0, weapon=[0]):
self.size = size
self.name = name
if self.size == 0:
self.hp = 10
self.size = 'Small'
self.weapon = item('Small Claws', [1, 4], 'Small')
if self.size == 1:
self.hp = 20
self.size = 'Medium'
self.weapon = item('Fists', [2, 6], 'Medium')
if self.size == 2:
self.hp = 30
self.size = 'Large'
self.weapon = item('Maul', [1, 12], 'Large')
else:
self.hp = 10
self.size = 'Small'
#Allows to instantiate a monster holding a specific weapon. Will not fire if a specific weapon argument was not supplied.
if weapon[0] != 0:
self.weapon = item(weapon[0], weapon[1], weapon[2])
def battle(playerCharacter, battleLevel=1, enemy=None):
turn = random.randrange(0, 2) + 1
print('\n' + 'Battle Initiated.')
b = raw_input()
if battleLevel == 1 and enemy == None:
a = random.randrange(0, 2) + 1
if a == 1:
enemy = monster('Small Creature #1', 0, ['Small Claws', [1, 4], 'Small'])
if a == 2:
enemy = monster('Small Creature #2', 0, ['Sharp Claws', [2, 5], 'Small'])
while enemy.hp > 0 and playerCharacter.hp > 0:
print ('Player | ' + enemy.name)
if playerCharacter.hp == 100:
print (' ' + str(playerCharacter.hp) + ' | ' + str(enemy.hp))
else:
print (' ' + str(playerCharacter.hp) + ' | ' + str(enemy.hp))
print (' o | x')
print ('')
if turn == 1:
print ('The enemy is attacking you! (press enter)')
b = raw_input()
attackRoll = enemy.weapon.attackRoll()
playerCharacter.hp -= attackRoll
print ('The enemy hit you with its ' + enemy.weapon.name + ' dealing ' + str(attackRoll) + ' damage! (press enter)')
b = raw_input()
if enemy.hp <= 0:
print ('You have been defeated by the ' + enemy.name + '! (press enter)')
b = raw_input()
turn = 2
elif turn == 2:
print ('It is your turn to fight! Press enter to attack!')
b = raw_input()
if playerCharacter.inventory['Equipped'] != None:
attackRoll = playerCharacter.inventory['Equipped'].attackRoll()
else:
attackRoll = 1
enemy.hp -= attackRoll
if playerCharacter.inventory['Equipped'] != None:
print ('You hit the enemy with your ' + playerCharacter.inventory['Equipped'].name + ' dealing ' + str(attackRoll) + ' damage! (press enter)')
else:
print ('You hit the enemy with your fists dealing 1 damage!')
b = raw_input()
if enemy.hp <= 0:
print ('You have defeated the ' + enemy.name + '! (press enter)')
b = raw_input()
return enemy.size
turn = 1
else:
return
def battleTreasure(val, currentPlayer):
diceRoll1 = random.randrange(0, 20) + 1
diceRoll2 = random.randrange(0, 5) + 1
if val == 'Small' and diceRoll1 < 15:
currentPlayer.inventory['Gold'] += diceRoll2
print('You gained ' + str(diceRoll2) + ' gold from winning the battle!')
b = raw_input()
print('You now have ' + str(currentPlayer.inventory['Gold']) + ' gold.')
b = raw_input()
http://cecilsunkure.blogspot.com/2010/04/mini-rpg-just-started.htmlhttp://cecilsunkure.blogspot.com/2010/05/mini-rpg-continued.htmlI had plans to add in armor, any other types of items I wanted, and lots more rooms, NPC characters, and possibly an ability to load a .txt file with a pre-configured map layout. Although since I'm grounded and trying to get to college I can't work on things like this anymore.
None.