create account

Code Combat - Bank Raid by shenchensucc

View this thread on: hive.blogpeakd.comecency.com
· @shenchensucc ·
$3.12
Code Combat - Bank Raid
CodeCombat这一款游戏我在之前已经有介绍过。简单来说,就是一个可以学习代码的游戏,这里有特定的游戏函数来训练新手熟悉代码中的基本逻辑。while循环,for循环,if判断,数组等等

今天这一关很有意思,首次使用使用hero.findEnemies()来一次吧所有的敌人都查询到一个数组里面,然后使用enemies[enemyIndex]来调用每一个敌人,一下次把效率提高了不少。

很好的游戏,让我可以继续学习。


![image.png](https://cdn.steemitimages.com/DQmVnX9RrG9vZcJmdaVNz4iDKCZKCkziHo9Mwe3THgimato/image.png)

游戏源码如下:
```
# Wait for ogres, defeat them and collect gold.

while True:
    enemies = hero.findEnemies()
    # enemyIndex is used to iterate the enemies array.
    enemyIndex = 0
    # While enemyIndex is less than len(enemies)
    while enemyIndex < len(enemies):
        # Attack the enemy at enemyIndex
        enemy = enemies[enemyIndex]
        hero.attack(enemy)
        # Increase enemyIndex by one.
        enemyIndex += 1
    coins = hero.findItems()
    # coinIndex is used to iterate the coins array.
    coinIndex = 0
    while coinIndex < len(coins):
        # Get a coin from the coins array using coinIndex
        coin = coins[coinIndex]
        # Collect that coin.
        hero.moveXY(coin.pos.x, coin.pos.y)
        # Increase coinIndex by one.
        coinIndex += 1
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 208 others
properties (23)
authorshenchensucc
permlinkcode-combat-bank-raid
categorycn
json_metadata{"tags":["cn","cn-reader","cn-curation","whalepower","cn-programming"],"image":["https://cdn.steemitimages.com/DQmVnX9RrG9vZcJmdaVNz4iDKCZKCkziHo9Mwe3THgimato/image.png"],"app":"hiveblog/0.1","format":"markdown"}
created2020-06-26 04:18:21
last_update2020-06-26 04:18:21
depth0
children0
last_payout2020-07-03 04:18:21
cashout_time1969-12-31 23:59:59
total_payout_value1.660 HBD
curator_payout_value1.462 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,104
author_reputation100,205,759,373,709
root_title"Code Combat - Bank Raid"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,182,027
net_rshares9,845,155,621,855
author_curate_reward""
vote details (272)