コード例 #1
0
class Board:
    def __init__(self):
        def onDrawBoardClick(button):
            self.boardSetup()
            self.draw_board()

        self.button = Button(300,
                             600,
                             txt="Nieuw Bord",
                             bgColor=(255, 255, 255),
                             onClick=onDrawBoardClick,
                             w=350,
                             h=60)

        def onBackButtonClick(button):
            self.goToMainMenu = True

        self.goToMainMenu = False
        self.backButton = Button(700,
                                 600,
                                 txt="Terug",
                                 onClick=onBackButtonClick)

    def boardSetup(self):
        self.board = []
        self.wood = loadImage('Hout.jpg')
        self.stone = loadImage('Stone.jpg')
        self.metal = loadImage('Metaal.jpg')
        self.water = loadImage('Water.jpg')
        self.grain = loadImage('Graan.png')
        self.empty = loadImage('empty_wood.jpg')
        for n in range(5):
            self.board.append(self.wood)
            self.board.append(self.stone)
            self.board.append(self.metal)
            self.board.append(self.grain)
        for n in range(48):
            self.board.append(self.empty)
        for n in range(23):
            self.board.append(self.water)

    def draw_board(self):
        self.amount_pieces = 0
        self.amount_rows = 0
        self.piece_x = 180
        self.piece_y = -50

        def row(self, amount_pieces, piece_x, piece_y):
            while self.amount_pieces < 13:
                self.piece = random.choice(self.board)
                self.piece.resize(
                    75, 75
                )  #Make them smaller so all the pieces can be displayed on the window
                image(self.piece, self.piece_x, self.piece_y)
                self.piece_x += 75
                self.amount_pieces += 1
                self.board.remove(self.piece)

        while self.amount_rows < 7:
            self.amount_pieces = 0
            self.piece_y += 75
            self.piece_x = 12
            row(self, self.amount_pieces, self.piece_x, self.piece_y)
            self.amount_rows += 1

    def setup(self):
        #fullScreen()
        #self.font=loadFont('BlackChancery-48.vlw')

        self.font = loadFont('BlackChancery.vlw')

        self.img = loadImage('TITLESCREEN2.png')
        # background(255,165,0)
        self.img.resize(1000, 726)  #resize to the size of the screen

        self.boardSetup()

    def drawOnce(self):
        #background(self.img)
        textFont(self.font)

    def draw(self):
        # if self.board==[]:
        #     self.boardSetup()
        self.button.update()
        self.backButton.update()
        self.button.draw()
        self.backButton.draw()
