-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hero.hs
134 lines (108 loc) · 3.8 KB
/
Hero.hs
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
module Hero
( Hero(..)
, Weapon(..)
, Armor(..)
, Shoe(..)
, deductHealth
, setHealth
, changeWeapon
, changeArmor
, changeShoes
, heroIsDead
, totalAttackPower
, totalHealthPoints
, totalSpeed
, totalDefense
, displayInfoHero
, displayInfoEquipment
) where
import Armor
import Shoes
import Weapons
data Hero = Hero
{ baseHealthPoints :: Int
, baseAttackPower :: Int
, baseSpeed :: Int
, baseDefense :: Int
, currentWeapon :: Weapon
, currentArmor :: Armor
, currentShoes :: Shoe
} deriving (Show, Eq)
-- Function to calculate total attack power of the hero
totalAttackPower :: Hero -> Int
totalAttackPower hero =
baseAttackPower hero
+ weaponDamage (currentWeapon hero)
+ armorAttackBonus (currentArmor hero)
+ shoeAttackBonus (currentShoes hero)
-- Function to calculate total health points of the hero
totalHealthPoints :: Hero -> Int
totalHealthPoints hero =
baseHealthPoints hero
+ armorHealthBonus (currentArmor hero)
+ shoeHealthBonus (currentShoes hero)
-- Function to calculate total speed of the hero
totalSpeed :: Hero -> Int
totalSpeed hero = baseSpeed hero + shoeSpeed (currentShoes hero)
-- Function to calculate total defense of the hero
totalDefense :: Hero -> Int
totalDefense hero =
baseDefense hero
+ armorDefense (currentArmor hero)
+ shoeDefense (currentShoes hero)
-- Function to deduct health from the hero
deductHealth :: Hero -> Int -> Hero
deductHealth hero deduction =
hero {baseHealthPoints = (baseHealthPoints hero) - deduction}
-- Function to add health to the hero, if the player wins the battle
setHealth :: Hero -> Int -> Hero
setHealth hero newHealth = hero {baseHealthPoints = newHealth}
-- Function to change the hero's weapon
changeWeapon :: Hero -> Weapon -> Hero
changeWeapon hero newWeapon = hero {currentWeapon = newWeapon}
-- Function to change the hero's armor
changeArmor :: Hero -> Armor -> Hero
changeArmor hero newArmor = hero {currentArmor = newArmor}
-- Function to change the hero's shoes
changeShoes :: Hero -> Shoe -> Hero
changeShoes hero newShoes = hero {currentShoes = newShoes}
-- Function to check if the hero is dead
heroIsDead :: Hero -> Bool
heroIsDead hero = (totalHealthPoints hero) <= 0
--------------------------------------------------------------------
-- Display information about the hero
--------------------------------------------------------------------
displayInfoHero :: Hero -> IO ()
displayInfoHero hero = do
putStrLn "------------------------- Hero Stats -------------------------"
putStrLn
$ "Attack Power: "
++ show (totalAttackPower hero)
++ ", Health Points: "
++ show (totalHealthPoints hero)
++ ", Speed: "
++ show (totalSpeed hero)
++ ", Defense: "
++ show (totalDefense hero)
displayInfoWeapon (currentWeapon hero)
displayInfoArmor (currentArmor hero)
displayInfoShoe (currentShoes hero)
putStrLn "--------------------------------------------------------------"
--------------------------------------------------------------------
-- Display information about the equipment
--------------------------------------------------------------------
displayInfoEquipment :: Hero -> IO ()
displayInfoEquipment hero = do
putStrLn "------------------------- Hero Equipment -------------------------"
putStrLn
$ "Weapon: "
++ weaponName (currentWeapon hero)
++ ", Armor: "
++ armorName (currentArmor hero)
++ ", Shoes: "
++ shoeName (currentShoes hero)
-- Call the functions to display the information of the weapon, armor, and shoes
displayInfoWeapon (currentWeapon hero)
displayInfoArmor (currentArmor hero)
displayInfoShoe (currentShoes hero)
putStrLn "------------------------------------------------------------------"