Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from random import randint
- class Field:
- # initialisation
- def __init__(self, pos_hero):
- self.playing_field = ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']
- self.count_of_stone = 7
- self.stones = [randint(0, 4) for j in range(self.count_of_stone * 2)]
- for i in range(7):
- self.playing_field[self.stones[i]][self.stones[i + 1]] = 'S'
- self.playing_field[pos_hero[0]][pos_hero[1]] = 'H'
- # add things on the field
- # respawn stones?
- def print(self):
- for i in range(5):
- for j in range(5):
- if j != 4:
- print(self.playing_field[i][j], end='')
- else:
- print(self.playing_field[i][j])
- class Hero:
- def __init__(self):
- self.name = 'Artur'
- self.hp = 10
- self.backpack_count = 0
- self.backpack = []
- self.pos = [randint(0, 4), randint(0, 4)]
- self.last_button = ''
- self.field = None
- # def __init__(self):
- # pass
- # action
- def print_inventory(self):
- for i in range(len(self.backpack)):
- print(self.backpack[i], end='')
- print()
- def change_pos(self, button):
- self.last_button = button
- if (button == 'S' or button == 's') and self.pos[0] + 1 < 6:
- if self.field.playing_field[self.pos[0] + 1][self.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')
- self.field.playing_field[self.pos[0]][self.pos[1]] = '*'
- self.pos[0] += 1
- self.field.playing_field[self.pos[0]][self.pos[1]] = 'H'
- if (button == 'W' or button == 'w') and self.pos[0] - 1 > -1:
- if self.field.playing_field[self.pos[0] - 1][self.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')
- self.field.playing_field[self.pos[0]][self.pos[1]] = '*'
- self.pos[0] -= 1
- self.field.playing_field[self.pos[0]][self.pos[1]] = 'H'
- if (button == 'D' or button == 'd') and self.pos[1] + 1 < 6:
- if self.field.playing_field[self.pos[0]][self.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')
- self.field.playing_field[self.pos[0]][self.pos[1]] = '*'
- self.pos[1] += 1
- self.field.playing_field[self.pos[0]][self.pos[1]] = 'H'
- if (button == 'A' or button == 'a') and self.pos[1] - 1 > -1:
- if self.field.playing_field[self.pos[0]][self.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')
- self.field.playing_field[self.pos[0]][self.pos[1]] = '*'
- self.pos[1] -= 1
- self.field.playing_field[self.pos[0]][self.pos[1]] = 'H'
- def drop_stone(self):
- if self.last_button.lower() == 'w' and self.pos[0] - 1 > -1:
- field.playing_field[self.pos[0] - 1][self.pos[1]] = 'S'
- hero.backpack.pop()
- hero.backpack_count -= 1
- elif self.last_button.lower() == 's' and self.pos[0] + 1 < 6:
- field.playing_field[self.pos[0] + 1][self.pos[1]] = 'S'
- hero.backpack.pop()
- hero.backpack_count -= 1
- elif self.last_button.lower() == 'a' and self.pos[1] - 1 > -1:
- field.playing_field[self.pos[0]][self.pos[1] - 1] = 'S'
- hero.backpack.pop()
- hero.backpack_count -= 1
- elif self.last_button.lower() == 'd' and self.pos[1] + 1 < 6:
- field.playing_field[self.pos[0]][self.pos[1] + 1] = 'S'
- hero.backpack.pop()
- hero.backpack_count -= 1
- hero = Hero()
- field = Field(hero.pos)
- field.print()
- hero.field = field
- 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':
- hero.drop_stone()
- if button.lower() == 'w' or button.lower() == 's' or button.lower() == 'a' or button.lower() == 'd':
- hero.change_pos(button)
- if hero.backpack_count > 0 and button.lower() != 'i':
- print('count items in backpack =', hero.backpack_count)
- if button.lower() != 'i':
- field.print()
- print(hero.pos)
Add Comment
Please, Sign In to add comment