HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonMinor

Pokemon-style text battle game

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
battletextstylegamepokemon

Problem

I took a crack at making a Pokemon-style text battle game in Python 3 to practice object-oriented programming a bit, inspired this project on Reddit, but I did not follow every instruction.

```
import random

Type_Monster=['ice','fire','grass']

Possible_Monster_name=['Mulu','Lume','Manda','Bomna','Kasa','Kama','Mutswe','Mako','Kela','Mate','Kasa','Mula','Matu','Kachi','Moba','Kala','Koleo','Meba','Mufo','Ilis','Sila','Sidab','Nannu','Sili','Lili','Ayabil','Meta','Nanna','Anum', 'Trump', 'Bot', 'Nevergonnagiveyouup','Bernie', "Hilliary", 'life', 'Baka', 'Kald','Aston','Óinthu','Roo','Wolftrarg', 'Stark','Bojack','Rick','Ci','Yourmom','Sartre','Nean','Xōtez','Tōxo','Darkmelswannan','Lannister','Greyjoy','Littlefinger','Spider','San','Lala','What','Sorry']

class Monsters:
'class for monsters that fight the player'
def __init__(self,name,health,types,defense,offense,quickness):
'''initalizes the health, types, defense point, offense point and quickness point.'''
Monsters.name=name
Monsters.health=health
Monsters.types=types
Monsters.defense=defense
Monsters.offense=offense
Monsters.quickness=quickness

class Player:
def __init__(self,name,health,types,defense,offense,quickness,experience=0):
'''initilzies the health, types, defense point, offense point and quickness point.'''
Player.name=name
Player.health=health
Player.types=types
Player.defense=defense
Player.offense=offense
Player.quickness=quickness
self.experience=experience
def eat(self,food):
''''method that will be called if the player eats something. The player can either eat good potion or suicide pill'''
if (food=='good_potion'):
self.health=self.health+10
if (food=='suicide_pill'):
self.health=self.health-10

class Skills:
'''class on skills, which consist of strong attacks, weak attacks, and heals'''
def __init__(self,strong_attack_name,weak_attack_name,heal_name):
'''this function lets the player initli

Solution

The class Monstersonly stores data, so a namedtuple would be a better alternative:

from collections import namedtuple
Monster = namedtuple("Monster", "name health types defense offense quickness")

monster = Monster("a", 100, "b", 100, 100, 100)


The dodge-method of your Skill class can be simplified a lot:

def dodge(self, quickness):
  if quickness  10 and quickness <= 20:
    return random.choice([1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]) == 1
  ...


It seems that human_turn is always equal to not computer_turn. You can drop computer_turn and alter your loop conditions to:

while not human_turn:
  ...
while human_turn:
  ...


As long as a function only return booleans you don't need to compare its return value to True:

if Skills.dodge(Monster, Monster.quickness):


does the same as your:

if Skills.dodge(Monster,Monster.quickness)==True:


The two conditions if potion=='suicide_pill': and if potion=='good_potion': do actually the same. You can combine them to:

names.eat(potion)
print ("{} picked {}! {} now has {} health left.".format(names.name,  potion, names.name, names.health))
human_skill = None
computer_turn = True
human_turn = False
break

Code Snippets

from collections import namedtuple
Monster = namedtuple("Monster", "name health types defense offense quickness")

monster = Monster("a", 100, "b", 100, 100, 100)
def dodge(self, quickness):
  if quickness <= 10:
    return random.choice([1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1
  if quickness > 10 and quickness <= 20:
    return random.choice([1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]) == 1
  ...
while not human_turn:
  ...
while human_turn:
  ...
if Skills.dodge(Monster, Monster.quickness):
if Skills.dodge(Monster,Monster.quickness)==True:

Context

StackExchange Code Review Q#154627, answer score: 6

Revisions (0)

No revisions yet.