Help wth None glitch. Whenever I click a button (rock, paper or scissors) it's meant to change the self.player; self.ruling and self.computer variables. Please help fix this.
Thanks in advance!
Here's the code:
# coding: utf-8
from scene import *
import random
choices = '🌚', '📄', '✂️'
class rps(Scene):
def __init__(self):
self.player = None
self.ruling = None
self.computer = None
def setup(self):
self.button = Button(Rect(self.size.w/2-60, self.size.h/1-150, 125, 125))
self.button.background = Color(0,0,0,0)
self.button.stroke = Color(0,0,0,0)
self.button.image = 'Moon_2'
self.button.action = self.rock_action
self.add_layer(self.button)
self.button1 = Button(Rect(self.size.w/2-60, self.size.h/1-290, 125, 125))
self.button1.background = Color(0,0,0,0)
self.button1.stroke = Color(0,0,0,0)
self.button1.image = 'Page_Facing_Up'
self.button1.action = self.paper_action
self.add_layer(self.button1)
self.button2 = Button(Rect(self.size.w/2-60, self.size.h/1-450, 125, 125))
self.button2.background = Color(0,0,0,0)
self.button2.stroke = Color(0,0,0,0)
self.button2.image = 'Scissors'
self.button2.action = self.scissors_action
self.add_layer(self.button2)
def rock_action(self):
self.button.background = Color(0,0,0,0)
self.player = '🌚'
self.computer = random.choice(choices)
run(ending())
def paper_action(self):
self.button1.background = Color(0,0,0,0)
self.player = '📄'
self.computer = random.choice(choices)
run(ending())
def scissors_action(self):
self.button2.background = Color(0,0,0,0)
self.player = '✂️'
self.computer = random.choice(choices)
run(ending())
def get_ruling(player_choice, opponent_choice):
if player_choice == opponent_choice:
return "Draw"
elif player_choice == '🌚':
return 'Win' if opponent_choice == '✂️' else 'Lose'
elif player_choice == '📄':
return 'Win' if opponent_choice == '🌚' else 'Lose'
else: # player_choice == '✂️'
return 'Win' if opponent_choice == '📄' else 'Lose'
def draw(self):
background(0, 0.05, 0.2)
self.root_layer.update(self.dt)
self.root_layer.draw()
if self.player == "🌚" and self.computer == "🌚":
self.ruling = "Draw"
if self.player == "✂️" and self.computer == "✂️":
self.ruling = "Draw"
if self.player == "📄" and self.computer == "📄":
self.ruling = "Draw"
if self.player == "🌚" and self.computer == "✂️":
self.ruling = "Win"
if self.player == "🌚" and self.computer == "📄":
self.ruling = "Lose"
if self.player == "📄" and self.computer == "🌚":
self.ruling = "Win"
if self.player == "📄" and self.computer == "✂️":
self.ruling = "Lose"
if self.player == "✂️" and self.computer == "🌚":
self.ruling = "Lose"
if self.player == "✂️" and self.computer == "📄":
self.ruling = "Win"
global pp
global cc
global rr
pp = self.player
cc = self.computer
rr = self.ruling
class ending(Scene):
def setup(self):
self.next = Button(Rect(self.size.w/2+77, self.size.h/1-480, 80, 40), 'Next')
self.next.background = Color(1,1,1)
self.next.stroke = Color(1,1,1)
self.next.action = self.next_action
self.add_layer(self.next)
def next_action(self):
self.next.background = Color(1,1,1)
self.player = '🌚'
self.computer = random.choice(choices)
run(rps(), PORTRAIT)
def draw(self):
background(0,0.05,0.2)
tint(1,1,1)
text('\nYou {}!\n\n\n\n'.format(rr, pp, cc), x=self.size.w/3+50, y=self.size.h/5*3+20, font_size=60)
text('\n\n\n\nYou chose:\n{}\n\nComputer chose:\n{}'.format(rr, pp, cc), x=self.size.w/3+29, y=self.size.h/5*3, font_size=35)
self.next.draw()
run(rps(), PORTRAIT)