コード例 #2
0
class Markt:
    def __init__(self, tellers):

        self.movetoMainMenu = False
        self.backButton = Button(1300,
                                 950,
                                 txt='Terug',
                                 onClick=self.onBackClick,
                                 w=250,
                                 h=50)
        self.tellers = tellers
        self.showcard = False
        self.boughtbags = 0
        self.enoughbrick = True
        self.enoughgrain = True
        self.price = 3
        self.effect14 = False
        self.clicked = False
        self.resourcename = 'nothing'
        self.enoughmats = True
        self.chosenmat = 5
        self.pressed = False
        self.enoughmatspp = True
        self.buttons = [
            Button(200,
                   150,
                   txt="EffectKaart",
                   onClick=self.chosencard,
                   w=250,
                   h=50),
            Button(200, 250, txt="Reset", onClick=self.reset, w=250, h=50),
            Button(1300, 250, txt="Rugzak", onClick=self.backpack, w=250,
                   h=50),
            Button(850,
                   470,
                   txt="Gebruik",
                   onClick=self.Effect14Used,
                   w=250,
                   h=50),
            Button(1300,
                   550,
                   txt="Krachtpunt P1",
                   onClick=self.powerup1,
                   w=250,
                   h=50),
            Button(1300,
                   650,
                   txt="Krachtpunt P2",
                   onClick=self.powerup2,
                   w=250,
                   h=50),
            Button(1300,
                   750,
                   txt="Krachtpunt P3",
                   onClick=self.powerup3,
                   w=250,
                   h=50),
            Button(1300,
                   850,
                   txt="Krachtpunt P4",
                   onClick=self.powerup4,
                   w=250,
                   h=50),
        ]

        self.resourcesbuttons = [
            Button(200,
                   600,
                   txt="Hout",
                   onClick=self.Exchangewood,
                   w=250,
                   h=50),
            Button(200,
                   700,
                   txt="Steen",
                   onClick=self.Exchangebrick,
                   w=250,
                   h=50),
            Button(200,
                   800,
                   txt="Ijzer",
                   onClick=self.Exchangemetal,
                   w=250,
                   h=50),
            Button(200,
                   900,
                   txt="Graan",
                   onClick=self.Exchangegrain,
                   w=250,
                   h=50),
        ]

        self.matsbuttons = [
            Button(550, 600, txt="Hout", onClick=self.pluswood, w=250, h=50),
            Button(550, 700, txt="Steen", onClick=self.plusstone, w=250, h=50),
            Button(550, 800, txt="Ijzer", onClick=self.plusmetal, w=250, h=50),
            Button(550, 900, txt="Graan", onClick=self.plusgrain, w=250, h=50),
        ]

        self.errorbuttons = [
            Button(1650, 350, txt="OK", onClick=self.NoBrickError, w=100,
                   h=50),
            Button(500, 300, txt="OK", onClick=self.NoGrainError, w=100, h=50),
            Button(850, 750, txt="OK", onClick=self.NoMatserror, w=100, h=50),
            Button(1600,
                   730,
                   txt="OK",
                   onClick=self.NoMatsppError,
                   w=100,
                   h=50),
        ]

    def onBackClick(self, self1):
        self.movetoMainMenu = True

    def powerup1(self, self1):

        if self.tellers.wood >= self.price and self.tellers.brick >= self.price and self.tellers.metal >= self.price and self.tellers.grain >= self.price:
            self.tellers.power1 += 1
            self.tellers.wood -= self.price
            self.tellers.brick -= self.price
            self.tellers.metal -= self.price
            self.tellers.grain -= self.price
        else:
            self.enoughmatspp = False

    def powerup2(self, self1):

        if self.tellers.wood >= self.price and self.tellers.brick >= self.price and self.tellers.metal >= self.price and self.tellers.grain >= self.price:
            self.tellers.power2 += 1
            self.tellers.wood -= self.price
            self.tellers.brick -= self.price
            self.tellers.metal -= self.price
            self.tellers.grain -= self.price
        else:
            self.enoughmatspp = False

    def powerup3(self, self1):

        if self.tellers.wood >= self.price and self.tellers.brick >= self.price and self.tellers.metal >= self.price and self.tellers.grain >= self.price:
            self.tellers.power3 += 1
            self.tellers.wood -= self.price
            self.tellers.brick -= self.price
            self.tellers.metal -= self.price
            self.tellers.grain -= self.price
        else:
            self.enoughmatspp = False

    def powerup4(self, self1):

        if self.tellers.wood >= self.price and self.tellers.brick >= self.price and self.tellers.metal >= self.price and self.tellers.grain >= self.price:
            self.tellers.power4 += 1
            self.tellers.wood -= self.price
            self.tellers.brick -= self.price
            self.tellers.metal -= self.price
            self.tellers.grain -= self.price
        else:
            self.enoughmatspp = False

    def chosencard(self, self1):

        self.card = random.choice(self.effectcards)

        if self.card == self.effectcards[9]:
            self.tellers.effect10 = True
        if self.card == self.effectcards[13] and self.effect14 == True:
            self.card = random.choice(self.effectcards2)
        if self.tellers.grain >= self.price:
            self.showcard = True
            self.buttons[0].enabled = False
            self.tellers.grain -= self.price
        else:
            self.enoughgrain = False
            self.price = 3

    def effectcard(self):

        if self.showcard == True:
            image(self.card, 352, 77)

    def reset(self, self1):

        self.showcard = False
        self.buttons[0].enabled = True
        if self.card == self.effectcards[13]:
            self.effect14 = True
        if self.card == self.effectcards[4]:
            self.price = self.price // 2
        else:
            self.price = 3

    def backpack(self, self1):

        if self.tellers.brick >= self.price:
            self.tellers.bagcount = True
            self.buttons[2].enabled = False
            self.tellers.brick -= self.price
            self.tellers.capacity += 3
        else:
            self.enoughbrick = False

    def NoBrickError(self, self1):

        self.enoughbrick = True

    def NoGrainError(self, self1):

        self.enoughgrain = True

    def Effect14Used(self, self1):

        self.effect14 = False

    def Exchangewood(self, self1):

        if self.tellers.wood >= self.price:
            self.tellers.wood -= self.price
            self.clicked = True
            self.chosenmat = 0
        else:
            self.resourcename = 'Hout'
            self.enoughmats = False
            self.clicked = True
            self.chosenmat = 5

    def Exchangebrick(self, self1):

        if self.tellers.brick >= self.price:
            self.tellers.brick -= self.price
            self.clicked = True
            self.chosenmat = 1
        else:
            self.resourcename = 'steen'
            self.enoughmats = False
            self.clicked = True
            self.chosenmat = 5

    def Exchangemetal(self, self1):

        if self.tellers.metal >= self.price:
            self.tellers.metal -= self.price
            self.clicked = True
            self.chosenmat = 2
        else:
            self.resourcename = 'Ijzer'
            self.enoughmats = False
            self.clicked = True
            self.chosenmat = 5

    def Exchangegrain(self, self1):

        if self.tellers.grain >= self.price:
            self.tellers.grain -= self.price
            self.clicked = True
            self.chosenmat = 3

        else:
            self.resourcename = 'Graan'
            self.enoughmats = False
            self.clicked = True
            self.chosenmat = 5

    def pluswood(self, self1):

        if (self.tellers.wood + self.tellers.metal + self.tellers.brick +
                self.tellers.grain) < (self.tellers.capacity):
            self.tellers.wood += 1
            self.clicked = False

    def plusstone(self, self1):

        if (self.tellers.wood + self.tellers.metal + self.tellers.brick +
                self.tellers.grain) < (self.tellers.capacity):
            self.tellers.brick += 1
            self.clicked = False

    def plusmetal(self, self1):

        if (self.tellers.wood + self.tellers.metal + self.tellers.brick +
                self.tellers.grain) < (self.tellers.capacity):
            self.tellers.metal += 1
            self.clicked = False

    def plusgrain(self, self1):

        if (self.tellers.wood + self.tellers.metal + self.tellers.brick +
                self.tellers.grain) < (self.tellers.capacity):
            self.tellers.grain += 1
            self.clicked = False

    def NoMatserror(self, self1):

        self.clicked = False
        self.enoughmats = True

    def NoMatsppError(self, self1):
        self.enoughmatspp = True

    def setup(self):
        self.effectcards = []
        self.effectcards2 = []
        self.backgr = loadImage('BG.png')
        for self.i in range(1, 21):
            self.filename = 'effectkaart' + str(self.i) + '.png'
            self.effectcards.append(loadImage(self.filename))
        for self.i in range(1, 21):
            self.filename = 'effectkaart' + str(self.i) + '.png'
            if self.i != 14:
                self.effectcards2.append(loadImage(self.filename))

    def draw(self):
        image(self.backgr, 0, 0)
        self.backButton.update()
        self.backButton.draw()
        for self.x in range(3):
            self.buttons[self.x].draw()
            self.buttons[self.x].update()
        fill(0)
        text("Effectkaart", 500, 20)
        noFill()
        rect(350, 75, 304, 341, 5)
        self.effectcard()
        if not self.enoughbrick:
            rect(1500, 100, 300, 300)
            fill(0)
            text(
                '\n' + 'Onvoldoende' + '\n' + 'steen voor' + '\n' +
                'een rugzak!', 1650, 100)
            self.errorbuttons[0].draw()
            self.errorbuttons[0].update()

        if not self.enoughgrain:
            fill(0)
            text(
                'Onvoldoende' + '\n' + 'graan voor' + '\n' +
                'een effectkaart!', 500, 100)
            self.errorbuttons[1].draw()
            self.errorbuttons[1].update()
        if self.effect14:
            rect(700, 77, 304, 341, 5)
            image(self.effectcards[13], 702, 79)
            self.buttons[3].draw()
            self.buttons[3].update()
        if self.buttons[0].enabled == True:
            self.buttons[1].enabled = False
        else:
            self.buttons[1].enabled = True
        fill(0)
        text('Wissel : ', 200, 500)
        text('Voor : ', 550, 500)
        for i in range(4):
            self.resourcesbuttons[i].draw()
            self.resourcesbuttons[i].update()
            self.matsbuttons[i].draw()
            self.matsbuttons[i].update()
            if self.clicked:
                self.resourcesbuttons[i].enabled = False
                if self.enoughmats and i != self.chosenmat:
                    self.matsbuttons[i].enabled = True
            else:
                self.resourcesbuttons[i].enabled = True
                self.matsbuttons[i].enabled = False

        if not self.enoughmats:
            fill(0)
            text('Onvoldoende' + '\n' + self.resourcename + '!', 850, 630)
            noFill()
            rect(700, 600, 300, 200, 5)
            self.errorbuttons[2].draw()
            self.errorbuttons[2].update()
        for self.i in range(4, 8):
            self.buttons[self.i].draw()
            self.buttons[self.i].update()
        if not self.enoughmatspp:
            noFill()
            rect(1450, 550, 300, 250, 5)
            fill(0)
            text('Onvoldoende' + '\n' + 'Resources!', 1600, 600)
            self.errorbuttons[3].draw()
            self.errorbuttons[3].update()
            for self.i in range(4, 8):
                self.buttons[self.i].enabled = False
        else:
            for self.i in range(4, 8):
                self.buttons[self.i].enabled = True
