Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update snake.py #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions snake.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, start, dirnx=1, dirny=0, color=(255,0,0)):
self.dirny = dirny # "L", "R", "U", "D"
self.color = color


def move(self, dirnx, dirny):
self.dirnx = dirnx
self.dirny = dirny
Expand All @@ -46,6 +47,7 @@ def draw(self, surface, eyes=False):
class snake():
body = []
turns = {}


def __init__(self, color, pos):
#pos is given as coordinates on the grid ex (1,5)
Expand All @@ -54,6 +56,7 @@ def __init__(self, color, pos):
self.body.append(self.head)
self.dirnx = 0
self.dirny = 1


def move(self):
for event in pygame.event.get():
Expand Down Expand Up @@ -98,6 +101,7 @@ def reset(self,pos):
self.dirnx = 0
self.dirny = 1


def addCube(self):
tail = self.body[-1]
dx, dy = tail.dirnx, tail.dirny
Expand All @@ -113,6 +117,7 @@ def addCube(self):

self.body[-1].dirnx = dx
self.body[-1].dirny = dy


def draw(self, surface):
for i,c in enumerate(self.body):
Expand All @@ -133,7 +138,6 @@ def redrawWindow():
pass



def drawGrid(w, rows, surface):
sizeBtwn = w // rows

Expand Down Expand Up @@ -191,8 +195,7 @@ def main():
break

redrawWindow()

main()



if __name__ == '__main__':
main()