-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperfunctions.py
More file actions
49 lines (42 loc) · 1.67 KB
/
Copy pathhelperfunctions.py
File metadata and controls
49 lines (42 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Dr. McCartin-Lim's Adventure Game Engine 0.75
#Updated by Fardin for his game
import sys
import textwrap
import builtins
#Overriding the built-in print function to word wrap what's printed
def print(*strings,sep=" ",end="\n",file=sys.stdout, flush=False):
#Concatenate all the strings together into catstring
catstring = ""
count = 0
for string in strings:
catstring += string
if count < len(strings)-1:
catstring += sep
count += 1
#Create a wrapped string from catstring
wrappedstring = ""
count = 0
wrapper = textwrap.TextWrapper()
wrapper.replace_whitespace = False
for string in catstring.splitlines():
wrappedstring += wrapper.fill(string)
if count < len(catstring.splitlines())-1:
wrappedstring += "\n"
count += 1
#Call built-in print function with wrappedstring and pass-in other parameters
builtins.print(wrappedstring,end=end,file=file,flush=flush)
#General function to create a string from a list of objects
def stringFromList(itemList, andWord="and"):
#If the list only has one item in it, return string representing that item
if len(itemList)==1:
return str(itemList[0])
else:
strToReturn = ""
for i in range(0,len(itemList)):
if i == len(itemList) - 1:
strToReturn = strToReturn + andWord + " " + str(itemList[i])
elif i == len(itemList) - 2:
strToReturn = strToReturn + str(itemList[i]) + " "
else:
strToReturn = strToReturn + str(itemList[i]) + ", "
return strToReturn