kasim01 发表于 2018-1-21 18:45:56

37课后作业的小游戏编程

本帖最后由 kasim01 于 2018-1-21 18:49 编辑

自己重新写了一下,感觉和标准答案还是不太一样的。。。


**** Hidden Message *****
      
   



h20060304 发表于 2018-1-22 02:32:29

为什么还隐藏代码呢

yingxiongtao 发表于 2018-1-23 09:36:41

大家都好厉害,作品区是一个交流学习的好地方,向你们学习{:5_105:}

brucewen007 发表于 2018-1-23 10:27:16

{:5_91:}

子非吾 发表于 2018-1-23 10:47:18

观摩

清歌终南 发表于 2018-1-27 16:05:36


大家都好厉害,作品区是一个交流学习的好地方,向你们学习

昔日少年郎 发表于 2018-1-28 06:01:45

考虑考虑看看

愤怒的蜗牛 发表于 2018-2-24 22:21:27

666

Sert_My 发表于 2018-3-1 10:32:22

77777777777777666666666666

LC_ilmlp 发表于 2018-4-19 23:58:23

看看

参商 发表于 2018-4-20 01:33:04

。666

fdk少东家 发表于 2018-4-23 21:56:33

132

猥琐哥哥 发表于 2018-4-24 17:04:28

11

z1446773686 发表于 2018-4-25 14:01:54

学习

张子铭 发表于 2018-4-25 15:11:28

瞅瞅

幽梦三影 发表于 2018-6-3 13:19:12

import random
class tortoise:
    def __init__(self):
      self.HP = 100
      self.x = random.randint(0,10)
      self.y = random.randint(0,10)
      self.a = random.randint(-2,2)
      self.b = random.randint(-2,2)
    def move(self):         
      self.a = random.randint(-2,2)
      self.b = random.randint(-2,2)
      if abs(self.a) + abs(self.b) <= 2 and 0 <= self.a + self.x <= 10 and 0 <= self.b + self.y <= 10 and self.HP > 0:         
            self.x += self.a
            self.y += self.b
            self.HP -= 1
      return (self.x,self.y)
    def eat(self):
      self.HP += 10
      if self.HP > 100:
            self.HP = 100
class fish:
    def __init__(self):      
      self.x = random.randint(0,10)
      self.y = random.randint(0,10)
      self.a = random.randint(-2,2)
      self.b = random.randint(-2,2)
    def move(self):         
      self.a = random.randint(-2,2)
      self.b = random.randint(-2,2)
      if abs(self.a) + abs(self.b) == 1 and 0 <= self.a + self.x <= 10 and 0 <= self.b + self.y <= 10:
            self.x += self.a
            self.y += self.b
      return (self.x,self.y)
                        
t = tortoise()
flist = []
for i in range(10):
    f = fish()
    flist.append(f)
while 1:
    if not t.HP:
      print("乌龟血槽空了")
      break      
    pos = t.move()
    for each in flist:   
      if each.move() == pos:
            t.eat()
            deadf = flist.pop()
            print(deadf,"被吃掉了")
    if flist == []:
      print("鱼被吃光了")
      break

jilm9446 发表于 2018-6-3 16:48:29

观摩学习

R.Westbrook 发表于 2018-6-6 19:25:01

好厉害

yajunyoou@gmail 发表于 2018-6-7 00:24:20

好厉害                  

yajunyoou@gmail 发表于 2018-6-7 00:24:56

好厉害
页: [1] 2 3 4 5
查看完整版本: 37课后作业的小游戏编程