Esempio n. 1
0
 def run(self):
     while self.nedotaknjena or stevilo_eksplodiranih_zog > 0:
         self.x, self.y = risar.miska
         if risar.klik and not self.klik:
             self.klik = True
             risar.klik = False
             self.klik_time = time.time()
         elif self.klik:
             if time.time() - self.klik_time > 4:
                 self.nedotaknjena = False
                 self.zoga_miske.krog.hide()
                 self.zoga_miske.already_exploded = True
         else:
             self.zoga_miske.move(self.x, self.y)
         for self.zoga in self.zoge:
             if self.zoga.moving:
                 self.zoga.move(None, None)
             else:
                 if self.zoga.explosion:
                     self.zoga.explosion_timer()
             if self.klik and not self.zoga.explosion and not self.zoga.already_exploded \
                     and not self.zoga_miske.already_exploded and self.zoga.collision_ball(self.zoga_miske):
                 self.zoga.explode()
                 self.nedotaknjena = False
                 eksplodirane_zoge.append(self.zoga)
             if not self.zoga.explosion and not self.zoga.already_exploded:
                 for eksplodirana_zoga in eksplodirane_zoge:
                     if self.zoga.collision_ball(eksplodirana_zoga):
                         self.zoga.explode()
                         eksplodirane_zoge.append(self.zoga)
                         break
         risar.cakaj(0.02)
     risar.pobrisi()
def main():

    from unittest.mock import Mock
    from itertools import count

    if hasattr(Oseba, "premik") and Oseba.premik.__code__.co_argcount == 1:
        Oseba.premik = lambda self, osebe, f=Oseba.premik: f(self)

    for method in ("premik", "okuzi_se", "okuzi_bliznje", "zdravi_se"):
        if not hasattr(Oseba, method):
            setattr(Oseba, method, Mock())

    globals().setdefault("nijz", None)

    osebe = [Oseba() for _ in range(100)]
    for oseba in osebe[:5]:
        oseba.okuzi_se()
    for oseba in osebe:
        if hasattr(Oseba, "vrni_krog") and hasattr(Oseba, "v_izolacijo"):
            oseba.vrni_krog().setOnClick(oseba.v_izolacijo)

    for cas in count():
        for oseba in osebe:
            oseba.zdravi_se()
            oseba.okuzi_bliznje(osebe)
            oseba.premik(osebe)
        if nijz and cas % 10 == 0:
            nijz.porocaj()
        risar.cakaj(0.02)
def za_8():
    krogi = []
    for i in range(30):
        krog = risar.krog(
            randint(15, risar.maxX - 15), randint(15, risar.maxY - 15), 10,
            risar.barva(randint(0, 150), randint(0, 150), randint(0, 150)), 3)
        krogi.append([krog, 2 * random() + 3, 2 * random() + 3])
    miska = risar.krog(risar.miska[0], risar.miska[1], 30,
                       risar.barva(255, 255, 255), 3)
    for i in range(1000):
        if not risar.klik:
            checkx, checky = risar.miska
            miska.setPos(checkx, checky)
        for n in range(len(krogi)):
            item, new_x, new_y = krogi[n]
            item.setPos(item.x() + new_x, item.y() + new_y)
            if checkx-33 < item.x() < checkx+33 \
                    and checky-33 < item.y() < checky+33 and risar.klik:
                exit()
            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
                #risar.barvaOzadja(risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)))
            if not (15 < item.y() < risar.maxY - 15):
                #risar.barvaOzadja(risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)))
                krogi[n][2] = -new_y

        risar.cakaj(0.02)
Esempio n. 4
0
def za_8():
    '''
    Draws 30 circles at random positions, moves the around. Draws an extra circle, around mouse coordinates.
    Mouse circle follows mouse until first left click. After the click circle stops, program terminates when first
    circle touches mouse circle.
    Speed of movement is 5, circles bounce upon hitting edge.
    Calls create_circles, to create actual objects.
    :return:
    '''
    krogi = create_circles(30)
    miska = risar.krog(risar.miska[0], risar.miska[1], 30,
                       risar.barva(255, 255, 255), 3)

    while True:
        if not risar.klik:
            checkx, checky = risar.miska
            miska.setPos(checkx, checky)
        for n in range(len(krogi)):
            item, new_x, new_y, *s = krogi[n]
            item.setPos(item.x() + new_x, item.y() + new_y)
            if checkx-33 < item.x() < checkx+33 \
                    and checky-33 < item.y() < checky+33 and risar.klik:
                     exit()
            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
            if not (15 < item.y() < risar.maxY - 15):
                krogi[n][2] = -new_y
        risar.cakaj(0.02)
