Kithgard地牢
注意:在调用函数时,要在函数的后面加上括号内容,不然在python中,将不会认为你在调用这个函数内容,而你的英雄将像木头同样站在原地不会执行上左下右的移动!!!python
hero.moveRight()
hero.moveDown()
hero.moveRight()
1
2
3
深藏的宝石
hero.moveRight()
hero.moveDown()
hero.moveUp()
hero.moveUp()
hero.moveRight()
1
2
3
4
5
内容讲解:咱们能够给这个方法去传递相应的参数,例如以下的代码内容,咱们给予参数2,这时代码会识别让你的英雄移动2步,而再也不是1步了。函数
在使用方法相同内容时,咱们能够合并方法内容示例能够合并为以下:it
hero.moveRight()
hero.moveDown()
hero.moveUp(2)
hero.moveRight()
1
2
3
4
幽影守卫
hero.moveRight()
hero.moveUp()
hero.moveRight()
hero.moveDown()
hero.moveRight()
1
2
3
4
5
健忘的宝石匠
当代码不超过9条会有额外的奖励方法
hero.moveRight()
hero.moveDown()
hero.moveRight()
hero.moveRight()
hero.moveUp()
hero.moveRight()
1
2
3
4
5
6
按照咱们上面讲的合并也可写成新手
hero.moveRight()
hero.moveDown()
hero.moveRight(2)
hero.moveUp()
hero.moveRight()
1
2
3
4
5
真实姓名
hero.moveRight()
hero.attack("Brak")
hero.attack("Brak")
hero.moveRight()
hero.attack("Treg")
hero.attack("Treg")
1
2
3
4
5
6
不详的征兆
hero.moveRight()
hero.moveRight()
hero.moveUp()
hero.moveRight()
hero.moveRight()
hero.moveRight()
hero.moveDown()
hero.moveRight()
hero.moveDown()
hero.moveRight()
1
2
3
4
5
6
7
8
9
10
繁琐的看着让人头疼,新手能够这样逐步的写,那愈来愈熟练的时候咱们就须要让咱们的代码简明了注释
hero.moveRight(2)
hero.moveUp()
hero.moveRight(3)
hero.moveDown()
hero.moveRight()
hero.moveDown()
hero.moveRight()
1
2
3
4
5
6
7
逆时针回转
hero.moveDown()
hero.moveDown()
hero.moveRight()
hero.moveUp()
hero.moveRight()
1
2
3
4
5
或移动
hero.moveDown(2)
hero.moveRight()
hero.moveUp()
hero.moveRight()
1
2
3
4
名称解释:
定义函数:
1.函数代码块使用 def关键字开头定义,后面跟上函数名称和 ( ),后面再接上冒号
2.任何传入的参数都应该放到 括号里面
3.完成特定功能的一个语句组,经过调用函数名来完成语句组的功能
4.第二行开始函数里面的内容使用缩进
5.若是函数有返回值,我们使用 return,若是没有写return,默认表示返回 None
6.函数名必须如下划线或者字母开头,能够包含数字、字母、下划线等组合,不能够包含标点符号!
7.函数名称不能同样,若是同样那么后面的函数定义覆盖前面的定义
8.函数名若是同样,可是大小写不同,是能够的,算做两个不一样的函数
9.函数名能不能使用保留字,一样会将内置函数覆盖掉
10.定义函数的时候,若是对函数进行注释,使用三个引号的注释方式
--------------------- 数字