This commit is contained in:
2023-09-13 13:37:54 +08:00
parent 426cfbaeaa
commit 1a11df1d52
2 changed files with 120 additions and 19 deletions

View File

@@ -31,7 +31,7 @@ class Task(socketserver.BaseRequestHandler):
# 11 * 11 的maze
if seed % 3 == 0:
maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
@@ -39,10 +39,11 @@ class Task(socketserver.BaseRequestHandler):
[1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1],
[1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0],
[1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
start = [1, 0]
end = [9, 10]
start = [1, 1]
end = [9, 9]
# ddddssssssddddss
elif seed % 3 == 1:
maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
@@ -54,46 +55,81 @@ class Task(socketserver.BaseRequestHandler):
[1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1]]
start = [10, 3]
end = [10, 5]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
start = [9, 3]
end = [9, 5]
# waawwwwwwwddssddsssdssas
else:
maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1],
maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1],
[1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1],
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0],
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
start = [0, 10]
end = [7, 10]
start = [1, 9]
end = [7, 9]
# aassaaaaaassddddsssddsddww
return maze, start, end
def check_position(self,maze:list,position:list)->bool:
if maze[position[0]][position[1]] == 1:
return False
else:
return True
def game(self):
self.send(b"Try to solve this maze")
self.send(b"Use wasd to move")
maze, start, end = self.select_maze(random.randint(0,99))
position = start
while position != end:
move = self.recv(b'Try to move: ').decode()
if not move:
print("Connection closed by the client.")
return False
if len(move) != 1:
self.send(b'Invalid lenth')
return False
continue
if move not in 'wasd':
self.send(b'Invalid instruction')
return False
continue
if move == "w":
pass
position[0] -= 1
if self.check_position(maze,position):
self.send(b"You moved one step up")
else:
self.send(b"You bumped into the wall")
position[0] += 1
elif move == "s":
pass
position[0] += 1
if self.check_position(maze,position):
self.send(b"You moved one step down")
else:
self.send(b"You bumped into the wall")
position[0] -= 1
elif move == "a":
pass
position[1] -= 1
if self.check_position(maze,position):
self.send(b"You moved one step left")
else:
self.send(b"You bumped into the wall")
position[1] += 1
else:
pass
position[1] += 1
if self.check_position(maze,position):
self.send(b"You moved one step right")
else:
self.send(b"You bumped into the wall")
position[1] -= 1
return True
def handle(self):
@@ -115,7 +151,8 @@ class ForkedServer(socketserver.ForkingMixIn, socketserver.TCPServer):
if __name__ == "__main__":
flag = bytes(os.getenv("FLAG"),"utf-8")
# flag = bytes(os.getenv("FLAG"),"utf-8")
flag = b'11111111111111'
HOST, PORT = '0.0.0.0', 10001
server = ForkedServer((HOST, PORT), Task)
server.allow_reuse_address = True