def principal():
    janela = Screen()
    janela.setup(800,600)
    janela.title('Digimon, digitais, Digimon são campeões!')
    janela.bgcolor('white')
    carregaimagens('personagens', janela)
    carregaimagens ('digimons', janela)
    carregaimagens('digimonftowners', janela)
    carregaimagens('fundos', janela)
    cria_personagens()
    abertura(janela)
    ato2(janela)
    ato3(janela)
    ato4(janela)
    ato5(janela)
    ato6(janela)
    ato7(janela)
    ato8(janela)
    #finale(janela)
    fechamento(janela)
    debora_animacao(janela)
示例#2
0
from turtle import Turtle, Screen
from paddle import Paddle
from ball import Ball
import time
from scoreboard import Scoreboard

screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=680)
screen.title("Pong")
screen.tracer(0)

r_paddle = Paddle((350, 0))
l_paddle = Paddle((-350, 0))
ball = Ball()
scoreboard = Scoreboard()

screen.listen()
screen.onkey(r_paddle.go_down, "Down")
screen.onkey(r_paddle.go_up, "Up")

screen.onkey(l_paddle.go_down, "s")
screen.onkey(l_paddle.go_up, "w")

game_on = True

while game_on:
    time.sleep(ball.move_speed)
    screen.update()
    ball.move()
示例#3
0
from turtle import Turtle, Screen
import random

is_race_on = False
screen = Screen()
screen.setup(width=500, height=400)
screen.title("Turtle Racing Game")
user_bet = screen.textinput(title="Make your bet", prompt="Which turtle will win the race? Enter a color: ")
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
y_positions = [-70, -40, -10, 20, 50, 80]
all_turtles = []

#Create 6 turtles
for turtle_index in range(0, 6):
    new_turtle = Turtle(shape="turtle")
    new_turtle.penup()
    new_turtle.color(colors[turtle_index])
    new_turtle.goto(x=-230, y=y_positions[turtle_index])
    all_turtles.append(new_turtle)

if user_bet:
    is_race_on = True

while is_race_on:
    for turtle in all_turtles:
        #230 is 250 - half the width of the turtle.
        if turtle.xcor() > 230:
            is_race_on = False
            winning_color = turtle.pencolor()
            if winning_color == user_bet:
                print(f"You've won! The {winning_color} turtle is the winner!")
示例#4
0
        # Append turtles to list
        all_turtles.append(new_turtle)


if user_choice:
    is_race_on = True
    start_lineup()

while is_race_on:

    for turtle in all_turtles:
        # Turtle has won if he gets to 230 x cor
        # 230 is cor where turtle head touch right most of screen
        if turtle.xcor() > 230:
            winning_color = turtle.pencolor()
            # Check if user won
            if winning_color == user_choice:
                screen.title(
                    f"You've won! The {winning_color} turtle is the winner")
                print(f"You've won! The {winning_color} turtle is the winner")
            else:
                screen.title(
                    f"You've lost! The {winning_color} turtle is the winner")
                print(f"You lost! The {winning_color} turtle is the winner")
            is_race_on = False
        # Loop through turtles and move them by a random int
        rand_distance = random.randint(0, 10)
        turtle.forward(rand_distance)

screen.exitonclick()
示例#5
0
import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard

screen = Screen()
screen.title("Turtle Crossing")
screen.setup(width=600, height=600)
screen.tracer(0)

player = Player()
car_manager = CarManager()
scoreboard = Scoreboard()

screen.listen()
screen.onkey(player.go_up, "Up")

game_is_on = True
while game_is_on:
    time.sleep(0.1)
    screen.update()

    car_manager.create_cars()
    car_manager.move_cars()

    # Detect collision with car
    for car in car_manager.all_cars:
        if car.distance(player) < 20:
            game_is_on = False
            scoreboard.game_over()
示例#6
0
from turtle import Turtle, Screen
from paddle import Paddle
from ball import Ball
import time
from scoreboard import Scoreboard

s = Screen()
s.bgcolor("black")
s.setup(width=800, height=600)
s.title("Pong")
s.tracer(0)

ball = Ball()
r_paddle = Paddle(350, 0)
l_paddle = Paddle(-350, 0)
scoreboard = Scoreboard()
# p = Paddle(282,250)

s.listen()
s.onkey(r_paddle.go_up, "Up")
s.onkey(r_paddle.go_down, "Down")

s.onkey(l_paddle.go_up, "w")
s.onkey(l_paddle.go_down, "s")

game_is_on = True
while game_is_on:
    time.sleep(ball.move_speed)
    s.update()
    ball.move()
    if ball.ycor() > 300 or ball.ycor() < -300:
示例#7
0
from turtle import Screen, Turtle
from paddle import Paddle
from ball import Ball
from scoreboard import Scoreboard
import time

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600

tim = Turtle('circle')

screen = Screen()
screen.setup(SCREEN_WIDTH, SCREEN_HEIGHT)
screen.bgcolor('black')
screen.title("MY PONG GAME")
screen.tracer(0)
r_paddle = Paddle('right')
l_paddle = Paddle('left')
ball = Ball()
scoreboard = Scoreboard()

screen.listen()
screen.onkeypress(r_paddle.up, 'Up')
screen.onkeypress(r_paddle.down, 'Down')
screen.onkeypress(l_paddle.up, 'w')
screen.onkeypress(l_paddle.down, 's')
# ball.speed(2)
tim.hideturtle()
tim.penup()
tim.color('white')
tim.setheading(90)
示例#8
0
import random
import time

screen = Screen()
paddle = Paddle()
ball = Ball()
scoreboard = Scoreboard()

# index 0 paddle on the right
paddle.create_paddle(-350)
paddle.create_paddle(350)
ball.create_ball()

screen.setup(width=800, height=600)
screen.bgcolor("black")
screen.title("My PingPong Game")
screen.listen()

screen.onkey(paddle.go_up1, "w")
screen.onkey(paddle.go_down1, "s")
screen.onkey(paddle.go_up2, "p")
screen.onkey(paddle.go_down2, ";")

screen.tracer(0)

Game_On = True

while Game_On:
    time.sleep(0.01)
    screen.update()
    ball.ball_move()
示例#9
0
from turtle import Screen, time
from snake import Snake
from food import Food
from scoreboard import Score

screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor("black")
screen.title("Welcome to Snake Game")
screen.tracer(0)

snake = Snake()
food = Food()
scoreboard = Score()

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()
    '''Detect collision with food'''

    if snake.head.distance(food) < 15:
        food.refresh()
示例#10
0
文件: race.py 项目: zhd204/Python
from turtle import Turtle, Screen
import random

turtles = []
colors = ["red", "orange", "black", "green", "blue", "purple"]
screen = Screen()
screen.setup(width=500, height=400)
screen.bgcolor("azure3")
screen.title("Welcome to the turtle race game!")

# Setting up user interface at the beginning
user_bet = screen.textinput(
    title="Make your bet",
    prompt="Which turtle will win the race? Enter a color from the following:\n"
    "red, orange, black, green, blue, purple: ").lower()
while True:
    if user_bet not in colors:
        user_bet = screen.textinput(
            title="Make your bet",
            prompt="Invalid entry. Enter a color from the following:\n"
            "red, orange, black, green, blue, purple: ").lower()
    else:
        break

# Setting up turtles at the starting line
y_cor_interval = int(screen.window_height() * 0.5 / (len(colors) - 1))
y_cor = -100
for color in colors:
    turtle = Turtle(shape="turtle")
    turtle.color(color)
    turtle.penup()
示例#11
0
# A turtle in a big pond that knows your voice

from turtle import Turtle, Screen

print("Creating and Ocean")
ocean = Screen()
ocean.title("Lets find Nemo")

print("Creating a turtle")
bob = Turtle()

print("Defining some commands")


def keyLeft():
    bob.left(45)


