-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShooter.py
82 lines (52 loc) · 2.41 KB
/
Shooter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class Shooter:
def __init__(self):
self._your_gun = None
self._your_bullet = None
self._type_bullet = None
self._count_bullet = None
self._all_gun = {'Submachine Gun': (100, 10, 0.5), 'Assault Rifle': (200, 20, 1),
'Pistol': (80, 8, 0.5), 'Shotgun': (50, 40, 4), 'Sniper Rifle': (1000, 30, 3)}
self._bullets_name = {"A": (0.5, 1), 'B': (1, 1.5), 'C': (3, 3), 'D': (4, 2)}
def set_gun_by_name(self, name: str) -> None:
if name not in self._all_gun.keys():
raise ValueError("ur gun doesn't found")
else:
self._your_gun = name
# print(f'selected: {self._your_gun }')
def add_bullet_of_given_size_to_gun(self, size: float, count: int) -> None:
_size_exist = 0
self._count_bullet = count
if self._your_gun == None:
raise ValueError("you haven't yet selected your gun!")
if self._count_bullet < 0:
raise ValueError("you selected minus of bullet count")
for key, value in self._bullets_name.items():
if value[0] == size:
self._your_bullet = size
self._type_bullet = key
_size_exist += 1
if _size_exist == 0:
raise ValueError("size of bullet invalid")
# print(self._type_bullet)
if self._all_gun[self._your_gun][2] != self._your_bullet:
raise ValueError("your gun and bullet doesnt match toghter")
def shoot_to_target(self, target_x: int, target_y: int, target_distance: int, aim_x: int, aim_y: int) -> float:
if self._count_bullet <= 0:
raise ValueError("you haven't got bulllet")
else:
self._count_bullet -= 1
if self._your_gun == None:
raise ValueError("you haven't yet selected your gun!")
if target_x <= aim_x <= target_x + 10 and target_y <= aim_y <= target_y + 10:
if self._all_gun[self._your_gun][0] < target_distance:
return 0
else:
return (self._all_gun[self._your_gun][1] * self._bullets_name[self._type_bullet][1])
else:
raise ValueError("your squre isnt overlapping")
# shooter = Shooter()
# shooter.set_gun_by_name('Submachine Gun')
# shooter.add_bullet_of_given_size_to_gun(0.5, 1)
# result = shooter.shoot_to_target(1, 1, 200000, 5, 4)
# print(result)
# result should be 10