Este Juego, escrito como un script en Python, te va haciendo una serie de preguntas y tienes que elegir la respuesta correcta para que aparezca la siguiente pregunta.

En teoria vas ganando puntos, esa parte aun está en desarrollo, sin embargo el juego funciona si eliges las respuestas corectas. Si te equivocas termina.

Vamos por partes,

  • primero llamo al directorio donde tengo, en mi sistema Python,
  • empiezo a definir las clases Robots, Humans y main.

En main esta el grueso del programa pero debemos de definir las variables antes para poder invocarlas en el main:

!/usr/bin/python3
class Robots:
def init(self):
pass
def WalkLikeARobot(self, WalkingStyle):
self.WalkingStyle = WalkingStyle
return self.WalkingStyle
def CareLikeARobot(self):
print("takes care like a robot.")
class Humans:
def __init__(self, nature = "good"):
    self.nature = nature
def GoodHumanBeing(self):
    print("need not repeat, a good human beung is always", self.nature)
def BadHumanBeing(self):
    self.nature = ("need not repeat, a bad human being is always", self.nature) 
    print(self.nature)
def WalkLikeARobot(self, WalkingStyle):
    self.WalkingStyle = WalkingStyle
    return self.WalkingStyle      
def main():

Una vez definidas las variables entro en el «main», tengo que asignar valores a las variables que irán cambiando de valor según se vaya ejecutando el programa.

def main():
robu = Robots()
# robu.CareLikeARobot()
# print (robu.WalkLikeARobot("A robot walks like a robot and nothing hapends."))
GoodMan = Humans()
# print (GoodMan.nature)
# GoodMan.GoodHumanBeing()
BadMan = Humans()
# BadMan.nature = "bad"
# pint(BadMan.nature)
# BadMan.BadHumanBeing()
# print (BadMan.WalkLikeARobot("he is human but walks like a robot"))
# when a bad man walks like a robot many things happen
WhenABadManWalksLikeARobot = BadMan.WalkLikeARobot(dict(change = 'he becomes a monster inside',
act = 'he kills fellow people' ,
feel = 'he enjoys torturing animals',
care = 'he cares for none',
look = 'he looks a normal human being',
state = 'finally he destroys himself:'))
# there are lot of actions that take place

A continuacion empiezo con el bucle con if, else, en este programa las opciones que están en el if funcionan pero debe de haber algún fallo en los else ya que no los coge. Esto se revisará en posteriores mejoras del código. Le indico que tiene que sacar por pantalla con print

print = ("What happends when a Bad Man walks like a Robot?")
change = input("Tell us what kind of change may take place inside him?\n Choose between 'monster' and 'angel'," "and type here …>>>>")
WhenABadManWalksLikeARobot['change'] = change
reward = 0
if change == 'monster':
        reward = 1000
        print = ("You have won ", reward, "points.")
        print = ("What does he do? :", WhenABadManWalksLikeARobot['act'])    
        change = input("Now tell us what the monster feels inside while killing people?\n Choose between 'great' and 'sad',"
            "and type here....>>>>")
        WhenABadManWalksLikeARobot['change'] == change
        if change == 'great':
            print = ("You have won the second round:")
            reward = 10000
            print = ("You have won ", reward, "points.")
            pint = ("What he feels inside? :", WhenABadManWalksLikeARobot
            ['feel'])
            change = input("Tell us does the monster care for anyone?\n Choose between 'yes' and 'no',"
                "and type here...>>>>")
            WhenABadManWalksLikeARobot['change'] == change
            if change == 'no':
                print = ("You have won the third round:")
                reward = 100000
                print = ("You have won ", reward, "points.")
                print = ("What he feels inside= :", WhenABadManWalksLikeARobot
                ['care'])
                change = input("Tell us does the monster look like a normal human being?\n Choose between 'yes' and 'no',"
                    "and type here...>>>>")
                WhenABadManWalksLikeARobot['change'] = change
                if change == 'yes':
                    print = ("You have won the fourth round:")
                    reward = 1000000
                    print = ("You have won ", reward, "points.")
                    print = ("What does he look like? :", WhenABadManWalksLikeARobot['look'])
                    change = input("Tell us what happends to the monster finally? Does he destroy himself\n Choose between 'yes' and 'no',"
                        "and type here...>>>>")
                    WhenABadManWalksLikeARobot['change'] = change
                    if change == 'yes ':
                        print = ("You have won Jackpot.", reward, "points.")
                        reward = 10000000
                    else:
                        print = ("You have change the course of game. It ends here. You Lost", reward - 100000, "points.")
                else:
                    print = ("You have change the course of game. It ends here. You lost", reward - 1000, "points.")
            else:
                print = ("You have changed the course of game. It ends here. You lost", reward - 100, "pints.")
        else:
            print = ("You have changed the course of the game. It ends here. You have lost", reward - 10, "points.")
    else:
        print = ("You have changed the course of game. It ends here and you have won no point.")