def keyRight():
    bob.right(45)


def keyUp():
    bob.forward(20)


def keyDown():
    bob.backward(20)


def keyHome():
示例#12
0
# import required modules
from turtle import Screen
from time import sleep
from spaceship import SpaceShip
from aliens import Invaders
from scoreboard import ScoreBoard

# setting up the game screen
game_screen = Screen()
game_screen.setup(width=600, height=650)
game_screen.bgcolor("black")
game_screen.title("Space Invaders")
game_screen.tracer(0)
game_screen.listen()

# setup and display each game component
space_ship = SpaceShip()

aliens = Invaders()
scores = ScoreBoard()
game_on = True
loops = 0


def end_game():
    """A function that ends the game abruptly"""

    global game_on
    game_on = False

示例#13
0
from turtle import Screen
from paddle import Paddle
from ball import Ball
from brick_manager import BrickManager
from scoreboard import Scoreboard
import time

screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=800)
screen.title("Breakout")
screen.tracer(0)

bricks = BrickManager()
paddle = Paddle()
ball = Ball()
scoreboard = Scoreboard()

screen.listen()
screen.onkey(paddle.move_left, "Left")
screen.onkey(paddle.move_right, "Right")

game_over = False

while not game_over:
    screen.update()
    time.sleep(ball.move_speed)
    ball.move()

    # Detect collision with walls:
    if ball.xcor() >= 380 or ball.xcor() <= -380:
示例#14
0
        ts.getcanvas().postscript(file="letter.eps")
        imgNew = Image.open("letter.eps")
        #imgNew.convert("RGBA")
        imgNew.save('letter1.png', quality=90, lossless=True)
        messagebox.showinfo("Message Box",
                            "Drawing saved as image file successfully.")
    else:
        print("Some error occured")


def dragging(x, y):
    yertle.ondrag(None)
    #yertle.setheading(yertle.towards(x, y))
    yertle.goto(x, y)
    yertle.ondrag(dragging)


screen = Screen()
#screen.bgcolor("orange")
yertle = Turtle('classic')
screen.register_shape("pen1.gif")
yertle.shape("pen1.gif")
yertle.speed('fast')
screen.title("Draw characters here")
yertle.pensize(5)
#yertle.pencolor("white")
yertle.turtlesize(stretch_wid=2, stretch_len=2, outline=5)
yertle.onclick(dragging)
yertle.onrelease(dialogue, btn=1, add=None)
screen.mainloop()
示例#15
0
from turtle import Screen
from paddle import Paddle
from ball import Ball
from scoreboard import Scoreboard
import time

# set up the game area
screen = Screen()
screen.setup(width=800, height=600)
screen.bgcolor("black")
screen.title("PONG")
screen.tracer(0)

# create the game components
left_paddle = Paddle((-350, 0))
right_paddle = Paddle((350, 0))
ball = Ball()

#keybindings
screen.listen()
screen.onkey(left_paddle.up, "w")
screen.onkey(left_paddle.down, "s")
screen.onkey(right_paddle.up, "Up")
screen.onkey(right_paddle.down, "Down")

# create the scoreboard
scoreboard = Scoreboard()

game_on = True