Esempio n. 5
0
def naloga8_pomembnost():
    from collections import defaultdict

    oznake = naloga6_povezave(False, True)
    kraji = TestBase.kraji
    pov = dvosmerno(povezave(5, kraji))
    koord = koordict(kraji)
    barve = [risar.modra, risar.zelena, risar.rumena, risar.rdeca, risar.rjava]
    zacetki = [random.choice(kraji)[0] for _ in range(5)]
    poti = list(zip(*(potnik(zacetek, 1000, pov) for zacetek in zacetki)))
    krogi = [risar.krog(tx(koord[zacetek][0]), ty(koord[zacetek][1]),
                        5, sirina=4, barva=barva)
             for zacetek, barva in zip(zacetki, barve)]

    obiski = defaultdict(int)
    for kraji0, kraji1 in zip(poti, poti[1:]):
        for kraj in kraji0:
            obiski[kraj] += 1
            oznake[kraj].setPlainText(f"{kraj}: {obiski[kraj]}")
        xy0 = [koord[kraj] for kraj in kraji0]
        xy1 = [koord[kraj] for kraj in kraji1]
        for i in [0.1, 0.3, 0.6, 0.9, 1]:
            for (x0, y0), (x1, y1), krog in zip(xy0, xy1, krogi):
                krog.setPos(tx(x0 * (1 - i) + x1 * i), ty(y0 * (1 - i) + y1 * i))
            risar.cakaj(0.005)
    risar.stoj()
Esempio n. 6
0
 def forward(self, a):
     phi = radians(90 - self.angle)
     nx = self.x + a * cos(phi)
     ny = self.y + a * sin(phi)
     if self.pen_active:
         risar.crta(self.x, self.y, nx, ny)
     self.x, self.y = nx, ny
     self.update()
     risar.cakaj(self.pause)
Esempio n. 7
0
 def undo(self):
     if len(self.seznam) > 0:
         zadnja_crta = self.seznam[len(self.seznam) - 1][0]
         kot = self.seznam[len(self.seznam) - 1][3]
         x = self.seznam[len(self.seznam) - 1][1]
         y = self.seznam[len(self.seznam) - 1][2]
         risar.odstrani(zadnja_crta)
         self.fly(x, y, kot)
         seznam1 = self.seznam[: len(self.seznam) - 1]
         self.seznam = seznam1
         risar.cakaj(3)
Esempio n. 8
0
def naloga7_potnik():
    naloga6_povezave(False, True)
    pov = dvosmerno(povezave(5, TestBase.kraji))
    kraji = TestBase.kraji
    koord = koordict(kraji)
    pot = potnik(random.choice(kraji)[0], 1000, pov)
    krog = risar.krog(0, 0, 5, sirina=4, barva=risar.zelena)
    for kraj0, kraj1 in zip(pot, pot[1:]):
        x0, y0 = koord[kraj0]
        x1, y1 = koord[kraj1]
        for i in [0.1, 0.3, 0.6, 0.9, 1]:
            krog.setPos(tx(x0 * (1 - i) + x1 * i), ty(y0 * (1 - i) + y1 * i))
            risar.cakaj(0.005)
def za_6():
    krog = risar.krog(
        randint(15, risar.maxX - 15), randint(15, risar.maxY - 15), 10,
        risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)), 3)
    x, y = 2 * random() + 3, 2 * random() + 3
    t = time.time()
    for i in range(1000):
        if time.time() - t > 20:
            exit()
        krog.setPos(krog.x() + x, krog.y() + y)
        if not (15 < krog.x() < risar.maxX - 15):
            x = -x
        if not (15 < krog.y() < risar.maxY - 15):
            y = -y
        risar.cakaj(0.02)
