Exemple #1
0
def play_game(screen):
    frog = Frog(FROG_IMAGE)

    cars = create_cars()
    cars_2 = create_cars()
    cars.extend(cars_2)

    score = Display(color='white', x=-450, y=350)
    game_over = Display('white', 0, 0)

    while True:
        score.display_score(frog.lvl)

        for car in cars:
            car.forward(car.speed)
            frog.move(screen)
            teleport(car)

            if (frog.frog_passed_lvl(LIMIT_UP)):
                random_car = random.choice(cars)
                random_car.speed += 1

                change_car_positions(cars)
            if car.run_over_frog(frog):
                game_over.display_game_over()
                return

        screen.update()
        time.sleep(0.01)

	# If Frog is NOT on solid ground (top or bottom), move WITH the log.
	if frog.y != row[0] and frog.y != row[9]:

		# for loop with, 'row[]' is 'log[i-1]'

		# Which ever row we are on, set Frog's velocity to that of the Log it's on.

		for i in range(len(row)):
			# Which ever row frog is on...
			if frog.y == row[i]:
				# Set Frog's velocity to that Log's velocity.
				frog.vel = logs[i-1].vel 	# One less than that of 'row[]'


		# MOVE Frog
		frog.move()



	# UPDATE
	pygame.display.update()

# END LOOP if run == False



# If Main Loop == False
pygame.quit()
Exemple #3
0
class HangmanWidget(object):
    """ The GUI stuff """
    def __init__(self, window):
        self.hangman = Hangman()
        self.window = window

        # create a new pen to write the dashes
        self.pen = Frog(self.window)
        self.pen.visible = False
        self.pen.write(' '.join('_' for char in self.hangman.word))

        if SHOW_SOLUTION:
            # show the solution
            solution = Frog(self.window)
            solution.visible = False
            solution.jumpto(0, 50)
            solution.write(' '.join(char for char in self.hangman.word))

        # prepare a pen for writing the gallow
        self.gallow_writer = Frog(self.window)
        self.gallow_writer.visible = False
        self.gallow_writer.jump(-150)

    def reset(self):
        """ clear the whole window and restart the game """
        # delete the 'frogs'
        self.pen.exit()
        self.gallow_writer.exit()
        self.__init__(self.window)

    def attempt(self, event):
        guessed_char = event['name']

        # lock the pen if it is just writing
        if self.gallow_writer.active:
            return

        self.gallow_writer.speed = 'max'

        # TODO: write a list of all guessed letters

        # right attempt
        if guessed_char.lower() in self.hangman.word:
            self.pen.write(self.hangman.guess(guessed_char))
            if len(self.hangman.right_attempts) == len(set(self.hangman.word)):
                self.gallow_writer.message(
                    'info',
                    'Congratulation! You guessed the word correctly!'
                )
                # start a new game
                self.reset()

        # wrong attempt
        else:
            # the number of mistakes
            num_mistakes = len(self.hangman.wrong_attempts)

            figures = [
                self.hill,
                self.first_beam,
                self.second_beam,
                self.bracket,
                self.rope,
                self.head,
                self.body,
                self.first_leg,
                self.second_leg,
                self.first_arm,
                self.second_arm,
            ]

            # only draw a figure if the guessed
            # letter was not already guessed earlier
            if guessed_char not in self.hangman.attempts:
                figures[num_mistakes]()

            self.hangman.guess(guessed_char)

    def hill(self):
        self.gallow_writer.turnto(90)
        self.gallow_writer.circle(50, 180)

    def first_beam(self):
        self.gallow_writer.circle(50, -90, draw = False)
        self.gallow_writer.turnto(90)
        self.gallow_writer.move(100)

    def second_beam(self):
        self.gallow_writer.turnto(0)
        self.gallow_writer.move(100)

    def bracket(self):
        # move back and build the supporting beam (and yes, the strange
        # number 36 is necessary because the gallow must be hit exactly
        # on the right place)
        self.gallow_writer.jump(-75)
        self.gallow_writer.turnto(225)
        self.gallow_writer.move(36)

        # don't forget to to move to the place where the man will be hung
        self.gallow_writer.jump(-36)
        self.gallow_writer.turnto(0)
        self.gallow_writer.jump(75)

    def rope(self):
        self.gallow_writer.turnto(270)
        self.gallow_writer.move(25)

    def head(self):
        self.gallow_writer.turnto(0)
        self.gallow_writer.circle(-15)

    def body(self):
        self.gallow_writer.turnto(270)
        self.gallow_writer.jump(30)
        self.gallow_writer.move(50)

    def first_leg(self):
        self.gallow_writer.turnto(225)
        self.gallow_writer.move(25)

    def second_leg(self):
        self.gallow_writer.jump(-25)
        self.gallow_writer.turnto(315)
        self.gallow_writer.move(25)

    def first_arm(self):
        self.gallow_writer.jump(-25)
        self.gallow_writer.turnto(90)
        self.gallow_writer.jump(25)
        self.gallow_writer.turnto(135)
        self.gallow_writer.move(25)

    def second_arm(self):
        """ last figure -> user lost! """
        self.gallow_writer.jump(-25)
        self.gallow_writer.turnto(45)
        self.gallow_writer.move(25)
        self.gallow_writer.message(
            'Info',
            'You lost! Shame on you! The word was: ' + self.hangman.word
        )
        # start a new game
        self.reset()
