2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python初心者がエナジードリンクあるあるをコード化してみた

Posted at

エナジードリンクは体への負担が大きいという事を伝えたい…
それだけのためにお題にしました。(クラスと呼び出しをファイル分けて書いていないのは許してください)

import sys

class Monena:
    def __init__(self):
        self.physical = 50
        self.mental = 50
        self.destruction = False
        self.physical_recovery = 0
        self.mental_recovery = 0


    def status_check(self):
        print('体力は' + str(self.physical))
        print('気力は' + str(self.mental))

        if self.physical < 0 or self.mental < 0:
            self.destruction = True
            print('アウトー!!!')
            sys.exit()

    def work(self, physical_damage, mental_damage):
        print('さあ今日も仕事するか…')
        self.physical = self.physical - physical_damage
        self.mental = self.mental - mental_damage
        self.physical_recovery = physical_damage
        self.mental_recovery = mental_damage

        if self.physical + self.mental < 50:
            self.monena()

        print('ようやく仕事終わった…')
        self.status_check()
        self.sleep()


    def monena(self):
        boost = 100 - (self.physical + self.mental)
        self.mental = self.mental + boost
        self.physical_recovery = self.physical_recovery - int(boost / 2)
        self.mental_recovery = self.mental_recovery - int(boost / 2)

        print('ヒャッハー!')
        self.status_check()


    def sleep(self):
        print('疲れた…寝よう…')

        if self.physical + self.physical_recovery > 50:
            self.physical = 50
        else:
            self.physical = self.physical + self.physical_recovery

        if self.mental + self.mental_recovery > 50:
            self.mental = 50
        else:
            self.mental = self.mental + self.mental_recovery

        self.get_up()


    def get_up(self):
        print('おはよう…もう朝か…')
        self.status_check()


monena = Monena()
monena.work(20, 20)
monena.work(30, 30)
monena.work(20, 20)
monena.work(30, 30)
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?