-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApple.py
More file actions
38 lines (28 loc) · 861 Bytes
/
Apple.py
File metadata and controls
38 lines (28 loc) · 861 Bytes
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
import pygame
import random
# this is just for fun comment
def isIn(pos, listofPos):
for point in listofPos:
if pos == point:
return True
return False
class Apple():
def __init__(self):
random.seed()
self.x = None
self.y = None
def getX(self):
return self.x
def getY(self):
return self.y
def setPos(self, xMax, yMax):
self.x = (random.randint(0, xMax - 10) // 10) * 10
self.y = (random.randint(0, yMax - 10) // 10) * 10
def placeApple(self, listofPos, xMax, yMax):
while True:
pos = self.setPos(xMax, yMax)
if not isIn((self.x, self.y), listofPos):
break
return pos
def drawApple(self, surface, size):
pygame.draw.rect(surface, (255, 0, 0), (self.x, self.y, size, size))