Esempio n. 10
0
def za_6():
    '''
    Draws a circle at random position, moves it around for 20 seconds.
    Speed of movement is 5. Bounces upon hitting edge.
    Calls create_circles, to create actual objects.
    :return:
    '''
    krog, x, y, *n = create_circles(1)
    st = time.time()
    while True:
        if time.time()-st > 20:
            exit()
        krog.setPos(krog.x() + x, krog.y() + y)
        if not (15 < krog.x() < risar.maxX-15):
            x = -x
        if not (15 < krog.y() < risar.maxY-15):
            y = -y
        risar.cakaj(0.02)
Esempio n. 11
0
def za_7():
    '''
    Draws randomly colored circles 30 circles on random coordinates, moves them around for 20 seconds.
    Speed of movement is 5, circles bounce upon hitting edge.
    Calls create_circles, to create actual objects.
    :return:
    '''
    krogi = create_circles(30)
    st = time.time()
    while True:
        if time.time() - st > 20:
            exit()
        for n in range(len(krogi)):
            item, new_x, new_y, *s = krogi[n]
            item.setPos(item.x() + new_x, item.y() + new_y)
            if not (15 < item.x() < risar.maxX-15):
                krogi[n][1] = -new_x
            if not (15 < item.y() < risar.maxY-15):
                krogi[n][2] = -new_y

        risar.cakaj(0.02)
def za_7():
    krogi = []
    for i in range(30):
        krog = risar.krog(
            randint(15, risar.maxX - 15), randint(15, risar.maxY - 15), 10,
            risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)), 3)
        krogi.append([krog, 2 * random() + 3, 2 * random() + 3])
    t = time.time()
    for i in range(1000):

        for i in range(1000):
            if time.time() - t > 20:
                exit()
        for n in range(len(krogi)):
            item, new_x, new_y = krogi[n]
            item.setPos(item.x() + new_x, item.y() + new_y)
            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
                #risar.barvaOzadja(risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)))
            if not (15 < item.y() < risar.maxY - 15):
                #risar.barvaOzadja(risar.barva(randint(0, 255), randint(0, 255), randint(0, 255)))
                krogi[n][2] = -new_y

        risar.cakaj(0.02)
Esempio n. 13
0
                    break

        return cas

    def premik(self, miskaKlik=None):

        if self.eksplodiranost:
            return

        self.x += self.hitrostX
        self.y += self.hitrostY

        if self.x + self.r >= risar.maxX - 1 or self.x - self.r <= 0:
            self.hitrostX *= -1

        if self.y + self.r >= risar.maxY - 1 or self.y - self.r <= 0:
            self.hitrostY *= -1

        if miskaKlik and self.casZaEksplozijo(miskaKlik):
            self.zogca.hide()
            self.zogca = self.eksplodirajMe()

        self.zogca.setPos(self.x, self.y)


kontekst = Kontekst()

while kontekst.laufa:
    risar.cakaj(kontekst.waitCas)
    kontekst.narisiKomponente()
Esempio n. 14
0
 def wait(self, s):
     risar.cakaj(s)
