-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevelGenerator.py
137 lines (117 loc) · 3.64 KB
/
levelGenerator.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os,time
from characters import *
from level import *
from getch import *
class LevelGenerator:
def main():
os.system('clear')
print("1. Edit Existing")
print("2. Start from Scratch")
ch = getchS()
filename = "level"
if ch is '1':
while True:
try:
print()
print("All levels :")
os.system("ls ./levels/ | grep -oP '^((?!Enemy).)*$' | sed -e 's/\.txt$//'")
print()
print("Enter Level Name : ",end='')
filename = input()
level = Level(0,0,"./levels/"+filename+".txt")
break
except FileNotFoundError:
print("Level Does not exist! Try again")
else:
level = Level(0,0,"./designs/"+filename+".txt")
enemies = []
enemiesstr = []
try:
file = open("./levels/"+filename+"Enemy.txt","r")
for line in file:
enemiesstr.append(line)
goomba = eval(line)
goomba.cannotCross=['T','|','/','\\','`']
enemies.append(goomba)
except:
pass
rules = Element(0,0)
while True:
rules.design = ["| b : brick | c : coin | s : spring | t : tunnel | p : pit |","| m : coinbrick | h : health | g : gun | e : enemy | q : done |"]
level.printOnTop(*enemies,rules)
choice = getchS()
if choice is 'b':
obj = Character(0,level.pos,2,"./designs/brick.txt")
obj.cannotCross=['T','/','\\','`','-']
elif choice is 'c':
obj = Character(0,level.pos,2,"./designs/coin.txt")
obj.cannotCross=['T','|','/','\\','`','-']
elif choice is 's':
obj = Character(0,level.pos,2,"./designs/spring.txt")
obj.cannotCross=['|','/','\\','`','-']
elif choice is 't':
obj = Character(0,level.pos,2,"./designs/tunnel.txt")
obj.cannotCross=['T','|','/','\\','`','-']
elif choice is 'p':
obj = Character(0,level.pos,2,"./designs/pit.txt")
obj.cannotCross=['/','\\','`','-']
elif choice is 'm':
obj = Character(0,level.pos,2,"./designs/coinbrick.txt")
obj.cannotCross=['T','/','\\','`','-']
elif choice is 'h':
obj = Character(0,level.pos,2,"./designs/life.txt")
obj.cannotCross=['T','/','\\','`','-']
elif choice is 'g':
obj = Character(0,level.pos,2,"./designs/gun.txt")
obj.cannotCross=['T','|','/','\\','`','-']
elif choice is 'e':
obj = Character(1,level.pos,2,"./designs/goomba1.txt","./designs/goomba2.txt")
obj.cannotCross=['T','|','/','\\','`']
elif choice is 'q':
break
else:
continue
rules.design = ["| w : up | s : down | a : left | d : right | x : delete | p : place |"]
while True:
os.system("clear")
level.printOnTop(obj,*enemies,rules)
move = getchS()
if move is 'a':
if obj.x > level.pos:
obj.moveLeft(level)
elif move is 'd':
if obj.x < 250:
if obj.x < level.pos+(40)-obj.width:
obj.moveRight(level)
else:
if obj.moveRight(level):
level.pos+=1
rules.x+=1
elif move is 'w':
if obj.y>0:
obj.moveUp(level)
elif move is 's':
if obj.y < 23-obj.height:
obj.moveDown(level)
elif move is 'x':
break
elif move is 'p':
if choice is 'e':
enemies.append(obj)
enemystr = "Goomba(1,"+str(obj.x)+","+str(obj.y)+",\"./designs/goomba1.txt\",\"./designs/goomba2.txt\")"
enemiesstr.append(enemystr)
else:
level.place(obj)
break
if ch is not '1':
print("Enter Level Name : ",end='')
filename = input()
open("./levels/"+filename+".txt", "w").close()
file = open("./levels/"+filename+".txt","a")
open("./levels/"+filename+"Enemy.txt", "w").close()
enemyfile = open("./levels/"+filename+"Enemy.txt","a")
for line in level.design:
file.write(line+"\n")
for line in enemiesstr:
enemyfile.write(line+"\n")
main()