Back to articles
Day 21 of 100

Day 21 of 100

via Dev.to BeginnersPalak Hirave

Finished my snake game! It's supposed to be simple to play and yet my score never seems to go above five. What's your high score? I also learnt about slicing lists and tuples and what is class inheritance. main.py from turtle import Screen from snake import Snake from food import Food from scoreboard import Scoreboard import time screen = Screen () screen . setup ( width = 600 , height = 600 ) screen . bgcolor ( " black " ) screen . title ( " My Snake Game " ) screen . tracer ( 0 ) snake = Snake () scoreboard = Scoreboard () food = Food () screen . listen () screen . onkey ( snake . up , " Up " ) screen . onkey ( snake . down , " Down " ) screen . onkey ( snake . left , " Left " ) screen . onkey ( snake . right , " Right " ) game_is_on = True while game_is_on : screen . update () time . sleep ( 0.1 ) snake . move () if snake . head . distance ( food ) < 15 : food . refresh () scoreboard . increase_score () snake . extend () if snake . head . xcor () > 295 or snake . head . xcor () < -

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
5 views

Related Articles