Changeset 12 for client.py

Show
Ignore:
Timestamp:
02/03/08 16:52:57 (4 years ago)
Author:
mike
Message:

Added hand checking code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • client.py

    r11 r12  
    1111from twisted.internet import defer 
    1212from pprint import PrettyPrinter 
     13from string import split 
    1314 
    1415pprinter = PrettyPrinter().pprint 
    1516 
    16 def dealWithData(data): 
    17     pprinter(data) 
     17def makeAction( action, value): 
     18    msg = { "method":"action", 
     19            "action":action, 
     20            "value":value } 
    1821 
    1922class PokerClientProtocol(NetstringReceiver): 
     23    def dealWithData(self,data): 
     24        print "---------------" 
     25        pprinter(data) 
     26        if data["you"]["required_action"]: 
     27            print "---------------" 
     28            print "We need some input. Possible actions:" 
     29            p_acts = data["you"]["possible_actions"] 
     30            vals = [None,None] 
     31            while not vals[0] in p_acts: 
     32                pprinter(p_acts) 
     33                str = raw_input('Action? format: <action> OR <action>,<value>:\n') 
     34                vals = split(str,",") 
     35                vals.append(None) 
     36            self.sendString( cjson.encode(makeAction(vals[0], vals[1]))) 
     37 
    2038    def __init__(self,table_name, user_id, client_id ): 
    2139        self.table_name = table_name 
     
    3351         
    3452        decoded = cjson.decode(line) 
    35         dealWithData(decoded) 
     53        self.dealWithData(decoded) 
    3654         
    3755    def connectionLost(self, reason):