Python作业水桶小游戏

编写Python程序,实现一个小游戏。 共有三个水桶,容量分别是8升、5升和3升,玩家可对每个水桶做如下操作: 按F或(f)键注满一个桶 按E或(e)键清空一个桶 按P或(p)键从一个桶向另一个桶倒水 按Q或(q)键退出游戏 当玩家使得任意一个水桶的水量是4升时,则玩家获胜,程序显示玩家操作的总步数并停止游戏。

# -*- coding: utf-8 -*-

class Bucket:
    def __init__(self,volume):
        self.volume = volume
        self.now_v = 0

    def Full_Bucket(self):
        self.now_v = self.volume

    def Purge_Bucket(self):
        self.now_v = 0

    def Pour(self,other_Bucket):
        other_Bucket.now_v += self.now_v
        if other_Bucket.now_v > other_Bucket.volume:
            self.now_v = other_Bucket.now_v - other_Bucket.volume
            other_Bucket.now_v = other_Bucket.volume
        else:
            self.now_v = 0

def print_h(v1,now_v1,v2,now_v2,v3,now_v3):
    for i in range(1,v1+1):
        print("    "+str(v1+1 - i)+"|",end = "")
        for j in range(1,5):
            if v1+1-i > now_v1:
                print(" ",end = "")
            else:
                print("W",end = "")
        print("|",end = "")
        print("     ",end = "")

        if v1+1-i>v2:
            print(" ",end = "")
        else:
            print(str(v1+1 - i)+"|",end = "")
        for j in range(1,5):
            if v1+1-i > now_v2:
                print(" ",end = "")
            else:
                print("W",end = "")
        if v1+1-i>v2:
            print(" ",end = "")
        else:
            print("|",end = "")

        print("     ",end = "")
        if v
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值