def remakeConfig(): config = dict() popup.error("Incorrect Config", "No config file exists or is broken! Creating new one!") fout = open("config.txt", "wt") fout.write(defaultVals.config()) fout.close() return parseConfigVals(defaultVals.config().split("\n"))
def run(): #Grab some vals from the config config = dict() fin = fout = None #Load and parse the config file. try: fin = open("config.txt", "rt") contents = fin.readlines() assert(defaultVals.verify(contents, "config")) config = parseConfigVals(contents) except: config = remakeConfig() finally: if fin != None: fin.close() if fout != None: fout.close() pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.mixer.init() pygame.mixer.set_num_channels(32) pygame.init() pygame.display.set_caption("15-112: Touhou") pygame.display.set_icon(pygame.image.load(os.path.join(os.path.curdir,"img","gui","icon.png"))) pygame.mouse.set_visible(1) pygame.event.set_allowed([pygame.QUIT,pygame.KEYDOWN,pygame.KEYUP]) screenSize = config["Screen Size"].split("x") trueWidth = int(screenSize[0]) trueHeight = int(screenSize[1]) win = pygame.display.set_mode((trueWidth,trueHeight)) game = Touhou(config, win) try: game.run() except: popup.error("Fatal Error", "Yikes! A fatal error just occurred!\nFear not though, I'll just restart the program.\nBasically, pygame sucks.") run()
def getShipPos(self, whichPlayer = 0): highest = None found = 0 for row in xrange(len(self.unitPos)): for col in xrange(len(self.unitPos[row])): currentVal = self.unitPos[row][col] if whichPlayer == 0 and currentVal.isdigit(): if highest<currentVal: highest = currentVal found += 1 if whichPlayer == 1 and currentVal.isalpha(): if highest<currentVal: highest = currentVal found += 1 if whichPlayer == 0 and found != int(highest): popup.error("Invalid Map!", "You have an invalid map!") if whichPlayer == 1 and found != ord(highest.lower())-ord('a')+1: popup.error("Invalid Map!", "You have an invalid map!") pos = dict() for row in xrange(len(self.unitPos)): for col in xrange(len(self.unitPos[row])): val = self.unitPos[row][col] if whichPlayer == 0 and val.isdigit(): pos[TESTUNITLIST[val]] = [col,row] #COL ROW -> X Y. NOTE THE INVERTED ORDER if whichPlayer == 1 and val.isalpha(): pos[TESTUNITLIST[val]] = [col,row] #COL ROW -> X Y. NOTE THE INVERTED ORDER return pos