-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyDwarf.py
executable file
·338 lines (295 loc) · 13 KB
/
pyDwarf.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/usr/bin/python3.4
#-----------------------------------------------------------------------------------------------
# Name: A tunnel building program for the avid Minecraft Pi dwarf.
# Purpose: Designed to build descending, ascending and straight tunnels in Minecraft Pi.
# This is written very simply for debugging/learning purposes.
# Most of this code is designed to handle user input.
# Eventually this will be integrated into a user interface with QT and pyQT.
# Version: Development
# Author: benjo charlie
# Created: 2016
# This is an octothorp # Spread the word.
#-----------------------------------------------------------------------------------------------
# Import libraries and set up the globals
import mcpi.minecraft as minecraft
from random import randrange
mc = minecraft.Minecraft.create()
x, y, z = mc.player.getPos()
mc.postToChat("Immeasurable halls, filled with an everlasting music of")
mc.postToChat("water that tinkles into pools, as fair as Kheled-Zaram")
mc.postToChat("in the starlight.")
#############################################################################################################
class UserInput(object):
def __init__(self):
self.start = "Schist!"
# Get the data from the user:
def getinput(self, i):
# Python likes a Global declared in every DEF to be sure you know what you're playing with.
global tunnel
global compass
global length
global elevation
global deep
elevation = "Z"
# Loop through the options until all requirements are satisfied.
while i:
if i == 1:
tunnel = input("\nWhat type of tunnel are we building, a Hallway or Steps? H, S >> ")
if tunnel in ("H", "S", "h", "s", "hall", "stairs"):
if tunnel in ("H", "h", "hall"):
tunnel = "H"
i += 2
tunneltype="Hallway"
# Debug: print(tunneltype)
elif tunnel in ("S", "s", "stairs"):
tunnel = "S"
i += 1
tunneltype = "Stairwell"
# Debug: print(tunneltype)
else:
print("Usage ", i)
i = printscreen.usage(1)
elif i == 2:
if tunnel in ("S", "s", "stairs"):
elevation = input("\nDo you want the stairs to go up or down? U,D >> ")
if elevation in ("U", "D", "u", "d", "Up", "Down", "up", "down"):
if elevation in ("U", "u", "Up", "up"):
elevation = "U"
elif elevation in ("D", "d", "Down", "down"):
elevation = "D"
i += 2
else:
i = printscreen.usage(2)
else:
i += 2
elif i == 3:
if tunnel == "H":
elevation = input("\nDo you want a Glass Hallway or Lighted? G,L >> ")
if elevation in ("G", "L", "g", "l", "glass", "lighted", "Glass", "Lighted"):
i += 1
if elevation in ("G", "g", "glass", "Glass"):
elevation = "G"
elif elevation in ("L", "l", "lighted", "Lighted"):
elevation = "L"
else:
i = printscreen.usage(3)
print("Usage ", i)
elif i == 4:
compass = input("\nWhat direction shall we dig? N,E,S or W? >> ")
if compass in ("N", "E", "S", "W", "n", "e", "s", "w", "north", "east", "south", "west"):
i += 1
if compass in ("N", "n", "north"):
compass = "N"
direction = "Northerly"
elif compass in ("E", "e", "east"):
compass = "E"
direction = "Easterly"
elif compass in ("S", "s", "south"):
compass = "S"
direction = "Southerly"
elif compass in ("W", "w", "west"):
compass = "W"
direction = "Westerly"
else:
i = printscreen.usage(4)
print("Usage ", i)
elif i == 5:
while True:
try:
print("\nHow deep/far do you want to dig?\n")
length = int(input("[keypad] 1-128 >> "))
if length in (range(1, 129)):
break
except:
i = printscreen.usage(5)
deep = length
i += 1
else:
print("\n *** Building a ", tunneltype, ",", deep, "blocks deep in a ", direction, " direction. ***\n")
return length, compass, elevation
#############################################################################################################
class OutputToScreen(object):
def __init__(self):
self.start = "Schist!"
def usage(self, u):
if u == 1:
print("""\
Usage: Tunnel type [H, S]
-H Hallway Build a hallway type tunnel
-S Steps Build a stairwell type tunnel
""")
return 1
elif u == 2:
print("""\
Usage: Up or Down [U, D]
-U Upward staircase Build a stairwell going up 45 degrees
-D Downward staircase Build a stairwell going down 45 degrees
""")
return 2
elif u == 3:
print("""\
Usage: Glass or Lighted [G, L]
-G Glass Walls Build a hallway with glass walls
-L Glowstone Walls Build a hallway with Glowstone
""")
return 3
elif u == 4:
print("""\
Usage: Direction [N, E, S, W]
-N North Build a tunnel in the northern direction
-E East Build a tunnel in the eastern direction
-S South Build a tunnel in the southern direction
-W West Build a tunnel in the western direction
""")
return 4
elif u == 5:
print("""\
Usage: Length [1-128]
-Integer input ranging 1-128
""")
mc.postToChat("The Dwarves delved too greedily and too deep.")
return 5
else:
print("Something went terribly wrong. We shouldn't be here!!!")
mc.postToChat("This new Gandalf is more grumpy than the old one.")
raise SystemExit
# Random dwarf quote generator
def gimli(self):
# Everyone should have a Random dwarf quote generator.
quote = [
"I'm always last, and I don't like it.",
"Faithless is he who says farewell when the road darkens.",
"They had no honor in life. They have none now in death.",
"Whatever luck you live by... let's hope it lasts the night.",
"It's true you don't see many dwarf women. And in fact, "
"they are so alike in voice and appearance, that they "
"are often mistaken for dwarf men.",
"I cannot jump the distance, you'll have to toss me.",
"And you know what this Dwarf says to that? Ishkhaqwi ai "
"durugnul! I spit upon your grave!",
"There is some good stonework here.",
"You may do as you please in madness.",
"I have but returned to take what is mine; for I am the last of my people.",
"The new Gandalf is grumpier than the old one.",
"The Dwarves delved too greedily and too deep.",
"The air must be thin up there, elf, for ye are daft to come up with that plan",
"Never turn down an ale, who knows if it may be your last.",
"Her beard is winking at me.",
"Wherever there are elves, there are lies!",
"Nothing a hammer can't solve.",
"You can kill a dwarf, but you can never vanquish one!",
"The stones will sing if you let them.",
"Dwarven women are like axes. As dangerous from the back as from the front.",
"A mead in the hand, is worth two goblin heads in the bush.",
"Leave iron to rest before you hammer it.",
"You are softer than sandstone and drier than talc!",
"Cave toads speak little, but when they do, listen.",
"A pebble will stay dry inside, no matter how long it is submerged in a pool of water.",
"Nothing evens a race like an axe to the kneecaps.",
"The smallest pebble was once the biggest stone, the biggest stone was once bigger."]
mc.postToChat(quote[randrange(0, len(quote))])
#############################################################################################################
class DwarfMiner(object):
def __init__(self):
self.start = "Schist!"
# Define 'drill' function
def drill(self, L, D, A):
# Set up the local variables.
# Blocks are assigned from bottom left to upper right.
# y1 is player level, y2 is up.
# Default to MELONS for debuging
roofBlock=103
floorBlock=103
wallBlock=103
x1, y1, z1 = mc.player.getPos()
x2, y2, z2 = x1, y1+2, z1
R, F = 0, 0
# xz1, xz2 : Set the step width (block breadth) to 5 blocks wide corresponding to direction.
# R, F : Set the roof and floor steps data value to correspond with the direction.
if D == "N":
x1, x2, R, F = x1-2, x1+2, 7, 2
elif D == "E":
z1, z2, R, F = z1-2, z1+2, 4, 1
elif D == "S":
x1, x2, R, F = x1+2, x1-2, 6, 3
elif D == "W":
z1, z2, R, F = z1+2, z1-2, 5, 0
# Set the tiles for step type construction and orientate to corresponding direction.
if A in ("U", "D"):
roofBlock=156
floorBlock=156
wallBlock=89
if A == "U":
if D == "N":
R, F = 6, 3
elif D == "E":
R, F = 5, 0
elif D == "S":
R, F = 7, 2
elif D == "W":
R, F = 4, 1
elif A == "D":
if D == "N":
R, F = 7, 2
elif D == "E":
R, F = 4, 1
elif D == "S":
R, F = 6, 3
elif D == "W":
R, F = 5, 0
else:
#set to NETHER REACTOR CORE for debuging if things went terribly wrong.
wallBlock=247
roofBlock=247
floorBlock=247
if A in ("L", "G"):
R, F = 0, 0
if A == "L":
wallBlock=89
roofBlock=155
floorBlock=155
elif A == "G":
wallBlock=20
roofBlock=20
floorBlock=20
else:
#set to CACTUS for debuging if things went terribly wrong.
wallBlock=81
roofBlock=81
floorBlock=81
# Build it
for n in range(1, L):
# xz1, xz2 : Set the step depth and starting point corresponding to direction
if D == "N":
z1, z2, = z1-1, z1-1
elif D == "E":
x1, x2, = x1+1, x1+1
elif D == "S":
z1, z2, = z1+1, z1+1
elif D == "W":
x1, x2, = x1-1, x1-1
# Build the Roof-Floor-Tunnel-Walls using one 5x5x1 block at a time
# Set the roof tiles. We do this first to stop that nasty sand falling in!
mc.setBlocks(x1, y2+1, z1, x2, y2+1, z2, roofBlock, R)
# Set the floor tiles.
mc.setBlocks(x1, y1-1, z1, x2, y1-1, z2, floorBlock, F)
# Dig between floor/roof tiles with a 3Wx3H block for each loop.
mc.setBlocks(x1, y1, z1, x2, y2, z2, 0)
# Build the walls.
mc.setBlocks(x1, y1-1, z1, x1, y2+1, z1, wallBlock)
mc.setBlocks(x2, y1-1, z2, x2, y2+1, z2, wallBlock)
# Decrement/Increment the depth by 1 block and reset height for next loop
if A in ("U", "D"):
if A == "U":
y1 += 1
elif A == "D":
y1 -= 1
y2 = y1 + 2
#############################################################################################################
# Run it
printscreen = OutputToScreen()
userinput = UserInput()
length, compass, elevation = userinput.getinput(1)
miner = DwarfMiner()
miner.drill(length, compass, elevation)
printscreen.gimli()