def block_on_challenge(ignore_response, params, at_end=1, stall_time=60, debug=False, eval_response=True): global conn1, heartbeat; if(not conn1 or not heartbeat): MAR_exit(2); xtime = 0; # Give them 60 seconds while(xtime < stall_time): if(xtime == (stall_time-30)): Display.sysMsg('30 seconds remaining...'); elif(xtime == (stall_time-10)): Display.sysMsg('10 seconds remaining...'); sleeptime = time.clock(); if(xtime % 5 == 0): # Setup our internal environment conn1.params = params; conn1.makeNulls = True; response = conn1.request(); # print 'tempresp -> ', response if(response and response != ignore_response): if(eval_response): response = json_decode(response, debug); conn1.makeNulls = False; return response; sleeptime = 1 - (time.clock() - sleeptime); if(sleeptime > 0): time.sleep(sleeptime); xtime = xtime + 1; # We timed-out! else: if(at_end == 1): Display.evnMsg('Request TIMED OUT. Destroying room...'); conn1.params = {"u":u, "p":p, "python":1, "type":"kil", "SID":SID}; response = conn1.request(); Display.sysMsg('Room Destroyed!'); heartbeat.pauseFlag = False; conn1.makeNulls = False; return False;
import sys, threading, os, time; from DisplayInterface import Display; class Autodeath(threading.Thread): """ Die after x seconds """ def __init__(self): # Clear the timer self.countdown = time.clock(); threading.Thread.__init__(self, None, None, "Autodeath Thread"); self.daemon = True; self.start(); def run(self): self.countdown = time.clock(); while(self.countdown + 30 > time.clock()): time.sleep(1); os._exit(1); challenger = sys.argv[1]; if(challenger and 0 < len(challenger) <= 25): death = Autodeath(); Display.sysMsg(('----- MAR Battle Request Warning! -----').center(53)); Display.sysMsg(time.strftime("%m/%d/%Y @ [%I:%M:%S]").center(51),"\n\n\n"); Display.evnMsg("You have a pending battle request from " +challenger+"!"); Display.evnMsg("Type 'Challenge' and then '"+challenger+"'"); Display.evnMsg("in the main window to accept or do nothing to decline.\n"); Display.sysMsg('This window will automatically close in 30 seconds.'); Display.cooked_input(' Press "Enter" to immediately close this window.', True);
# Challenge someone! Woooo! if(i == 0): heartbeat.pauseFlag = True; conn1.params = {"u":u, "p":p, "python":1, "type":"cha", "SID":SID}; conn1.params['chal'] = Display.cooked_input('> Enter the username of the player you\'d like to challenge: '); Display.sysMsg('Conversing with the server...'); response = conn1.request(); # Waiting for Challengee to accept/deny if(response == "$ChallengerWaiting"): Display.gameMsg('Waiting for a response from', conn1.params['chal']+'...'); response = block_on_challenge('$NoDice', {"u":u, "p":p, "python":1, "type":"bat2", "SID":SID}); if(response != False): first = (False if response['opponent'] == response['first'] else True); Display.evnMsg('Challenge Accepted! '+(response['opponent']+' is' if not first else 'You\'re') + ' up first.'); Display.sysMsg('Preparing battlefield...'); time.sleep(5); MAR_battle(response['opponent'], first); else: Display.errorMsg("Connection to server was dropped. Please try again."); # Waiting for challenger's client to acknowledge our acceptance of their initial challenge elif(response == "$ChallengedWaiting"): Display.sysMsg('Waiting for acknowlegement...'); response = block_on_challenge('$NoDice', {"u":u, "p":p, "python":1, "type":"bat3", "SID":SID}); if(response != False): first = (False if response['opponent'] == response['first'] else True); Display.evnMsg('Challenge Acknowledged! '+(response['opponent']+' is' if not first else 'You\'re') + ' up first.'); Display.sysMsg('Preparing battlefield...'); time.sleep(5);
def MAR_exit(status=0): if(status == 0): Display.gameMsg('Program Terminated.'); else: Display.errorMsg('Program Terminated Unexpectedly ('+str(status)+')!'); Display.evnMsg('(C) Copyright 2010 - Dark Gray. All Rights Reserved.'); Display.pause(); os._exit(status);
# Based on the distance from the answer, print a different result (to the same line) if fdist <= length * modifiers[0] / 100: print "slightly off." elif dist > 0: if fdist <= length * modifiers[1] / 100: print "too low." else: print "WAY too low!" else: if fdist <= length * modifiers[1] / 100: print "too high." else: print "WAY too high!" else: Display.errorMsg("That's not a letter,", name + ". You've lost two turns for that!") maxTries = maxTries - 2 report = maxTries - (tries + 1) Display.gameMsg("You have", (report if report > 0 else "no"), "tries remaining.") tries = tries + 1 if answer == -1: Display.playerMsg("Good job!") else: Display.errorMsg("You failed", name + ".\nThe correct answer was " + answer + ".") state = Display.cooked_input("Try again? (y/n) ") Display.evnMsg("(C) Copyright 2010 - Dark Gray. All Rights Reserved.") except KeyboardInterrupt: pass Display.errorMsg("Program Terminated.") Display.pause()