This commit is contained in:
2026-07-30 11:35:10 +05:00
commit 8a3ec978ad
113 changed files with 3384 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
%% Zoottelkeeper: Beginning of the autogenerated index file list %%
[[Programming/OAP/oop.py|oop.py]]
[[Programming/OAP/varrirors.py|varrirors.py]]
[[Programming/OAP/Warrior2.py|Warrior2.py]]
[[Programming/OAP/ООП|ООП]]
%% Zoottelkeeper: End of the autogenerated index file list %%
+68
View File
@@ -0,0 +1,68 @@
from random import randint
class Warrior:
def __init__(self):
self.name = None
self.hp = 100
self.damage = 10
self.defense = 10
self.ultimate = False
def info(self):
print('___________________')
print('Name: {}'.format(self.name))
print('HP: {}'.format(self.hp))
print('___________________')
def attack(self, enemy):
self.damage = randint(5, 50)
if self.damage >= 50 and not self.ultimate:
self.ultimate = True
enemy.hp -= self.damage
enemy.hp = max(0, enemy.hp)
print(f"{self.name} uses an ULTIMATE attack! Hit -{self.damage}. {enemy.name}'s HP: {enemy.hp}")
elif self.damage <= 30:
if self.damage > enemy.defense:
enemy.hp -= self.damage
enemy.hp = max(0, enemy.hp)
print(f"{self.name} attacks! Hit -{self.damage}. {enemy.name}'s HP: {enemy.hp}")
else:
print(f"{enemy.name} is parrying {self.name}'s attack!")
if enemy.hp <= 0:
print(f"\n{enemy.name} is defeated!")
class Swordsman(Warrior):
def __init__(self, name):
super().__init__()
self.name = name
self.hp = 100
self.damage = 0
self.defense = 20
self.ultimate = False
class Dragon(Warrior):
def __init__(self, name):
super().__init__()
self.name = name
self.hp = 200
self.damage = 0
self.defense = 0
self.ultimate = False
hero = Swordsman('Hero')
dragon = Dragon('Dragon')
while hero.hp > 0 and dragon.hp > 0:
attacker, defender = (hero, dragon) if randint(0, 1) == 1 else (dragon, hero)
attacker.attack(defender)
if defender.hp <= 0:
print(f"\n{attacker.name} is the winner!")
hero.info()
dragon.info()
break
+13
View File
@@ -0,0 +1,13 @@
class Human:
def __init__(self):
self.health = 100
self.money = 100
class Student(Human):
def __init__(self, name, age):
super().__init__()
self.name = name
self.age = age
student1 = Student("kir", 20)
print(student1.money)
+51
View File
@@ -0,0 +1,51 @@
class Dish():
def __init__(self, name, price):
self.price = price
self.name = name
def prepare():
pass
class MainCource(Dish):
def __init__(self, name, price, weight):
super().__init__(name, price)
self.weight = weight
def prepare(self):
return f"Ваше блюдо {self.name} массой {self.weight} готовится!"
class Drink(Dish):
def __init__(self, name, price, capacity):
super().__init__(name, price)
self.capacity = capacity
def prepare(self):
return f"Ваш напиток {self.name} объемом {self.capacity} мл готовится!"
class Desert(Dish):
def __init__(self, name, price, kkal):
super().__init__(name, price)
self.kkal = kkal
def prepare(self):
return f"Ваш дессерт {self.name} каллорийностью {self.kkal} готовится!"
class Wallet():
def __init__(self, vol):
self.vol = vol
def __add__(self):
add = input("На сколько едениц вы хотите пополнить кошелек?\n>> ")
self.vol += add
class Order():
def __init__(self, dish1, dish2, di):
print("### Добро пожаловать, Александр! Это ваша любимая шаурмечка. Что будете брать сегодня?####")
print(f"У меня есть {wallet.vol} рублей.")
for dish in order:
print(dish.prepare())
wallet.vol = wallet.vol - dish.price
print(f'Вкусно поел! Осталось {wallet.vol} рублей.')
+54
View File
@@ -0,0 +1,54 @@
from random import randint
class Warrior:
def __init__(self, name):
self.name = name
self.hp = 100
self.type = ''
self.damage = 0
self.ultimate = False
self.parrying = 0
def info(self):
print('___________________')
print('Name: {}'.format(self.name))
print('HP: {}'.format(self.hp))
print('Type: {}'.format(self.type))
print('___________________')
def attack(self, enemy):
self.damage = randint(5, 50)
if self.damage >= 50 and not self.ultimate:
self.ultimate = True
enemy.hp -= self.damage
enemy.hp = max(0, enemy.hp)
print(f"{self.name} uses an ULTIMATE attack! Hit -{self.damage}. {enemy.name}'s HP: {enemy.hp}")
elif self.damage <= 30:
if self.damage > enemy.parrying:
enemy.hp -= self.damage
enemy.hp = max(0, enemy.hp)
print(f"{self.name} attacks! Hit -{self.damage}. {enemy.name}'s HP: {enemy.hp}")
else:
print(f"{enemy.name} is parrying {self.name} attack!")
if enemy.hp <= 0:
print(f"{enemy.name} is defeated!")
swordsman = Warrior('adam',)
swordsman.type = 'swordsman'
swordsman.parrying = 20
mag = Warrior('eva')
mag.type = 'magician'
mag.parrying = 15
while mag.hp > 0 and swordsman.hp > 0:
# Decide randomly who attacks
attacker, defender = (swordsman, mag) if randint(0, 1) == 0 else (mag, swordsman)
attacker.attack(defender)
# Check if the defender is defeated
if defender.hp <= 0:
print(f"\n{attacker.name} is the winner!")
print(f"{swordsman.info()}\n{mag.info()}")
break
+54
View File
@@ -0,0 +1,54 @@
**ООП** – парадигма программирования в которой все объекты представляются в виде экземпляров классов. Каждый класс обладает своими атрибутами и методами.
**Атрибуты** - данные, характеризующие класс.
**Методы** - функции, которые экземпляр класса может выполнять. С помощью методов можно влиять на атрибуты классов.
```python
class Human:
name = 'human'
age = 0
sex = "male"
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
def info(self):
print("Name:", self.name)
print("Age:", self.age)
print("Sex:", self.sex)
def Speak(self):
print(f"Hello, i'm {self.name}")
kirill = Human(name="kirill", age=17, sex="male")
katya = Human(name='Kate', age=18, sex="female")
```
## Наследование в ООП
**Наследование** в ООП это концепция, позволяющая классу, наследовать атрибуты и методы от другого класса.
![[th-1161040066.jpg]]
```python
class Human():
def __init__(self):
self.health = 100;
self.strenth = 100;
self.brain = 100;
self.money = 0
class Student(Human):
Human.health = 70
Human.money = 0
Human.brain = -10
Human.strenth = 70
student1 = Student()
print(student1.brain)
```
### Перегрузка операторов
**Перегрузка операторов** - возможность определять собственное поведение для стандартных операторов языка python при работе с объектами пользовательских классов.