The hunter game (part 1)

17 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.96
List Price:  €92.81
You save:  €27.84
£55.77
List Price:  £79.68
You save:  £23.90
CA$95.68
List Price:  CA$136.70
You save:  CA$41.01
A$106.02
List Price:  A$151.47
You save:  A$45.44
S$94.41
List Price:  S$134.88
You save:  S$40.47
HK$546.80
List Price:  HK$781.18
You save:  HK$234.37
CHF 63.34
List Price:  CHF 90.49
You save:  CHF 27.15
NOK kr761.11
List Price:  NOK kr1,087.35
You save:  NOK kr326.23
DKK kr485.02
List Price:  DKK kr692.92
You save:  DKK kr207.89
NZ$116.42
List Price:  NZ$166.33
You save:  NZ$49.90
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,660.01
List Price:  ৳10,943.35
You save:  ৳3,283.33
₹5,835.78
List Price:  ₹8,337.18
You save:  ₹2,501.40
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,416.31
List Price:  ₨27,738.77
You save:  ₨8,322.46
฿2,572.74
List Price:  ฿3,675.50
You save:  ฿1,102.76
₺2,264.43
List Price:  ₺3,235.04
You save:  ₺970.61
B$356.70
List Price:  B$509.60
You save:  B$152.89
R1,295.44
List Price:  R1,850.72
You save:  R555.27
Лв127.05
List Price:  Лв181.51
You save:  Лв54.46
₩94,909.58
List Price:  ₩135,590.93
You save:  ₩40,681.35
₪259.50
List Price:  ₪370.74
You save:  ₪111.23
₱3,993.87
List Price:  ₱5,705.78
You save:  ₱1,711.90
¥10,712.31
List Price:  ¥15,303.96
You save:  ¥4,591.65
MX$1,187.89
List Price:  MX$1,697.07
You save:  MX$509.17
QR254.57
List Price:  QR363.69
You save:  QR109.12
P950.82
List Price:  P1,358.38
You save:  P407.55
KSh9,247.76
List Price:  KSh13,211.65
You save:  KSh3,963.89
E£3,352.12
List Price:  E£4,788.95
You save:  E£1,436.83
ብር4,006.43
List Price:  ብር5,723.72
You save:  ብር1,717.28
Kz58,511.64
List Price:  Kz83,591.64
You save:  Kz25,080
CLP$65,950.47
List Price:  CLP$94,219
You save:  CLP$28,268.52
CN¥506.53
List Price:  CN¥723.64
You save:  CN¥217.11
RD$4,055.76
List Price:  RD$5,794.19
You save:  RD$1,738.43
DA9,420.16
List Price:  DA13,457.95
You save:  DA4,037.79
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.52
List Price:  Q775.06
You save:  Q232.54
GY$14,601.52
List Price:  GY$20,860.22
You save:  GY$6,258.69
ISK kr9,764.23
List Price:  ISK kr13,949.49
You save:  ISK kr4,185.26
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,236.34
List Price:  L1,766.28
You save:  L529.93
ден3,998.59
List Price:  ден5,712.52
You save:  ден1,713.92
MOP$561.77
List Price:  MOP$802.57
You save:  MOP$240.79
N$1,291.99
List Price:  N$1,845.78
You save:  N$553.78
C$2,569.36
List Price:  C$3,670.67
You save:  C$1,101.31
रु9,319.09
List Price:  रु13,313.56
You save:  रु3,994.46
S/260.54
List Price:  S/372.22
You save:  S/111.67
K269.79
List Price:  K385.44
You save:  K115.64
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,882.68
List Price:  ZK2,689.66
You save:  ZK806.98
L323.40
List Price:  L462.03
You save:  L138.62
Kč1,628.77
List Price:  Kč2,326.92
You save:  Kč698.14
Ft25,305.79
List Price:  Ft36,152.68
You save:  Ft10,846.88
SEK kr755.02
List Price:  SEK kr1,078.64
You save:  SEK kr323.62
ARS$61,468.17
List Price:  ARS$87,815.44
You save:  ARS$26,347.26
Bs483.33
List Price:  Bs690.51
You save:  Bs207.17
COP$271,845.87
List Price:  COP$388,367.89
You save:  COP$116,522.02
₡35,672.25
List Price:  ₡50,962.55
You save:  ₡15,290.29
L1,724.16
List Price:  L2,463.20
You save:  L739.03
₲522,510.75
List Price:  ₲746,475.93
You save:  ₲223,965.17
$U2,674.97
List Price:  $U3,821.56
You save:  $U1,146.58
zł281.37
List Price:  zł401.98
You save:  zł120.60
Already have an account? Log In

Transcript

Thank you for coming back to the course. In this lesson, we are going to talk about our final project, which is the hunter game. First we create a new Python file. We can save it in the desktop, whatever folder you want, and then we name it as witch hunter.py. And we save it. Now we have this Python file, we are going to type in our code here.

First, we import the random package. Then we also import the term package. Next, we are going to do the things that we have learned in our previous lesson, which is to define our parent class which and then inside that, we have to define our initialization function, which takes three parameter self Name and metal. After that, we assigned a passing parameter to the object variable name and level. Then we define an other function which is the representation function which takes only one parameter. The purpose of this function is to return the current status and value of this object.

So we are going to return a string which tell us the name and the level of the which we will use the format function here we've coded banquette and then we are going to define the attack function of the which we name it as witchcraft attack. This function is going to take only one parameter which is the object itself and it will return random number between one to 10. And then we're going to multiply this random number by the Navajo of the rich. After that, we are going to defy the subclass, which is called the fire which this fire which subclass is going to inherit from the parent class, which this card also has an initialization function, which takes four parameters is still the name, the level and one extra parameter called define staff. Inside this initialization function, the first step was is to call the super function.

