[Python] Codecombat 攻略 Sarven 沙漠 (1-43关)截止至36关

首页:https://cn.codecombat.com/play
语言:Python

 

第二界面:Sarven沙漠(43关)
时间:4-11小时
内容:算术运算,计数器,while循环,break(跳出循环),数组,字符串比较,寻找最小最大值。
网页:https://cn.codecombat.com/play/desert

 

闯关:
第1关:强壮的沙牦牛
子网页:https://cn.codecombat.com/play/level/the-mighty-sand-yak?

# 当牦牛靠近时向右移动10米来躲避
# 躲避4头牦牛完成此关

while True:
    # 使用你的灵石获取你当前的 x 和 y 位置。
    x = hero.pos.x
    y = hero.pos.y
    
    # 找到最近的耗牛。
    yak = hero.findNearestEnemy()
    
    # 使用 if 仅仅当牦牛少于10米距离的时候。
    if hero.distanceTo(yak) < 10:
        # 向右移动,添加10到你的x位置。
        x = x + 10
        # 使用 moveXY 来移动!
        hero.moveXY(x, y)
        pass

 

第2关:绿洲
子网页:https://cn.codecombat.com/play/level/oasis?

# 向绿洲移动
# Move left to avoid nearby yaks.

while True:
    x = hero.pos.x
    y = hero.pos.y
    enemy = hero.findNearestEnemy()
    if enemy and hero.distanceTo(enemy) < 10:
        # 通过在你的X坐标上减去10来移动到左边
        x = x - 10
        # Use moveXY to move to the new x, y position.
        hero.moveXY(x, y)
        pass
    else:
        # 通过在你的X坐标上加上10来移动到右边
        x = x + 10
        # Use moveXY to move to the new x, y position.
        hero.moveXY(x, y)
        pass

 

 

第3关:盆地的践踏
子网页:https://cn.codecombat.com/play/level/basin-stampede?

# Keep moving right, but adjust up and down as you go.

while True:
    enemy = hero.findNearestEnemy()
    xPos = hero.pos.x + 5
    yPos = 17
    if enemy:
        # Adjust y up or down to get away from yaks.
        if enemy.pos.y > hero.pos.y:
            # If the Yak is above you, subtract 3 from yPos.
            yPos = yPos - 3
            pass
        elif enemy.pos.y < hero.pos.y:
            # If the Yak is below you, add 3 to yPos.
            yPos = yPos + 3
            pass
    hero.moveXY(xPos, yPos)

 

第4关:萨文路
子网页:https://cn.codecombat.com/play/level/sarven-road?

第一次:

# 到达绿洲。小心新的敌人:食人魔侦察兵!
# 通过添加你当前的X位置和Y位置以向上向右走

while True:
    # If there's an enemy, attack.
    enemy = hero.findNearestEnemy()
    xPos = hero.pos.x
    yPos = hero.pos.y
    if enemy:
        hero.attack(enemy)
    # Else, keep moving up and to the right. 
    else:
        xPos = xPos + 5
        yPos = yPos + 5
        hero.moveXY(xPos, yPos)
    pass

 

第5关:十字路口
子网页:https://cn.codecombat.com/play/level/crossroads?

# 使用  fire-trap 打败进攻的食人魔

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        # If the enemy is to the left of the hero:
        if enemy.pos.x < hero.pos.x:
            # 如果敌人从左边进攻,在左边建一个fire-trap(火焰陷阱)
            hero.buildXY("fire-trap", 25, 34)
            pass
        # If the enemy is to the right of the hero:
        elif enemy.pos.x > hero.pos.x:
            # 如果敌人从右边进攻,在右边建一个fire-trap(火焰陷阱)
            hero.buildXY("fire-trap", 55, 34)
            pass
        # If the enemy is below the hero:
        elif enemy.pos.y < hero.pos.y:
            # 如果敌人从下边进攻,在下边建一个fire-trap(火焰陷阱)
            hero.buildXY("fire-trap", 40, 19)
            pass
        # If the enemy is above the hero:
        elif enemy.pos.y > hero.pos.y:
            # 如果敌人从上边进攻,在上边建一个fire-trap(火焰陷阱)
            hero.buildXY("fire-trap", 40, 49)
            pass
    # Move back to the center.
    hero.moveXY(40, 34)

 

第6关:雷蹄
子网页:https://cn.codecombat.com/play/level/thunderhooves?

# 到达绿洲,
# 用栅栏引导砂牦牛到你去的地方

while True:
    yak = hero.findNearestEnemy()
    if yak:
        # 如果它的 y 值大于你的,那么耗牛在你前面
        if yak.pos.y > hero.pos.y:
            # 如果耗牛在你前面,在它后面10米建立一个栅栏
            hero.buildXY("fence", yak.pos.x, yak.pos.y - 10)
        else: 
            if yak.pos.y < hero.pos.y:
            # 如果耗牛在你后面,在它前面10m 建立一个栅栏
                hero.buildXY("fence", yak.pos.x, yak.pos.y + 10)
        pass
    else:
        # 向右移动10走向绿洲
        hero.moveXY(hero.pos.x + 10, hero.pos.y)
        pass

 

第7关:截擎
子网页:https://cn.codecombat.com/play/level/interception?

# Stand between the peasant and the tower.

while True:
    enemy = hero.findNearestEnemy()
    friend = hero.findNearestFriend()
    # Calculate x by adding friend.pos.x to enemy.pos.x
    # 然后除以2
    # Check the guide if you need more help!
    x = (friend.pos.x + enemy.pos.x) / 2
    # Now do the same for y
    y = (friend.pos.y + enemy.pos.y) / 2
    # 移动到您计算的X和Y坐标。
    hero.moveXY(x, y)

 

第8关:猎杀行动
子网页:https://cn.codecombat.com/play/level/operation-killdeer?

# 引诱这些食人魔进入陷阱,这些食人魔非常小心
# 只有英雄受伤了他们才会跟着英雄

# 这个函数会检查英雄的生命值
# 并返回一个布尔型(Boolean)的值。

def shouldRun():
    if hero.health < hero.maxHealth / 2:
        return True
    else:
        return False

while True:
    enemy = hero.findNearestEnemy()
    # 当shouldRun()返回True时 移动到X点 True
    if shouldRun():
        hero.moveXY(75, 37)
    # 否则,攻击!
    else:
        hero.attack(enemy)

 

第9关:医疗注意
子网页:https://cn.codecombat.com/play/level/medical-attention?

# 当你生命值少于一半时,请求医疗人员的治疗。

while True:
    currentHealth =
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值