Advertisement
Ridz112

Untitled

Nov 22nd, 2021
25
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pygame import *
  2.  
  3. init()
  4. import random
  5. class dungeon():
  6.     def __init__(self): #
  7.         self.map = [[0,0,0,0,0],
  8.                     [0,0,0,0,0],
  9.                     [0,0,0,0,0],
  10.                     [0,0,0,0,0],
  11.                     [0,0,0,0,0]]
  12.  
  13.         self.spawnpointx = random.randint(0,2)
  14.         self.spawnpointy = random.randint(0, 2)
  15.         self.playerlocationx = self.spawnpointx
  16.         self.playerlocationy = self.spawnpointy
  17.         self.enemy_room = random.randint(1,2)
  18.  
  19.  
  20.  
  21.     def generatemap(self):
  22.         posx = 0
  23.         posy = 0
  24.         while posx < 5 and posy < 5:
  25.             self.map[posx][posy] = "R"
  26.             posx = posx + 1
  27.             while posx == 5:
  28.                 posx = 0
  29.                 posy = posy + 1
  30.  
  31.         posx = 0
  32.         posy = 0
  33.  
  34.         while posx < 5 and posy < 5:
  35.             if self.enemy_room == 2:
  36.                 self.map[posx][posy] = "E"
  37.             self.enemy_room = random.randint(1, 2)
  38.             posx = posx + 1
  39.             while posx == 5:
  40.                 posx = 0
  41.                 posy = posy + 1
  42.  
  43.         self.map[self.spawnpointy][self.spawnpointx] = "S"
  44.  
  45.         return self.map
  46.  
  47.     def display(self):
  48.         i = 0
  49.         while i < len(self.map):
  50.             print(self.map[i])
  51.             i += 1
  52.  
  53.     def findlocation(self):
  54.         print("You are in the coordinates:","(",self.playerlocationx,",",self.playerlocationy,")","Your are in:",self.map[self.playerlocationy][self.playerlocationx])
  55.         self.display()
  56.  
  57.  
  58.  
  59.  
  60.     def moveright(self):
  61.         print("You have moved right")
  62.         self.playerlocationx += 1
  63.         self.findlocation()
  64.  
  65.     def moveleft(self):
  66.         print("You have moved left")
  67.         self.playerlocationx -= 1
  68.         self.findlocation()
  69.  
  70.     def moveup(self):
  71.         print("You have moved up")
  72.         self.playerlocationy -= 1
  73.         self.findlocation()
  74.  
  75.     def movedown(self):
  76.         print("You have moved down")
  77.         self.playerlocationy += 1
  78.         self.findlocation()
  79.  
  80.  
  81.  
  82.  
  83. Dungeon = dungeon()
  84. print("Note - the starting indexes is 0")
  85.  
  86. Dungeon.generatemap()
  87. Dungeon.display()
  88. Dungeon.findlocation()
  89. while True:
  90.  
  91.     for e in event.get():
  92.         if e.type == constants.QUIT: # to quit game (close tab)
  93.             pass
  94.  
  95.         if e.type == KEYDOWN:
  96.  
  97.             if e.key == K_RIGHT:
  98.                 Dungeon.moveright()
  99.  
  100.             if e.key == K_LEFT:
  101.                 Dungeon.moveleft()
  102.  
  103.             if e.key == K_UP:
  104.                 Dungeon.moveup()
  105.  
  106.             if e.key == K_DOWN:
  107.                 Dungeon.movedown()
  108.  
  109.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement