Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » Chuck Norris Vs. Bruce Lee Python Game
- OrcaCat
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
I was bored and wanted to do something so I made this.
This was created 5/25/2013 in Python 2.7.
Feel free to edit the code or give me a suggestion.
FAQ
Q: I'm getting the error
A: You're using Python 3. Replace raw_input with input.
This was created 5/25/2013 in Python 2.7.
Feel free to edit the code or give me a suggestion.
# Update log # Added 2 player mode. AI is random. 5/25/13 '''Chuck Norris vs. Bruce Lee by OrcaCat AKA PiesAreSquared. Created 5/25/13''' def askplayer(): '''Asks which player the human wants to be''' ans = "" while ans != "1" and ans != "2": ans = raw_input("Would you like to play as\n1: Chuck Norris, or\n2: Bruce Lee?\n") if ans == "1": return ("norris", "lee") elif ans == "2": return ("lee", "norris") def askplayermode(): ans = "" while ans != "1" and ans != "2": ans = raw_input("Would you like to play\n1: 1 player, or\n2: 2 player?\n") if ans == "1": return "oneplayer" elif ans == "2": return "twoplayer" def askmove(player): ans = "" while ans != "1" and ans != "2" and ans != "3" and ans != "4": ans = raw_input(player + "'s move:\n1: kick\n2: punch\n3: defensive punch\n4: block\n") if ans == "1": return "kick" elif ans == "2": return "punch" elif ans == "3": return "defensive punch" elif ans == "4": return "block" def findmove(): rand = random.randrange(4) if rand == 0: return "kick" elif rand == 1: return "punch" elif rand == 2: return "defensive punch" elif rand == 3: return "block" def damage(attacker,defender,move): if move == "kick": defender.hp -= (attacker.attack/defender.defense)*10# lol attacker.attack and defender.defense attacker.attack -= 5 elif move == "punch": defender.hp -= (attacker.attack/defender.defense)*5 defender.defense -= 2 attacker.attack -= 2 elif move == "defensive punch": defender.hp -= (attacker.attack/defender.defense)*2 attacker.defense += 5 elif move == "block": attacker.defense += 10 attacker.attack += 4 class player: def __init__(self,hp,defense,attack): self.hp = hp self.defense = defense self.attack = attack import random '''Main''' norris = player(100.0,100.0,100.0) lee = player(100.0,100.0,100.0) print ("Welcome to Chuck Norris Vs. Bruce Lee. Norris goes first, but Lee sees what Norris does.\n\n") mode = askplayermode() if mode == "oneplayer": human,ai = askplayer() '''Main loop''' while norris.hp > 0 and lee.hp > 0: if mode == "twoplayer": move1 = askmove("Norris") move2 = askmove("Lee") elif mode == "oneplayer": if human == "norris": move1 = askmove("Norris") move2 = findmove() elif human == "lee": move1 = findmove() move2 = askmove("Lee") print ("\n\n\nChuck Norris used " + str(move1) +"!") print ("Bruce Lee used " + str(move2) +"!") damage(norris,lee,move1) damage(lee,norris,move2) print ("\n\n\nHP:\nNorris: " + str(norris.hp) + "\nLee: " + str(lee.hp)+ "\n\n\n") '''Finishing''' if norris.hp <= 0 and lee.hp <= 0: print ("Tie!") elif norris.hp <= 0: print ("Bruce Lee wins!") elif lee.hp <= 0: print ("Chuck Norris wins!") raw_input("Press the enter key to quit.")
Q: I'm getting the error
Traceback (most recent call last):
File "C:[b][/b]/Python3x/Chuck vs Lee.py", line 39, in <module>
move1 = askmove("Norris")
File "C:[b][/b]/Python3x/Chuck vs Lee.py", line 5, in askmove
ans = raw_input(player + "'s move:\n1: kick\n2: punch\n3: defensive punch\n4: block\n")
NameError: global name 'raw_input' is not defined
Last edited by OrcaCat (May 26, 2013 04:47:05)
- OrcaCat
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
It's made with python. Isn't this offtopic?
I'll request a move to TIMaC.
- davidkt
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
I like python too, but python's not scratch.
- OrcaCat
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
This is a game made with python, not scratch, so it either belongs here or in TIMaC. I like python too, but python's not scratch.
- ImagineIt
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
Traceback (most recent call last):
File "C:/Python33/Chuck vs Lee.py“, line 39, in <module>
move1 = askmove(”Norris“)
File ”C:/Python33/Chuck vs Lee.py“, line 5, in askmove
ans = raw_input(player + ”'s move:\n1: kick\n2: punch\n3: defensive punch\n4: block\n")
NameError: global name ‘raw_input’ is not defined
>>>
File "C:/Python33/Chuck vs Lee.py“, line 39, in <module>
move1 = askmove(”Norris“)
File ”C:/Python33/Chuck vs Lee.py“, line 5, in askmove
ans = raw_input(player + ”'s move:\n1: kick\n2: punch\n3: defensive punch\n4: block\n")
NameError: global name ‘raw_input’ is not defined
>>>
Last edited by ImagineIt (May 25, 2013 23:53:57)
- OrcaCat
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
You're using Python 3.3. This was made in 2.7. Replace all cases of raw_input with input. Traceback (most recent call last):
File "C:/Python33/Chuck vs Lee.py“, line 39, in <module>
move1 = askmove(”Norris“)
File ”C:/Python33/Chuck vs Lee.py“, line 5, in askmove
ans = raw_input(player + ”'s move:\n1: kick\n2: punch\n3: defensive punch\n4: block\n")
NameError: global name ‘raw_input’ is not defined
>>>
- OrcaCat
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
I just added 2 player mode, along with some code simplification.
LOL, I kicked so much that I actually healed the opponent when I attacked xD
LOL, I kicked so much that I actually healed the opponent when I attacked xD
Last edited by OrcaCat (May 26, 2013 04:57:10)
- OrcaCat
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
I'm revamping the code right now so it's more OOPy and easier to mod. I might need a little help.
- mythbusteranimator
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
Where can I run this if I don't have python
- OrcaCat
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
Where can I run this if I don't have pythonskulpt.org
- dantefrizzoli
-
100+ posts
Chuck Norris Vs. Bruce Lee Python Game
Where can I run this if I don't have python
I would just download a Python Virtual Machine and run it locally.
- pugluv4ever
-
100+ posts
Chuck Norris Vs. Bruce Lee Python Game
Cool! I'm learning python also. 

- OrcaCat
-
1000+ posts
Chuck Norris Vs. Bruce Lee Python Game
Right now, I'm revamping this with more OOP; this will make it easier to mod.
- mthom41
-
3 posts
Chuck Norris Vs. Bruce Lee Python Game
I made a simpler version of a battle game. I haven't learned about classes yet, so I used dictionaries and strings.
i didn't use any of your code, though.
#Hello World Battle
#By mthom41. My first python project
print ‘Hello, world!’
print ‘This is my first independent python program!’
print “So… let's play a little game.”
raw_input('Ready?')
plname = raw_input('your name?')
import random
player = {
‘name’ : plname,
‘HP’ : 100,
‘Atk’ : 5,
‘Def’ : 1
}
ai = {
‘name’ : ‘Z5000’,
‘HP’ : 100,
‘Atk’ : 8,
‘Def’ : 6
}
def make_move(x, attacker, defender):
if x == 1:
attacker += 1
return ‘Defend’
if x == 2:
defender = defender - (attacker - defender)
defender = defender - 1
if attacker > 2:
attacker = attacker - 1
return ‘Attack’
if x == 3:
attacker += 1
return ‘Poison’
def askmove(guy, other):
print ‘Moves: \n1> Defend \n2> Attack \n3> Poison’
move = int(raw_input('What do you want to do?(Type the number)'))
print ‘\n’, player, ‘used’, make_move(move, guy, other)
make_move(move, guy, other)
return move
def findmove(guy):
rnd = random.randrange(1, 4)
print guy, ‘used’, make_move(rnd, guy, player)
return make_move(rnd, guy, player)
#Main Loop
while player > 0 and ai > 0 :
askmove(player, ai)
findmove(ai)
print ‘\n’, player, ‘HP:’, player, ‘\nZ5000 HP: ’, ai, ‘\n’
#End Game
if player < 1:
print ‘\n\n’, player, ‘ was slain!!’
elif ai < 1:
print ‘\n\n’, ai, ‘ was slain!!’
i didn't use any of your code, though.
#Hello World Battle
#By mthom41. My first python project

print ‘Hello, world!’
print ‘This is my first independent python program!’
print “So… let's play a little game.”
raw_input('Ready?')
plname = raw_input('your name?')
import random
player = {
‘name’ : plname,
‘HP’ : 100,
‘Atk’ : 5,
‘Def’ : 1
}
ai = {
‘name’ : ‘Z5000’,
‘HP’ : 100,
‘Atk’ : 8,
‘Def’ : 6
}
def make_move(x, attacker, defender):
if x == 1:
attacker += 1
return ‘Defend’
if x == 2:
defender = defender - (attacker - defender)
defender = defender - 1
if attacker > 2:
attacker = attacker - 1
return ‘Attack’
if x == 3:
attacker += 1
return ‘Poison’
def askmove(guy, other):
print ‘Moves: \n1> Defend \n2> Attack \n3> Poison’
move = int(raw_input('What do you want to do?(Type the number)'))
print ‘\n’, player, ‘used’, make_move(move, guy, other)
make_move(move, guy, other)
return move
def findmove(guy):
rnd = random.randrange(1, 4)
print guy, ‘used’, make_move(rnd, guy, player)
return make_move(rnd, guy, player)
#Main Loop
while player > 0 and ai > 0 :
askmove(player, ai)
findmove(ai)
print ‘\n’, player, ‘HP:’, player, ‘\nZ5000 HP: ’, ai, ‘\n’
#End Game
if player < 1:
print ‘\n\n’, player, ‘ was slain!!’
elif ai < 1:
print ‘\n\n’, ai, ‘ was slain!!’
- mthom41
-
3 posts
Chuck Norris Vs. Bruce Lee Python Game
Woops. i did use you random # generator for the AI.
also, it didn't post it correctly. i have a bunch of stuff in square brackets.
also, it didn't post it correctly. i have a bunch of stuff in square brackets.
- Discussion Forums
- » Things I'm Making and Creating
-
» Chuck Norris Vs. Bruce Lee Python Game