Hey guys,
Im starting to learn python for blender applications, and made this,
it works up until I define Rand (as in random choice for rock paper or scissors,)
can anyone help?
P.S. Sorry, its very disorganized! :o
import random
Name = raw_input ("Enter Name here: ")
print "Hello " + Name + "! I am a python script specialy designed for a game called rock paper scissors!"
answer = raw_input ("Do you want to play? : ")
if answer == ("yes"):
print "Okay! Lets play!"
PC = raw_input ("Choose rock, paper, or scissors: ")
rand = random.randint(1, 3) #1 means rock, 2 means paper, 3 means scissors
if PC == ("rock"):
if rand == ("1"):
print "Tie game!"
elif rand == ("2"):
print "Game lost!"
elif rand == ("3"):
print "Game Win!"
if PC == ("paper"):
if rand == ("2"):
print "Tie game!"
elif rand == ("3"):
print "Game lost!"
elif rand == ("1"):
print "Game Win!"
if PC == ("scissors"):
if rand == ("3"):
print "Tie game!"
elif rand == ("1"):
print "Game lost!"
elif rand == ("2"):
print "Game Win!"
else :
print "aww!"
import random
Name = raw_input ("Enter Name here: ")
print "Hello " + Name + "! I am a python script specialy designed for a game called rock paper scissors!"
answer = raw_input ("Do you want to play? : ")
if answer == ("yes"):
print "Okay! Lets play!"
PC = raw_input ("Choose rock, paper, or scissors: ")
rand = random.randint(1, 3) #1 means rock, 2 means paper, 3 means scissors
if PC == ("rock"):
if rand == (1):
print "Tie game!"
elif rand == 2:
print "Game lost!"
elif rand == 3:
print "Game Win!"
if PC == ("paper"):
if rand == 2:
print "Tie game!"
elif rand == 3:
print "Game lost!"
elif rand == 1:
print "Game Win!"
if PC == ("scissors"):
if rand == 3:
print "Tie game!"
elif rand == 1:
print "Game lost!"
elif rand == 2:
print "Game Win!"
else :
print "aww!"
also, I’d use a switch statement instead of all those ifs , but that’s juts me
it works in pywin32, but not blender 2.5 python window.
how do you get the input to work properly from blender ?
import random
Name = raw_input ("Enter Name here: ")
print "Hello " + Name + "! I am a python script specialy designed for a game called rock paper scissors!"
answer = raw_input ("Do you want to play? : ")
if answer == ("yes"):
print "Okay! Lets play!"
PC = raw_input ("Choose rock, paper, or scissors: ")
rand = random.randint(1, 3) #1 means rock, 2 means paper, 3 means scissors
if rand == 1:
print "I choose rock!"
if rand == 2:
print "I choose paper!"
if rand == 3:
print "I choose scissors!"
if PC == "rock":
if rand == 1:
print "Tie game!"
elif rand == 2:
print "Game lost!"
elif rand == 3:
print "Game Win!"
if PC == "paper":
if rand == 2:
print "Tie game!"
elif rand == 3:
print "Game lost!"
elif rand == 1:
print "Game Win!"
if PC == "scissors":
if rand == "3":
print "Tie game!"
elif rand == "1":
print "Game lost!"
elif rand == "2":
print "Game Win!"
else :
print "aww!"
Now, How do I restart the code, I can’t find any good recursion explanations?
Here is my rock paper scissors program. A bit more optimized, but it is just to give you an idea of whats out there:
############################################
# Rock paper scissors #
# a game (not created, but programed) #
# by Sunjay Varma - www.sunjay-varma.com #
############################################
import random
def RockPaperScissors():
# just some initialization stuff
print "Welcome to rock paper scissors.
Please type your choice when you are given your turn.
There are three choices:
1) Rock -or- r
2) Paper -or- p
3) Scissors -or- s
To quit, just press enter on your turn without typing anything (or type quit)
Start!
Score: CPU=0 Player=0"
playerscore, cpuscore = 0,0
playing = 1
while playing:
try:playermove = {'r':'rock', 'p':'paper', 's':'scissors'}[raw_input('
Human\'s turn: ').strip().lower()[0]]
except: playing = 0; continue
cpumove = random.choice(['rock', 'paper', 'scissors'])
print 'CPU\'s turn: '+cpumove
if playermove == cpumove:
print 'Tie!'
else:
judge = {('rock','paper'):False,('paper', 'scissors'):False,('scissors','rock'):False}
if not judge.get((playermove, cpumove), True):
cpuscore += 1
print 'Player lost!'
print 'CPU='+str(cpuscore)+' Player='+str(playerscore)
else:
playerscore += 1
print 'CPU lost!'
print 'CPU='+str(cpuscore)+' Player='+str(playerscore)
print 'Final scoring: '+'CPU='+str(cpuscore)+' Player='+str(playerscore)
print "
Thanks for playing!"
raw_input("Press <enter> to quit!")
RockPaperScissors()
That would take a little more effort. These scripts are no good for a real 3 dimensional program like Blender. Depending on how you do it, it can be very complicated or not.
It really depends.
Do you want it to be strictly 2D? Or do you want something fancy 3D?
I guess we could start 2D.
Just get a picture of all three parts and load (UV map) them onto planes.
Then we start making the basic logic. How much do you know about logic bricks and Game Engine Python?
The first step would be to show the mouse.
import Rasterizer; Rasterizer.showMouse(1)
Place that line in a new text document in the Blender Text Editor. Name the file showMouse.py and place it in the text field of a Python script controller.
Connect an Always sensor, with True level triggering off, to the controller.
Press “p” while hovering the mouse over the 3D view to play the game engine and see your mouse show!