-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.py
160 lines (141 loc) · 5.2 KB
/
Player.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 13 00:29:13 2018
@author: X
"""
import random
from Map_ import *
from Weapon import *
from Bag import *
class Player(object):
def __init__(self,initalLoaction): #(y,x) y is the vertical axis, x is the horizen axis
self.__currentLocation = initalLoaction
self.locInfo = ''
self.__Y = self.__currentLocation[0]
self.__X = self.__currentLocation[1]
self.__Health=100
self.__Defense = 0
self.__Speed = 0
self.__Shooting_skill = 0
self.__Fighting_skill = 0
self.__hand = None
self.bag_ = None
self.weaponSlot = None
self.bulletSlot = None
pass
def initalizeCharacterStatus(self):
self.__Defense = random.randint(50,90)
self.__Speed = random.randint(50,90)
self.__Shooting_skill = random.randint(50,90)
self.__Fighting_skill = random.randint(50,90)
pass
def setCharacterStatus(self,property_):
pass
def getCharacterStatus(self):
print("Health: ",self.__Health)
print("Defense: ",self.__Defense)
print("Speed: ",self.__Speed)
print("Shooting_skill: ",self.__Shooting_skill)
print("Fighting_skill: ",self.__Fighting_skill)
if self.__hand is not None:
print("Weapon:{name}({shortname})|{gunInfo}".format(name = self.__hand.Name,\
shortname = self.__hand.shortName,gunInfo = self.__hand.type.gunInfo()))
else:
print("Weapon:Fist")
pass
def move(self,direction,map_):
if direction == 'w':
walk = (-1,0)
elif direction == 's':
walk = (1,0)
elif direction == 'a':
walk = (0,-1)
else:
walk = (0,1)
__locationTemp = (self.__currentLocation[0]+walk[0],self.__currentLocation[1]+walk[1])
if (__locationTemp[0]<0) or (__locationTemp[1]<0):
self.locInfo = "You can't move to there."
self.__currentLocation = self.__currentLocation
elif (__locationTemp[0]>map_.height-1) or (__locationTemp[1]>map_.width-1):
self.locInfo = "You can't move to there."
self.__currentLocation = self.__currentLocation
elif (map_.getMap(__locationTemp)==0):
self.locInfo = "There is no room."
self.__currentLocation = self.__currentLocation
else:
self.__currentLocation = __locationTemp
self.locInfo = "Move to cell"+str(self.__currentLocation)
pass
def locationInfo(self):
print(self.locInfo)
pass
def attack(self):
if self.__hand is None:
demageValue = int(self.__Fighting_skill/10)+6
else:
weaponInHand = self.__hand.type
demageValue = weaponInHand.shoot()
return demageValue
pass
def getItem(self,item_,bag,itemList):
isFull = bag.addItem(item_)
if isFull != True:
itemList.removeItem(self.__currentLocation)
print('Get',item_.Name)
else:
print('The {bag} is full.'.format(bag=bag.bagName))
pass
def useItem(self,item_,bag):
itemInHand = bag.popItem(item_)
if itemInHand is None:
print('No such thing in your bag.')
else:
print('use',itemInHand.type)
self.updataCharacterStatus(itemInHand)
pass
def useWeapon(self,weapon,weaponSlot):
isWeaponExist=False
for weapon_ in weaponSlot.bag_:
if weapon==weapon_.shortName:
self.__hand=weapon_
print('{weapon} is equiped'.format(weapon=weapon_.Name))
isWeaponExist=True
break
if isWeaponExist==False:
print('No such thing in your bag.')
pass
def reloadWeapon(self,bulletBag__):
if (self.__hand is None) or (self.__hand.type.isReloadable==False):
print('Unreloadable')
else:
weaponInHand = self.__hand.type
neededBullet = weaponInHand.magazine-weaponInHand.bullet
weaponInHand.reload(bulletBag__,neededBullet)
pass
def fist(self):
self.__hand = None
def discardItem(self,item_,bag):
disItem = bag.popItem(item_)
if disItem is None:
print('No such thing in your bag.')
else:
print('{item} has been discarded.'.format(item=disItem.Name))
disItem = None
pass
def discardWeaponInHand(self,discardWeapon):
if self.__hand is not None and self.__hand.shortName == discardWeapon:
self.__hand=None
pass
def updataCharacterStatus(self,item_):
self.__Health += item_.type.Health
if self.__Health>100:
self.__Health=100
self.__Defense += item_.type.Defense
self.__Speed += item_.type.Speed
self.__Shooting_skill += item_.type.Shooting_skill
self.__Fighting_skill += item_.type.Fighting_skill
def getLocation(self):
currentLocation = self.__currentLocation
return currentLocation
pass
pass