while game_on:
示例#16
0
def main():

    from tkinter import messagebox
    import turtle
    from turtle import Turtle, Screen
    import random
    from coolname import generate_slug
    turtle.colormode(255)
    screen = Screen()
    screen.title("Let's race! ")
    screen.bgcolor('lavenderblush')
    screen.setup(width=.75, height=0.75, startx=None, starty=None)

    def create(num):
        colors = [(255, 51, 192), (223, 45, 168),
                  (191, 38, 144), (159, 32, 120), (128, 26, 96), (96, 19, 72),
                  (64, 13, 48), (32, 6, 24), (156, 208, 216), (154, 213, 175),
                  (241, 171, 151), (229, 212, 16), (125, 115, 160)]
        x = -450
        y = -150
        players = []
        for turtles in range(num):
            name = Turtle()
            name.name = generate_slug(2)
            name.shape('turtle')
            name.penup()
            name.color(random.choice(colors))
            name.setx(x)
            name.sety(y)
            name.write(f'  {name.name}\n', True, align="right")
            name.pendown()
            name.pensize(2)
            y += 50
            players.append(name)
        return players

    def finish_line():
        line_dude = Turtle()
        line_dude.hideturtle()
        line_dude.shape('turtle')
        line_dude.color((241, 13, 77))
        line_dude.penup()
        line_dude.setheading(90)
        line_dude.speed(0)
        line_dude.setpos(400, -200)
        line_dude.showturtle()
        line_dude.pendown()
        line_dude.speed(1)
        line_dude.forward(50 * num + 50)
        line_dude.hideturtle()

    num = int(
        screen.numinput("Number of Players",
                        "How many players in the race?:",
                        3,
                        minval=0,
                        maxval=10))

    players = create(num)
    finish_line()
    finish = 400
    messagebox.askquestion(title="Let's play!", message="ready to play?")
    if 'yes':
        game_on = True
        while game_on:
            for turtl in players:
                if turtl.xcor() >= finish - 1:
                    game_on = False
                    messagebox.askokcancel('winner', f'{turtl.name} won! yes!')
                    print(f'{turtl.name}')
                    break
                else:
                    rand_distance = random.randint(1, 10)
                    turtl.forward(rand_distance)

    if messagebox.askyesno(title="again?", message="Want to play again?"):
        turtle.clearscreen()
        main()
    else:
        turtle.clearscreen()

    screen.listen()
    screen.exitonclick()
示例#17
0
class MazeGraphics(object):
    def __init__(self, config):
        self.width = config.getValueAsInt("maze", "maze_size")
        self.height = config.getValueAsInt("maze", "maze_size")
        self.bg_color = config.getValue("maze", "bg_color")
        self.line_color = config.getValue("maze", "line_color")
        self.line_centroid_color = config.getValue("maze", "line_centroid_color")
        self.forward_centroid_color = config.getValue("maze", "forward_centroid_color")
        self.reverse_centroid_color = config.getValue("maze", "reverse_centroid_color")
        self.path_color = config.getValue("maze", "path_color")
        self.screen = Screen()
        self.setupTurtle(self.width, self.height)

    def setupTurtle(self, width, height):
        self.screen.tracer(False)
        self.screen.screensize(width, height)
        # some basic turtle settings
        self.screen.setworldcoordinates(-1, -1, width + 1, height + 1)
        self.screen.title("Random Turtle Maze")
        self.screen.bgcolor(self.bg_color)
        self.screen.delay(None)
        self.designer = Turtle(visible=False)

    def drawGrid(self):
        for i in xrange(0, self.width + 1):
            self.drawXLines(i, self.width, self.line_color)
        for i in xrange(0, self.height + 1):
            self.drawYLines(i, self.width, self.line_color)
        self.screen.update()

    def drawXLines(self, position, width, color):
        self.drawLines(position, 0, width, color, 90)

    def drawYLines(self, position, width, color):
        self.drawLines(0, position, width, color, 0)

    def drawLines(self, xPosition, yPosition, width, color, heading):
        self.designer.up()
        self.designer.setposition(xPosition, yPosition)
        self.designer.color(color)
        self.designer.down()
        self.designer.setheading(heading)
        self.designer.forward(width)
        self.designer.up()

    def drawCentroid(self, cell, color):
        """
        Draw a centroid for animation purposes but then overwrite it.
        """
        self.designer.setposition(cell.centroid)
        self.designer.dot(5, color)
        self.screen.update()
        self.designer.dot(5, self.bg_color)

    def removeWall(self, posx, posy, heading, color):
        """
            We tear down walls to build the maze
        """
        self.designer.up()
        self.designer.setposition(posx, posy)
        self.designer.down()
        self.designer.color(color)
        self.designer.setheading(heading)
        self.designer.forward(1)
        self.designer.up()
        self.screen.update()

    def drawPath(self, cell1, cell2):
        """
            This draws a line for the solution as it's worked out.
        """
        self.designer.setposition(cell1.centroid)
        self.designer.color(self.path_color)
        direction = self.getDirection(cell1, cell2)
        if direction == "N":
            self.designer.setheading(90)
            self.designer.down()
            self.designer.forward(1)
            self.designer.up()
        elif direction == "S":
            self.designer.setheading(270)
            self.designer.down()
            self.designer.forward(1)
            self.designer.up()
        elif direction == "W":
            self.designer.setheading(0)
            self.designer.down()
            self.designer.forward(1)
            self.designer.up()
        elif direction == "E":
            self.designer.setheading(0)
            self.designer.down()
            self.designer.backward(1)
            self.designer.up()
        self.drawCentroid(cell2, self.line_centroid_color)
        self.screen.update()

    def getDirection(self, currCell, nextCell):
        direction = None
        if nextCell.x < currCell.x:
            direction = "E"
        elif nextCell.x > currCell.x:
            direction = "W"
        elif nextCell.y < currCell.y:
            direction = "S"
        elif nextCell.y > currCell.y:
            direction = "N"
        return direction
