code combat - SARVEN SAVIOR

Words
176
Reading
1 min
Listen
Play
6y

这个游戏已经越来越好玩了,有逻辑,有步骤,还有各种新的函数。这一局加入了array的概念,还有循环,简单的游戏让我复习了几种函数的用法。

本局就是要叫每一个士兵的名字,然后叫他们回家。最后在路口处建立fence,这样就可以挡住新来的敌人。

image.png

image.png

源代码如下,仅供参考:

  # An ARRAY is a list of items.

  # This array is a list of your friends' names.
  friendNames = ['Joan', 'Ronan', 'Nikita', 'Augustus']

  # Array indices start at 0, not 1!
  friendIndex = 0

  # Loop over each name in the array.
  # The len() function gets the length of the list.
   while friendIndex < len(friendNames):
    # Use square brackets to get a name from the array.
    friendName = friendNames[friendIndex]
    
    # Tell your friend to go home.
    # Use + to connect two strings.
    hero.say(friendName + ', go home!')
    
    # Increment friendIndex to get the next name.
    friendIndex += 1
    
# Retreat to the oasis and build a "fence" on the X.
hero.buildXY("fence", 30, 30)
code combat - SARVEN SAVIOR | Ecency