Para cerrar es sumamente importante cerrar el «main» con las siguientes líneas, si no se usa la indentación adecuada, no funcionará.

if name == "main":
main()

Finalmente el programa queda así

!/usr/bin/python3
class Robots:
def init(self):
pass
def WalkLikeARobot(self, WalkingStyle):
self.WalkingStyle = WalkingStyle
return self.WalkingStyle
def CareLikeARobot(self):
print("takes care like a robot.")
class Humans:
def __init__(self, nature = "good"):
    self.nature = nature
def GoodHumanBeing(self):
    print("need not repeat, a good human beung is always", self.nature)
def BadHumanBeing(self):
    self.nature = ("need not repeat, a bad human being is always", self.nature) 
    print(self.nature)
def WalkLikeARobot(self, WalkingStyle):
    self.WalkingStyle = WalkingStyle
    return self.WalkingStyle      
def main():
robu = Robots()
# robu.CareLikeARobot()
# print (robu.WalkLikeARobot("A robot walks like a robot and nothing hapends."))
GoodMan = Humans()
# print (GoodMan.nature)
# GoodMan.GoodHumanBeing()
BadMan = Humans()
# BadMan.nature = "bad"
# pint(BadMan.nature)
# BadMan.BadHumanBeing()
# print (BadMan.WalkLikeARobot("he is human but walks like a robot"))
# when a bad man walks like a robot many things happen
WhenABadManWalksLikeARobot = BadMan.WalkLikeARobot(dict(change = 'he becomes a monster inside',
act = 'he kills fellow people' ,
feel = 'he enjoys torturing animals',
care = 'he cares for none',
look = 'he looks a normal human being',
state = 'finally he destroys himself:'))
# there are lot of actions that take place
print = ("What happends when a Bad Man walks like a Robot?")
change = input("Tell us what kind of change may take place inside him?\n Choose between 'monster' and 'angel'," "and type here …>>>>")
WhenABadManWalksLikeARobot['change'] = change
reward = 0
if change == 'monster':
        reward = 1000
        print = ("You have won ", reward, "points.")
        print = ("What does he do? :", WhenABadManWalksLikeARobot['act'])    
        change = input("Now tell us what the monster feels inside while killing people?\n Choose between 'great' and 'sad',"
            "and type here....>>>>")
        WhenABadManWalksLikeARobot['change'] == change
        if change == 'great':
            print = ("You have won the second round:")
            reward = 10000
            print = ("You have won ", reward, "points.")
            pint = ("What he feels inside? :", WhenABadManWalksLikeARobot
            ['feel'])
            change = input("Tell us does the monster care for anyone?\n Choose between 'yes' and 'no',"
                "and type here...>>>>")
            WhenABadManWalksLikeARobot['change'] == change
            if change == 'no':
                print = ("You have won the third round:")
                reward = 100000
                print = ("You have won ", reward, "points.")
                print = ("What he feels inside= :", WhenABadManWalksLikeARobot
                ['care'])
                change = input("Tell us does the monster look like a normal human being?\n Choose between 'yes' and 'no',"
                    "and type here...>>>>")
                WhenABadManWalksLikeARobot['change'] = change
                if change == 'yes':
                    print = ("You have won the fourth round:")
                    reward = 1000000
                    print = ("You have won ", reward, "points.")
                    print = ("What does he look like? :", WhenABadManWalksLikeARobot['look'])
                    change = input("Tell us what happends to the monster finally? Does he destroy himself\n Choose between 'yes' and 'no',"
                        "and type here...>>>>")
                    WhenABadManWalksLikeARobot['change'] = change
                    if change == 'yes ':
                        print = ("You have won Jackpot.", reward, "points.")
                        reward = 10000000
                    else:
                        print = ("You have change the course of game. It ends here. You Lost", reward - 100000, "points.")
                else:
                    print = ("You have change the course of game. It ends here. You lost", reward - 1000, "points.")
            else:
                print = ("You have changed the course of game. It ends here. You lost", reward - 100, "pints.")
        else:
            print = ("You have changed the course of the game. It ends here. You have lost", reward - 10, "points.")
    else:
        print = ("You have changed the course of game. It ends here and you have won no point.")            
if name == "main":
main()

Es muy importante guardar el script con extension .py y darle permisos de ejecución.

sudo chmod 750 robot.py
./robot.py
h4nna@h4nnahack:~/python$ ./robot.py
Tell us what kind of change may take place inside him?
Choose between 'monster' and 'angel',and type here …>>>>monster
Now tell us what the monster feels inside while killing people?
Choose between 'great' and 'sad',and type here….>>>>
Categorías: Python

0 comentarios

Deja una respuesta

Marcador de posición del avatar