Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from random import randint
- playing_field = ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']
- count_of_stone = 7
- stones = [randint(0, 4) for i in range(count_of_stone*2)]
- for i in range(7):
- playing_field[stones[i]][stones[i+1]] = 'S'
- hero_pos_x = randint(0, 4)
- hero_pos_y = randint(0, 4)
- playing_field[hero_pos_x][hero_pos_y] = 'H'
- pos = [hero_pos_x, hero_pos_y]
- last_button = ''
- def drop_stone(last_btn, pos):
- if last_btn.lower() == 'w' and pos[0] - 1 > -1:
- playing_field[pos[0]-1][pos[1]] = 'S'
- hero.backpack.pop()
- hero.backpack_count -= 1
- elif last_btn.lower() == 's' and pos[0] + 1 < 6:
- playing_field[pos[0]+1][pos[1]] = 'S'
- hero.backpack.pop()
- hero.backpack_count -= 1
- elif last_btn.lower() == 'a' and pos[1] - 1 > -1:
- playing_field[pos[0]][pos[1]-1] = 'S'
- hero.backpack.pop()
- hero.backpack_count -= 1
- elif last_btn.lower() == 'd' and pos[1] + 1 < 6:
- playing_field[pos[0]][pos[1]+1] = 'S'
- hero.backpack.pop()
- hero.backpack_count -= 1
- def change_pos(btn, pos):
- if (btn == 'S' or btn == 's') and pos[0] + 1 < 6:
- if playing_field[pos[0]+1][pos[1]] == 'S':
- print('If U want take stone, pls press F')
- a = input()
- if a.lower() == 'f':
- hero.backpack_count += 1
- hero.backpack.append('Stone')
- playing_field[pos[0]][pos[1]] = '*'
- pos[0] += 1
- playing_field[pos[0]][pos[1]] = 'H'
- if (btn == 'W' or btn == 'w') and pos[0] - 1 > -1:
- if playing_field[pos[0] - 1][pos[1]] == 'S':
- print('If U want take stone, pls press F')
- a = input()
- if a.lower() == 'f':
- hero.backpack_count += 1
- hero.backpack.append('Stone')
- playing_field[pos[0]][pos[1]] = '*'
- pos[0] -= 1
- playing_field[pos[0]][pos[1]] = 'H'
- if (btn == 'D' or btn == 'd') and pos[1] + 1 < 6:
- if playing_field[pos[0]][pos[1] + 1] == 'S':
- print('If U want take stone, pls press F')
- a = input()
- if a.lower() == 'f':
- hero.backpack_count += 1
- hero.backpack.append('Stone')
- playing_field[pos[0]][pos[1]] = '*'
- pos[1] += 1
- playing_field[pos[0]][pos[1]] = 'H'
- if (btn == 'A' or btn == 'a') and pos[1] - 1 > -1:
- if playing_field[pos[0]][pos[1]-1] == 'S':
- print('If U want take stone, pls press F')
- a = input()
- if a.lower() == 'f':
- hero.backpack_count += 1
- hero.backpack.append('Stone')
- playing_field[pos[0]][pos[1]] = '*'
- pos[1] -= 1
- playing_field[pos[0]][pos[1]] = 'H'
- return pos
- def printing_field(playing_field):
- for i in range(5):
- for j in range(5):
- if j != 4:
- print(playing_field[i][j], end='')
- else:
- print(playing_field[i][j])
- class Hero:
- species = 'lion'
- name = 'Artur'
- hp = 10
- backpack_count = 0
- backpack = []
- # def __init__(self, lvl):
- # self.lvl = lvl
- # def __init__(self):
- # pass
- # action
- def print_inv(self):
- if len(self.backpack) != 0:
- for i in range(len(self.backpack)):
- if i != len(self.backpack):
- print(self.backpack[i], end='')
- else:
- print(self.backpack[i])
- printing_field(playing_field)
- hero = Hero
- while hero.hp > 0:
- print('press one of keys WASD, Q to drop stone, I to check inventory')
- button = str(input())
- if button.lower() == 'i':
- print(hero.backpack)
- if button.lower() == 'q':
- drop_stone(last_button, pos)
- if button.lower() == 'w' or button.lower() == 's' or button.lower() == 'a' or button.lower() == 'd':
- pos = change_pos(button, pos)
- last_button = button
- if hero.backpack_count > 0 and button.lower() != 'i':
- print('count items in backpack =', hero.backpack_count)
- if button.lower() != 'i':
- printing_field(playing_field)
- print(pos[0], pos[1])
Add Comment
Please, Sign In to add comment