博客
关于我
CodeCombat代码全记录(Python学习利器)--边地森林(第二章)代码10
阅读量:341 次
发布时间:2019-03-04

本文共 4132 字,大约阅读时间需要 13 分钟。

从本章节之后,我们开始学习数字内容相关的知识,更进一步熟悉python中的四则运算,注意多看下提示!!

德雅啤酒(似曾相识的味道)

# 你可以把字符串连起来,或者把数字连接到字符串中。# Sing along, using string concatenation:# X potions of health on the wall!# X potions of health!# Take Y down, pass it around!# X-Y potions of health on the wall.potionsOnTheWall = 10numToTakeDown = 1while True:    hero.say(potionsOnTheWall + " potions of health on the wall!")    # 唱出下一句:    hero.say(potionsOnTheWall + " potions of health!")    # 唱出下一句:    hero.say("Take" + numToTakeDown + " down, pass it around!")    potionsOnTheWall -= numToTakeDown    # 唱出最后一句:    hero.say(potionsOnTheWall + " potions of health on the wall!")

巫师之门

# Move to Laszlo and get his secret number.hero.moveXY(30, 13)las = hero.findNearestFriend().getSecret()# 向 Laszlo 的数字中加7就能得到 Erzsebet的号码# Move to Erzsebet and say her magic number.erz = las + 7hero.moveXY(17, 26)hero.say(erz)# 将 Erzsebet 的数字除以 4 得到 Simoyi 的数字。# Go to Simonyi and tell him his number.sim = erz / 4hero.moveXY(30, 39)hero.say(sim)# 将 Simonyi 的数字乘以 Laszlo 的数字得到 Agata 的数字。# Go to Agata and tell her her number.aga = sim * lashero.moveXY(43, 26)hero.say(aga)

Backwoods Bombardier(边地投弹)

二营长,我的意大利炮呢,开炮!!

在这里插入图片描述

# The pos property is an object with x and y properties.# pos.x is a number representing the horizontal position on the map# pos.y is a number representing the vertical position on the mapwhile True:    enemy = hero.findNearestEnemy()    if enemy:        x = enemy.pos.x        # Get the enemy's y position!        y = enemy.pos.y # ∆ Change this!                # say the x and y position separated by a comma        hero.say(x + "," + y)    else:        hero.say("Cease" + " Fire!")

The Wizard’s Haunt(巫师出没)

# 移动到 Zsofia 的身边,从他那得到秘密号码hero.moveXY(18, 20)zso = hero.findNearestFriend().getSecret()# 将 Zsofia 的数字除以 4 得到 Mihaly 的数字。# Move to Mihaly and say his magic number.mih = zso / 4hero.moveXY(30, 15)hero.say(mih)# 把 Mihaly 的号码除以5来得到 Beata 的号码# Move to Beata and say her magic number.bea = mih / 5hero.moveXY(42, 20)hero.say(bea)# 将 用'Mihaly'的数字减去'Beata'的数字,来得到 Sandor 的数字。。# Move to Sandor and say his magic number.san = mih - beahero.moveXY(38, 37)hero.say(san)

金币屑

# 跟随硬币的轨迹来到红色 X 标记的出口while True:    # 这能找到最近的敌人。    item = hero.findNearestItem()    if item:        # 这将物品的 pos,就是坐标,存储在变量中。        itemPosition = item.pos        # 将物品的 X 和 Y 坐标放进变量。        itemX = itemPosition.x        itemY = itemPosition.y        # Now, use moveXY to move to itemX and itemY:        hero.moveXY(itemX, itemY)

The Wizard’s Plane(巫师天际层)

# Move to Eszter and get the secret number from her.hero.moveXY(16, 32)esz = hero.findNearestFriend().getSecret()# Multiply by 3 and subtract 2 to get Tamas's number.# Remember to use parentheses to do calculations in the right order.# Move to Tamas and say his magic number.tam = (esz * 3) - 2hero.moveXY(24, 28)hero.say(tam)# Subtract 1 and multiply by 4 to get Zsofi's number.# Move to Zsofi and say her magic number.zso = (tam - 1) * 4hero.moveXY(32, 24)hero.say(zso)# Add Tamas's and Zsofi's numbers, then divide by 2 to get Istvan's number.# Move to Istvan and say his magic number.ist = (tam + zso) / 2hero.moveXY(40, 20)hero.say(ist)# Add Tamas's and Zsofi's numbers. Subtract Istvan's number from Zsofi's. Multiply the two results to get Csilla's number.# Move to Csilla and say her magic number.csi = (tam + zso) * ( zso - ist)hero.moveXY(48,16)hero.say(csi)

白兔

# 跟随发光石引导陷阱while True:    item = hero.findNearestItem()    if item:        # 使用 item.pos 将物品位置保存为一个新的变数        # 使用 pos.x 和 pos.y 保存坐标        x = item.pos.x        y = item.pos.y        # 使用 moveXY() 和 X 与 Y 变数移动至坐标        hero.moveXY(x, y)        pass

未知的距离

# 你的任务是告诉他兽人的距离。# 这个函数寻找最近的敌人,并返回距离。# If there is no enemy, the function returns 0.def nearestEnemyDistance():    enemy = hero.findNearestEnemy()    result = 0    if enemy:        result = hero.distanceTo(enemy)    return resultwhile True:    # Call nearestEnemyDistance() and    # save the result in the variable enemyDistance.    enemyDistance = nearestEnemyDistance()    # If the enemyDistance is greater than 0:     if enemyDistance > 0:        # Say the value of enemyDistance variable.        hero.say(enemyDistance)

转载地址:http://txie.baihongyu.com/

你可能感兴趣的文章
MySQL - ERROR 1406
查看>>
mysql - 视图
查看>>
MySQL - 解读MySQL事务与锁机制
查看>>
MTTR、MTBF、MTTF的大白话理解
查看>>
mt_rand
查看>>
mysql -存储过程
查看>>
mysql /*! 50100 ... */ 条件编译
查看>>
mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
查看>>
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>
MySQL 8.0开始Group by不再排序
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>