Hey, something that could do with being added to the first post under Python libraries is
. It's a library I've taken to using for my game. It's enables lots of nice little console things but is lacking in a few places. I went ahead and created my own little addition to it, which I'll just toss in a spoiler. I named it dunlib simply because I intended it for dungeon crawl games. I apologize for the hugeness of the opening bit of the code there. Half the stuff probably isn't necessary, but I keep it along anyways.
import WConio
charlist = [
'\x00', #Null
'\x01', #Smiley
'\x02', #Filled Smiley
'\x03', #Heart
'\x04', #Diamond
'\x05', #Club
'\x06', #Spade
'\x07', #Centered Dot
'\x08', #Inverted and Centered Dot
'\x09', #Circle
'\x0a', #Inverted Circle
'\x0b', #Male Symbol
'\x0c', #Female Symbol
'\x0d', #Singular Eighth Note
'\x0e', #Bridged Eighth Note
'\x0f', #Sunburst Thing-it
'\x10', #Right-facing Triangle
'\x11', #Left-facing Triangle
'\x12', #Up/Down Arrows
'\x13', #Double Exclamation Mark
'\x14', #Pilcrow
'\x15', #Section Symbol
'\x16', #Lower Block
'\x17', #Up/Down Arrows and Underline
'\x18', #Up Arrow
'\x19', #Down Arrow
'\x1a', #Right Arrow
'\x1b', #Left Arrow
'\x1c', #'L' Shaped Thing-it
'\x1d', #Left/Right Arrows
'\x1e', #Up Facing Triangle
'\x1f', #Down Facing Triangle
' ', #Space
'!',
'"',
'#',
'$',
'%',
'&',
"'",
'(',
')',
'*',
'+',
',',
'-',
'.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
';',
'<',
'=',
'>',
'?',
'@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'[',
'\x5c', #\
']',
'^',
'_',
'`',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'{',
'|',
'}',
'~',
'\x7f', #House
'\x80', #C-cedilla
'\x81', #e-umlaut
'\x82', #e-acute
'\x83', #a-circumflex
'\x84', #a-umlaut
'\x85', #a-grave
'\x86', #a-ring
'\x87', #c-cedilla
'\x88', #e-circumflux
'\x89', #e-umlaut
'\x8a', #e-grave
'\x8b', #i-umlaut
'\x8c', #i-circumflex
'\x8d', #i-grave
'\x8e', #A-umlaut
'\x8f', #A-ring
'\x90', #E-acute
'\x91', #ae
'\x92', #AE
'\x93', #o-circumflex
'\x94', #o-umlaut
'\x95', #o-grave
'\x96', #u-circumflex
'\x97', #u-grave
'\x98', #y-umlaut
'\x99', #O-umlaut
'\x9a', #U-umlaut
'\x9b', #Cent Sign
'\x9c', #Pound Sign
'\x9d', #Yen Sign
'\x9e', #Pesetas sign/Pts
'\x9f', #Italic F
'\xa0', #a-acute
'\xa1', #i-acute
'\xa2', #o-acute
'\xa3', #u-acute
'\xa4', #n-tilde
'\xa5', #N-tilde
'\xa6', #Ordinal Indicator
'\xa7', #Degree Sign
'\xa8', #Inverted Question Mark
'\xa9', #Negation (downturned end on left)
'\xaa', #Negation (downturned end on right)
'\xab', #1/2
'\xac', #1/4
'\xad', #Inverted Exclamation Mark
'\xae', #Open Guillement
'\xaf', #Close Guillement
#Window Drawing Characters...
'\xb0', #Light Shading
'\xb1', #Medium Shading
'\xb2', #Dark Shading
'\xb3', #Single Vertical
'\xb4', #Single Vertical + Single Left
'\xb5', #Single Vertical + Double Left
'\xb6', #Double Vertical + Single Left
'\xb7', #Double Bottom + Single Left
'\xb8', #Single Bottom + Double Left
'\xb9', #Double Vertical + Double Left
'\xba', #Double Vertical
'\xbb', #Double Bottom + Double Left
'\xbc', #Double Top + Double Left
'\xbd', #Double Top + Single Left
'\xbe', #Single Top + Double Left
'\xbf', #Single Bottom + Single Left
'\xc0', #Single Top + Single Right
'\xc1', #Single Top + Single Horizontal
'\xc2', #Single Bottom + Single Horizontal
'\xc3', #Single Vertical + Single Right
'\xc4', #Single Horizontal
'\xc5', #Single Vertical + Single Horizontal
'\xc6', #Single Vertical + Double Right
'\xc7', #Double Vertical + Single Right
'\xc8', #Double Top + Double Right
'\xc9', #Doubel Bottom + Double Right
'\xca', #Double Top + Double Horizontal
'\xcb', #Double Bottom + Double Horiz
'\xcc', #Double Vert + Double Right
'\xcd', #Double Horiz
'\xce', #Double Vert + Double Horiz
'\xcf', #Single Top + Double Horiz
'\xd0', #Double Top+ Single Horiz
'\xd1', #Double Horiz + Single Bottom
'\xd2', #Single Horiz + Double Bottom
'\xd3', #Double Top + Single Right
'\xd4', #Single Top + Double Right
'\xd5', #Single Bottom + Double Right
'\xd6', #Double Bottom + Single Right
'\xd7', #Double Vert + Single Horiz
'\xd8', #Single Vert + Double Horiz
'\xd9', #Single Top + Single Left
'\xda', #Single Bottom + Single Right
'\xdb', #Full Block
'\xdc', #Bottom Block
'\xdd', #Left Block
'\xde', #Right Block
'\xdf', #Top Block
#End Window Drawing Characters...
'\xe0', #alpha
'\xe1', #Beta
'\xe2', #Gamma
'\xe3', #pi
'\xe4', #Sigma
'\xe5', #sigma
'\xe6', #mu
'\xe7', #tau
'\xe8', #Phi
'\xe9', #Theta
'\xea', #Omega
'\xeb', #delta
'\xec', #Infinity
'\xed', #phi
'\xee', #epsilon
'\xef', #Intersection
'\xf0', #Congruent/Biconditional
'\xf1', #Plus + Minus Signs
'\xf2', #Greater than or equal to
'\xf3', #Less than or equal to
'\xf4', #Top of Integral Sign
'\xf5', #Bottom of Integral Sign
'\xf6', #Obelus/Division Sign
'\xf7', #Approximate Sign
'\xf8', #Degree Sign
'\xf9', #Small Centered Dot
'\xfa', #Interpunct
'\xfb', #Square Root Sign
'\xfc', #Exponent n
'\xfd', #Squared
'\xfe', #Small Block
'\xff' #NBSP
]
#Basically a more streamlined WConio.puttext()
def putchar(x, y, char, color = '\x07'): #charcolor is the combination character and color code that WConio.gettext supplies...
WConio.puttext(x, y, x, y, char + color)
#Draws a box between the four points and fills it in
def windraw(left, top, right, bottom, cc = '\x07', quick = 0):
xpos, ypos = 0, 1
#Top line + top corners
while xpos <= (right - left):
if xpos == 0:
putchar(left, top, charlist[201], cc)
putchar(left, bottom, charlist[200], cc)
elif xpos == (right - left):
putchar(right, top, charlist[187], cc)
putchar(right, bottom, charlist[188], cc)
else:
putchar(left + xpos, top, charlist[205], cc)
putchar(left + xpos, bottom, charlist[205], cc)
xpos += 1
while ypos < (bottom - top):
putchar(left, top + ypos, charlist[186], cc)
putchar(right, top + ypos, charlist[186], cc)
wpos = 1
while (wpos < (right - left - 1)) and not quick:
putchar(left + wpos, top + ypos, charlist[255], cc)
wpos += 1
ypos += 1
#Draws a block of color
def blodraw(left, top, right, bottom, cc = '\x07', opacity = 1):
xpos, ypos = 0, 0
while xpos <= (right - left):
while ypos <= (bottom - top):
putchar(left + xpos, top + ypos, charlist[176 + opacity], cc)
ypos += 1
xpos += 1
ypos = 0
def putstring(x, y, text, color = '\x07'):
index = 0
while index < len(text):
putchar(x + index, y, text[index], color)
index += 1
#
class Menu(object):
def __init__(self, x, y, options, colorhi = '\xf7', colorlo = '\x07'):
self.x, self.y = x, y
self.options = options
self.colorhi, self.colorlo = colorhi, colorlo
self.index = 0
while self.index < len(self.options):
putstring(self.x, self.y + self.index, self.options[self.index], colorlo)
self.index += 1
self.index = 0
def select(self, index):
putstring(self.x, self.y + self.index, self.options[self.index], self.colorlo)
putstring(self.x, self.y + index, self.options[index], self.colorhi)
self.index = index
return self.index
def inrange(self, index):
if 0 <= index < len(self.options):
return index
else:
return self.index
def select_up(self):
if self.index != 0:
self.select(self.index - 1)
def select_down(self):
if self.index != len(self.options) - 1:
self.select(self.index + 1)