示例#18
0
import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard

screen = Screen()
screen.setup(width=600, height=600)
screen.tracer(0)
screen.title("Turtle Crosser")
player = Player()
car_manager = CarManager()
score_board = Scoreboard()
screen.listen()
screen.onkey(player.go_up, "Up")
game_is_on = True
while game_is_on:
    time.sleep(0.1)
    screen.update()
    car_manager.create_car()
    car_manager.move_cars()
    for car in car_manager.all_cars:
        if car.distance(player) < 20:
            game_is_on = False
            score_board.game_over()
    # Detect successfull crossing
    if player.is_at_finish_line():
        player.go_to_start()
        car_manager.level_up()
        score_board.level_up()
        setBall()
    elif y > courtHeight / 2 - turtleFactor:
        ball.setheading(-ball.heading())
    elif x > courtWidth / 2 - turtleFactor:
        ball.setheading(180 - ball.heading())
    elif x < turtleFactor - courtWidth / 2:
        ball.setheading(180 - ball.heading())
    else:
        collision(player, ball)

    screen.ontimer(move, 20)  #every after twenty ms call the move() function


#screen
screen = Screen()
screen.title("Jakob's Pong")
screen.bgcolor("black")
screen.setup(width=1.0, height=1.0)

#Court Border
border = Turtle(visible=False)
border.speed("fastest")
border.color("white")
draw_border()

#setup ball
ball = Turtle("circle")
ball.penup()
ball.color("white")

#setup player paddle
示例#20
0
from turtle import Screen
from Paddle import Paddle
from Ball import Ball
from Scoreboard import Scoreboard
import time

# Instance of both classes
screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.title("Pong Game")
screen.tracer(0)

left_paddle = Paddle(-350, 0)
right_paddle = Paddle(350, 0)

ball = Ball()

score = Scoreboard()

# Listen
screen.listen()

screen.onkey(left_paddle.go_up, "w")
screen.onkey(left_paddle.go_down, "s")

screen.onkey(right_paddle.go_up, "Up")
screen.onkey(right_paddle.go_down, "Down")

game_is_on = True
while game_is_on:
示例#21
0
from turtle import Screen, Turtle, bye, Terminator
from _tkinter import TclError

from game_object import GameObject, objs, Obstacle

from time import sleep

# Constants
FRAMERATE = 30

# Window
wn = Screen()
wn.setup(height=800, width=1000)
wn.title('Stupid game shit')
wn.bgcolor('#220022')
wn.tracer(0)
wn.listen()

# Goodbye to the game
wn.onkeypress(bye, 'Escape')

# Players
player1 = GameObject('circle', '#880000', 1, 1, -200, 0)
player1.binds(wn, ['w', 's', 'a', 'd'])

