Exemplo n.º 1
0
def run_game():
    # Some stuff needed by PyGame
    pygame.init()

    # use Joystick and Controller
    pygame.joystick.init()
    joystick = pygame.joystick.Joystick(0)
    joystick.init()

    # todo: new sounds
    pygame.mixer.init()
    pygame.mixer.music.load('./Music/Tetris Edit 1 Export 3.mp3')
    new_block = pygame.mixer.Sound('./Music/New_Block.wav')
    game_over_sound = pygame.mixer.Sound('./Music/GameOver.wav')
    break_sound = pygame.mixer.Sound('./Music/break.wav')
    lines1_3 = pygame.mixer.Sound('./Music/1.-3.lane.wav')
    line4 = pygame.mixer.Sound('./Music/4.lane.wav')
    # pygame.mixer.music.play(-1)
    pygame.mixer.music.set_volume(0.5)
    pygame.mixer.music.play(-1)

    gamepad = Controller.Controller(joystick)

    # drawer for playfield
    rgg_led_drawer = rgbleddrawer.RgbLedDrawer()

    # drawer for scoreboard
    led_matrix_drawer = Matrix_Drawer.LedMatrixDrawer()

    # Playgrounds
    color_playground = Playground.Playground(20, 10)
    red_playground = Playground.Playground(8, 32)

    score1 = 0
    score2 = 0
    collision = Collision.Collision_Dedektor()

    clock = pygame.time.Clock()  # type: pygame.time.Clock
    clock_titlescreen(color_playground, rgg_led_drawer, red_playground, led_matrix_drawer, Controller)
    game_over = False
    while not game_over:
        color_playground.add_object(Objects.Objecttype.paddle_left, 3, 3)
        rgg_led_drawer.draw_playground(color_playground)
    #todo: here is were the game is written
    del led_matrix_drawer
    del rgg_led_drawer
    pygame.event.get()
    pygame.quit()
Exemplo n.º 2
0
 def test_playground_any_gield_empty(self):
     """Playground.is_any_field_empty() should give expected results for mentioned input"""
     for given_fields, expected in self.expected_values_any_field_empty:
         test_playground = Playground.Playground()
         test_playground.fields = given_fields
         result = test_playground.is_any_field_empty()
         self.assertEqual(expected, result)
Exemplo n.º 3
0
 def test_playground_field_empty(self):
     """Playground.is_field_empty() should give expected results for mentioned input"""
     for tup in self.expected_values_field_empty:
         test_playground = Playground.Playground()
         test_playground.fields = tup[0]
         result = test_playground.is_field_empty(tup[1], tup[2])
         self.assertEqual(tup[3], result)
Exemplo n.º 4
0
def clock_titlescreen(color_playground, rgg_led_drawer, red_playground, led_matrix_drawer, controller):
    while True:
        color_playground.clear()
        red_playground.clear()
        # TODO: this is a quite ugly hack, since NumberToBlock only supports 4 digit numbers
        now = datetime.datetime.now()
        min = now.time().minute
        hour = now.time().hour
        mon = now.date().month
        today = now.date().day
        sec = now.time().second
        year = now.date().year % 100
        color_playground.add_block(numbertoblock.NumberToBlock.get_block(hour * 100), 0, 0)
        color_playground.add_block(numbertoblock.NumberToBlock.get_block(min * 100), 0, 6)
        color_playground.add_block(numbertoblock.NumberToBlock.get_block(sec * 100), 0, 12)
        red_playground.add_block(numbertoblock.NumberToBlock.get_block(today * 100 + mon), 0, 0)
        red_playground.add_block(numbertoblock.NumberToBlock.get_block(year * 100), 21, 0)

        rgg_led_drawer.draw_playground(color_playground)
        led_matrix_drawer.draw_playground(red_playground)
        pygame.time.Clock().tick(1)

        result = controller.get_button_pressed((1, 1), Collision.Collision_Dedektor(),
                                               Playground.Playground(20, 10))
        if result == "Restart":
            break
    color_playground.clear()
    red_playground.clear()
