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

? #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

? #18

Show file tree
Hide file tree
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
141 changes: 141 additions & 0 deletions barebones/Snake game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import turtle
import random
import time

# creating screen
screen = turtle.Screen()
screen.setup(width=700, height=700)
screen.title('Snake game')
screen.bgcolor('black')
screen.tracer(0)

turtle.speed(5)
turtle.pensize(5)
turtle.penup()
turtle.goto(-310, 250)
turtle.pendown()
turtle.color('red')
turtle.forward(600)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.forward(500)
turtle.penup()
turtle.hideturtle()

score = 0
delay = 0.1

snake = turtle.Turtle()
snake.shape('square')
snake.color('#00C957')
snake.penup()
snake.goto(0, 0)
snake.pendown()
snake.direction = 'stop'

food = turtle.Turtle()
food.shape('square')
food.color('#CAFF70')
food.penup()
food.goto(30, 30)

old_food = []

scoring = turtle.Turtle()
scoring.speed(0)
scoring.color('#F0F8FF')
scoring.penup()
scoring.hideturtle()
scoring.goto(0, 301)
scoring.write('Score: ', align='center', font=("Arial", 24, 'bold'))


def snake_go_up():
if snake.direction != 'down':
snake.direction = 'up'


def snake_go_down():
if snake.direction != 'up':
snake.direction = 'down'


def snake_go_left():
if snake.direction != 'right':
snake.direction = 'left'


def snake_go_right():
if snake.direction != 'left':
snake.direction = 'right'


screen.listen()
screen.onkeypress(snake_go_up, 'Up')
screen.onkeypress(snake_go_down, 'Down')
screen.onkeypress(snake_go_left, 'Left')
screen.onkeypress(snake_go_right, 'Right')


def snake_move():
if snake.direction == "up":
y = snake.ycor()
snake.sety(y + 10)

if snake.direction == "down":
y = snake.ycor()
snake.sety(y - 10)

if snake.direction == "left":
x = snake.xcor()
snake.setx(x - 10)

if snake.direction == "right":
x = snake.xcor()
snake.setx(x + 10)


while True:
screen.update()
if snake.distance(food) < 20:
x = random.randint(-290, 270)
y = random.randint(-240, 240)
food.goto(x, y)
scoring.clear()
score += 1
scoring.write("Score:{}".format(score), align="center", font=("Arial", 24, "bold"))
delay -= 0.001

new_fruit = turtle.Turtle()
new_fruit.speed(0)
new_fruit.shape('circle')
new_fruit.color('#DC143C')
new_fruit.penup()
old_food.append(new_fruit)

for index in range(len(old_food) - 1, 0, -1):
a = old_food[index - 1].xcor()
b = old_food[index - 1].ycor()

old_food[index].goto(a, b)

if len(old_food) > 0:
a = snake.xcor()
b = snake.ycor()
old_food[0].goto(a, b)
snake_move()


if snake.xcor() > 280 or snake.xcor() < -300 or snake.ycor() > 240 or snake.ycor() < -240:
time.sleep(1)
screen.clear()
screen.bgcolor('#8B1A1A')
scoring.goto(0, 0)
scoring.write(" GAME OVER \n Your Score is {}".format(score), align="center", font=("Courier", 30, "bold"))

time.sleep(delay)

turtle.Terminator()
54 changes: 54 additions & 0 deletions barebones/WheelOfColors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Wheel of colors, a game similar to the wheel of fortune,
# Choose a color then spin the wheel,
# And await your destiny

print('''Welcome to the wheel of colors, where you can gamble to your hearts content.
Here, if your first guess is correct, your bet is doubled and returned
If your second guess is correct, your bet is unchanged and returned

''')

import random

# All possible colors
colorsInWheel = ['red', 'yellow', 'blue', 'green', 'orange', 'purple', 'black']
# Amount in purse
purse = 500


while purse > 0:
# Players Guess
guess1 = str(input('Choose one color : '))
guess2 = str(input('Choose another color : '))

# The players bet
bet = int(input('Enter your bet : '))

# The color it lands on
theColor = random.choice(colorsInWheel)

# The Checking system
if guess1 == theColor:
print('Wow! You got it correct! You get', bet * 2, '!')
purse = purse + (bet * 2)
print('''You have', purse, 'in your purse!

''')

elif guess2 == theColor:
print('Wow! You got it correct! You get', bet, '!')
purse = purse + bet
print('''You have''', purse, '''in your purse!

''')

else:
print('Sorry! The color was :', theColor, '. Better luck next time')
purse = purse - bet
print('''You have''', purse, '''in your purse!

''')


else:
print('Sorry! You do not have any money left.')