player2 = GameObject('square', '#008800', 1, 1, 200, 0)
player2.binds(wn, ['Up', 'Down', 'Left', 'Right'])

# Their lives
player1.lives = 3
player2.lives = 3
示例#22
0
文件: Brush.py 项目: w7x8/Brush
import turtle
from turtle import Turtle, Screen
import random

colors = [
    'snow', 'red', 'blue', 'green', 'purple', 'yellow', 'orange', 'black',
    'grey', 'cyan', 'pink'
]
brushes = ['classic', 'arrow', 'turtle', 'triangle', 'circle', 'square']

screen = Screen()
screen.title("Brush")
screen.bgcolor('snow')
screen.setup(width=800, height=800)

brush = Turtle()
brush.speed(-1)
brush.width(3)


def stamp():
    brush.stamp()


def up():
    brush.seth(90)
    brush.forward(100)


def down():
    brush.seth(270)
示例#23
0
from utils import maze, rows, cols, start, finish
import time


class Block(Turtle):
    def __init__(self, color1):
        Turtle.__init__(self)
        self.shape("square")
        self.color(color1)
        self.shapesize(0.5)
        self.penup()
        self.speed(0)


wn = Screen()
wn.bgcolor("black"), wn.title("Stima Maze"), wn.setup(1000, 1000)


def pos_to_sc(x, y):
    return (-432 + (x * 12), 312 - (y * 12))


def draw_maze(maze):
    b = Block("white")
    for y in range(len(maze)):
        for x in range(len(maze[y])):
            if maze[y][x] == 1:
                b.goto(pos_to_sc(x, y))
                b.stamp()

示例#24
0
from turtle import Screen
from snake import Snake
from food import Food
from scoreboard import Scoreboard
import time
import random

game_on = True

screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor("black")
screen.tracer(0)
screen.title("Sneaky snake")

segments = []

snake = Snake()
food = Food()
scoreboard = Scoreboard()

screen.listen()
screen.onkey(snake.up, "Up")
screen.onkey(snake.down, "Down")
screen.onkey(snake.left, "Left")
screen.onkey(snake.right, "Right")

while game_on:
    screen.update()
    time.sleep(0.1)
    snake.move()
示例#25
0
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("Snake game")
screen.tracer(0)

snake = Snake()
food = Food()
scoreboard = Scoreboard()

screen.listen()
screen.onkey(key="Up", fun=snake.up)
screen.onkey(key="Down", fun=snake.down)
screen.onkey(key="Left", fun=snake.left)
screen.onkey(key="Right", fun=snake.right)

screen.update()

game_is_on = True
time.sleep(3)
while game_is_on:
    screen.update()
    time.sleep(0.1)
    snake.move()
示例#26
0
def desenho(leo, raio):
    '''Faz uma pétala'''
    heading = leo.heading()
    leo.circle(raio,
               60)  #(raio do círculo, parte do círculo desenhada em graus)
    leo.left(120)
    leo.circle(raio, 60)
    leo.setheading(heading)


comp = int(input("Qual é o comprimento das pétalas? "))
petala = int(input("Quantas pétalas você deseja? "))

est = Screen()
est.bgcolor('blue')
est.title('Flor de Lis')

leo = Turtle()

leo.color('green', 'limegreen')
leo.pensize(5)

# Posiciona a caneta lá embaixo
leo.penup()
leo.goto(0, -200)
leo.pendown()
leo.left(45)

talo(leo)

# Pétalas
示例#27
0
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('Snake Game')
screen.tracer(0)

snake = Snake()
food = Food()
scoreboard = Scoreboard()

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:
示例#28
0
from turtle import Screen, Turtle
from snake import Snake
import time


# Screen settings 
WIDTH = 600
HEIGHT = 600
S_COLOR = "#000"

s = Screen()
s.setup(WIDTH, HEIGHT)
s.bgcolor(S_COLOR)
s.title("Snake Game")
s.tracer(0)


snake = Snake()