コード例 #3
0
class tellers:
    def __init__(self, Names):
        self.Names = Names

        def onBackButtonClick(button):
            self.goToMainMenu = True

        self.goToMainMenu = False
        self.backButton = Button(1000,
                                 300,
                                 txt="Terug",
                                 onClick=onBackButtonClick)
        self.effect10 = False
        self.wood = 0
        self.brick = 0
        self.metal = 0
        self.grain = 0
        self.stamina1 = 7
        self.stamina2 = 7
        self.stamina3 = 7
        self.stamina4 = 7
        self.win_points = 0
        self.capacity = 10
        self.power1 = 2
        self.power2 = 2
        self.power3 = 2
        self.power4 = 2
        self.days = 0
        self.bagcount = False
        self.newdeck = False
        self.action11chosen = False
        self.actionbagcap = False
        self.w = 1920
        self.h = 1080
        self.buttons2 = [
            Button(330, 100, txt="+", onClick=self.addition_wood, w=100, h=50),
            Button(100, 100, txt="-", onClick=self.sub_wood, w=100, h=50),
            Button(330, 250, txt="+", onClick=self.addition_brick, w=100,
                   h=50),
            Button(100, 250, txt="-", onClick=self.sub_brick, w=100, h=50),
            Button(330, 400, txt="+", onClick=self.addition_metal, w=100,
                   h=50),
            Button(100, 400, txt="-", onClick=self.sub_metal, w=100, h=50),
            Button(330, 550, txt="+", onClick=self.addition_grain, w=100,
                   h=50),
            Button(100, 550, txt="-", onClick=self.sub_grain, w=100, h=50),
            Button(730,
                   100,
                   txt="+",
                   onClick=self.addition_stamina1,
                   w=100,
                   h=50),
            Button(500, 100, txt="-", onClick=self.sub_stamina1, w=100, h=50),
            Button(730,
                   250,
                   txt="+",
                   onClick=self.addition_stamina2,
                   w=100,
                   h=50),
            Button(500, 250, txt="-", onClick=self.sub_stamina2, w=100, h=50),
            Button(730,
                   400,
                   txt="+",
                   onClick=self.addition_stamina3,
                   w=100,
                   h=50),
            Button(500, 400, txt="-", onClick=self.sub_stamina3, w=100, h=50),
            Button(730,
                   550,
                   txt="+",
                   onClick=self.addition_stamina4,
                   w=100,
                   h=50),
            Button(500, 550, txt="-", onClick=self.sub_stamina4, w=100, h=50),
            #Button(730, 670, txt="+", onClick =self.addition_winning, w = 100, h = 50),
            Button(330,
                   670,
                   txt="+",
                   onClick=self.addition_capacity,
                   w=100,
                   h=50),
            Button(100, 670, txt="-", onClick=self.sub_capacity, w=100, h=50),
            #Button(500, 670, txt="-", onClick =self.sub_winning, w = 100, h = 50),
            Button(1000,
                   100,
                   txt="Dag voorbij",
                   onClick=self.playersdone,
                   w=300,
                   h=50),
            Button(1000,
                   200,
                   txt="reset",
                   onClick=self.another_card,
                   w=300,
                   h=50),
            Button(330, 790, txt="+", onClick=self.powerup1, w=100, h=50),
            Button(100, 790, txt="-", onClick=self.powerdown1, w=100, h=50),
            Button(330, 890, txt="+", onClick=self.powerup3, w=100, h=50),
            Button(100, 890, txt="-", onClick=self.powerdown3, w=100, h=50),
            Button(730, 790, txt="+", onClick=self.powerup2, w=100, h=50),
            Button(500, 790, txt="-", onClick=self.powerdown2, w=100, h=50),
            Button(730, 890, txt="+", onClick=self.powerup4, w=100, h=50),
            Button(500, 890, txt="-", onClick=self.powerdown4, w=100, h=50)
        ]

    def powerup1(self, self1):
        self.power1 += 1

    def powerdown1(self, self1):
        if self.power1 > 0:
            self.power1 -= 1

    def powerup2(self, self1):
        self.power2 += 1

    def powerdown2(self, self1):
        if self.power2 > 0:
            self.power2 -= 1

    def powerup3(self, self1):
        self.power3 += 1

    def powerdown3(self, self1):
        if self.power3 > 0:
            self.power3 -= 1

    def powerup4(self, self1):
        self.power4 += 1

    def powerdown4(self, self1):
        if self.power4 > 0:
            self.power4 -= 1

    def addition_winning(self, self1):

        if self.win_points < 20:
            self.win_points += 1

    def sub_winning(self, self1):

        if self.win_points > 0:
            self.win_points -= 1

    def addition_capacity(self, self1):

        self.capacity += 1

    def sub_capacity(self, self1):

        if self.capacity > 10 and self.capacity != self.brick + self.metal + self.wood + self.grain:
            self.capacity -= 1

    def addition_stamina1(self, self1):

        self.stamina1 += 1

    def sub_stamina1(self, self1):

        if self.stamina1 > 0:
            self.stamina1 -= 1

    def addition_stamina2(self, self1):

        self.stamina2 += 1

    def sub_stamina2(self, self1):
        if self.stamina2 > 0:
            self.stamina2 -= 1

    def addition_stamina3(self, self1):
        self.stamina3 += 1

    def sub_stamina3(self, self1):

        if self.stamina3 > 0:
            self.stamina3 -= 1

    def addition_stamina4(self, self1):
        self.stamina4 += 1

    def sub_stamina4(self, self1):
        if self.stamina4 > 0:
            self.stamina4 -= 1

    def addition_wood(self, self1):
        if (self.wood + self.metal + self.brick +
                self.grain) < (self.capacity):
            self.wood += 1

    def sub_wood(self, self1):
        if self.wood > 1:
            self.wood -= 1
        else:
            self.wood = 0

    def addition_brick(self, self1):
        if (self.wood + self.metal + self.brick +
                self.grain) < (self.capacity):
            self.brick += 1

    def sub_brick(self, self1):
        if self.brick > 1:
            self.brick -= 1
        else:
            self.brick = 0

    def addition_metal(self, self1):
        if (self.wood + self.metal + self.brick +
                self.grain) < (self.capacity):
            self.metal += 1

    def sub_metal(self, self1):
        if self.metal > 1:
            self.metal -= 1
        else:
            self.metal = 0

    def addition_grain(self, self1):
        if (self.wood + self.metal + self.brick +
                self.grain) < (self.capacity):
            self.grain += 1

    def sub_grain(self, self1):
        if self.grain > 1:
            self.grain -= 1
        else:
            self.grain = 0

    def playersdone(self, self1):
        self.players_done = True
        if self.effect10:
            self.days += 0
        else:
            self.days += 1
            self.effect10 = False
        return self.players_done

    def action_card(self):
        self.clicked = 0
        if self.players_done:
            image(self.card, 1203, 83)
            self.buttons2[18].enabled = False
            if self.card == self.action11 and self.newdeck == False:
                self.action11chosen = True
                self.actionbagcap = True

    def another_card(self, self1):
        global card
        global players_done
        global clicked
        global buttons2
        self.players_done = False
        self.clicked += 1
        self.card = random.choice(self.action_cards)
        self.action_cards.remove(self.card)
        self.buttons2[18].enabled = True
        self.effect10 = False
        if self.actionbagcap:
            self.capacity += 5
            self.actionbagcap = False
        if self.clicked == 1:
            redraw()

    def winning(self, self1):
        global win_count
        global player_win
        if self.player_win:
            win_count += 1

    def setup(self):
        global players_done
        global action_cards
        global card
        global players_done
        global clicked
        global action11
        self.img = loadImage("BG.png")
        self.bag = loadImage("bag.png")
        self.players_done = False
        self.clicked = 0
        self.action11 = loadImage('actiekaart11.png')
        self.action_cards = [self.action11]
        for self.i in range(1, 21):
            self.filename = "actiekaart" + str(self.i) + ".png"
            if self.i != 10 and self.i != 11:
                self.action_cards.append(loadImage(self.filename))
        self.card = random.choice(self.action_cards)
        self.action_cards.remove(self.card)

    def draw(self):
        self.player1 = self.Names[0]
        self.p1_display = 'Stamina ' + str(self.player1)
        self.player2 = self.Names[1]
        self.p2_display = 'Stamina ' + str(self.player2)
        self.player3 = self.Names[2]
        self.p3_display = 'Stamina ' + str(self.player3)
        self.player4 = self.Names[3]
        self.p4_display = 'Stamina ' + str(self.player4)
        if self.action_cards == []:
            self.newdeck = True
            for self.i in range(1, 21):
                self.filename = "actiekaart" + str(self.i) + ".png"
                if self.i != 10 and self.i != 11:
                    self.action_cards.append(loadImage(self.filename))
        image(self.img, 0, 0)
        if self.bagcount:
            image(self.bag, 850, 450)
        if self.action11chosen:
            image(self.bag, 1000, 450)
        noFill()
        rect(1200, 80, 305, 342, 5)
        fill(0)
        text('Actie kaart', 1350, 20)
        text('HOUT', 220, 20)
        text(str(self.wood), 220, 80)
        text('STEEN', 220, 170)
        text(str(self.brick), 220, 230)
        text('IJZER', 220, 320)
        text(str(self.metal), 220, 380)
        text('GRAAN', 220, 480)
        text(str(self.grain), 220, 530)
        text(str(self.p1_display), 620, 20)
        text(str(self.stamina1), 620, 80)
        text(str(self.p2_display), 620, 170)
        text(str(self.stamina2), 620, 230)
        text(str(self.p3_display), 620, 320)
        text(str(self.stamina3), 620, 380)
        text(str(self.p4_display), 620, 480)
        text(str(self.stamina4), 620, 530)
        text('Overwinningspunten', 620, 600)
        text(str(self.win_points), 620, 650)
        text('Opslag Capaciteit', 220, 600)
        text(str(self.capacity), 220, 650)
        text(str(self.power1), 220, 780)
        text('KrachtPunten ' + str(self.player1), 215, 720)
        text(str(self.power3), 220, 880)
        text('KrachtPunten ' + str(self.player2), 215, 825)
        text(str(self.power2), 620, 780)
        text('KrachtPunten ' + str(self.player3), 615, 720)
        text(str(self.power4), 620, 880)
        text('KrachtPunten ' + str(self.player4), 615, 825)
        if self.buttons2[18].enabled == True:
            self.buttons2[19].enabled = False
        else:
            self.buttons2[19].enabled = True
        self.action_card()

        for button in self.buttons2:
            button.update()
            button.draw()
            button.update()

        self.backButton.update()
        self.backButton.draw()