Пример #1
0
 def begin(self):
     self.printdebug(": BEGIN")
     if self.server:
         self.whites = getcards(self.whites, False)
         self.blacks = getcards(self.blacks, True)
         self.scramble()
         self.scores = {None:0}
         for a in self.c.c:
             self.queue[a].append(strlist(self.getwhites(self.cards), ";;"))
             self.scores[a] = 0
         self.hand = self.getwhites(self.cards)
         self.order = [None]+self.c.c.keys()
         self.x = -1
         self.app.display("Loaded with "+str(len(self.blacks))+" black cards and "+str(len(self.whites))+" white cards.")
     else:
         self.czar = False
         self.hand = map(card, self.receive().split(";;"))
         self.app.display("Loaded.")
     self.black = None
     self.phased = False
     self.waiting = False
     self.onsent("end", self.endwait)
     self.onsent("phase1", self.phasewait)
     self.onsent("phase2", self.phaseturn)
     self.onsent("score", self.replyscore)
     self.onsent("pick", self.pickwait)
     if self.server:
         self.broadcast("Connected players are: "+strlist(self.names.values(), ", ")+".")
     self.app.display("You just drew: "+strlist(self.hand, "; "))
     self.endturn(False)
     self.ready = True
Пример #2
0
 def phaseturn(self, arg="", a=None):
     self.phased = True
     if self.server == None:
         return False
     else:
         self.printdebug(": PHASE")
         if self.server:
             if self.played:
                 played = [(self.played, None)]
             else:
                 played = []
             played += self.receive()
             self.played = {}
             for m,a in played:
                 if m != "$":
                     if not islist(m):
                         m = map(card, m.split(";;"))
                     self.whites.extend(m)
                     self.played[strlist(m, ";;")] = a
             played = {}
             for m,a in self.played.items():
                 played[strlist(m.split(";;"), "; ")] = a
             self.played = played
             if self.x:
                 self.send(strlist(self.played.keys(), ";;"), self.order[self.x])
                 for a in self.c.c:
                     if a != self.order[self.x]:
                         self.queue[a].append(strlist(self.getwhites(self.black.blanks), ";;"))
                 drew = self.getwhites(self.black.blanks)
                 self.hand.extend(drew)
                 self.app.display("You just drew: "+strlist(drew, "; "))
             else:
                 for a in self.c.c:
                     self.queue[a].append(strlist(self.getwhites(self.black.blanks), ";;"))
             out = "\nThe cards played were:\n"
             keys = self.played.keys()
             for x in xrange(1, len(keys)+1):
                 out += str(x)+". "+strlist(keys[x-1].split(";;"), "; ")+"\n"
             self.broadcast(out)
         else:
             if self.played:
                 self.send(strlist(self.played, ";;"))
             else:
                 self.send("$")
             if self.czar:
                 self.played = self.receive().split(";;")
             else:
                 drew = map(card, self.receive().split(";;"))
                 self.hand.extend(drew)
                 self.app.display("You just drew: "+strlist(drew, "; "))
         self.newinfo()
         if self.isczar():
             self.app.display("Make your choice, Card Czar.")
         else:
             self.app.display("The Card Czar is making their choice.")
             self.phased = False
         self.waiting = "end"
     return True
Пример #3
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)
Пример #4
0
 def sendscores(self):
     out = []
     for a in self.scores:
         name = self.names[a]
         out.append(""+name+" ("+str(self.scores[a])+")")
     self.broadcast("The current awesome point totals are: "+strlist(out, ", ")+".")