示例#1
0
 def onClicked(self, events):
     for event in events:
         if event.type == pygame.MOUSEBUTTONDOWN and (event.button == 1
                                                      or event.button == 3):
             # creation of an array that stores all possible inventories
             cases = [[gui.Gui.getPositionCoords(self.eq.bb), self.eq],
                      [gui.Gui.getPositionCoords(self.bar.bb), self.bar]]
             # get the non-None value from the array (get the coords of the mouse that's inside a bounding box
             # of an container)
             val = next((case for case in cases if case[0] is not None),
                        None)
             if val is not None:
                 # get the relative coordinates in the container
                 slot = (val[0][0] - val[1].bb[0] // 32,
                         val[0][1] - val[1].bb[1] // 32)
                 # get copies of item instances in the inv
                 item = val[1].container.getItemInSlot(slot).__copy__()
                 hand = self.item_in_hand.__copy__()
                 # lef click check
                 if event.button == 1:
                     # swaping
                     if item.item != hand.item:
                         val[1].container.takeItem(item.quantity, slot)
                         self.item_in_hand = item
                         val[1].container.addItem(hand.item, hand.quantity,
                                                  slot)
                     # leaving item
                     else:
                         val[1].container.addItem(hand.item, hand.quantity,
                                                  slot)
                         self.item_in_hand = Slot.Slot("empty")
                 else:
                     # picking up half of the stack
                     if hand.item == "empty":
                         amount = item.quantity // 2 + item.quantity % 2
                         val[1].container.takeItem(amount, slot)
                         self.item_in_hand = item
                         self.item_in_hand.quantity = amount
                     # leaving individual pieces
                     elif item.item == "empty" or item.item == hand.item:
                         val[1].container.addItem(hand.item, 1, slot)
                         self.item_in_hand.quantity -= 1
                         if self.item_in_hand.quantity == 0:
                             self.item_in_hand = Slot.Slot("empty")
                     # swaping if items are different
                     else:
                         val[1].container.takeItem(item.quantity, slot)
                         self.item_in_hand = item
                         val[1].container.addItem(hand.item, hand.quantity,
                                                  slot)
示例#2
0
	def __init__(self, x, y, sizeX, sizeY):
		self.rect = Rectangle.Rectangle(x, y, sizeX, sizeY)
		
		self.BoardW = 9
		self.BoardH = 9
		self.SlotW = self.rect.Width / self.BoardW
		self.SlotH = self.rect.Height / self.BoardH
		
		self.Slots = []
		self.EmptySlots = []
		for i in range(0, self.BoardW):
			self.Slots.append([])
			for j in range(0, self.BoardH):
				slot = Slot.Slot(self.rect.X + i * self.SlotW, self.rect.Y + j *self.SlotH)
				self.Slots[i].append(slot)
				self.EmptySlots.append([i, j])
				
		self.PickedSlot = None
		self.PickBox = None
		
		self.WaitTpyes = []
		
		self.Score = 0
		self.State = "WaitPrep" # WaitPrep/Idle/WaitMove/WaitClear/WaitPut
		self.firstTime = 1
		self.GameOver = 0
		
		# Wait状态族临时量
		self.WaitMove = None
		self.WaitRemove = None
示例#3
0
	def __init__(self, x, y, sizeX, sizeY):
		self.rect = Rectangle.Rectangle(x, y, sizeX, sizeY)
		
		self.BoardW = 9
		self.BoardH = 9
		self.SlotW = self.rect.Width / self.BoardW
		self.SlotH = self.rect.Height / self.BoardH
		
		self.Slots = []
		self.EmptySlots = []
		for i in range(0, self.BoardW):
			self.Slots.append([])
			for j in range(0, self.BoardH):
				slot = Slot.Slot(self.rect.X + i * self.SlotW, self.rect.Y + j *self.SlotH,0.86, 0.82)
				self.Slots[i].append(slot)
				self.EmptySlots.append([i, j])
				
		self.PickedSlot = None
		self.PickBox = None
		
		self.WaitTypes = []
		
		self.Score = 0
		self.GameOver = 0
		
		self.RDPrepSlot(3)
		self.RDPutSlot()
		self.RDPrepSlot(3)
    def __init__(self, hf1, hf2):
        self.tbl = []

        for i in range(s.Slot.MAX_TBL):
            self.tbl.append(s.Slot())
        
        self.hash_func1 = hf1
        self.hash_func2 = hf2
示例#5
0
 def setCard(self, cardNumber=5):
     self.slot = []
     for i in range(5):
         temp = []
         for i in range(cardNumber):
             slot = Slot.Slot(i, (450 + 120 * i, 530), self.screen, 0.2,
                              self.deck)
             temp.append(slot)
         self.slot.append(temp)
示例#6
0
def make_slots(dates, gyms, times):
    slots = []

    for d in dates:
        for g in gyms:
            for c in g.courts:
                for t in times:
                    slots.append(Slot(d, g, c, t))

    return slots
示例#7
0
 def InitData(Type):
     if (Type == 'A'):
         Own = Location(XD, YD)
     elif (Type == 'B'):
         Own = Location(XD, -YD)
     elif (Type == 'C'):
         Own = Location(-XD, YD)
     elif (Type == 'D'):
         Own = Location(-XD, -YD)
     else:
         Own = Location.InitDestination()
     Xaxis = Own[X] / XD
     Yaxis = Own[Y] / YD
     TmpS = []
     for x in range(1, LOW_BOUND):
         for y in range(1, SUP_BOUND):
             TmpS.append(
                 Slot([
                     Location(x * Xaxis, y * Yaxis),
                     random.uniform(CONST_SUP_FEE, CONST_INF_FEE), True,
                     ManagerPrefer(),
                     Location(0, 0), 0
                 ]))
     return TmpS, Own
示例#8
0
class Inventory:
    gui_handler = Gui.Gui()
    bar = gui.Bar.Bar()
    eq = gui.Equipment.Equipment()

    picked_slot = 0
    clicked_slot = None
    item_in_hand = Slot.Slot("empty")

    eq_opened = False
    crafting_opened = False

    def draw_bar(self, window):
        self.bar.draw(window, self.gui_handler)

    def draw_eq(self, window):
        self.eq.draw(window, self.gui_handler)

    # crafting nie dziala bo i tak nikt go nie zrobil to nie chce mi sie na razie naprawiac
    def draw_crafting(self, window):
        self.gui_handler.drawGrid(window, [], 40, (-14, -4, 3, 3))

    def draw_picked_slot(self, window):
        self.gui_handler.pickSlot(
            window,
            (self.bar.bb[0] // 32 + self.picked_slot, self.bar.bb[1] // 32))

    def draw_item_in_hand(self, window):
        if self.item_in_hand.item != "empty":
            pos = pygame.mouse.get_pos()
            self.gui_handler.drawTexture(window, self.item_in_hand, pos)

    def change_picked_slot(self, events):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 5:
                    self.picked_slot += 1
                    self.picked_slot %= 10
                if event.button == 4:
                    self.picked_slot -= 1
                    self.picked_slot %= 10
            elif event.type == pygame.KEYDOWN:
                if slot_keys.get(
                        event.key, 2137
                ) != 2137:  # basically check if event.key in dictionary
                    self.picked_slot = slot_keys[event.key]  # set slot

    # this function does all the logic of moving items in inventory
    def onClicked(self, events):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN and (event.button == 1
                                                         or event.button == 3):
                # creation of an array that stores all possible inventories
                cases = [[gui.Gui.getPositionCoords(self.eq.bb), self.eq],
                         [gui.Gui.getPositionCoords(self.bar.bb), self.bar]]
                # get the non-None value from the array (get the coords of the mouse that's inside a bounding box
                # of an container)
                val = next((case for case in cases if case[0] is not None),
                           None)
                if val is not None:
                    # get the relative coordinates in the container
                    slot = (val[0][0] - val[1].bb[0] // 32,
                            val[0][1] - val[1].bb[1] // 32)
                    # get copies of item instances in the inv
                    item = val[1].container.getItemInSlot(slot).__copy__()
                    hand = self.item_in_hand.__copy__()
                    # lef click check
                    if event.button == 1:
                        # swaping
                        if item.item != hand.item:
                            val[1].container.takeItem(item.quantity, slot)
                            self.item_in_hand = item
                            val[1].container.addItem(hand.item, hand.quantity,
                                                     slot)
                        # leaving item
                        else:
                            val[1].container.addItem(hand.item, hand.quantity,
                                                     slot)
                            self.item_in_hand = Slot.Slot("empty")
                    else:
                        # picking up half of the stack
                        if hand.item == "empty":
                            amount = item.quantity // 2 + item.quantity % 2
                            val[1].container.takeItem(amount, slot)
                            self.item_in_hand = item
                            self.item_in_hand.quantity = amount
                        # leaving individual pieces
                        elif item.item == "empty" or item.item == hand.item:
                            val[1].container.addItem(hand.item, 1, slot)
                            self.item_in_hand.quantity -= 1
                            if self.item_in_hand.quantity == 0:
                                self.item_in_hand = Slot.Slot("empty")
                        # swaping if items are different
                        else:
                            val[1].container.takeItem(item.quantity, slot)
                            self.item_in_hand = item
                            val[1].container.addItem(hand.item, hand.quantity,
                                                     slot)

    def update(self, events):
        self.change_picked_slot(events)
        if self.eq_opened:
            self.onClicked(events)

    def draw(self, window):
        self.draw_bar(window)
        self.draw_picked_slot(window)
        if self.eq_opened:
            self.draw_eq(window)
            self.gui_handler.drawHighlighted(window, self.eq.bb)
            self.gui_handler.drawHighlighted(window, self.bar.bb)
            self.draw_item_in_hand(window)
示例#9
0
    def __init__(self, num_rows, num_columns, game_mode):
        # Initialize a board with num_rows rows and num_columns columns
        self.table = False
        self.num_rows = num_rows
        self.num_columns = num_columns
        if game_mode == "AgentsLearn" or game_mode == "TeachAgents":
            self.container = [[
                slt.Slot(i, j, slt.Slot.SIZE, slt.Slot.SIZE,
                         j * slt.Slot.SIZE + 50,
                         i * slt.Slot.SIZE + cfg.Y_MARGIN)
                for j in range(num_columns)
            ] for i in range(num_rows)]
        else:
            self.container = [[
                slt.Slot(i, j, slt.Slot.SIZE, slt.Slot.SIZE,
                         j * slt.Slot.SIZE + cfg.X_MARGIN,
                         i * slt.Slot.SIZE + cfg.Y_MARGIN)
                for j in range(num_columns)
            ] for i in range(num_rows)]

        self.maxqnew = 1
        self.q = []
        self.num_rows = num_rows
        self.num_columns = num_columns
        self.total_slots = num_rows * num_columns
        self.num_slots_filled = 0
        self.last_visited_nodes = []
        self.last_value = 0

        self.state = [[0 for j in range(num_columns)] for i in range(num_rows)]
        self.prev_state = None
        self.prev_move = (None, None, None)
        # initialize the internal graph representation of the board
        # where every node is connected to all the other nodes in the 8
        # directions surrounding it to which it already contains pointers
        self.representation = [[
            stn.SlotTrackerNode() for j in range(num_columns)
        ] for i in range(num_rows)]
        for i in range(num_rows):
            prev_row_index = i - 1
            next_row_index = i + 1
            for j in range(num_columns):
                prev_col_index = j - 1
                next_col_index = j + 1
                current_node = self.representation[i][j]
                if prev_row_index >= 0 and prev_col_index >= 0:
                    current_node.top_left = self.representation[
                        prev_row_index][prev_col_index]
                if prev_row_index >= 0:
                    current_node.top = self.representation[prev_row_index][j]
                if prev_row_index >= 0 and next_col_index < num_columns:
                    current_node.top_right = self.representation[
                        prev_row_index][next_col_index]
                if prev_col_index >= 0:
                    current_node.left = self.representation[i][prev_col_index]

                if next_col_index < num_columns:
                    current_node.right = self.representation[i][next_col_index]
                if next_row_index < num_rows and prev_col_index >= 0:
                    current_node.bottom_left = self.representation[
                        next_row_index][prev_col_index]

                if next_row_index < num_rows:
                    current_node.bottom = self.representation[next_row_index][
                        j]
                if next_row_index < num_rows and next_col_index < num_columns:
                    current_node.bottom_right = self.representation[
                        next_row_index][next_col_index]
示例#10
0
 def __init__(self, corners):
     self.corners = corners  # tuple
     self.content = []
     self.size = self.corners[2] * self.corners[3]
     for i in range(self.size):
         self.content.append(Slot.Slot("empty"))
示例#11
0
def init(data):
    # There is only one init, not one-per-mode
    data.mode = "start"
    data.score = 0
    data.numPlayers = 1
    data.countdown = 5
    data.timerDelay = 10  #10000 is a second
    data.levels = readLevels([], [], 'gameFiles')
    #allSongs is a 3D list: a list with songs (that are 2D lists themselves)
    data.allSongs = []
    readNotes(data, data.levels, [], 0)
    data.scoreboard = readScoreboard('gameFiles\scoreboard.txt', [])

    #actual music
    data.songs = readSongs('songs', [])

    #aesthetics
    data.startTimer = 0
    data.startScreenNotes = []
    data.endTimer = 0

    ##BUTTONS
    #start screen buttons
    data.start = StartButton(data.width // 2, data.height // 2 + 50)
    data.help = HelpButton(data.width - 50, 50)
    data.addScreen = AddScreenButton(50, 50)
    #choice screen buttons
    data.one = oneButton(250, 300)
    data.two = twoButton(750, 300)
    data.backChoice = BackButton(50, 50)
    #help screen buttons
    data.backHelp = BackButton(50, 50)
    #end screen buttons
    data.retry = RetryButton(50, 50)
    if (data.numPlayers == 1):
        data.highScore = HighScoreButton(data.width // 2,
                                         data.height // 2 + 50)
    #scoreboard screen buttons
    data.backScore = BackButton(50, 50)
    #add screen buttons
    data.backAdd = BackButton(50, 50)
    data.add = AddButton(data.width - 50, 50)

    ##SLOTS
    #one player
    data.rslot = Slot(0)
    data.bslot = Slot(1)
    data.yslot = Slot(2)
    data.gslot = Slot(3)

    #two player
    data.r1slot = Slot(0)
    data.b1slot = Slot(1)
    data.y1slot = Slot(2)
    data.g1slot = Slot(3)
    data.r2slot = Slot(4)
    data.b2slot = Slot(5)
    data.y2slot = Slot(6)
    data.g2slot = Slot(7)

    ##GENERAL GAME
    data.countdown = 5  #the game countdown til it reaches game over
    #every five circles the a second is added back
    data.timerCounter = 0  #starts off with no seconds
    data.musicPaused = False
    data.timerCounter = 0
    data.currentLevel = 0
    data.notes = data.allSongs[data.currentLevel]
    data.currentNotes = []

    #two player
    data.currentNotesP1 = []
    data.currentNotesP2 = []
    data.scoreP1 = 0
    data.scoreP2 = 0

    ##ADD SCREEN OPTIONS
    data.rows = 60
    data.cols = 4
    data.selection = (-1, -1)

    data.createNotes = []
    for row in range(data.rows):
        notes = [0, 0, 0, 0]
        security = copy.copy(notes)
        data.createNotes.append(security)

    data.marginX = data.width // 4
    data.marginY = 10
示例#12
0
def twoPersonPlayKeyPressed(event, data):
    if (event.keysym == 'p'):
        data.musicPaused = not data.musicPaused
    elif (event.keysym == 'a'):
        check = Slot(0)
        for note in data.currentNotesP1:
            if (check.overlap(note.x, note.y)):
                data.scoreP1 += 1
                note.color = 'white'
                data.currentNotesP1.remove(note)
    elif (event.keysym == 's'):
        check = Slot(1)
        for note in data.currentNotesP1:
            if (check.overlap(note.x, note.y)):
                data.scoreP1 += 1
                note.color = 'white'
                data.currentNotesP1.remove(note)
    elif (event.keysym == 'd'):
        check = Slot(2)
        for note in data.currentNotesP1:
            if (check.overlap(note.x, note.y)):
                data.scoreP1 += 1
                note.color = 'white'
                data.currentNotesP1.remove(note)
    elif (event.keysym == 'f'):
        check = Slot(3)
        for note in data.currentNotesP1:
            if (check.overlap(note.x, note.y)):
                data.scoreP1 += 1
                note.color = 'white'
                data.currentNotesP1.remove(note)

    #player 2
    if (event.keysym == 'y'):
        data.musicPaused = not data.musicPaused
    elif (event.keysym == 'h'):
        check = Slot(4)
        for note in data.currentNotesP2:
            if (check.overlap(note.x, note.y)):
                data.scoreP2 += 1
                note.color = 'white'
                data.currentNotesP2.remove(note)
    elif (event.keysym == 'j'):
        check = Slot(5)
        for note in data.currentNotesP2:
            if (check.overlap(note.x, note.y)):
                data.scoreP2 += 1
                note.color = 'white'
                data.currentNotesP2.remove(note)
    elif (event.keysym == 'k'):
        check = Slot(6)
        for note in data.currentNotesP2:
            if (check.overlap(note.x, note.y)):
                data.scoreP2 += 1
                note.color = 'white'
                data.currentNotesP2.remove(note)
    elif (event.keysym == 'l'):
        check = Slot(7)
        for note in data.currentNotesP2:
            if (check.overlap(note.x, note.y)):
                data.scoreP2 += 1
                note.color = 'white'
                data.currentNotesP2.remove(note)
    elif (event.keysym == 'e'):
        data.timerCounter = 4000
        data.countdown = 5
    elif (event.keysym == 'q'):
        data.mode = 'end'
示例#13
0
def onePersonPlayKeyPressed(event, data):
    if (event.keysym == 'p'):
        data.musicPaused = not data.musicPaused
    elif (event.keysym == 'a'):
        check = Slot(0)
        for note in data.currentNotes:
            if (check.overlap(note.x, note.y)):
                data.score += 1
                note.color = 'white'
                data.currentNotes.remove(note)
    elif (event.keysym == 's'):
        check = Slot(1)
        for note in data.currentNotes:
            if (check.overlap(note.x, note.y)):
                data.score += 1
                note.color = 'white'
                data.currentNotes.remove(note)
    elif (event.keysym == 'd'):
        check = Slot(2)
        for note in data.currentNotes:
            if (check.overlap(note.x, note.y)):
                data.score += 1
                note.color = 'white'
                data.currentNotes.remove(note)
    elif (event.keysym == 'f'):
        check = Slot(3)
        for note in data.currentNotes:
            if (check.overlap(note.x, note.y)):
                data.score += 1
                note.color = 'white'
                data.currentNotes.remove(note)
    elif (event.keysym == 'e'):
        data.timerCounter = 4000
        data.countdown = 5
    elif (event.keysym == 'q'):
        data.mode = 'end'