0

I want to be able to reshuffle/re-randomize the numbers which is outputs. Is there any way to do that from anywhere in the code? Here's the class which I'm referencing:

class Foe(Actor): #v constructor v
    def __init__(self, image):
        super().__init__(image)
        self.rotation = random.uniform(-2.5, 2.5)
        firside = random.randint(1, 8) #picks a random number between 1 and 8 (starting point)
        secside = random.randint(1, 8) #"------------------------------------" (ending point)
        while firside == secside or secside == firside + 1 or secside == firside - 1 or firside == 8 and secside == 1 or firside == 1 and secside == 8: #keeps randomizing the secside variable till its not the same as the firside or not a number close to it
            secside = random.randint(1, 8)

        if firside == 1: #the starting point is in the top right of the screen (top right till top middle) and this code picks a random position between these point
            self.fx = random.randint(0, 425)
            self.fy = -40
        if secside == 1: #the ending point is in the top right of the screen (top right till top middle) and this code picks a random position between these point
            self.dx = random.randint(0, 425)
            self.dy = -40
        if firside == 2: #north left
            self.fx = random.randint(426, 850)
            self.fy = -40
        if secside == 2:
            self.dx = random.randint(426, 850)
            self.dy = -40
        if firside == 3:  #west right
            self.fx = 880
            self.fy = random.randint(0, 212)
        if secside == 3:
            self.dx = 880
            self.dy = random.randint(0, 212)
        if firside == 4:  #west left
            self.fx = 880
            self.fy = random.randint(213, 425)
        if secside == 4:
            self.dx = 880
            self.dy = random.randint(213, 425)
        if firside == 5:   #south right
            self.fx = random.randint(0, 425)
            self.fy = 465
        if secside == 5:
            self.dx = random.randint(0, 425)
            self.dy = 465
        if firside == 6:   #south left
            self.fx = random.randint(426, 850)
            self.fy = 465
        if secside == 6:
            self.dx = random.randint(426, 850)
            self.dy = 465
        if firside == 7:   #east right
            self.fx = -40
            self.fy = random.randint(0, 212)
        if secside == 7:
            self.dx = -40
            self.dy = random.randint(0, 212)
        if firside == 8:   #east left
            self.fx = -40
            self.fy = random.randint(213, 425)
        if secside == 8:
            self.dx = -40
            self.dy = random.randint(213, 425)
        

    
    if main_menu == False:
        foeResetter()

(the code chooses a random position for the foe to spawn at and a random postion for the foe's destination position) Thanks in advance for any help you give :)

Whi_24
  • 41
  • 4
  • What do you mean by "repeat this class"? You can create as many instances of a class as you want. Read about [Instance Objects](https://docs.python.org/3/tutorial/classes.html#instance-objects) and [Class](https://docs.python.org/3/tutorial/classes.html). – Rabbid76 Dec 07 '21 at 13:22
  • I want to be able to re-randomize the variable's inside the class. How would I go about doing that? – Whi_24 Dec 07 '21 at 14:32
  • 1
    Every time when you create a new instance, the instance attributes get new random values. – Rabbid76 Dec 07 '21 at 14:34

0 Answers0