Okorosso

Untitled

Sep 13th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.27 KB | None | 0 0
  1. import random
  2. from random import randint
  3. playing_field = ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']
  4. count_of_stone = 7
  5. stones = [randint(0, 4) for i in range(count_of_stone*2)]
  6. for i in range(7):
  7.     playing_field[stones[i]][stones[i+1]] = 'S'
  8. hero_pos_x = randint(0, 4)
  9. hero_pos_y = randint(0, 4)
  10. playing_field[hero_pos_x][hero_pos_y] = 'H'
  11. pos = [hero_pos_x, hero_pos_y]
  12. last_button = ''
  13.  
  14.  
  15. def drop_stone(last_btn, pos):
  16.     if last_btn.lower() == 'w' and pos[0] - 1 > -1:
  17.         playing_field[pos[0]-1][pos[1]] = 'S'
  18.         hero.backpack.pop()
  19.         hero.backpack_count -= 1
  20.     elif last_btn.lower() == 's' and pos[0] + 1 < 6:
  21.         playing_field[pos[0]+1][pos[1]] = 'S'
  22.         hero.backpack.pop()
  23.         hero.backpack_count -= 1
  24.     elif last_btn.lower() == 'a' and pos[1] - 1 > -1:
  25.         playing_field[pos[0]][pos[1]-1] = 'S'
  26.         hero.backpack.pop()
  27.         hero.backpack_count -= 1
  28.     elif last_btn.lower() == 'd' and pos[1] + 1 < 6:
  29.         playing_field[pos[0]][pos[1]+1] = 'S'
  30.         hero.backpack.pop()
  31.         hero.backpack_count -= 1
  32.  
  33.  
  34. def change_pos(btn, pos):
  35.     if (btn == 'S' or btn == 's') and pos[0] + 1 < 6:
  36.         if playing_field[pos[0]+1][pos[1]] == 'S':
  37.             print('If U want take stone, pls press F')
  38.             a = input()
  39.             if a.lower() == 'f':
  40.                 hero.backpack_count += 1
  41.                 hero.backpack.append('Stone')
  42.         playing_field[pos[0]][pos[1]] = '*'
  43.         pos[0] += 1
  44.         playing_field[pos[0]][pos[1]] = 'H'
  45.     if (btn == 'W' or btn == 'w') and pos[0] - 1 > -1:
  46.         if playing_field[pos[0] - 1][pos[1]] == 'S':
  47.             print('If U want take stone, pls press F')
  48.             a = input()
  49.             if a.lower() == 'f':
  50.                 hero.backpack_count += 1
  51.                 hero.backpack.append('Stone')
  52.         playing_field[pos[0]][pos[1]] = '*'
  53.         pos[0] -= 1
  54.         playing_field[pos[0]][pos[1]] = 'H'
  55.     if (btn == 'D' or btn == 'd') and pos[1] + 1 < 6:
  56.         if playing_field[pos[0]][pos[1] + 1] == 'S':
  57.             print('If U want take stone, pls press F')
  58.             a = input()
  59.             if a.lower() == 'f':
  60.                 hero.backpack_count += 1
  61.                 hero.backpack.append('Stone')
  62.         playing_field[pos[0]][pos[1]] = '*'
  63.         pos[1] += 1
  64.         playing_field[pos[0]][pos[1]] = 'H'
  65.     if (btn == 'A' or btn == 'a') and pos[1] - 1 > -1:
  66.         if playing_field[pos[0]][pos[1]-1] == 'S':
  67.             print('If U want take stone, pls press F')
  68.             a = input()
  69.             if a.lower() == 'f':
  70.                 hero.backpack_count += 1
  71.                 hero.backpack.append('Stone')
  72.         playing_field[pos[0]][pos[1]] = '*'
  73.         pos[1] -= 1
  74.         playing_field[pos[0]][pos[1]] = 'H'
  75.     return pos
  76.  
  77.  
  78. def printing_field(playing_field):
  79.     for i in range(5):
  80.  
  81.         for j in range(5):
  82.             if j != 4:
  83.                 print(playing_field[i][j], end='')
  84.             else:
  85.                 print(playing_field[i][j])
  86.  
  87.  
  88. class Hero:
  89.     species = 'lion'
  90.     name = 'Artur'
  91.     hp = 10
  92.     backpack_count = 0
  93.     backpack = []
  94.     # def __init__(self, lvl):
  95.     #     self.lvl = lvl
  96.     # def __init__(self):
  97.     #     pass
  98.  
  99.     # action
  100.     def print_inv(self):
  101.         if len(self.backpack) != 0:
  102.             for i in range(len(self.backpack)):
  103.                 if i != len(self.backpack):
  104.                     print(self.backpack[i], end='')
  105.                 else:
  106.                     print(self.backpack[i])
  107.  
  108.  
  109. printing_field(playing_field)
  110. hero = Hero
  111.  
  112. while hero.hp > 0:
  113.     print('press one of keys WASD, Q to drop stone, I to check inventory')
  114.     button = str(input())
  115.     if button.lower() == 'i':
  116.         print(hero.backpack)
  117.     if button.lower() == 'q':
  118.         drop_stone(last_button, pos)
  119.  
  120.     if button.lower() == 'w' or button.lower() == 's' or button.lower() == 'a' or button.lower() == 'd':
  121.         pos = change_pos(button, pos)
  122.         last_button = button
  123.  
  124.     if hero.backpack_count > 0 and button.lower() != 'i':
  125.         print('count items in backpack =', hero.backpack_count)
  126.     if button.lower() != 'i':
  127.         printing_field(playing_field)
  128.         print(pos[0], pos[1])
Add Comment
Please, Sign In to add comment