Exemplo n.º 5
0
    def __init__(self, usb, dbg_handle, parent=None):
        super(MainDebugger, self).__init__(parent)
        self.setupUi(self)

        self.active_event = None

        self.usb = usb
        self.dbg_handle = dbg_handle
        self.usb_thread = EventReceiveThread(usb, dbg_handle)

        AddressFormatter.AddressFormatter(self.usb, self.dbg_handle)

        self.bp_manager = BreakpointManager(self.usb, self.dbg_handle,
                                            self.treeBreakpoints)
        expr_eval = ExpressionEvaluator(self.usb, self.dbg_handle, self)
        self.expr_eval = expr_eval

        self.adapters = []
        self.adapters.append(Lazy(usb, dbg_handle))
        self.adapters.append(
            AdapterMemoryLayout(usb, dbg_handle, self.treeMemory))
        self.adapters.append(AdapterThreadList(self.treeThreads))
        self.adapters.append(AdapterStateLabel(self.labelState))
        self.adapters.append(AdapterRegisters(usb, dbg_handle, self))
        self.adapters.append(
            AdapterStackTrace(usb, dbg_handle, self.treeStackTrace))
        self.adapters.append(
            AdapterView(usb, dbg_handle, expr_eval, self.lineCmdView0,
                        self.textOutputView0))
        self.adapters.append(
            AdapterView(usb, dbg_handle, expr_eval, self.lineCmdView1,
                        self.textOutputView1))
        self.adapters.append(
            AdapterView(usb, dbg_handle, expr_eval, self.lineCmdView2,
                        self.textOutputView2))
        self.adapters.append(Playground(usb, dbg_handle, self))

        self.connect(self.usb_thread, SIGNAL('onDbgEvent(PyQt_PyObject)'),
                     self.onDbgEvent)
        self.usb_thread.start()

        self.lineCmd.returnPressed.connect(self.onUserCmd)
Exemplo n.º 6
0
                    Label(frame, image=human_carry_apple_img).grid(row=row, column=col)
                else:
                    Label(frame, image=agent_img).grid(row=row, column=col)
            elif item == CELL_APPLE_STORAGE_CLOSE:
                Label(frame, image=apple_storage_closed_img).grid(row=row, column=col)
            col += 1
        row += 1


# game components initialize
principal = Actor(PRINCIPAL_X, PRINCIPAL_Y)
agent = Actor(AGENT_X, AGENT_Y)
storage = Storage(STORAGE_X, STORAGE_Y)

# bind the playground and the actors
playground = Playground.Playground(PLAYGROUND_HEIGHT, PLAYGROUND_WIDTH, principal, agent, storage)
agent.set_playground(playground)
principal.set_playground(playground)

# graphic UI
root = Tk()
frame = Frame(root)
frame.bind('<KeyPress>', processKeyboardEvent)
frame.pack()
frame.focus_set()

# set image ******************************** maybe optimized later
ground_img = PhotoImage(file=IMAGE_GROUND)
human_img = PhotoImage(file=IMAGE_HUMAN)
human_carry_apple_img = PhotoImage(file=IMAGE_HUMAN_CARRY_APPLE)
agent_img = PhotoImage(file=IMAGE_AGENT)
Exemplo n.º 7
0
        self.playground.set_pixel(3, 9, (0, 0, 255))
        self.playground.set_pixel(3, 10, (0, 0, 255))
        self.playground.set_pixel(3, 11, (0, 0, 255))
        self.playground.set_pixel(4, 11, (0, 0, 255))

        self.playground.set_pixel(5, 9, (0, 255, 0))
        self.playground.set_pixel(5, 10, (0, 255, 0))
        self.playground.set_pixel(5, 11, (0, 255, 0))
        self.playground.set_pixel(6, 8, (0, 255, 0))
        self.playground.set_pixel(6, 10, (0, 255, 0))
        self.playground.set_pixel(7, 9, (0, 255, 0))
        self.playground.set_pixel(7, 10, (0, 255, 0))
        self.playground.set_pixel(7, 11, (0, 255, 0))

        self.playground.set_pixel(7, 8, (255, 255, 0))
        self.playground.set_pixel(8, 9, (255, 255, 0))
        self.playground.set_pixel(8, 10, (255, 255, 0))
        self.playground.set_pixel(8, 11, (255, 255, 0))
        self.playground.set_pixel(9, 8, (255, 255, 0))

        Leonardo = Painter()
        Leonardo.write_text("* START")


