Created
October 15, 2016 19:02
-
-
Save SpaceVoyager/cde408d36417250f74f5d447395b36a2 to your computer and use it in GitHub Desktop.
hangman.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scene import * | |
from ui import * | |
import speech | |
def is_point_inside_rect(point, rect): | |
x = rect[0] | |
y = rect[1] | |
w = rect[2] | |
h = rect[3] | |
if point.x >= x-w/2 and point.x <= x+w/2 and point.y >= y-h/2 and point.y <= y+h/2: | |
return True | |
else: | |
return False | |
class MyScene (Scene): | |
def setup(self): | |
self.background_color = 'white' | |
keyboard_font = ('Futura', 40) | |
letters = 'QWERTYUIOPASDFGHJKLZXCVBNM' | |
i = 0 | |
keyboard_y = 220 | |
key_height = 80 | |
key_width = 100 | |
for letter in letters: | |
x = i*(key_width+2)+ 54 | |
i += 1 | |
if i < 11: | |
y = keyboard_y | |
elif i < 20: | |
x = (i-11)*(key_width+2) + 104 | |
y = keyboard_y - key_height -2 | |
else: | |
y= keyboard_y-2*key_height-4 | |
x = (i-21)*(key_width+2) + 308 | |
self.button_rect = (x, y, key_width, key_height) | |
self.button_shape = ShapeNode(path=Path.rounded_rect(100, 250, self.button_rect[2], self.button_rect[3], 5), fill_color='blue', stroke_color='black', parent=self) | |
self.button_shape.position = (self.button_rect[0], self.button_rect[1]) | |
self.button_label = LabelNode(letter, keyboard_font, parent=self) | |
self.button_label.position = (self.button_rect[0], self.button_rect[1]) | |
self.button_label.color = 'white' | |
self.button_label.z_position = 1 | |
def touch_began(self, touch): | |
speech.say('you touched ') | |
if is_point_inside_rect(touch.location, self.button_rect): | |
speech.say(' inside button') | |
else: | |
speech.say('outside button') | |
run(MyScene()) | |
''' | |
def newgame(): | |
word = console.input_alert('Please enter a phrase you have in mind:') | |
return word | |
canvas.clear() | |
word = newgame() | |
font = 'Arial Rounded MT Bold' | |
canvas.draw_text(word, 50, 100, font_name=font, font_size=100) | |
word_len = len(word) | |
underscores = '' | |
for i in range(word_len): | |
underscores += '_ ' | |
canvas.draw_text(underscores, 0, 200, font_name=font, font_size=100) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment