-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathteam3.py
More file actions
283 lines (196 loc) · 7.47 KB
/
Copy pathteam3.py
File metadata and controls
283 lines (196 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import turtle as t
import random
import time
from tkinter import *
score = 0
life = 10 # 초기 점수와
# 기본 setting
player = t.Turtle() # 거북이 객체 생성
screen = t.Screen()
score_board = t.Turtle()
shape_list = ["turtle", "circle", "triangle", "square"] # 추가 : 캐릭터 모양 추가
player.shape(shape_list[0])
player.speed(0)
player.up()
screen = t.Screen()
screen.title("Catch Turtle") # 그래픽 창 이름 지정
screen.setup(500,500) # 창 크기 500*500으로 설정
#score_board = t.Turtle()
score_board.color("white") # 보드판 색깔 지정
score_board.goto(150,150)
location_list = [(0,200), (0,-200), (200,0), (-200,0)] # 거북이의 위치(위, 아래, 오른쪽, 왼쪽) 리스트로 생성
def show_message(up, down): # 메세지 출력
player.goto(0,200)
player.write(up, False, "center", ("Arial", 20, "bold"))
player.goto(0,-200)
player.write(down, False, "center", ("Arial",15, "normal"))
player.goto(0,0)
player.showturtle()
def start(): # 게임 시작
playing = True
player.clear()
playing = game_play(playing)
game_end(playing)
def game_play(playing): # 게임 진행 함수
global random_name # 모양 변수 추가
maximum = time.time() + 30
while playing:
global life
if time.time() > maximum or life <= 0:
playing = False
return playing
random_name = random.choice(shape_list) # 추가 : 모양 랜덤 지정
player.shape(random_name) # 추가 : 모양 지정
player.showturtle()
player.up()
location = random.choice(location_list)
player.goto(location)
sleep_time = random.uniform(1, 2)
time.sleep(sleep_time)
def game_end(playing): # 게임 종료 함수
global score
if not playing:
score_board.clear()
text = "Your Score : %d" % score
show_message("Game Over!", text)
# show_message("Insert coins!",text)
score = 0
def turn_up(): # 위쪽 방향키 함수
global score,life
if player.position() == (0.00, 200.00):
score = score + 1
print(player.shape())
player.settiltangle(-45) # 추가 : -45도 회전
player.hideturtle()
show_life(life)
else :
life = life - 1
show_life(life)
show_score(score)
show_life(life)
def turn_down(): # 아래쪽 방향키 함수
global score,life
if player.position() == (0.00, -200.00):
score = score + 1
print(player.shape())
player.settiltangle(45) # 추가 : 45도 회전
player.hideturtle()
show_life(life)
else:
life = life - 1
show_life(life)
show_score(score)
show_life(life)
def turn_left(): # 왼쪽 방향키 함수
global score,life
if player.position() == (-200.00, 0.00):
score = score + 1
print(player.shape())
player.settiltangle(90) # 추가 : 90도 회전
player.hideturtle()
show_life(life)
else:
life = life - 1
show_life(life)
show_score(score)
show_life(life)
def turn_right(): # 오른쪽 방향키 함수
global score,life # 추가
if player.position() == (200.00, 0.00):
score = score + 1
print(player.shape())
player.settiltangle(0) # 추가 : 머리 방향 그대로
player.hideturtle()
show_life(life)
else :
life = life - 1
show_life(life)
show_score(score)
show_life(life)
def show_score(score): # 점수 출력
score_board.clear()
score_board.color("white")
score_board.goto(150, 150)
score_board.pencolor("black")
score_board.write("Score : %d" % score, False, "left", ("Arial", 13, "bold"))
score_board.color("white")
def show_life(life): # 목습 출력
score_board.color("white")
score_board.goto(50, 150)
score_board.pencolor("red")
score_board.write("Life : %d" % life, False, "left", ("Arial", 13, "bold"))
score_board.color("white")
# ========================================================================= #
# main part
def main(): # 메인 함수 호출
screen.onkeypress(start, "space") # 스페이스 바를 누르면 start 함수 실행
screen.onkeypress(turn_right, "Right") # 오른쪽 키를 누르면 right 함수 실행
screen.onkeypress(turn_left, "Left")
screen.onkeypress(turn_up, "Up")
screen.onkeypress(turn_down, "Down")
screen.listen() # 이 명령어를 실행시켜야 키 입력모드가 실행되어 입력된 키에 반응
show_message("Let's Catch Turtles!", "[Press Space]") # 게임 시작하기 전 첫 화면
t.done()
# ========================================================================== #
# GUI part
root = Tk() # tikinter 객체 생성
root.title("Catch Turtle") # 창 이름
w,h = 1200,700
sw,sh = root.winfo_screenwidth(),root.winfo_screenheight()
x,y = (sw - w)/2 , (sh - h)/2
root.geometry("%dx%d+%d+%d"%(w,h,x,y)) # 창을 중앙으로 설정
photo = PhotoImage(file = "/Users/gim-wansig/Desktop/oss_project/oss_project/images (1).png",master = root) # image
label1 = Label(root,width = 450,height = 450,relief = "solid",borderwidth = 10,padx = 5, pady = 10,image = photo)
label1.pack()
def rule():
root = Tk()
root.title("Game Rules")
w,h = 600,300
sw,sh = root.winfo_screenwidth(),root.winfo_screenheight()
x,y = (sw - w) / 2, (sh-h)/2
root.geometry("%dx%d+%d+%d" %(w,h,x,y)) # 창을 중앙으로 설정
label2 = Label(root,relief = "solid",borderwidth = 10,padx = 5, pady = 10,text = " == 게임 규칙 ==")
label2.pack()
label3 = Label(root,text = "1: 제한 시간은 30초가 주어집니다.")
label3.pack()
label4 = Label(root,text = "2: 키보드의 방향키를 이용하여 조작합니다.")
label4.pack()
label5 = Label(root,text = "3: 거북이 or 원 or 삼각형 or 사각형 모양이 랜덤하게 출현합니다.")
label5.pack()
label6 = Label(root,text = "4: 캐릭터 방향과 키보드 방향이 일치시 1점 획득합니다.")
label6.pack()
label7 = Label(root,text = "5: 목숨은 10개이며, 다른 방향을 선택시 목숨이 -1되니 주의해주세요.")
label7.pack()
label8 = Label(root,text = "6: 집중력 100% 필수!!")
label8.pack()
chkbox1 = Checkbutton(root, text="규칙을 확인했습니다.")
chkbox1.deselect()
chkbox1.pack()
btn3 = btn1 = Button(root,padx = 5, pady= 10, text= "Start", command=main)
btn3.pack() # options button
btn0 = Button(root,width = 22,height = 3,padx = 5, pady= 10,text = "Game Start", command = rule,highlightcolor = "green")
btn0.pack() # start button
def option():
root2 = Tk()
root2.title("Options Window")
w,h= 500,100
sw,sh = root2.winfo_screenwidth(),root2.winfo_screenheight()
x,y = (sw-w)/2,(sh-h)/2
root2.geometry("%dx%d+%d+%d"%(w,h,x,y)) # 창을 중앙으로 설정
chkbox1 = Checkbutton(root2, text="score 나타내기")
chkbox1.select()
chkbox1.pack()
chkbox2 = Checkbutton(root2, text="키보드로 게임하기")
chkbox2.select()
chkbox2.pack()
chkbox3 = Checkbutton(root2, text="친구와 대결하기")
chkbox3.deselect()
chkbox3.pack()
btn1 = Button(root, width=18, height=3, padx=5, pady=10, text="Options", command=option)
btn1.pack() # options button
def exit(): # exit 함수
global root
root.destroy()
btn2 = Button(root, width=12, height=5, padx=5, pady=10, text="Exit", command=exit)
btn2.pack() # Game exit button
root.mainloop()