質問編集履歴
1
マークダウンにし、プログラムの動きなどを記述
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
###該当のソースコード
|
22
22
|
|
23
|
-
|
23
|
+
```lang-python
|
24
24
|
|
25
25
|
from PyQt5.QtCore import (QLineF, QPointF, QRectF, Qt)
|
26
26
|
|
@@ -44,6 +44,8 @@
|
|
44
44
|
|
45
45
|
super(TicTacToe, self).__init__()
|
46
46
|
|
47
|
+
#盤の情報記憶
|
48
|
+
|
47
49
|
self.board = [[-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
|
48
50
|
|
49
51
|
[-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[-1, -1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
|
@@ -72,7 +74,9 @@
|
|
72
74
|
|
73
75
|
self.now = self.kuro
|
74
76
|
|
77
|
+
|
78
|
+
|
75
|
-
|
79
|
+
#盤の情報を設定
|
76
80
|
|
77
81
|
def reset(self):
|
78
82
|
|
@@ -96,7 +100,9 @@
|
|
96
100
|
|
97
101
|
return
|
98
102
|
|
99
|
-
|
103
|
+
#self.board[y][x]が0であればself.turnを1にし黒の番にする
|
104
|
+
|
105
|
+
#self.board[y][y]が1であればself.turnを-2にし白の番にする
|
100
106
|
|
101
107
|
if self.board[y][x] == -1:
|
102
108
|
|
@@ -136,17 +142,7 @@
|
|
136
142
|
|
137
143
|
painter.setPen(Qt.black)
|
138
144
|
|
139
|
-
|
145
|
+
|
140
|
-
|
141
|
-
painter.drawLine(0,100,300,100)
|
142
|
-
|
143
|
-
painter.drawLine(0,200,300,200)
|
144
|
-
|
145
|
-
painter.drawLine(100,0,100,300)
|
146
|
-
|
147
|
-
painter.drawLine(200,0,200,300)
|
148
|
-
|
149
|
-
"""
|
150
146
|
|
151
147
|
self.goban_left_top_x = 30
|
152
148
|
|
@@ -170,45 +166,21 @@
|
|
170
166
|
|
171
167
|
|
172
168
|
|
173
|
-
|
174
|
-
|
175
|
-
#
|
169
|
+
#盤の黒い縦線と横線の記述
|
176
|
-
|
177
|
-
#painter.drawLine(x,30,x,270)
|
178
170
|
|
179
171
|
for x in range(self.goban_left_top_x, self.goban_left_top_x + self.length_of_between * self.goban_line_num, self.length_of_between):
|
180
172
|
|
181
173
|
painter.drawLine(x, self.goban_left_top_y, x, self.goban_left_top_y + self.length_of_between * (self.goban_line_num - 1))
|
182
174
|
|
183
|
-
|
175
|
+
|
184
176
|
|
185
177
|
for y in range(self.goban_left_top_y, self.goban_left_top_y + self.length_of_between * self.goban_line_num, self.length_of_between):
|
186
178
|
|
187
179
|
painter.drawLine(self.goban_left_top_x, y, self.goban_left_top_x + self.length_of_between * (self.goban_line_num - 1), y)
|
188
180
|
|
189
|
-
|
181
|
+
|
190
|
-
|
191
|
-
|
182
|
+
|
192
|
-
|
193
|
-
|
183
|
+
|
194
|
-
|
195
|
-
for x in range(3):
|
196
|
-
|
197
|
-
if self.board[y][x] == self.O:
|
198
|
-
|
199
|
-
painter.setPen(Qt.red)
|
200
|
-
|
201
|
-
painter.drawEllipse(QPointF(50+x*100, 50+y*100), 30, 30)
|
202
|
-
|
203
|
-
elif self.board[y][x] == self.X:
|
204
|
-
|
205
|
-
painter.setPen(Qt.blue)
|
206
|
-
|
207
|
-
painter.drawLine(20+x*100, 20+y*100, 80+x*100, 80+y*100)
|
208
|
-
|
209
|
-
painter.drawLine(20+x*100, 80+y*100, 80+x*100, 20+y*100)
|
210
|
-
|
211
|
-
"""
|
212
184
|
|
213
185
|
for y in range(1, 16):
|
214
186
|
|
@@ -238,13 +210,13 @@
|
|
238
210
|
|
239
211
|
|
240
212
|
|
213
|
+
#マウスを押したときのイベント(黒の縦線と横線の交差するところに碁を置くための記述)
|
214
|
+
|
241
215
|
def mousePressEvent(self, event):
|
242
216
|
|
243
217
|
pos = event.pos()
|
244
218
|
|
245
|
-
|
219
|
+
|
246
|
-
|
247
|
-
|
248
220
|
|
249
221
|
hantei_ryouiki_satan = int(self.goban_left_top_x - int(self.length_of_between / 2))
|
250
222
|
|
@@ -288,11 +260,7 @@
|
|
288
260
|
|
289
261
|
self.graphicsView = QGraphicsView()
|
290
262
|
|
291
|
-
#scene = QGraphicsScene(self)
|
292
|
-
|
293
|
-
scene = QGraphicsScene(self.graphicsView)
|
263
|
+
scene = QGraphicsScene(self.graphicsView)
|
294
|
-
|
295
|
-
#scene.setSceneRect(0, 0, 100, 100)
|
296
264
|
|
297
265
|
self.graphicsView.setScene(scene)
|
298
266
|
|
@@ -300,77 +268,35 @@
|
|
300
268
|
|
301
269
|
scene.addItem(self.tic_tac_toe)
|
302
270
|
|
303
|
-
|
271
|
+
|
304
|
-
|
305
|
-
self.kuro_button = QPushButton('黒', self)
|
306
|
-
|
307
|
-
self.kuro_button.setCheckable(True)
|
308
|
-
|
309
|
-
self.kuro_button.clicked[bool].connect(self.setColor)
|
310
|
-
|
311
|
-
#scene.addItem(self.kuro_button)
|
312
|
-
|
313
|
-
self.siro_button = QPushButton('白', self)
|
314
|
-
|
315
|
-
self.siro_button.setCheckable(True)
|
316
|
-
|
317
|
-
self.siro_button.clicked[bool].connect(self.setColor)
|
318
|
-
|
319
|
-
#scene.addItem(self.siro_button)
|
320
|
-
|
321
|
-
self.space_button = QPushButton('なし', self)
|
322
|
-
|
323
|
-
self.space_button.setCheckable(True)
|
324
|
-
|
325
|
-
self.space_button.clicked[bool].connect(self.setColor)
|
326
|
-
|
327
|
-
#scene.addItem(self.space_button)
|
328
|
-
|
329
|
-
"""
|
330
272
|
|
331
273
|
vbox = QVBoxLayout()
|
332
274
|
|
333
|
-
|
275
|
+
|
334
|
-
|
335
|
-
#vbox.addWidget(self.siro_button)
|
336
|
-
|
337
|
-
#vbox.addWidget(self.space_button)
|
338
276
|
|
339
277
|
vbox.addWidget(self.graphicsView)
|
340
278
|
|
341
279
|
self.setLayout(vbox)
|
342
280
|
|
343
|
-
|
344
|
-
|
345
|
-
|
281
|
+
|
346
|
-
|
347
|
-
|
348
282
|
|
349
283
|
#画面の大きさ
|
350
284
|
|
351
285
|
scene.setSceneRect(0, 0, 600, 600)
|
352
286
|
|
353
|
-
|
354
|
-
|
355
|
-
#self.setScene(scene)
|
356
|
-
|
357
|
-
#self.graphicsView.setScene(scene)
|
358
|
-
|
359
|
-
#self.setCacheMode(QGraphicsView.CacheBackground)
|
360
|
-
|
361
|
-
|
362
|
-
|
363
287
|
mainLayout = QHBoxLayout()
|
364
288
|
|
365
289
|
mainLayout.addLayout(vbox)
|
366
290
|
|
367
291
|
|
368
292
|
|
369
|
-
|
293
|
+
|
370
294
|
|
371
295
|
self.setWindowTitle("Tic Tac Toe")
|
372
296
|
|
297
|
+
|
298
|
+
|
373
|
-
|
299
|
+
#Rキーを押したら終了する
|
374
300
|
|
375
301
|
def keyPressEvent(self, event):
|
376
302
|
|
@@ -382,35 +308,11 @@
|
|
382
308
|
|
383
309
|
super(MainWindow, self).keyPressEvent(event)
|
384
310
|
|
385
|
-
|
386
|
-
|
387
|
-
|
311
|
+
|
388
|
-
|
389
|
-
|
312
|
+
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
313
|
+
|
394
|
-
|
395
|
-
|
314
|
+
|
396
|
-
|
397
|
-
|
315
|
+
|
398
|
-
|
399
|
-
self.tic_tac_toe.now = self.tic_tac_toe.siro
|
400
|
-
|
401
|
-
elif source.text() == "なし":
|
402
|
-
|
403
|
-
self.tic_tac_toe.now = self.tic_tac_toe.space
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
316
|
|
415
317
|
if __name__ == '__main__':
|
416
318
|
|
@@ -425,3 +327,5 @@
|
|
425
327
|
mainWindow.show()
|
426
328
|
|
427
329
|
sys.exit(app.exec_())
|
330
|
+
|
331
|
+
```
|