if __name__ == "__main__":
    painter = Ws2812Painter.Ws2812Painter()
    playground = Playground.Playground(10, 20)
    s = Startmenu(playground)
    painter.paint(playground)
    time.sleep(100000)
Exemplo n.º 8
0
class GameUtil:

    pplayground = Playground.Playground()
    current_row = 0
    current_col = 1
    turn = Player.Player('', '')

    def print_on_start(self):
        print('Welcome to Tic-Tac-Toe game!')

    def print_game_result(self, player_a, player_b):
        """Prints final result: who is a winner or if it is a draw."""
        outp = ''
        result, winner = self.is_winner()
        if result:
            outp += 'The winner is: '
            if winner == player_a.get_pl_id():
                outp += player_a.get_name() + ' with: ' + player_a.get_pl_id()
            else:
                outp += player_b.get_name() + ' with: ' + player_b.get_pl_id()
        else:
            outp += 'There is a draw. Nobody has won.'
        return outp

    def create_player(self, player_id):
        """Creates player for game."""
        player_name = raw_input('Enter player\'s name for ' + str(player_id) +
                                ' : ')
        player = Player.Player(player_name, player_id)
        return player

    def is_winner(self):
        """
        Checks whether there is a winner
        :return: tuple(True if it is winner or False if it isn't, sign 'O' or 'X' of winner)
        """
        if (self.pplayground.get_field(0, 0) != ' ' and
            (self.pplayground.get_field(0, 0) == self.pplayground.get_field(
                0, 1) == self.pplayground.get_field(0, 2)
             or self.pplayground.get_field(0, 0) == self.pplayground.get_field(
                 1, 0) == self.pplayground.get_field(2, 0)
             or self.pplayground.get_field(0, 0) == self.pplayground.get_field(
                 1, 1) == self.pplayground.get_field(2, 2))):
            return True, self.pplayground.get_field(0, 0)
        elif (self.pplayground.get_field(0, 1) != ' ' and
              self.pplayground.get_field(0, 1) == self.pplayground.get_field(
                  1, 1) == self.pplayground.get_field(2, 1)):
            return True, self.pplayground.get_field(0, 1)
        elif (
                self.pplayground.get_field(0, 2) != ' ' and
            (self.pplayground.get_field(0, 2) == self.pplayground.get_field(
                1, 2) == self.pplayground.get_field(2, 2)
             or self.pplayground.get_field(0, 2) == self.pplayground.get_field(
                 1, 1) == self.pplayground.get_field(2, 0))):
            return True, self.pplayground.get_field(0, 2)
        elif (self.pplayground.get_field(1, 0) != ' ' and
              self.pplayground.get_field(1, 0) == self.pplayground.get_field(
                  1, 1) == self.pplayground.get_field(1, 2)):
            return True, self.pplayground.get_field(1, 0)
        elif (self.pplayground.get_field(2, 0) != ' ' and
              self.pplayground.get_field(2, 0) == self.pplayground.get_field(
                  2, 1) == self.pplayground.get_field(2, 2)):
            return True, self.pplayground.get_field(2, 0)
        else:
            return False, ''

    def get_playground(self):
        return self.pplayground

    def get_cur_row(self):
        return self.current_row

    def get_cur_col(self):
        return self.current_col

    def set_turn(self, pturn):
        self.turn = pturn
        print('It\'s ' + str(self.turn.get_name()) + '\'s turn.')

    def get_turn(self):
        return self.turn

    def get_player_turn(self):
        inp = raw_input('Enter field name (e.g. 1A):')
        return inp

    def parse_input(self, inp):
        """Parser for user input about which field he puts sign"""
        inp.upper()
        if re.search(r'^[1-3][ABC]$', inp):
            if inp[1] == 'A':
                self.current_col = 0
            elif inp[1] == 'B':
                self.current_col = 1
            elif inp[1] == 'C':
                self.current_col = 2
            self.current_row = int(inp[0]) - 1
            return True
        else:
            print('Invalid input.')
            return False
Exemplo n.º 9
0
def doDraw(way):
    play = Playground.Playground(way)
    play.run()


#doDraw("")