need to create a second snake

This commit is contained in:
2020-01-21 12:03:01 -07:00
parent 2a264c4bec
commit d2ad045b82
7 changed files with 58 additions and 4 deletions

3
HW1/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/workspace.xml

13
HW1/.idea/HW1.iml generated Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

View File

@@ -0,0 +1,5 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" />
</settings>
</component>

7
HW1/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>

8
HW1/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/HW1.iml" filepath="$PROJECT_DIR$/.idea/HW1.iml" />
</modules>
</component>
</project>

6
HW1/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@@ -40,7 +40,7 @@ def main():
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption('Wormy')
pygame.display.set_caption('Snakes')
showStartScreen()
while True:
@@ -55,10 +55,14 @@ def runGame():
wormCoords = [{'x': startx, 'y': starty},
{'x': startx - 1, 'y': starty},
{'x': startx - 2, 'y': starty}]
direction = RIGHT
# Start the apple in a random place.
apple = getRandomLocation()
apple2 = getRandomLocation()
apple3 = getRandomLocation()
while True: # main game loop
for event in pygame.event.get(): # event handling loop
@@ -87,8 +91,14 @@ def runGame():
if wormCoords[HEAD]['x'] == apple['x'] and wormCoords[HEAD]['y'] == apple['y']:
# don't remove worm's tail segment
apple = getRandomLocation() # set a new apple somewhere
elif wormCoords[HEAD]['x'] == apple2['x'] and wormCoords[HEAD]['y'] == apple2['y']:
# don't remove worm's tail segment
apple2 = getRandomLocation() # set a new apple somewhere
elif wormCoords[HEAD]['x'] == apple3['x'] and wormCoords[HEAD]['y'] == apple3['y']:
# don't remove worm's tail segment
apple3 = getRandomLocation() # set a new apple somewhere
else:
del wormCoords[-1] # remove worm's tail segment
del wormCoords[-1] # remove worm's tail segment
# move the worm by adding a segment in the direction it is moving
if direction == UP:
@@ -104,6 +114,8 @@ def runGame():
drawGrid()
drawWorm(wormCoords)
drawApple(apple)
drawApple(apple2)
drawApple(apple3)
drawScore(len(wormCoords) - 3)
pygame.display.update()
FPSCLOCK.tick(FPS)
@@ -129,8 +141,8 @@ def checkForKeyPress():
def showStartScreen():
titleFont = pygame.font.Font('freesansbold.ttf', 100)
titleSurf1 = titleFont.render('USU', True, WHITE, DARKGREEN)
titleSurf2 = titleFont.render('Agents', True, GREEN)
titleSurf1 = titleFont.render('Snakes', True, DARKGRAY, YELLOW)
titleSurf2 = titleFont.render('Snakes', True, WHITE)
degrees1 = 0
degrees2 = 0