You can use this input for your check. Inside the while statement place a 
keydown check and it should work. This is what I use for my game at the moment 
for single key strokes. I will send the while check in my second email to the 
list.

    Enjoy programming.

        Bruce

import msvcrt #INPUT KEYBOARD COMMANDS!

def key_Input(msg):
    "ENTER A KEY OR FUNCTION KEY, (ALT, CTRL, SHIFT...KEY)"
    # clear the keyboard buffer
    ch=""; ch1=""; sch=""
    while msvcrt.kbhit():
        ch = msvcrt.getch()
#    PlaySound ("Federation_Scan.ogg", 2, -1) #PLAY ANY SOUND HERE!
#    print "| "
#    print "Hit Return Or Escape To Quit or Move Using Cursor Keys:"
    print msg,
    while ch != chr(27) and ch != chr(13) and ch1 != chr(0) and ch1 != chr(224):
        ch1 = msvcrt.getch()
        ch = ch1
        if ch1 == chr(0) or ch1 == chr(224):
            ch = msvcrt.getch()
            sch = ch1+ch
            print; print "ch=%d ch1=%d" % (ord(ch), ord(ch1))
        else:
            ch = ch.upper()
            if ch in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
                msvcrt.putch(ch)
                sch+=ch
            elif ch == chr(8) and len(sch)>0:
                msvcrt.putch(ch)
                sch = sch[:len(sch)-1]
    if ch == chr(27): 
        i=len(sch)
        while i>0:
            i-=1
            msvcrt.putch(chr(8))
        sch="XXX"
        print sch
    print
    return (sch)


def key2Com( kbs):
    "CONVERT THE 0 AND 224 KEY CODES TO COMMANDS!"
    if len(kbs) < 2: return(kbs)
    if kbs[0] == chr(0):
        if kbs[1] == "O": kbs = "CMRS"
        elif kbs[1] == "Q": kbs = "CLRS"
    if kbs[0] == chr(224) and kbs[1] in MK224: kbs = MK224[ kbs[1]]
    return (kbs)


----- Original Message ----- 
From: Miguel Sicart 
To: pygame-users@seul.org 
Sent: Tuesday, January 29, 2008 5:06 AM
Subject: [pygame] timing question


Hi all,


I'm writing a little text-based game and I have stumbled upon a strange newbie 
problem.
In this game, the player has to input a number of commands in order to interact 
with the game. I am using raw_input to get input from the player.
My problem is that I want to make it turn based, and I want to limit the amount 
of time players have per turn. And I don't know how to do that. I have tried to 
create an event and push it to the event list, but it doesn't act until the 
player provides input, so it is not working.
So the idea is:
player provides specific input (raw_input)
game objects are affected by input
+1 turn
if turns = x:
game over


I am quite sure this is a simple problem, but I have been going around it for a 
couple of days with no success - help! :)


thanks!


mundial



 

Reply via email to