Skocz do zawarto艣ci

pomocy bo nie umiem w pytonga i mi sie drzwi nie 艂膮cz膮 do end rooma 馃槶馃槶馃槶馃槶馃槶


Akustyk

Recommended Posts

# author : Radek Z. and troszke Kuba S. (akustyczny kolega)
import pygame
import random
pygame.init()
class GenDungeon() :
聽 聽 def __init__(self , max_plate) :
聽 聽 聽 聽 self.max_plate = max_plate
聽 聽 聽 聽 self.map = []
聽 聽 聽 聽 self.room_type = {
聽 聽 聽 聽 聽 聽 0 : "empty_room" ,
聽 聽 聽 聽 聽 聽 1 : "start_room" ,
聽 聽 聽 聽 聽 聽 2 : "end_room" ,
聽 聽 聽 聽 聽 聽 3 : "enemy_room" ,
聽 聽 聽 聽 聽 聽 4 : "boss_room" ,
聽 聽 聽 聽 聽 聽 5 : "chest_room"
聽 聽 聽 聽 }
聽 聽 def gen_map(self ) :
聽 聽 聽 聽 self.gen_clear_map()
聽 聽 聽 聽 self.map[self.max_plate // 2][self.max_plate // 2] = 1
聽 聽 聽 聽 enemy_room = random.randint(4, 6)
聽 聽 聽 聽 chest_room = random.randint(2, 5)
聽 聽 聽 聽 boss_room = random.random()
聽 聽 聽 聽 if boss_room < 0.2:
聽 聽 聽 聽 聽 聽 boss_room = 1
聽 聽 聽 聽 else:
聽 聽 聽 聽 聽 聽 boss_room = 0
聽 聽 聽 聽 for _ in range(enemy_room):
聽 聽 聽 聽 聽 聽 self.gen_room(3)
聽 聽 聽 聽 聽 聽 print("enemy room")
聽 聽 聽 聽 for _ in range(chest_room):
聽 聽 聽 聽 聽 聽 self.gen_room(5)
聽 聽 聽 聽 聽 聽 print("chest room")
聽 聽 聽 聽 for _ in range(boss_room):
聽 聽 聽 聽 聽 聽 self.gen_room(4)
聽 聽 聽 聽 聽 聽 print("boss room")
聽 聽 聽 聽 self.gen_room(2)
聽 聽 def gen_clear_map(self) :
聽 聽 聽 聽 self.map = []
聽 聽 聽 聽 for x in range(self.max_plate) :
聽 聽 聽 聽 聽 聽 column = []
聽 聽 聽 聽 聽 聽 for y in range(self.max_plate) :
聽 聽 聽 聽 聽 聽 聽 聽 column.append(0)
聽 聽 聽 聽 聽 聽 self.map.append(column)
聽 聽 def gen_room(self, room_type):
聽 聽 聽 聽 while True:
聽 聽 聽 聽 聽 聽 x = random.randint(0 , self.max_plate-1)
聽 聽 聽 聽 聽 聽 y = random.randint(0 , self.max_plate-1)
聽 聽 聽 聽 聽 聽 somsiad = 0
聽 聽 聽 聽 聽 聽 start_room = False
聽 聽 聽 聽 聽 聽 cord = (
聽 聽 聽 聽 聽 聽 聽 聽 (x + 1 , y),
聽 聽 聽 聽 聽 聽 聽 聽 (x - 1 , y),
聽 聽 聽 聽 聽 聽 聽 聽 (x , y + 1),
聽 聽 聽 聽 聽 聽 聽 聽 (x , y - 1) 聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 聽 聽 聽 聽 )
聽 聽 聽 聽 聽 聽 for h in cord:
聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 cx , cy = h
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if self.map[cx][cy] in (1 ,2 , 3 , 4 , 5):
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 somsiad += 1
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if self.map[cx][cy] == 1:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 start_room = True
聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
聽 聽 聽 聽 聽 聽
聽 聽 聽 聽 聽 聽 if (room_type == 2) or (room_type == 4) or (room_type == 5):
聽 聽 聽 聽 聽 聽 聽 聽 if (somsiad > 0 and somsiad < 4 and not start_room) and self.map[x][y] == 0:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.map[x][y] = room_type
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break
聽 聽 聽 聽 聽 聽 else:
聽 聽 聽 聽 聽 聽 聽 聽 if (somsiad > 0 and somsiad < 4) and self.map[x][y] == 0:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.map[x][y] = room_type
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break
聽 聽 聽 聽 聽 聽 self.gen_door()
聽 聽 聽 聽 聽 聽 self.update_door()
聽 聽 def gen_door(self):
聽 聽 聽 聽 self.door = []
聽 聽 聽 聽 for x in range(self.max_plate):
聽 聽 聽 聽 聽 聽 column = []
聽 聽 聽 聽 聽 聽 for y in range(self.max_plate):
聽 聽 聽 聽 聽 聽 聽 聽 column.append([False , False , False , False])
聽 聽 聽 聽 聽 聽 self.door.append(column)
聽 聽 聽 聽 for x in range(self.max_plate):
聽 聽 聽 聽 聽 聽 for y in range(self.max_plate):
聽 聽 聽 聽 聽 聽 聽 聽 if self.map[x][y] == 1:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y]
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 cord = (
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 (x + 1 , y),
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 (x , y + 1),
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 (x , y - 1),
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 (x - 1 , y)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 )
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 for c in cord:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 sx , sy = c
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if self.map[sx][sy] != 0:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if sy == y-1:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][0] = True
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 elif sy == y+1:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][1] = True
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 elif sx == x+1:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][2] = True
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 elif sx == x-1:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][3] = True
聽 聽 聽 聽 self.update_door()
聽 聽 聽 聽 for _ in range(6):
聽 聽 聽 聽 聽 聽 for x in range(self.max_plate):
聽 聽 聽 聽 聽 聽 聽 聽 for y in range(self.max_plate):
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if (self.door[x][y] == [False , False , False , False]) and (self.map[x][y] > 0):
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if True in self.door[x][y-1]:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][0] = True
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if True in self.door[x][y+1]:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][1] = True
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if True in self.door[x-1][y]:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][3] = True
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if True in self.door[x+1][y]:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][2] = True
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.update_door()
聽 聽 def update_door(self):
聽 聽 聽 聽 for x in range(self.max_plate):
聽 聽 聽 聽 聽 聽 for y in range(self.max_plate):
聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if self.door[x][y-1][1] == True:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][0] = True
聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if self.door[x][y+1][0] == True:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][1] = True
聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if self.door[x+1][y][3] == True:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][2] = True
聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
聽 聽 聽 聽 聽 聽 聽 聽 try:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if self.door[x-1][y][2] == True:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 self.door[x][y][3] = True
聽 聽 聽 聽 聽 聽 聽 聽 except:
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 pass
"""
- zamieni膰 potem try except na lepsze sprawdzanie wyj艣cia poza map臋
"""
class Display():
聽 聽 def print_room(self , room , cord):
聽 聽 聽 聽 x , y = cord
聽 聽 聽 聽 cords = (
聽 聽 聽 聽 聽 聽 x * 50 ,
聽 聽 聽 聽 聽 聽 y * 50 ,
聽 聽 聽 聽 聽 聽 50 ,
聽 聽 聽 聽 聽 聽 50
聽 聽 聽 聽 )
聽 聽 聽 聽 match room:
聽 聽 聽 聽 聽 聽 case 0 :
聽 聽 聽 聽 聽 聽 聽 聽 color = "grey"
聽 聽 聽 聽 聽 聽 case 1 :
聽 聽 聽 聽 聽 聽 聽 聽 color = (255 , 175 , 10)
聽 聽 聽 聽 聽 聽 case 2 :
聽 聽 聽 聽 聽 聽 聽 聽 color = (0 ,200 , 0)
聽 聽 聽 聽 聽 聽 case 3 :
聽 聽 聽 聽 聽 聽 聽 聽 color = (255 , 0 , 0)
聽 聽 聽 聽 聽 聽 case 4 :
聽 聽 聽 聽 聽 聽 聽 聽 color = (255 , 255 , 0)
聽 聽 聽 聽 聽 聽 case 5 :
聽 聽 聽 聽 聽 聽 聽 聽 color = (0 , 0 , 255)
聽 聽 聽 聽 聽 聽 case None :
聽 聽 聽 聽 聽 聽 聽 聽 color = "black"
聽 聽 聽 聽
聽 聽 聽 聽 pygame.draw.rect(screen , color , cords)
聽 聽 def print_door(self , cord):
聽 聽 聽 聽 x , y , pos = cord
聽 聽 聽 聽 if pos[0]:
聽 聽 聽 聽 聽 聽 cords = (
聽 聽 聽 聽 聽 聽 x * 50 + 20 ,
聽 聽 聽 聽 聽 聽 y * 50 ,
聽 聽 聽 聽 聽 聽 10 ,
聽 聽 聽 聽 聽 聽 10
聽 聽 聽 聽 聽 聽 )
聽 聽 聽 聽 聽 聽 pygame.draw.rect(screen , "green" , cords)
聽 聽 聽 聽 if pos[1]:
聽 聽 聽 聽 聽 聽 cords = (
聽 聽 聽 聽 聽 聽 x * 50 + 20 ,
聽 聽 聽 聽 聽 聽 y * 50 + 40 ,
聽 聽 聽 聽 聽 聽 10 ,
聽 聽 聽 聽 聽 聽 10
聽 聽 聽 聽 聽 聽 )
聽 聽 聽 聽 聽 聽 pygame.draw.rect(screen , "green" , cords)
聽 聽 聽 聽 if pos[2]:
聽 聽 聽 聽 聽 聽 cords = (
聽 聽 聽 聽 聽 聽 x * 50 + 40 ,
聽 聽 聽 聽 聽 聽 y * 50 + 20,
聽 聽 聽 聽 聽 聽 10 ,
聽 聽 聽 聽 聽 聽 10
聽 聽 聽 聽 聽 聽 )
聽 聽 聽 聽 聽 聽 pygame.draw.rect(screen , "green" , cords)
聽 聽 聽 聽 if pos[3]:
聽 聽 聽 聽 聽 聽 cords = (
聽 聽 聽 聽 聽 聽 x * 50 ,
聽 聽 聽 聽 聽 聽 y * 50 + 20 ,
聽 聽 聽 聽 聽 聽 10 ,
聽 聽 聽 聽 聽 聽 10
聽 聽 聽 聽 聽 聽 )
聽 聽 聽 聽 聽 聽 pygame.draw.rect(screen , "green" , cords)
聽 聽 def print_map(self , g) :
聽 聽 聽 聽 plate = g.map
聽 聽 聽 聽 for x in range(g.max_plate ) :
聽 聽 聽 聽 聽 聽 for y in range(g.max_plate) :
聽 聽 聽 聽 聽 聽 聽 聽 self.print_room(plate[x][y] , (x , y) )
聽 聽 聽 聽 for x in range(g.max_plate):
聽 聽 聽 聽 聽 聽 for y in range(g.max_plate):
聽 聽 聽 聽 聽 聽 聽 聽 self.print_door((x , y , g.door[x][y]))
def main() :
聽 聽 global screen
聽 聽 sze = 50 * 11
聽 聽 screen= pygame.display.set_mode((sze , sze))
聽 聽 pygame.display.set_caption("dungeony")
聽 聽 g = GenDungeon(11)
聽 聽 d = Display()
聽 聽 g.gen_map()
聽 聽 while True :
聽 聽 聽 聽 for event in pygame.event.get() :
聽 聽 聽 聽 聽 聽 if event.type == pygame.QUIT :
聽 聽 聽 聽 聽 聽 聽 聽 quit()
聽 聽 聽 聽 screen.fill("black")
聽 聽 聽 聽 d.print_map(g)
聽 聽 聽 聽 pygame.display.update()
if __name__ == "__main__" :
聽 聽 main()

#jakby co to python wersja 3.13.9
Link do komentarza
Udost臋pnij na innych stronach

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Go艣膰
Odpowiedz...

×   Wklei艂e艣 zawarto艣膰 bez formatowania.   Usu艅 formatowanie

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Utw贸rz nowe...