발로 만든 게임.ㅋㅋ
import turtle as t
import random as r
import tkinter as tk
from tkinter import messagebox
def nemo(w, h, c):
t.fillcolor(c)
t.begin_fill()
t.fd(w)
t.rt(90)
t.fd(h)
t.rt(90)
t.fd(w)
t.rt(90)
t.fd(h)
t.end_fill()
def button(x, y, b_c, msg):
t.pu()
t.goto(x, y)
t.seth(0)
nemo(b_w, b_h, b_c)
t.goto(x + b_w/2, y - b_h)
t.pencolor('white')
t.write(msg, align = 'center', font=("Arial", 30, "normal"))
b_w = 200; b_h = 60
rock_x = 300; rock_y = 200
scissors_x = 300; scissors_y = 300
paper_x = 300; paper_y = 100
q_x = 300; q_y = -200
c_x = -500; c_y = 300; p_x = -100; p_y = 300
t.speed(500)
win = t.Screen()
win.setup(1200, 800)
button(scissors_x, scissors_y, 'blue', 'Scissors')
button(rock_x, rock_y, 'blue', 'Rock')
button(paper_x, paper_y, 'blue', 'Paper')
button(q_x, q_y, 'black', 'QUIT')
button(c_x, c_y, 'red', 'Computer')
button(p_x, p_y, 'green', 'Player')
t.addshape('imgs/scissors.gif')
t.addshape('imgs/rock.gif')
t.addshape('imgs/paper.gif')
t.title("ORIEL")
com = t.Turtle('imgs/paper.gif')
player = t.Turtle('imgs/paper.gif')
com.pu(); player.pu()
com.goto(-400, 0); player.goto(0, 0)
t.pu()
t.goto(999,999)
pw = 0; p = 2
cw = 0; c = 2
def game(c, p):
global cw
global pw
if p == 0:
if c == 0:
com.shape('imgs/scissors.gif')
elif c == 1:
com.shape('imgs/rock.gif')
cw += 1
else:
com.shape('imgs/paper.gif')
pw += 1
elif p == 1:
if c == 0:
com.shape('imgs/scissors.gif')
pw += 1
elif c == 1:
com.shape('imgs/rock.gif')
else:
com.shape('imgs/paper.gif')
cw += 1
elif p == 2:
if c == 0:
com.shape('imgs/scissors.gif')
cw += 1
elif c == 1:
com.shape('imgs/rock.gif')
pw += 1
else:
com.shape('imgs/paper.gif')
if pw == 2 or cw == 2:
if pw == 2:
print("I won the game. {}:{}".format(pw, cw))
elif cw == 2:
print("I lost the game. {}:{}".format(pw, cw))
msg_box = tk.messagebox.askquestion('ORIEL', 'Do you want to continue?', icon='info')
if msg_box == 'yes':
pw=0; cw=0
else:
win.bye()
def check(x, y):
if(x >= rock_x and x <= rock_x+b_w and
y <= rock_y and y >= rock_y-b_h):
p = 1
player.shape('imgs/rock.gif')
c = r.randint(0, 2)
game(c, p)
elif(x >= scissors_x and x <= scissors_x+b_w and
y <= scissors_y and y >= scissors_y-b_h):
p = 0
player.shape('imgs/scissors.gif')
c = r.randint(0, 2)
game(c, p)
elif(x >= paper_x and x <= paper_x+b_w and
y <= paper_y and y >= paper_y-b_h):
p = 2
player.shape('imgs/paper.gif')
c = r.randint(0, 2)
game(c, p)
elif(x >= q_x and x <= q_x+b_w and
y <= q_y and y >= q_y-b_h):
win.bye()
else:
t.goto(999,999)
win.onclick(check)
t.done()