質問編集履歴
1
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
......... .......
|
test
CHANGED
@@ -1,207 +1 @@
|
|
1
|
-
__イタリックテキスト__###################################
|
2
|
-
|
3
|
-
##### ストレス発散ゲーム #####
|
4
|
-
|
5
|
-
|
1
|
+
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
import tkinter as tk
|
10
|
-
|
11
|
-
from tkinter import messagebox
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#ウインドウ
|
20
|
-
|
21
|
-
win = tk.Tk()
|
22
|
-
|
23
|
-
win.title("ストレス発散ゲーム!!何個崩せるかな??")
|
24
|
-
|
25
|
-
win.geometry("425x625")
|
26
|
-
|
27
|
-
win.resizable(False, False)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#キャンバス
|
32
|
-
|
33
|
-
can = tk.Canvas(bg="pink" , width=400, height=600)
|
34
|
-
|
35
|
-
can.place(x=10, y=10)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#ゲームオーバー
|
42
|
-
|
43
|
-
def gameOver():
|
44
|
-
|
45
|
-
messagebox.showinfo("ストレス発散ゲーム", "もう1回チャレンジだ!!")
|
46
|
-
|
47
|
-
exit()
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
#ゲームクリア
|
52
|
-
|
53
|
-
def gameClear():
|
54
|
-
|
55
|
-
messagebox.showinfo("ストレス発散ゲーム", "おめでとうございます!!君って天才?!")
|
56
|
-
|
57
|
-
exit()
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
#ボール
|
62
|
-
|
63
|
-
ball_x = 50; ball_y = 500; bx = 5; by = -5
|
64
|
-
|
65
|
-
def drawBall():
|
66
|
-
|
67
|
-
global ball_x, ball_y, bx, by
|
68
|
-
|
69
|
-
can.create_oval(ball_x, ball_y, ball_x+20, ball_y+20, fill="white")
|
70
|
-
|
71
|
-
if ball_x<=0 or ball_x>=385 :
|
72
|
-
|
73
|
-
bx *= -1
|
74
|
-
|
75
|
-
if ball_y<=0 :
|
76
|
-
|
77
|
-
by *= -1
|
78
|
-
|
79
|
-
if ball_y>=603 :
|
80
|
-
|
81
|
-
gameOver()
|
82
|
-
|
83
|
-
if ball_y>=560 and ball_x>=rack_x-10 and ball_x<=rack_x+50 :
|
84
|
-
|
85
|
-
by *= -1
|
86
|
-
|
87
|
-
ball_x += bx; ball_y += by
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
#ラケット
|
92
|
-
|
93
|
-
rack_x =170; keyPress_R = False; keyPress_L = False
|
94
|
-
|
95
|
-
def rightKeyPress(event):
|
96
|
-
|
97
|
-
global keyPress_R
|
98
|
-
|
99
|
-
keyPress_R = True
|
100
|
-
|
101
|
-
def rightKeyRelease(event):
|
102
|
-
|
103
|
-
global keyPress_R
|
104
|
-
|
105
|
-
keyPress_R = False
|
106
|
-
|
107
|
-
def leftKeyPress(event):
|
108
|
-
|
109
|
-
global keyPress_L
|
110
|
-
|
111
|
-
keyPress_L = True
|
112
|
-
|
113
|
-
def leftKeyRelease(event):
|
114
|
-
|
115
|
-
global keyPress_L
|
116
|
-
|
117
|
-
keyPress_L = False
|
118
|
-
|
119
|
-
win.bind("<KeyPress-Right>", rightKeyPress)
|
120
|
-
|
121
|
-
win.bind("<KeyRelease-Right>", rightKeyRelease)
|
122
|
-
|
123
|
-
win.bind("<KeyPress-Left>", leftKeyPress)
|
124
|
-
|
125
|
-
win.bind("<KeyRelease-Left>", leftKeyRelease)
|
126
|
-
|
127
|
-
def drawRacket():
|
128
|
-
|
129
|
-
global rack_x
|
130
|
-
|
131
|
-
can.create_rectangle(rack_x, 580, rack_x+60, 595, fill="white")
|
132
|
-
|
133
|
-
if keyPress_R==True and rack_x<=350:
|
134
|
-
|
135
|
-
rack_x += 5
|
136
|
-
|
137
|
-
if keyPress_L==True and rack_x>=-10:
|
138
|
-
|
139
|
-
rack_x -= 5
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
#ブロック
|
144
|
-
|
145
|
-
block = []
|
146
|
-
|
147
|
-
for x in range(5) :
|
148
|
-
|
149
|
-
for y in range(4) :
|
150
|
-
|
151
|
-
block.append({"x":x*80+5, "y":y*40+10, "st":1})
|
152
|
-
|
153
|
-
def drawBlock() :
|
154
|
-
|
155
|
-
global ball_x, ball_y, by
|
156
|
-
|
157
|
-
block_count = 0
|
158
|
-
|
159
|
-
for i in range(len(block)):
|
160
|
-
|
161
|
-
x = block[i]["x"]
|
162
|
-
|
163
|
-
y = block[i]["y"]
|
164
|
-
|
165
|
-
st = block[i]["st"]
|
166
|
-
|
167
|
-
if ball_y<=y+30 and ball_x>=x-10 and ball_x<=x+60 and st==1 :
|
168
|
-
|
169
|
-
by *= -1
|
170
|
-
|
171
|
-
block[i]["st"] = 0
|
172
|
-
|
173
|
-
if st==1 :
|
174
|
-
|
175
|
-
can.create_rectangle(x, y, x+70, y+30, fill="white")
|
176
|
-
|
177
|
-
block_count += 1
|
178
|
-
|
179
|
-
if block_count == 0:
|
180
|
-
|
181
|
-
gameClear()
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
#表示ループ
|
186
|
-
|
187
|
-
def gameLoop():
|
188
|
-
|
189
|
-
can.delete("all")
|
190
|
-
|
191
|
-
drawBall()
|
192
|
-
|
193
|
-
drawRacket()
|
194
|
-
|
195
|
-
drawBlock()
|
196
|
-
|
197
|
-
win.after(15, gameLoop)
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
gameLoop()
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
#ウインドウループ
|
206
|
-
|
207
|
-
win.mainloop()
|