@hopebrooke/

pokemon game

Python

No description

fork
loading
Files
  • main.py
main.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
import random
import time
class pokemon():
  def __init__(self, myname, myattack, myelement):
    self.name = myname
    self.hp = 100
    self.attack = myattack
    self.element = myelement
  def getname(self):
    return(self.name)
  def gethp(self):
    return(self.hp)
  def sethp(self,newhp):
    self.hp = newhp
  def getattack(self):
    return(self.attack)
  def getelement(self):
    return(self.element)

  def attackopponent(self, opponent):
    attack2 = random.choice(attack1)
    print(self.name, "used", attack2.getname(), "attack on ", opponent.getname())
    opponent.receievehit(attack2.getdamage(),self)
  def receievehit(self, damage, opponent):
    self.sethp(self.hp - damage)
    if self.hp <= 0:
      print(self.name, "died :( \n")
    else:
      print(self.name, "says: ouch!, new hp:", self.hp, "\n")

class attacker(): 
  def __init__ (self, myname, mydamage):
    self.name = myname
    self.damage = mydamage
  def getdamage(self):
    return(self.damage)
  def getname(self):
    return(self.name)

p1 = pokemon("pikachu", "electric", "lightning")
p2 = pokemon ("snorlax", "normal", "eat")
attack1 = [attacker("lightning", 30), attacker("eat", 10), attacker("splash", 7)]


print("initisialising game \n")
time.sleep(2)
print("Player1 you are:", p1.getname())
time.sleep(2)
print("player2 you are:", p2.getname())
time.sleep(2)
print()
print("Let the battle commence! ", p1.getname(), "vs.", p2.getname())
time.sleep(1)
for i in range (3):
  print(3-i)
  time.sleep(1)
print("FIGHT! \n")
while p1.gethp() > 0 and p2.gethp()>0:
  time.sleep(2)
  p1.attackopponent(p2)
  if p2.gethp()>0:
    time.sleep(2)
    p2.attackopponent(p1)
if p1.gethp() <= 0:
  print("Player 2 wins! well done: ", p2.getname())
else:
  print("Player 1 wins! well done: ", p1.getname())