Esempio n. 15
0
def za_10_game(krogov):
    '''
    Draws x circles - krogov - at random positions, moves them around. Draws an extra circle, around mouse coordinates.
    Mouse circle follows mouse until first left click. After the click mouse circle stops, each circle that touches
    that circle explodes, thus creating another explosion node. Each circle that touches an explosion node, explodes
    as well. Program ends when there is no more exploded circles on canvas or time runs out. It display how many circles
    have exploded and terminates.
    Speed of movement is 5, circles bounce upon hitting edge.
    Explotion time is 4 seconds. Runout time is 20 seconds.
    Calls create_circles, to create actual objects.
    :return:
    '''

    krogi = create_circles(krogov)

    miska = risar.krog(risar.miska[0], risar.miska[1], 30,
                       risar.barva(255, 255, 255), 3)

    miska_start = 0
    miska_klik = False
    stevec = 0
    stop_koordinate = {"miska": (risar.miska[0], risar.miska[1])}
    while True:
        if not risar.klik:
            stop_koordinate["miska"] = (risar.miska[0], risar.miska[1])
            miska.setPos(risar.miska[0], risar.miska[1])

        for n in range(len(krogi)):
            item, new_x, new_y, count, startime, status = krogi[n]
            if time.time() - miska_start >= 4 and miska_klik:
                miska.hide()
                miska_klik = False
                del stop_koordinate["miska"]
                if len(stop_koordinate) == 0:
                    return stevec
            if startime != 0 and time.time() - krogi[n][4] >= 4:
                item.hide()
                krogi[n][4] = 0
                del stop_koordinate[item]
                if len(stop_koordinate) == 0:
                    return stevec
                continue
            elif status == True:
                continue
            item.setPos(item.x() + new_x, item.y() + new_y)
            if risar.klik and miska_start == 0:
                pobarvaj(miska, 200)
                miska_start = time.time()
                miska_klik = True
            for x, y in stop_koordinate.values():
                if x - 35.0 < item.x() < x + 35.0 and y - 35.0 < item.y() < y + 33.0 and risar.klik:
                    item.setRect(-30, -30, 60, 60)
                    pobarvaj(item, randint(120, 180))
                    stop_koordinate[item] = (item.x(), item.y())
                    krogi[n][4] = time.time()
                    krogi[n][5] = True
                    stevec += 1
                    break
            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
            if not (15 < item.y() < risar.maxY - 15):
                krogi[n][2] = -new_y
        risar.cakaj(0.02)
Esempio n. 16
0
 def update(self):
     self.body.setPos(self.x, self.y)
     phi = radians(90 - self.angle)
     self.head.setPos(self.x + 5 * cos(phi), self.y + 5 * sin(phi))
     risar.cakaj(self.pause)
def za_10_game(krogov):
    st = time.clock()

    krogi = create_circles(krogov)

    miska = risar.krog(risar.miska[0], risar.miska[1], 30,
                       risar.barva(255, 255, 255), 3)

    miska_start = 0
    miska_klik = False
    stevec = 0
    stop_koordinate = {"miska": (risar.miska[0], risar.miska[1])}
    for s in range(1000):
        if not risar.klik:
            stop_koordinate["miska"] = (risar.miska[0], risar.miska[1])
            miska.setPos(risar.miska[0], risar.miska[1])

        for n in range(len(krogi)):
            item, new_x, new_y, count, startime, status = krogi[n]
            if time.time() - miska_start >= 4 and miska_klik:
                miska.hide()
                miska_klik = False
                del stop_koordinate["miska"]
                if len(stop_koordinate) == 0:
                    return stevec
            if startime != 0 and time.time() - krogi[n][4] >= 4:
                item.hide()
                krogi[n][4] = 0
                del stop_koordinate[item]
                if len(stop_koordinate) == 0:
                    return stevec
                continue

            elif status == True:
                continue
            item.setPos(item.x() + new_x, item.y() + new_y)
            if risar.klik and miska_start == 0:
                pobarvaj(miska, 150)
                '''color = miska.pen().color().lighter()
                color.setAlpha(150)
                miska.setBrush(color)'''
                miska_start = time.time()
                miska_klik = True
            for x, y in stop_koordinate.values():
                if x - 35.0 < item.x() < x + 35.0 and y - 35.0 < item.y(
                ) < y + 33.0 and risar.klik:
                    item.setRect(-30, -30, 60, 60)
                    '''color = item.pen().color().lighter()
                        color.setAlpha(randint(120, 180))
                        item.setBrush(color)'''
                    pobarvaj(item, randint(120, 180))
                    stop_koordinate[item] = (item.x(), item.y())
                    krogi[n][4] = time.time()

                    krogi[n][5] = True
                    stevec += 1
                    break

            if not (15 < item.x() < risar.maxX - 15):
                krogi[n][1] = -new_x
            if not (15 < item.y() < risar.maxY - 15):
                krogi[n][2] = -new_y
        risar.cakaj(0.02)
        if time.clock() - st > 20:
            break
    return stevec
Esempio n. 18
0
barva = risar.nakljucna_barva()
r = 10

cas = time.time()
t = 0.02

