zoukankan      html  css  js  c++  java
  • python学习---模拟人生

    【软件说明& 注意事项】

    1、模拟人生(小孩买宠物)程序开发环境:
    OS:64位Windows 7
    IDE:pycharm4.0.4
    python版本:3.5.1 32位

    2、模拟人生(小孩买宠物)程序只做python学习使用,版权有作者所有,未经过作者本人同意,不得将此模拟人生(小孩买宠物)程序应用于商业用途。


    3、模拟人生(小孩买宠物)程序简述:

    1、程序模拟出2种角色,小孩与宠物。
    2、小孩的属性有初始化购买宠物的金额为1000元,初始幸福值为100
    3、小孩的方法有,摸宠物的头(宠物对应动作是咬你一口),摸宠物的尾巴(宠物对应的动作是摇尾巴),购买宠物等
    4、宠物的方法有,咬一口并且汪汪汪或者喵喵喵的叫,舔主人的手,摇尾巴三个方法
    5、宠物摇一次尾巴或者舔一次小孩的手,小孩的幸福值+20,宠物咬小孩一次,小孩的幸福值-30
    6、小孩最终幸福值>20时才会选择购买该宠物

    4、使用方法

    IDE环境或者linux下运行kids_and_pets.py

    流程图:

      1 __author__ = 'Bruce'
      2 '''-------模拟人生(小孩买宠物)--------'''
      3 class naughtykids():
      4     money = 1000
      5     happniess = 100
      6     def __init__(self,name):
      7         self.name = name
      8     def petswant(self,pet):
      9         print("%s:我来到宠物店,老板,我想要买一只%s " %(self.name,pet))
     10         self.pet = pet
     11     def touchpethead(self):
     12         print('%s:我摸一下它的头'%self.name)
     13     def touchpetail(self):
     14         print('%s:我摸一下它的尾巴'%self.name)
     15     def balance(self):
     16         self.money -= 400#宠物价格
     17         if self.happniess > 60:
     18             print('%s:太高兴了,我的宠物很喜欢我,我花了%s块就带它回家了'%(self.name,self.money))
     19         elif self.happniess < 0:
     20             print('%s:才不买你呢,讨厌的小家伙,哼哼....'%self.name)
     21         else:
     22             print('%s:小家伙还有点不喜欢我呢,哈哈哈,买回家好好调戏你'%self.name)
     23     def pain(self):#疼痛
     24         self.happniess-=30#被咬一次幸福值减30
     25         if self.happniess < 20:
     26             print("%s:每次都咬我,看来真不喜欢我,哼......"%self.name)
     27         elif self.happniess <40:
     28             print('%s:哦,它居然咬我,好疼,不开心...小兔崽子看我以后怎么收拾你'%self.name)
     29         else:
     30             print('%s:哈哈,小家伙居然会咬人,真是太喜欢了'%self.name)
     31     def happyfeel(self):
     32         self.happniess+=20#感到快乐一次幸福值加20
     33         print("%s:看起来它喜欢我"%self.name)
     34 
     35 class animal():
     36     def __init__(self,kind):
     37         self.kind = kind
     38     def wagtail(self,name='小宠物'):#摇尾巴
     39         print('%s:摇尾巴' %name)
     40     def bite(self,name):#咬人
     41         if self.kind == '小狗':
     42             print('%s:咬你一口,汪汪汪'%name)
     43         elif self.kind == '小猫':
     44             print('%s:咬你一口,喵喵喵'%name)
     45     def licking(self,name):#舔手
     46         print("%s:舔一下手" %name)
     47 
     48 def roleinit():#角色初始化,根据用户的选择初始化角色
     49     print('------宠物游戏------')
     50     rolelist = {'1':kids,'2':pets}
     51     while True:
     52         rolechoice=input('选择您的初始化游戏角色:
    --->1,小孩;
    --->2,宠物:').strip()
     53         if rolechoice in rolelist:
     54             return rolelist[rolechoice]()
     55         else:
     56             print("输入错误")
     57             continue
     58 def kids():
     59     name = input("请输入小盆友的名字:").strip()
     60     sexlist={'1':'男孩','2':'女孩'}
     61     while True:
     62         sex = input('请选择小盆友的性别:
    --->1,男孩;
    --->2,女孩:').strip()
     63         role = 'kids'
     64         if sex in sexlist:
     65             return name,sexlist[sex],role
     66         else:
     67             print("输入错误")
     68             continue
     69 def pets():
     70     kindslist={'1':'小狗','2':'小猫'}
     71     name = input("请输入宠物的名字:").strip()
     72     while True:
     73         kind = input("请输入宠物的种类:
    --->1,小狗;
    --->2,小猫:").strip()
     74         role='pets'
     75         if kind in kindslist:
     76             return name,kindslist[kind],role
     77         else:
     78             print("输入错误")
     79             continue
     80 
     81 def main_game(kidsname,kidsex,petskind,action=None,petname='小宠物'):#交互过程
     82     if action == 'touchpetail':#摸摸尾巴
     83         gamekids.touchpetail()
     84         gamepets.wagtail(petname)
     85         gamekids.happyfeel()
     86     elif action == 'touchpethead':#摸摸头
     87         gamekids.touchpethead()
     88         gamepets.bite(petname)#宠物咬了我一口
     89         gamekids.pain()
     90     elif action == 'licking':#舔手
     91         gamepets.licking(petname)
     92         gamekids.happyfeel()
     93         # gamekids.balance()
     94     elif action == 'wagtail':#摇尾巴
     95         gamepets.wagtail(petname)
     96         gamekids.happyfeel()
     97         gamekids.touchpetail()
     98     elif action == 'bite':
     99         gamepets.bite(petname)
    100         gamekids.pain()
    101 
    102 if __name__ == '__main__':
    103     res_select1,res_select2,role =roleinit()#名字,性别/种类,角色
    104     print('------游戏开始------')
    105     if role =='kids':
    106         print("%s:哈喽, 我叫%s, 我是一个%s,接下来就是我的故事..."%(res_select1,res_select1,res_select2))
    107         print('%s:今天我的心情非常好,我想去宠物店买一只宠物'%res_select1)
    108         rolelist = {'1':'小狗','2':'小猫'}
    109         pet = input("%s:我来到宠物店,我要买:
    --->1,小狗;
    --->2,小猫:"%res_select1).strip()
    110         gamekids = naughtykids(res_select1)#实例化小盆友
    111         gamepets = animal(rolelist[pet])#实例化小宠物
    112         while True:
    113             actionlist ={"1":'touchpethead','2':'touchpetail'}
    114             kidsaction = input("%s:%s真可爱,我要调戏一下它:
    --->1,摸摸头;
    --->2,摸摸尾巴:"%(res_select1,rolelist[pet])).strip()
    115             print("--------调戏现场--------")
    116             main_game(res_select1,res_select2,rolelist[pet],action=actionlist[kidsaction],petname='小宠物')#
    117             print("--------调戏现场--------")
    118             print('%s的幸福值:%s'%(res_select1,gamekids.happniess))
    119             continue_ornot = input("继续调戏Y/N:").strip().lower()
    120             if continue_ornot == 'y':
    121                 pass
    122             else:
    123                 break
    124         if gamekids.happniess > 20:#幸福值大于20都会去买
    125             gamekids.balance()#购买了宠物
    126         else:
    127             print("哼...讨厌你这只%s"%rolelist[pet])
    128         print("------游戏开始------")
    129 
    130     elif role == 'pets':
    131         print("%s:哈喽, 我叫%s, 我是一个%s,原本没有我什么故事的..."%(res_select1,res_select1,res_select2))
    132         print('%s:只是想安静的晒晒太阳,突然来了个小盆友,貌似注意到了我'%res_select1)
    133         kidslist = {'1':'小男孩','2':'小女孩'}
    134         kids = input("小盆友是男孩还是女孩:
    --->1,男孩;
    --->2,女孩:").strip()
    135         kidsname = input("小主人的名字叫:").strip()
    136         gamekids = naughtykids(kidsname)#实例化小盆友
    137         gamepets = animal(res_select2)#实例化小宠物
    138         while True:
    139             actionlist ={"1":'licking','2':'wagtail','3':'bite'}
    140             kidsaction = input("%s:愚蠢的人类,我要反调戏一下你:
    --->1,舔一下手;
    --->2,摇摇尾巴;
    --->3,咬一口:"%res_select1).strip()
    141             print("--------调戏现场--------")
    142             main_game(kidsname,kidslist[kids],res_select2,action=actionlist[kidsaction],petname=res_select1)
    143             print("--------调戏现场--------")
    144             print('%s的幸福值:%s'%(kidsname,gamekids.happniess))
    145             continue_ornot = input("继续调戏Y/N:").strip().lower()
    146             if continue_ornot == 'y':
    147                 pass
    148             else:
    149                 break
    150         if gamekids.happniess > 20:#幸福值大于20都会去买
    151             gamekids.balance()#购买了宠物
    152         else:
    153             print("哼...讨厌你这只%s"%res_select2)
    154         print("------游戏开始------")
    View Code
  • 相关阅读:
    Docker部署Tomcat
    Docker部署MySQL
    kettle 共享数据库连接(解决每次都需要创建数据库连接问题)
    Kettle8.2的安装与使用
    Kettle 使用JS脚本 增加UUID输出列
    kettle使用(mysql导入MongoDB)
    Eclipse从Git上下载代码
    Eclipse中使用git
    在windows下安装git中文版客户端并连接gitlab
    eclipse中git的安装、配置和使用
  • 原文地址:https://www.cnblogs.com/mzpy1119/p/5244947.html
Copyright © 2011-2022 走看看