def play(self):
     choice = ''
     self.display_title_bar()
     while choice != 'x':
         choice = self.get_user_choice()
         self.num_round = 0
         self.display_title_bar()
         while self.num_round < 3:
             if choice == '1':
                 # unos korisnikovog tekst
                 self.player_input = input(
                     "Odaberite rock, spock, paper, lizard ili scissors: "
                 ).lower()
                 # pretvorba korisnikovog tekst u broj
                 self.player_number = self.string_u_broj()
                 # racunalo odabire pomocu random metode
                 self.computer_number = random.randrange(0, 5)
                 ostatak = (self.player_number - self.computer_number) % 5
                 if (self.player_number == -1):
                     winner = "Greška"
                     raise RpslsError(101)
                 else:
                     if ostatak == 0:
                         winner = "Neriješeno"
                         self.num_round += 1
                     elif ostatak == 1 or ostatak == 2:
                         winner = "Vi (čovjek) pobjeđujete ovu rundu"
                         self.num_round += 1
                         self.player_points += 1
                     elif ostatak == 3 or ostatak == 4:
                         winner = "Računalo pobjeđuje ovu rundu"
                         self.num_round += 1
                         self.computer_points += 1
                 self.computer_choice_name = self.broj_u_string()
                 print("Vi (čovjek) ste odabrali: {}".format(
                     self.player_input.title()))
                 print("Računalo je odabralo: {}".format(
                     self.computer_choice_name.title()))
                 print(winner)
                 print("Igrač ima {} bodova:".format(self.player_points))
                 print("Komp ima {} bodova:".format(self.computer_points))
             elif choice == 'x':
                 print(
                     "\nHvala na pregledu/uređivanju dokumentarija.Pozdrav!"
                 )
             else:
                 raise RpslsError(104)
         if self.player_points > self.computer_points:
             print("Igrač pobijedio s {}:{} ".format(
                 self.player_points, self.computer_points))
         elif self.computer_points > self.player_points:
             print("Računalo pobijedilo s {}:{} ".format(
                 self.computer_points, self.player_points))
Ejemplo n.º 2
0
    def igra(self):
        self.get_user_choice
        self.player_input = input(
            "Odaberite rock, spock, paper, lizard ili scissors: ").lower()
        self.player_number = self.string_u_broj()
        self.computer_number = random.randrange(0, 5)
        ostatak = (self.player_number - self.computer_number) % 5

        if (self.player_number == -1):
            winner = "Greška"
            raise RpslsError(101)
        else:

            if ostatak == 0:
                winner = "Neriješeno"
                self.broj_rundi += 1
            elif ostatak == 1 or ostatak == 2:
                winner = "Vi (čovjek) pobjeđujete"
                self.broj_rundi += 1
                self.bodovi_igrac += 1

            elif ostatak == 3 or ostatak == 4:
                winner = "Računalo pobjeđuje"
                self.broj_rundi += 1
                self.bodovi_komp += 1

            self.computer_choice_name = self.broj_u_string()
            print("Vi (čovjek) ste odabrali: {}".format(
                self.player_input.title()))
            print("Računalo je odabralo: {}".format(
                self.computer_choice_name.title()))
            print(winner)
            print("Igrač ima {} bodova:".format(self.bodovi_igrac()))
            print("Komp ima {} bodova:".format(self.bodovi_komp()))
Ejemplo n.º 3
0
 def string_u_broj(self):
     """
 	pretvara naziv/tekst (rock, spock, paper, lizard, scissors) u broj (0, 1, 2, 3, 4)
     """
     if self.player_input == "rock":
         self.player_number = 0
     elif self.player_input == "spock":
         self.player_number = 1
     elif self.player_input == "paper":
         self.player_number = 2
     elif self.player_input == "lizard":
         self.player_number = 3
     elif self.player_input == "scissors":
         self.player_number = 4 
     else:
         self.player_number = -1
         raise RpslsError(102)
     return self.player_number
Ejemplo n.º 4
0
 def broj_u_string(self):
     """
     pretvara brojeve (0, 1, 2, 3, 4) u nazive/tekst (rock, spock, paper, lizard, scissors)
     """
     if self.computer_number == 0:
         self.computer_choice_name = "rock"
     elif self.computer_number == 1:
         self.computer_choice_name = "spock"
     elif self.computer_number == 2:
         self.computer_choice_name = "paper"
     elif self.computer_number == 3:
         self.computer_choice_name ="lizard"
     elif self.computer_number == 4:
         self.computer_choice_name = "scissors"
     else:
         self.computer_choice_name = None
         raise RpslsError(103)
     return self.computer_choice_name
Ejemplo n.º 5
0
    def play(self):
        """
        Glavna logika.
        Prvo, radi se korisnikov input, zatim pretvara korisnikov input u broj (metoda string_u_broj), utvrđuje pobjednika i 
        na kraju pretvara odabrani broj računalo_igrač_2-a u tekst(metoda broj_u_string) i ispisuje pobjenika (Winner-a) 
        """
        
        #unos korisnikovog teksta
        self.display_title_bar()
        self.get_user_choice()

        while (self.player != 2):
            playerZbroj = 0
            computerZbroj = 0

            if(self.player > 2 or self.player < 1):
                raise RpslsError(101)
            else:
                while (playerZbroj < 3 and computerZbroj < 3):
                    print("-"*50)
                    self.player_input = input("Odaberite rock, Spock, paper, lizard ili scissors: ").lower()
                    self.player_number = self.string_u_broj()
                    
                    self.computer_number = random.randrange(0,5)
                    ostatak = (self.player_number - self.computer_number)%5
                    
                    if(self.player_number == -1):
                        winner = "Greška"
                        raise RpslsError(101)
                    else:
                        if ostatak == 0:
                            winner = "Neriješeno"
                        elif ostatak == 1 or ostatak == 2:
                            winner = "Vi (čovjek) pobjeđujete"
                            playerZbroj += 1
                        elif ostatak == 3 or ostatak == 4:
                            winner = "Računalo pobjeđuje"
                            computerZbroj += 1
           
                    self.computer_choice_name = self.broj_u_string()
                    
                    print("-"*50)
                    print("\n")
                    print("Vi (čovjek) ste odabrali: {}".format(self.player_input.title()))
                    print("Računalo je odabralo: {}".format(self.computer_choice_name.title()))
                    print("-"*50)
                    print("Pobjednik ove runde je: {}".format(winner))
                    print("-"*50)
                    print("Igrač ima {} bodova.".format(playerZbroj))
                    print("Računalo ima {} bodova.".format(computerZbroj))

                if playerZbroj == 3:
                    print("Pobjednik igre je Igrač!")
                elif computerZbroj == 3:
                    print("Pobjednik igre je Računalo!")

                self.get_user_choice()

                print("-"*50)
                print("Ovo je kraj igre, hvala vam na igranju!")
                print("-"*50)