예제 #1
0
def main(screen):

    # create the cast {key: tag, value: list}
    cast = {}

    # create paddle
    x = int(constants.MAX_X / 2)
    y = int(constants.MAX_Y - 2)
    position = Point(x, y)
    paddle = Actor()
    paddle.set_text("===========")
    paddle.set_position(position)
    cast["paddle"] = [paddle]

    # create bricks
    cast["brick"] = []
    for x in range(5, 75):
        for y in range(2, 6):
            position = Point(x, y)
            brick = Actor()
            brick.set_text("*")
            brick.set_position(position)
            cast["brick"].append(brick)

    #create ball
    x = int(constants.MAX_X / 2)
    y = int(constants.MAX_Y / 2)
    position = Point(x, y)
    velocity = Point(1, -1)
    ball = Actor()
    ball.set_text("@")
    ball.set_position(position)
    ball.set_velocity(velocity)
    cast["ball"] = [ball]

    position = Point(0, 0)
    score = Actor()
    score.set_text(f"Score: ")
    score.set_position(position)
    score.set_velocity(position)
    cast["score"] = [score]

    # create the script {key: tag, value: list}
    script = {}

    input_service = InputService(screen)
    output_service = OutputService(screen)
    control_actors_action = ControlActorsAction(input_service)
    move_actors_action = MoveActorsAction()
    handle_collisions_acition = HandleCollisionsAction()
    draw_actors_action = DrawActorsAction(output_service)

    script["input"] = [control_actors_action]
    script["update"] = [move_actors_action, handle_collisions_acition]
    script["output"] = [draw_actors_action]

    # start the game
    director = Director(cast, script)
    director.start_game()
예제 #2
0
    def start_game(self):
        """Starts the game loop to control the sequence of play."""
        while self.keep_playing == True:
            self._cue_action("input")
            self._cue_action("update")
            self._cue_action("output")
            self.keep_playing = self._script["update"][1].checkGameOver()
            sleep(constants.FRAME_LENGTH)

        self.gameWon = self._script["update"][1].getWinCondition(
        )  #Checks if all bricks are destroyed

        if self.gameWon == True:
            self.endingText = "You won!"  #If all bricks gone, game is won.
        else:
            self.endingText = "Game Over! Try Again"  #if not, game over.

        self._cast = {}  #deletes all displayed objects

        x = int((constants.MAX_X / 2) - 5)
        y = int((constants.MAX_Y / 2) - 1)
        position = Point(x, y)
        endingScreen = Actor()  #creates new object to display - Ending Screen

        endingScreen.set_text(self.endingText)
        endingScreen.set_position(position)

        self._cast["endingScreen"] = [endingScreen]

        self._cue_action("output")  #displays the text object
        sleep(10)  #Delays game end so text can be read.
예제 #3
0
파일: word.py 프로젝트: gublerj/cse210-tc07
 def add_word(self, word, position, velocity):
     """
     This method will add a new word to the array storing all the words
     """
     words = Actor()
     words.set_text(word)
     words.set_position(position)
     words.set_velocity(velocity)
     self._list_of_words.append(words)
예제 #4
0
파일: cycle.py 프로젝트: FinestTurtle/TRON
    def _add_trail_bit(self, position, velocity, image):
        """Adds a new bit to the end of the trail.

        Args:
            self(Cycle): an instance of Cycle.
            position (Point): The bit's position.
            velocity (Point): The bit's velocity."""
        bit = Actor(image)
        bit.set_position(position)
        bit.set_velocity(velocity)
        self._trail_bits.append(bit)
예제 #5
0
    def __init__(self, input_service, output_service):
        """Class constructor

        Args:
            self (Director): An instance of director
        """
        self._input_service = input_service
        self._keep_playing = True
        self._output_service = output_service
        self._score = Score()
        self._word = WordActor()
        self.user_word = Actor()
        self.user_word._position._y = constants.MAX_Y + 1
예제 #6
0
    def add_words(self, text, position, velocity):
        """Adds a new segment to the speed using the given text, position and velocity.

        Args:
            self (speed): An instance of speed.
            text (string): The segment's text.
            position (Point): The segment's position.
            velocity (Point): The segment's velocity.
        """
        segment = Actor()
        segment.set_text(str(text))
        segment.set_position(position)
        segment.set_velocity(velocity)
        self._word_list.append(segment)
예제 #7
0
    def _add_segment(self, position, velocity):
        """Adds a new segment to the snake using the given text, position and velocity.

        Args:
            self (Snake): An instance of snake.
            text (string): The segment's text.
            position (Point): The segment's position.
            velocity (Point): The segment's velocity.
        """
        segment = Actor()
        segment.set_text(self._choose_word())
        segment.set_position(position)
        segment.set_velocity(velocity)
        self._segments.append(segment)
예제 #8
0
    def __init__(self, input_service, output_service):
        """The class constructor.
        
        Args:
            self (Director): an instance of Director.
        """
        self._word = Word()
        self._input_service = input_service
        self._keep_playing = True
        self._output_service = output_service
        self._score = Score()
        self._speed = Speed()
        self._guess = Guess()
        self._actor = Actor()

        self.correct = 0
예제 #9
0
 def _add_trail(self, image, position, velocity):
     trail = Actor(image)
     trail.set_position(position)
     trail.set_velocity(velocity)
     self._trails.append(trail)
예제 #10
0
 def _add_segment(self, text, position, velocity):
     segment = Actor()
     segment.set_text(text)
     segment.set_position(position)
     segment.set_velocity(velocity)
     self.word.append(segment)