Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be
on-topic
here, this one was resolved in a way less likely to help future readers.
Closed
9 years ago
.
I very much a noob so please forgive my scruffy confusing code. I am trying to make a game engine of my own for text based adventures with combat and such. here is the code:
import random
def drawBoard(board):
# This function prints out the board that it was passed.
# "board" is a list of 29 strings representing the board (ignore index 0)
print('|---+---+---+---+---+---+---|')
print('| | | | | | | |')
print('| ' + board[1] + ' | ' + board[2] + ' | ' + board[3] + ' | ' + board[4] + ' | ' + board[5] + ' | ' + board[6] + ' | ' + board[7] + ' | ')
print('| | | | | | | |')
print('|---+---+---+---+---+---+---|')
print('| | | | | | | |')
print('| ' + board[8] + ' | ' + board[9] + ' | ' + board[10] + ' | ' + board[11] + ' | ' + board[12] + ' | ' + board[13] + ' | ' + board[14] + ' | ')
print('| | | | | | | |')
print('|---+---+---+---+---+---+---|')
print('| | | | | | | |')
print('| ' + board[15] + ' | ' + board[16] + ' | ' + board[17] + ' | ' + board[18] + ' | ' + board[19] + ' | ' + board[20] + ' | ' + board[21] + ' | ')
print('| | | | | | | |')
print('|---+---+---+---+---+---+---|')
print('| | | | | | | |')
print('| ' + board[22] + ' | ' + board[23] + ' | ' + board[24] + ' | ' + board[25] + ' | ' + board[26] + ' | ' + board[27] + ' | ' + board[28] + ' | ')
print('| | | | | | | |')
print('|---+---+---+---+---+---+---|')
def whoGoesFirst():
if random.randint(0, 1) == 0: # coin flip 50/50 who starts combat
firstToSpawn = enemy
lastToSpawn = player
else:
firstToSpawn = player
lastToSpawn = enemy
# following chunk works out the spawn points of the first to enter
#and the last to enter, respectively. It then places them on the
#board in their respective spawn points, represented by their symbol
while firstToSpawn not in theBoard and lastToSpawn not in theBoard:
boardSpawn = '1 2 3 4 5 6 7 14 21 28 27 26 25 24 23 22 15 8'.split()
boardSpawnResult = random.choice(boardSpawn)
theBoard[int(boardSpawnResult)] = firstToSpawn
print(firstToSpawn + ' has entered the room.')
else:
if firstToSpawn in theBoard and lastToSpawn not in theBoard:
boardHalf = len(boardSpawn) / 2
boardHalf = int(boardHalf)
lastToSpawnPosition = int(boardSpawnResult) + boardHalf
if lastToSpawnPosition > len(boardSpawn):
lastToSpawnPosition = lastToSpawnPosition - len(boardSpawn)
lastToSpawnPosition = boardSpawn[lastToSpawnPosition]
theBoard[int(lastToSpawnPosition)] = lastToSpawn
print(lastToSpawn + ' has entered the room.')
if firstToSpawn == player:
playerLocale = int(boardSpawnResult)
global playerLocale
else:
playerLocale = int(lastToSpawnPosition)
global playerLocale
print(drawBoard(theBoard))
def shoot():
shotChance = int(playerStats[1]) - int(gangerStats[3])
didItHit = random.randint(int(shotChance), 100)
if didItHit < 65:
print(playerName + ' Missed the shot!')
elif didItHit >= 65:
didItCrit = random.randint(int(playerStats[5], 85))
if didItCrit >= 85:
shotDamage = 25 + weaponsGlock
print('Critical hit! ' + shotDamage)
else:
shotDamage = weaponsGlock
print(playerName + ' Hit the enemy for ' + shotDamage)
gangerStats[0] - shotDamage
if gangerStats[0] < 1:
print(playerName + ' killed the Ganger!')
#declaring globals and starting the program
while True:
theBoard = [' ']* 29
player = ' '
enemy = '!'
print('What\'s your name, Droog?')
playerName = input()
player = playerName[0].upper()
playerLocale = ' '
playerStats = '100 50 2 10 5 2'.split()
gangerStats = '65 20 1 5 3 5'.split()
weaponsGlock = 30
whoGoesFirst()
shoot()
while int(gangerStats[0]) > 0:
command = input('Type shoot to attack again:').lower
if command == 'shoot':
shoot()
else:
if int(gangerStats[0]) <= 0:
command = input('Type "searchbody" to loot dead enemies:').lower
The errors keep appearing for me in my shoot() function on the line where the randint is rolled for the didItCrit variable. Here's a copy of the error:
Traceback (most recent call last):
File "<string>", line 420, in run_nodebug
File "C:\Python33\practice programs\textAdventure\combatmodule.py", line 163, in <module>
shoot()
File "C:\Python33\practice programs\textAdventure\combatmodule.py", line 133, in shoot
didItCrit = random.randint(int(playerStats[5], 85))
ValueError: int() base must be >= 2 and <= 36
Any help would be massively appreciated.
–