鱼C论坛

 找回密码
 立即注册
查看: 4624|回复: 1

如何实现调用一次move()函数移动一个位置,如第一次移动X一个位置,第二次移动Y....

[复制链接]
发表于 2020-12-14 21:44:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
class Fish:
    def __init__(self):
        self.x=r.randint(0,10)
        self.y=r.randint(0,10)
    def move(self):
        print("我的初始位置是:",self.x,self.y)
        while(self.x>0 and self.y>0):
            count=0
            if count%2==0:
                self.x-=1
                print("我的位置是:",self.x,self.y)
                break
            else:
                self.y-=1
                print("我的位置是:",self.x,self.y)
                break
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-12-15 06:53:45 | 显示全部楼层
不知道这样满足不满足你的需求
  1. class Fish:
  2.     def __init__(self):
  3.         self.x=r.randint(0,10)
  4.         self.y=r.randint(0,10)
  5.     def move(self):
  6.         print("我的初始位置是:",self.x,self.y)
  7.         while(self.x>0 and self.y>0):
  8.             count=0
  9.             if count%2==0:
  10.                 self.x-=1
  11.                 print("我的位置是:",self.x,self.y)
  12.             else:
  13.                 self.y-=1
  14.                 print("我的位置是:",self.x,self.y)
  15.             count += 1 #如果想随机的话调用随机函数就行
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-15 17:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表