Esempio n. 1
0
 def start_timer(self, time):
     self.t = TimeThread(time, self)
     self.t.start()
Esempio n. 2
0
 def start_timer(self, time):
     self.t = TimeThread(time, self)
     self.t.start()
Esempio n. 3
0
class RockPaperScissors:
    """ Creates a game between two users,
    the user who ran the command and the
    first arg of the command.
    
    There is currently no validation on users
    or on amount of games going at once (gets a
    tad buggy if somebody starts a new game whilst
    one is already going).
    
    """


    def __init__(self, p1, p2):
        self.p1 = p1
        self.g1 = "none"
        self.p2 = p2.title()
        self.g2 = "none"
        self.start_timer(30)
        self.done = False
        
    def get_opponent(self, player):
        if player == self.p1:
            return self.p2
        else:
            return self.p1
        
    def start_timer(self, time):
        self.t = TimeThread(time, self)
        self.t.start()
        
    def guess(self, guess, nick):
        if nick == self.p1:
            self.g1 = guess
            guess = True
            
        elif nick.lower() == self.p2.lower():
            self.g2 = guess
            guess = True
        
        if guess:
            if self.g1 != "none" and self.g2 != "none":
                self._runnable()
                self.t.cancel()
            return True
        return False
        
    def get_done(self):
        return self.done
        
    def _runnable(self):
        text = self.result()
        c.say(self.p1 + ": " + self.g1 + ", " + self.p2 + ": " + self.g2)
        c.say(f.YELLOW + text)
        
    def result(self):
        points = config.get('rps-points')
        strp = str(points)
        if self.g1 == "rock":
            if self.g2 == "rock":
                return "Tie!"
            elif self.g2 == "paper":
                score.add(self.p2, points)
                return self.p2 + " wins! +" + strp
            elif self.g2 == "scissors":
                score.add(self.p1, points)
                return self.p1 + " wins! +" + strp
                
        elif self.g1 == "paper":
            if self.g2 == "rock":
                score.add(self.p1, points)
                return self.p1 + " wins! +" + strp
            elif self.g2 == "paper":
                return "Tie!"
            elif self.g2 == "scissors":
                score.add(self.p2, points)
                return self.p2 + " wins! +" + strp
                
        elif self.g1 == "scissors":
            if self.g2 == "rock":
                score.add(self.p2, points)
                return self.p2 + " wins! +" + strp
            elif self.g2 == "paper":
                score.add(self.p1, points)
                return self.p1 + " wins! +" + strp
            elif self.g2 == "scissors":
                return "Tie!"
                
        self.done = True        
        return "Somebody didn't decide!"
Esempio n. 4
0
class RockPaperScissors:
    """ Creates a game between two users,
    the user who ran the command and the
    first arg of the command.
    
    There is currently no validation on users
    or on amount of games going at once (gets a
    tad buggy if somebody starts a new game whilst
    one is already going).
    
    """
    def __init__(self, p1, p2):
        self.p1 = p1
        self.g1 = "none"
        self.p2 = p2.title()
        self.g2 = "none"
        self.start_timer(30)
        self.done = False

    def get_opponent(self, player):
        if player == self.p1:
            return self.p2
        else:
            return self.p1

    def start_timer(self, time):
        self.t = TimeThread(time, self)
        self.t.start()

    def guess(self, guess, nick):
        if nick == self.p1:
            self.g1 = guess
            guess = True

        elif nick.lower() == self.p2.lower():
            self.g2 = guess
            guess = True

        if guess:
            if self.g1 != "none" and self.g2 != "none":
                self._runnable()
                self.t.cancel()
            return True
        return False

    def get_done(self):
        return self.done

    def _runnable(self):
        text = self.result()
        c.say(self.p1 + ": " + self.g1 + ", " + self.p2 + ": " + self.g2)
        c.say(f.YELLOW + text)

    def result(self):
        points = config.get('rps-points')
        strp = str(points)
        if self.g1 == "rock":
            if self.g2 == "rock":
                return "Tie!"
            elif self.g2 == "paper":
                score.add(self.p2, points)
                return self.p2 + " wins! +" + strp
            elif self.g2 == "scissors":
                score.add(self.p1, points)
                return self.p1 + " wins! +" + strp

        elif self.g1 == "paper":
            if self.g2 == "rock":
                score.add(self.p1, points)
                return self.p1 + " wins! +" + strp
            elif self.g2 == "paper":
                return "Tie!"
            elif self.g2 == "scissors":
                score.add(self.p2, points)
                return self.p2 + " wins! +" + strp

        elif self.g1 == "scissors":
            if self.g2 == "rock":
                score.add(self.p2, points)
                return self.p2 + " wins! +" + strp
            elif self.g2 == "paper":
                score.add(self.p1, points)
                return self.p1 + " wins! +" + strp
            elif self.g2 == "scissors":
                return "Tie!"

        self.done = True
        return "Somebody didn't decide!"