The Super function is referring to the parent class. And then we will assign the remaining parameter first off to the object variable. After that, we will define the attack function of these five which object, we call it which calf attack. This function is going to call the rich class attack function from the parent class. Let's take a closer look. The super rich crowd craft attack is referring to the wish path attack function of the parent which costs which will then give us a random number times the level and then we will assign that to the base attack variable of this fire which object.

Dan, we track whether these five weeks has a fast stuff. Actually in Python, you can have a shorthand for checking whether wearable is true, we can just put the variable name here. If the variable equals to true, this if condition will be satisfied. And then we clean which graph is failing with fire. Because it is failing with fire, the base attack will be doubled. Otherwise, we just return the base attack ready.

Now, ness query a and our other sub costs which is called the evil witch evil wish. Also in heard from the parent caste which and it has its own individualization function which takes four parameters as well the self, the name, the level and this time it will take another extra parameter call back staff level. So, the concept is, if this evil which has a higher back staff level is sued have a more powerful attack. Similarly, we will also call the initialization function of the parent costs to assign a name and level and then we will assign the extra parameter brax top level to the object variable back staff level as well. After that is the attempt function defy the witchcraft attack. Which takes one parameter itself.

Similarly, we have to defy the base attack where do you will get the base attack? Where do you first from the parent class because for evil wish, you will always have the backstop so we don't have to check. We just need to pay now which cross with BRAC staff nevel the bank staff level is going to be multiply to the base attack and give out the attack where you so here we just had to tell people these people which have this certain backstop level, we will use the format function to pay now self taught prac staff level after debt, we return the actual asset value by multiplying Base attack by two and then further multiply that by the back staff level. And this past staff level later, we are going to pass in a value from one to three. And that is going to be multiply together.

All right, now we have all the classes defined, we will save our Python file, and then execute that in our shell. So we create a standard which object first. And then we assign the name rich with level one. After that, we double check what we have created. So we can see that we have a witch with nafa one. Next, we call the witchcraft attack function of the witch mec.

That we have an attack of six. Now let's instantiate a file which object. So we say the name of this file which object is fire which level is one. And we have to decide whether this fire which has a first off. So we assign a true value explicitly here to say we have a fire which we find off we check and find that the fire wish has been created. And then we trigger the wish crop attack function.

And we see that this Misha is failing with fire and attack value is 10. Now, let's create the evil witch object. we instantiate that with first the name evil witch and then a level of one. Now we are going to assign the best staff level to be free. Let's check. Okay, we have this evil witch being created.

That's called the witchcraft attack function. The witchcraft is with backstop level free. Because of this high backstop level, the attack is 54. After we have created free witches, we are going to define the hunter class. Go back to our Python file, we type in class Hunter. This hunter class will also have an initialization function which will also take three parameters Which is itself, the name and the level.

We will then repeat the same procedures to assign the name and Neto to the object where we are both. After the initialization function, we will define the attack function of the hunter class, this attack function will take in three parameters, one is itself and then the which object and then is an extra parameter to define whether this is a critical track, this critical show will either be true or false. After that, we will calculate the base damage by a random number between one to attend and multiply that with the level of The hunter after that, we will check whether this attack is a critical strike. If it is a critical strike we will say hundred damage because to the base damage double. If it is not a critical stripe, we will say 100 damage just equals to the face damage. Now in Python instead of waiting this long, if else Thema we can do a shorthand.

Here, we can use hunter damage equals to base damage times two if critical strike equals to true else we will say base damage. So, this statement here is saying that the hundred damage will be equals to base damage time to if critical strike equals true else hundred damage is equals to base damage this syntax here will perform exactly the same logic as the if else cause above. So, we really pay the if else cause we have this simple statement here. Next, we will say which damage equals to which thought which calf attack And we will bring you an attacked code banquette and we use the format function to display the hunter damage and we will also ping which attacked Cora banquette and use the format function to format the witch damage. Next, we want to tell people if this attack from the hunter is a critical strike.

So we will check whether it is a critical strike. And the way to do that is to define a critical strike message we assigned this variable To be banquette critical strike exclamation mark. If critical strike is true, of course, we can omit the equals to true syntax here else this message will be empty. So, what we are doing here is if critical strike is true, this critical strike message will be a string of critical strike. Otherwise, this message will be an empty string. And then in our ping function we add this critical strike message as the second parameter of the format function and it is going to replace the second quarterback After that we track if hunter damage is bigger than the witch damage.

If this is true, we will say you defeated occurred banquette and then the name off the witch and we will return true. Else we will pray now Cody banquette, when away and then we substitute the code of banquette with the name of the witch and then we return false now, this test Oh Hunter cross, we save this Python file. And then in our interactive shell, we instantiate the which object passing in the name, which and level one. And then we instantiate the hunter object passing in the name, Hunter and level one. Now, we ask the hunter to attack the witch. This attack function will take three parameters.

The first one itself will be the hunter. The second one will be the which object that we have just create. The last one is whether it is a critical Shrike. We assign that to true. Now let's see the result is that you attempt to And it is a critical stripe. However, the witch attack 10 the witch ran away and this function returns false.

Let's try it again. This time the hunter attack eight and it is also a critical strike the reach however, attack only for the hunter can defeat the which we have a true value. Now that's all about defining the cast. In our next lesson, we are going to complete our game. See you next time.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.