Exemple #4
0
class HangmanWidget(object):
    """ The GUI stuff """
    def __init__(self, window):
        self.hangman = Hangman()
        self.window = window

        # create a new pen to write the dashes
        self.pen = Frog(self.window)
        self.pen.visible = False
        self.pen.write(' '.join('_' for char in self.hangman.word))

        if SHOW_SOLUTION:
            # show the solution
            solution = Frog(self.window)
            solution.visible = False
            solution.jumpto(0, 50)
            solution.write(' '.join(char for char in self.hangman.word))

        # prepare a pen for writing the gallow
        self.gallow_writer = Frog(self.window)
        self.gallow_writer.visible = False
        self.gallow_writer.jump(-150)

    def reset(self):
        """ clear the whole window and restart the game """
        # delete the 'frogs'
        self.pen.exit()
        self.gallow_writer.exit()
        self.__init__(self.window)

    def attempt(self, event):
        guessed_char = event['name']

        # lock the pen if it is just writing
        if self.gallow_writer.active:
            return

        self.gallow_writer.speed = 'max'

        # TODO: write a list of all guessed letters

        # right attempt
        if guessed_char.lower() in self.hangman.word:
            self.pen.write(self.hangman.guess(guessed_char))
            if len(self.hangman.right_attempts) == len(set(self.hangman.word)):
                self.gallow_writer.message(
                    'info', 'Congratulation! You guessed the word correctly!')
                # start a new game
                self.reset()

        # wrong attempt
        else:
            # the number of mistakes
            num_mistakes = len(self.hangman.wrong_attempts)

            figures = [
                self.hill,
                self.first_beam,
                self.second_beam,
                self.bracket,
                self.rope,
                self.head,
                self.body,
                self.first_leg,
                self.second_leg,
                self.first_arm,
                self.second_arm,
            ]

            # only draw a figure if the guessed
            # letter was not already guessed earlier
            if guessed_char not in self.hangman.attempts:
                figures[num_mistakes]()

            self.hangman.guess(guessed_char)

    def hill(self):
        self.gallow_writer.turnto(90)
        self.gallow_writer.circle(50, 180)

    def first_beam(self):
        self.gallow_writer.circle(50, -90, draw=False)
        self.gallow_writer.turnto(90)
        self.gallow_writer.move(100)

    def second_beam(self):
        self.gallow_writer.turnto(0)
        self.gallow_writer.move(100)

    def bracket(self):
        # move back and build the supporting beam (and yes, the strange
        # number 36 is necessary because the gallow must be hit exactly
        # on the right place)
        self.gallow_writer.jump(-75)
        self.gallow_writer.turnto(225)
        self.gallow_writer.move(36)

        # don't forget to to move to the place where the man will be hung
        self.gallow_writer.jump(-36)
        self.gallow_writer.turnto(0)
        self.gallow_writer.jump(75)

    def rope(self):
        self.gallow_writer.turnto(270)
        self.gallow_writer.move(25)

    def head(self):
        self.gallow_writer.turnto(0)
        self.gallow_writer.circle(-15)

    def body(self):
        self.gallow_writer.turnto(270)
        self.gallow_writer.jump(30)
        self.gallow_writer.move(50)

    def first_leg(self):
        self.gallow_writer.turnto(225)
        self.gallow_writer.move(25)

    def second_leg(self):
        self.gallow_writer.jump(-25)
        self.gallow_writer.turnto(315)
        self.gallow_writer.move(25)

    def first_arm(self):
        self.gallow_writer.jump(-25)
        self.gallow_writer.turnto(90)
        self.gallow_writer.jump(25)
        self.gallow_writer.turnto(135)
        self.gallow_writer.move(25)

    def second_arm(self):
        """ last figure -> user lost! """
        self.gallow_writer.jump(-25)
        self.gallow_writer.turnto(45)
        self.gallow_writer.move(25)
        self.gallow_writer.message(
            'Info',
            'You lost! Shame on you! The word was: ' + self.hangman.word)
        # start a new game
        self.reset()