質問編集履歴
5
説明の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
二重ループを用いて6×4のブロック配置をしたいのですがうまくできないです。
|
2
2
|
```
|
3
|
-
|
3
|
+
import sys
|
4
4
|
import pygame
|
5
5
|
from pygame.locals import QUIT
|
6
6
|
from pygame.locals import Rect
|
4
説明の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -43,7 +43,7 @@
|
|
43
43
|
|
44
44
|
for block in blocks:
|
45
45
|
block.draw()
|
46
|
-
pygame.display.update()
|
46
|
+
pygame.display.update()
|
47
47
|
```
|
48
48
|
|
49
49
|

|
3
実行結果の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,4 +44,6 @@
|
|
44
44
|
for block in blocks:
|
45
45
|
block.draw()
|
46
46
|
pygame.display.update()コード
|
47
|
-
```
|
47
|
+
```
|
48
|
+
|
49
|
+

|
2
説明の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
二重ループを用いて6×4のブロック配置をしたいのですがうまくできないです。
|
2
2
|
```
|
3
|
+
mport sys
|
4
|
+
import pygame
|
5
|
+
from pygame.locals import QUIT
|
6
|
+
from pygame.locals import Rect
|
7
|
+
|
8
|
+
pygame.init()
|
9
|
+
|
10
|
+
SURFACE = pygame.display.set_mode((400,300))
|
11
|
+
pygame.display.set_caption("pygame window ")
|
12
|
+
class Block:
|
13
|
+
def __init__(self, color, rect):
|
14
|
+
self.color = color #ボールの色(R,G,B)
|
15
|
+
self.rect = rect #初期位置と大きさ(Rect を利用)
|
16
|
+
|
17
|
+
def draw(self):
|
18
|
+
pygame.draw.rect(SURFACE, self.color, self.rect)
|
19
|
+
|
3
20
|
left = 50
|
4
21
|
top = 50
|
5
22
|
width = 45
|
1
説明の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,5 +14,17 @@
|
|
14
14
|
rect = Rect(left, top, width, height)
|
15
15
|
blocks.append(Block(color, rect))
|
16
16
|
left = left+50
|
17
|
+
|
18
|
+
while True:
|
19
|
+
|
20
|
+
for event in pygame.event.get():
|
21
|
+
if event.type == QUIT:
|
22
|
+
pygame.quit()
|
17
|
-
|
23
|
+
sys.exit()
|
24
|
+
|
25
|
+
SURFACE.fill((0,0,0))
|
26
|
+
|
27
|
+
for block in blocks:
|
28
|
+
block.draw()
|
29
|
+
pygame.display.update()コード
|
18
30
|
```
|