def terminalOutput(cellMap): """ Print map on Terminal output. """ ## Colors associated to each features. dColor = {} for s in ("water", "forest", "path"): bg = "blue" if s == "water" else "green" if s == "forest" else "" for i in ("hero", "treasure", "trap", ""): t = "H" if i == "hero" else "T" if i == "treasure" else "^" if i == "trap" else " " dColor[(s,i)] = Colors.color(fgColor="red",bgColor=bg)(t) txt = '' for line in cellMap: previousCellType = False for cell in line: if previousCellType: # Space between 2 walls: set features wall for the space if cell.surface == "path": txt += dColor[(cell.surface,cell.item)] elif previousCellType == "path": txt += dColor[(cell.surface,cell.item)] elif previousCellType == cell.surface: txt += dColor[(cell.surface,cell.item)] elif previousCellType != cell.surface: txt += dColor[(cell.surface,cell.item)] # Just a space else: txt += ' ' txt += dColor[(cell.surface,cell.item)] previousCellType = dColor[(cell.surface,cell.item)] txt += '\n' return txt
def askQuestion(question, lChoices): """ Ask a question to the user, and return his answer. """ mess = "\n%s\n%s" %(colorQ(question), '\n'.join([ " [%s] %s" %(colorC(i+1), lChoices[i]) for i in range(len(lChoices))])) mess += "\n [%s] Quit\nChoice: %s" %(colorC('Q'), txt.buildColor(fgColor="Red")) choice = raw_input(mess) sys.stdout.write(txt.reset()) sys.stdout.flush() if choice.lower() == 'q': sys.exit(0) if choice not in map(str,range(1,len(lChoices)+1)): print "Your choice \"%s\" doesn't exist." %choice return askQuestion(question, lChoices) return int(choice) -1
""" Game in a window. """ print "Window version is currently not available." if __name__=='__main__': # rows, columns = map(int, os.popen('stty size', 'r').read().split()) print """ .-. .-. .--. |=======================| .--. .-. .-. | OO| | OO| / _.-' .-. .-. .''. | Welcome | .''. .-. .-. '-._ \ |OO | |OO | | | | | \ '-. '-' '-' '..' | To the PacmanPy game !| '..' '-' '-' .-' / | | | | '^^^' '^^^' '--' |=======================| '--' '^^^' '^^^' """ rootDir = getRootDir() colorQ = txt.color(fgColor='Cyan', bold=True) colorC = txt.color(fgColor='Yellow', bold=True) # =========== # === Select the graphical output version gameVersion = askQuestion("Select the graphical output version you want to play with:", ["Terminal version", "ASCII-art version", "Graphical version"]) mapPath = getMapPath() if gameVersion == 0: terminalVersion() elif gameVersion == 1: asciiArtVersion() elif gameVersion == 2: graphicalVersion() print "Exit Pacman"