-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset-up.py
105 lines (92 loc) · 2.84 KB
/
set-up.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
import random, string, os, shutil
def genRandString(length):
return ''.join(random.choice(string.ascii_lowercase) for i in xrange(length))
def strToNum(s):
x = []
for c in s:
# a is 97
x.append(ord(c)-96)
return x
def addStrsToNum(strs):
currSum = [0]*len(strs[0])
for s in strs:
x = strToNum(s)
for i in xrange(len(currSum)):
currSum[i] += x[i]
return currSum
def subtractNumsToStr(s1, s2):
r = ''
for i in xrange(len(s1)):
subtract = (s1[i] - s2[i] - 1) % 26 + 1
r += chr(subtract + 96)
return r
if os.path.exists("lvls"):
shutil.rmtree("lvls")
os.makedirs("lvls")
fileDir = "http://simmons-hall.scripts.mit.edu/space-waffle/lasers"
if os.path.exists("fileDir.txt"):
fin = open("fileDir.txt")
fileDir = fin.read().strip()
fin.close()
print fileDir
fin = open("lvlIndexSrc.html")
lvlIndexSrc = fin.read()
fin.close()
fout = open("lvls/index.html", "w")
fout.write(lvlIndexSrc)
fout.close()
fin = open("lvlSrc.html")
lvlSrc = fin.read()
fin.close()
numLvls = 13
target = "rankings"
lvls = []
for i in xrange(numLvls):
lvls.append(genRandString(len(target)))
#lvls.append(subtractNumsToStr(strToNum(target), addStrsToNum(lvls)))
lvls.append(target)
for i in xrange(numLvls):
os.makedirs("lvls/" + lvls[i])
fout = open("lvls/" + lvls[i] + "/index.html", "w")
fout.write(lvlSrc);
fout.close()
foutJs = open("lvls/" + lvls[i] + "/magic.js", "w")
foutJs.write("// Whoa there: cheating bunch are we?\n")
foutJs.write("// Yes, we did not go through the effort of obfuscating our code. Just play the game :D\n")
foutJs.write("\n" * 371);
foutJs.write("// What did we say about honesty-- where's the fun in this?\n");
foutJs.write("\n" * 934);
foutJs.write("// Really??\n");
foutJs.write("\n" * 934);
foutJs.write("// Much disppointment wow\n");
foutJs.write("var currentMap = " + str(i+1) + ";");
foutJs.write("var nextMap = \"" + lvls[i+1] + "\";");
foutJs.write("\n" * 614);
foutJs.close()
fin = open("last.html")
lastSrc = fin.read()
fin.close()
lastSrc = lastSrc.replace('http://apark93.mit.edu', fileDir)
os.makedirs("lvls/" + lvls[-1]);
fout = open("lvls/" + lvls[-1] + "/index.html", "w")
fout.write(lastSrc)
fout.close()
foutJs = open("lvls/" + lvls[-1] + "/last.js", "w")
output = "var levels = [\n";
for i in xrange(numLvls):
output += '"' + lvls[i] + '", \n'
output = output[:-3] + '];'
foutJs.write(output)
foutJs.close()
print lvls
fin = open("first.html")
moveSrc = fin.read()
fin.close()
firstSrc = moveSrc.replace("http://example.com", fileDir + "/lvls/" + lvls[0])
foutHtml = open("index.html", "w")
foutHtml.write(firstSrc)
foutHtml.close()
lastSrc = moveSrc.replace("http://example.com", fileDir + "/lvls/" + lvls[-1])
foutHtml = open("cheats.html", "w")
foutHtml.write(lastSrc)
foutHtml.close()