# Keybinds
s.listen()
s.onkey(snake.up, "Up")
s.onkey(snake.down, "Down")
s.onkey(snake.left, "Left")
s.onkey(snake.right, "Right")



game_on = True

while game_on:
示例#29
0
from turtle import Screen
import time
from snake import Snake
from food import Food
from scoreboard import Scoreboard

screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor("black")
screen.title("My Snake Game")
screen.tracer(0)

snake = Snake()
food = Food()
scoreboard = Scoreboard()
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()
        snake.extend()
        scoreboard.increase_score()
示例#30
0
from turtle import Screen
from paddle import Paddle
from ball import Ball
from scoreboard import ScoreBoard
import time

# Set-up Screen
width = 800
height = 600
screen = Screen()
screen.setup(width=width, height=height)
screen.colormode(255)
screen.bgcolor("black")
screen.title("Pong game :)")
screen.tracer(0)

# Paddle
r_paddle = Paddle((350, 0))
l_paddle = Paddle((-350, 0))
ball = Ball()
score_board = ScoreBoard()

# Controls
screen.listen()

# Left paddle
screen.onkey(r_paddle.move_up, "Up")
screen.onkey(r_paddle.move_down, "Down")
screen.onkeypress(fun=r_paddle.move_up, key="Up")
screen.onkeypress(fun=r_paddle.move_down, key="Down")
from turtle import Turtle, Screen

screen = Screen()

po = [-20, -40, -60]
for i in range(3):
    snake = Turtle("square")
    snake.penup()
    snake.color("white")
    snake.goto(x=po[i], y=0)

screen.setup(width=600, height=600)
screen.title("Snake Game")
screen.bgcolor("black")
screen.exitonclick()
示例#32
0
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("Snakes on a Flat, Black Plane")
screen.tracer(0)

scoreboard = Scoreboard()

eating = True

snake = Snake()
food = Food()

screen.listen()
screen.onkey(snake.up, "Up")
screen.onkey(snake.down, "Down")
screen.onkey(snake.right, "Right")
screen.onkey(snake.left, "Left")

while eating:
    screen.update()
    time.sleep(0.1)
    snake.move()
    # Detect food collision
    if snake.head.distance(food) < 15:
