zoukankan      html  css  js  c++  java
  • CodeCombat代码全记录(Python学习利器)--Kithgard地牢代码1

    Kithgard地牢
    注意:在调用函数时,要在函数的后面加上括号内容,否则在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步了。

    在使用方法相同内容时,我们可以合并方法内容示例可以合并为如下:

    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.定义函数的时候,如果对函数进行注释,使用三个引号的注释方式
    --------------------- 

  • 相关阅读:
    10分钟教你用VS2017将代码上传到GitHub
    【算法】C++用链表实现一个箱子排序附源代码详解
    【智能算法】粒子群算法(Particle Swarm Optimization)超详细解析+入门代码实例讲解
    【C/C++】10分钟教你用C++写一个贪吃蛇附带AI功能(附源代码详解和下载)
    【python】10分钟教你用python如何正确把妹
    【python】10分钟教你用python一行代码搞点大新闻
    【python】10分钟教你用python下载和拼接微信好友头像图片
    3. powerdesigner 生成mysql脚本,要求字段、表名有注释
    5. 回填表格复选框
    14. js字符串截取substring用法
  • 原文地址:https://www.cnblogs.com/ly570/p/11026705.html
Copyright © 2011-2022 走看看