Ejemplo n.º 1
0
def getcards(filenames, black=False):
    cards = []
    for name in filenames:
        try:
            f = openfile(name, "rb")
            for line in readfile(f).splitlines():
                line = basicformat(line)
                if line and not line.startswith("#"):
                    if line.endswith(":"):
                        if len(line) > 1 and line[-2] == "\\":
                            line = line[:-2]+line[-1]
                        else:
                            continue
                    elif not black and line.endswith(".") and len(line) > 1:
                        if line[-2] == "\\":
                            if len(line) > 2 and line[-3] == "\\":
                                line = line[:-2]
                            else:
                                line = line[:-2]+line[-1]
                        elif not containsany(line[:-1], ["!", "?", "."]):
                            line = line[:-1]
                    line = line.replace("\\n", "\n").replace("\\\n", "\\n")
                    cards.append(card(line, black))
                    if black:
                        cards[-1].black()
                    else:
                        cards[-1].white()
        except IOError:
            print("WARNING: Unable to find file "+str(name))
        finally:
            f.close()
    return list(set(cards))
Ejemplo n.º 2
0
 def process(self, inputstring):
     original = basicformat(inputstring)
     foriginal = superformat(original)
     if foriginal == "help":
         self.app.display("The available commands are: help, pick, play, score, hand, say, clear")
     elif foriginal.startswith("pick "):
         original = basicformat(original[5:])
         testnum = isreal(original)
         if testnum and (testnum <= 0 or testnum > len(self.played) or testnum != int(testnum)):
             self.app.display("That's not a valid card index.")
         else:
             if testnum:
                 if self.server:
                     played = self.played.keys()
                 else:
                     played = self.played
                 original = str(played[int(-1+testnum)])
             if not self.phased:
                 self.app.display("You can't pick yet, you're still in the playing stage.")
             elif not self.isczar():
                 self.app.display("You're not the Card Czar, so you're playing, not picking.")
             elif self.waiting != "end":
                 self.app.display("You have to wait for others until you can pick.")
             elif not self.played:
                 self.app.display("You can't pick multiple people's cards.")
             else:
                 test = False
                 for play in self.played:
                     if play.startswith(original):
                         original = play
                         test = True
                         break
                 if not test:
                     self.app.display("You can't pick a card that nobody played.")
                 else:
                     self.phased = False
                     if self.server:
                         self.scores[self.played[original]] += 1
                         self.broadcast("An awesome point was awarded to "+self.names[self.played[original]]+" for ("+original+").")
                     else:
                         self.trigger("pick", original, toall=False)
                     self.trigger("end")
                     if self.server:
                         self.sendscores()
     elif foriginal.startswith("play "):
         original = basicformat(original[5:])
         testnum = isreal(original)
         if testnum and (testnum <= 0 or testnum > len(self.hand) or testnum != int(testnum)):
             self.app.display("That's not a valid card index.")
         else:
             if testnum:
                 original = str(self.hand[int(-1+testnum)])
             if self.phased:
                 self.app.display("You can't play yet, you're still in the picking stage.")
             elif self.isczar():
                 self.app.display("You're the Card Czar, so you're picking, not playing.")
             elif self.waiting != "phase":
                 self.app.display("You have to wait for others until you can play.")
             elif len(self.played) >= self.black.blanks:
                 self.app.display("You can't play anymore cards this turn.")
             else:
                 test = False
                 for choice in self.hand:
                     choice = str(choice)
                     if choice.startswith(original):
                         original = choice
                         test = True
                         break
                 if not test:
                     if ";" in original:
                         for item in original.split(";"):
                             self.process("play "+item)
                     else:
                         self.app.display("You can't play a card that you don't have in your hand.")
                 else:
                     self.played.append(original)
                     self.app.display("You just played: "+str(self.played[-1]))
                     self.hand.remove(self.played[-1])
                     if len(self.played) < self.black.blanks:
                         self.app.display("You still have "+str(self.black.blanks-len(self.played))+" more cards to play.")
                     elif self.server:
                         self.schedule(self.phasewait)
                     else:
                         self.trigger("phase1", toall=False)
                     self.newinfo()
     elif foriginal == "score":
         if self.server:
             points = self.scores[None]
         else:
             self.trigger("score", toall=False)
             points = self.receive()
         self.app.display("You currently have "+str(points)+" awesome points.")
     elif foriginal == "hand":
         self.app.display("Your hand contains: "+strlist(self.hand, "; "))
     elif foriginal == "clear":
         self.app.clear("Display cleared.")
     elif foriginal.startswith("say "):
         self.textmsg(original[4:])
     elif original:
         self.textmsg(original)