示例#33
0
class TetrisBoard(object):
    def __init__(self, cols, rows):
        self.cols, self.rows = cols, rows
        self.screen = Screen()
        self.screen.screensize(BLOCKWIDTH*cols-50, BLOCKWIDTH*rows-50)
        self.screen.setup(BLOCKWIDTH*cols+12, BLOCKWIDTH*rows+12)
        self.screen.title("Turtle Tetris")
        self.screen.bgcolor("black")
        self.writer = Turtle()
        self.writer.ht()        
        self.label = None
        self.grid = {}
        self.screen.tracer(False)
        for row in range(rows):
            for col in range(cols):
                self.grid[(col, row)] = TetrisTurtle(col, row)
        self.screen.tracer(True)
        self.brick = TetrisBrick(self)
        self.result = 0
        self.LEVEL = 0.6
        self.keybuffer = KeyBuffer(self.screen,
                            ["Right", "Left", "Up", "Down", "space", "Escape"])
        self.reset()
        self.screen.listen()
        self.t1 = time()
        
    def reset(self):
        self.result = 0
        self.LEVEL = 0.600
        self.screen.tracer(False)
        self.writer.clear()
        if self.label:
            self.writer.clearstamp(self.label)
        for x in range(COLUMNS):
            for y in range(ROWS):
                self.grid[(x,y)].fillcolor("")
        self.screen.tracer(True)
        self.state = "NEWBRICK"
        
    def blink(self, y, n=1):
        for _ in range(n):
            for color in ("white", "black"):
                self.screen.tracer(False)
                for x in range(COLUMNS):
                    self.grid[(x,y)].pencolor(color)
                    sleep(self.LEVEL/10.0)
                self.screen.tracer(True)
            
    def display_result(self):
        tb = self
        tb.writer.color("white", "gray20")
        tb.writer.shape("square")
        tb.writer.shapesize(5, 15)
        tb.writer.goto(-4 ,0)
        self.label = tb.writer.stamp()
        tb.writer.goto(-2,3)
        tb.writer.write(str(tb.result) + " rows!",
                        align="center", font = ("Courier", 24, "bold") )
        tb.writer.goto(-2,-22)
        tb.writer.write("New game : <spacebar>",
                        align="center", font = ("Courier", 16, "bold") )
        tb.writer.goto(-2,-42)
        tb.writer.write("Quit : <escape>",
                        align="center", font = ("Courier", 16, "bold") )
        
    def getcolor(self, col, row):
        return self.grid[(col, row)].fillcolor()
    def setcolor(self, col, row, color):
        return self.grid[(col, row)].fillcolor(color)
    def rowfree(self, row):
        return not any([self.getcolor(col, row) for col in range(COLUMNS)])
    def rowfull(self, row):
        return all([self.getcolor(col, row) for col in range(COLUMNS)])

    def cleanup(self, shp):
        try:
            ymax = max([y for (x,y) in shp])
        except ValueError:
            self.state = "FINIS"
            return
        currenty = ymax
        while currenty > 0:
            if self.rowfull(currenty):
                self.blink(currenty, 2)
                self.result += 1
                if self.result == 8:
                    self.LEVEL = 0.4
                elif self.result == 20:
                    self.LEVEL = 0.25
                y = currenty
                while True:
                    self.screen.tracer(False)
                    for c in range(COLUMNS):
                        self.setcolor(c, y, self.getcolor(c, y-1))
                    self.screen.tracer(True)
                    if self.rowfree(y):
                        break
                    else:
                        y -= 1
            else:
                currenty -= 1
        tetris.state = "NEWBRICK"

    def run(self):
        tb = self
        b = self.brick
        ### actions to be done unconditionally
        if tb.state == "NEWBRICK":
            if b.reset():
                self.t1 = time()
                tb.state = "FALL"
            else:
                tb.state = "FINIS"
        t2 = time()
        if tb.state == "FALL" and t2 - self.t1 > self.LEVEL:
            b.down()
            b.apply("Step")
            self.t1 = t2
        ### actions bound to key events
        key = self.keybuffer.getkey()
        if key:
            if tb.state == "FALL":
                if key == "Left":
                    b.shiftleft()
                elif key == "Right":
                    b.shiftright()
                elif key == "Down":
                    b.drop()
                    tb.state = "CLEANUP"
                elif key == "Up":
                    b.turn()
                elif key == "space":
                    tb.state = "BREAK"
                b.apply(key)
            elif tb.state == "BREAK":
                if key == "space":
                    tb.state = "FALL"
            elif tb.state == "ADE":
                if key == "space":
                    tb.reset()
                    tb.state = "NEWBRICK"
                elif key == "Escape":
                    tb.screen.bye()
                
        if tb.state == "CLEANUP":
            tb.cleanup(b.shape1)
        if tb.state == "FINIS":
            tb.display_result()
            tb.state = "ADE"
        self.screen.ontimer(self.run, 100)    
示例#34
0
from turtle import Screen, Turtle
from random import randint

s = Screen()
s.setup(560,560)
s.title("A drunken turtle collecting ...")

s.tracer(False)
writer = Turtle(visible=False)
writer.penup()
writer.goto(0, -275)

coins = []
for i in range(-4,5):
  for j in range(-4, 5):
      if i == j == 0:
          continue
      c = Turtle(shape="circle")
      c.color("", "orange")
      c.shapesize(0.5)
      c.goto(40*i, 40*j)
      coins.append(c)
s.tracer(True)

DRUNKENNESS = 45       
t = Turtle(shape="turtle")
t.color("black","")
points = 0
while abs(t.xcor()) < 200 and abs(t.ycor()) < 200:
  t.forward(5)
  t.right(randint(-DRUNKENNESS, DRUNKENNESS))