risar.krog(x, y, r, barva, sirina=1)
while True:

    if x < r:
        vx = abs(vx)
    if x > risar.maxX - r:
        vx = -abs(vx)
    if y < r:
        vy = abs(vy)
    if y > risar.maxY - r:
        vy = -abs(vy)

    x += vx
    y += vy
    risar.krog(x, y, 10, barva, sirina=1)
    risar.cakaj(t)
    risar.pobrisi()
    c = abs(cas - time.time())
    if c > 20:
        print("a")
        break

risar.krog(x, y, 10, barva, sirina=1)
risar.stoj()
Esempio n. 19
0
 def wait(self, s=0):
     risar.cakaj(s)
Esempio n. 20
0
    circles = []
    m = Mouse()
    exploded_circles = []
    counter = []

    risar.QMessageBox.information(None, "Konec", "Level: {}. Razpočiti moraš {} žogic od {}.".format(game, req, balls))

    for fn in range(balls):
        circles.append(Circle())

    while not m.clicked or len(exploded_circles) > 0:
        i = 0
        while len(circles) > i:
            circ = circles[i]
            circ.move(m)
            i += 1
        risar.cakaj(0.02)

    if risar.klik and len(exploded_circles) == 0:
        number = len(counter)
        if number >= req:
            risar.QMessageBox.information(None, "Konec",
                                          "Uspelo ti je narediti level {}. Razpočil si {} žogic.".format(game, number))
            game += 1
        else:
            risar.QMessageBox.information(None, "Konec",
                                          "Žal ti ni useplo narediti levela {}. Razpočil si {} žogic od potrebnih {}.".format(
                                                  game, number, req))
    risar.pobrisi()
    risar.klik = False
Esempio n. 21
0
    kx.append(randint(-5, 5))
    ky.append(sqrt(speed**2 - kx[i]**2))

while True:

    if risar.levo:
        mx, my = risar.miska
        cas = time()

    if not risar.klik:
        mx, my = risar.miska

    miskaKrog.setPos(mx, my)

    for i in range(len(krogi)):
        krog = krogi[i]
        krog.setPos(krog.x() + kx[i], krog.y() + ky[i])

        if risar.klik and sqrt((krog.x() - mx)**2 + (krog.y() - my)**2) < 45:
            risar.stoj()

        if not (0 < krog.x() < risar.maxX):
            kx[i] = -kx[i]
        if not (0 < krog.y() < risar.maxY):
            ky[i] = -ky[i]

    if abs(cas - time()) >= 20 and risar.klik:
        break
    risar.cakaj(0.02)

risar.stoj()
Esempio n. 22
0
 def undo(self):
     if len(self.seznam) > 0:
         risar.odstrani(self.seznam[-1][0])
         self.fly(self.seznam[-1][1],self.seznam[-1][2],self.seznam[-1][3])
         del self.seznam[-1]
         risar.cakaj(1)
Esempio n. 23
0
 def update(self):
     self.body.setPos(self.x, self.y)
     self.head.setPos(self.x + 5 * cos(radians(90 - self.angle)), self.y + 5 * sin(radians(90 - self.angle)))
     risar.cakaj(self.pause)
Esempio n. 24
0
y = risar.maxY - 12
x = risar.maxX - 12
konec = time.time() + 20
krog = risar.krog(randint(0, y),
                  randint(0, y),
                  10,
                  barva=risar.nakljucna_barva(),
                  sirina=3)

while (time.time() < konec):
    krog.setPos(krog.x() + spremenljiva_x, krog.y() + spremenljiva_y)
    if not (12 < krog.x() < x):
        spremenljiva_x = -spremenljiva_x
    if not (12 < krog.y() < y):
        spremenljiva_y = -spremenljiva_y
    risar.cakaj(0.01)

#NALOGA ZA 7

seznam_krog = []
spremenljiva_x = []
spremenljiva_y = []
y = risar.maxY - 12
x = risar.maxX - 12
konec = time.time() + 20

for krogi in range(30):
    faca = risar.krog(randint(0, 400),
                      randint(0, 400),
                      10,
                      barva=risar.nakljucna_barva(),