码迷,mamicode.com
首页 > 其他好文 > 详细

「网易官方」极客战记(codecombat)攻略-游戏开发2-硬币游戏第 5 步:平衡-game-of-coins-step-5-balance

时间:2020-05-09 18:47:18      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:进入   ext   gre   布局   ref   点击   near   影响   erp   

技术图片
(点击图片进入关卡)

千里之堤,溃于蚁穴。

简介

在 Pac-man 风格的街机游戏系列的最后一关,我们将平衡游戏。

游戏逻辑准备就绪。 在之前的关卡中,我们使用高英雄速度等非均衡游戏参数而是简化游戏测试的早期阶段。

然而,游戏的最终版本应该是平衡的。 如果太容易,玩家会感到无聊。 如果太难了,那么他们会很沮丧,很快放弃。

为了简化平衡过程,我们已将所有游戏参数移至代码顶部 所以你可以在一个地方看到他们,并迅速做出改变。

目前游戏参数设置为噩梦难度。 尽量让它更容易。 别担心,没有 "ideal" 的参数,也没有正确的答案。

你决定参数应该是多少以及游戏有多难。 尝试使其具有挑战性,但有趣!

使用键盘或鼠标进行播放器控制:

  1. W -> 向上
  2. S -> 向下
  3. A -> 左边
  4. D -> 右边
  5. 鼠标点击 -> 移动到该点

默认代码

# 游戏测试人员不仅应该发现错误,还要解决平衡问题。
# 游戏参数
# 游戏参数定义游戏难度。
# 改变游戏参数来平衡游戏。
# 强化时间需要多长时间(秒)。
POWER_DURATION = 2 # ?
# 硬币,蘑菇和食人魔的得分值。
COIN_SCORE = 1 # ?
MUSHROOM_SCORE = 5 # ?
DEFEATED_SCORE = 10 # ?
# 每场比赛时间流逝得分减少多少。
TIME_SCORE = 1 # ?
# 玩家和食人魔的速度。
HERO_SPEED = 17 # ?
OGRE_SPEED = 15 # ?
# 食人魔产生延迟(秒)。
SPAWN_DELAY = 4 # ?
# 关卡布局
# 障碍和可收集的物品。
game.spawnXY("forest", 16, 16)
game.spawnXY("forest", 32, 16)
game.spawnXY("forest", 48, 16)
game.spawnXY("forest", 64, 16)
game.spawnXY("forest", 16, 32)
game.spawnXY("forest", 32, 32)
game.spawnXY("forest", 48, 32)
game.spawnXY("forest", 64, 32)
game.spawnXY("forest", 16, 48)
game.spawnXY("forest", 32, 48)
game.spawnXY("forest", 48, 48)
game.spawnXY("forest", 64, 48)
game.spawnXY("bronze-coin", 16, 8)
game.spawnXY("bronze-coin", 24, 8)
game.spawnXY("bronze-coin", 32, 8)
game.spawnXY("bronze-coin", 48, 8)
game.spawnXY("bronze-coin", 56, 8)
game.spawnXY("bronze-coin", 64, 8)
game.spawnXY("bronze-coin", 72, 8)
game.spawnXY("bronze-coin", 8, 16)
game.spawnXY("bronze-coin", 24, 16)
game.spawnXY("bronze-coin", 40, 16)
game.spawnXY("bronze-coin", 56, 16)
game.spawnXY("bronze-coin", 72, 16)
game.spawnXY("bronze-coin", 8, 24)
game.spawnXY("bronze-coin", 16, 24)
game.spawnXY("bronze-coin", 24, 24)
game.spawnXY("bronze-coin", 32, 24)
game.spawnXY("bronze-coin", 40, 24)
game.spawnXY("bronze-coin", 48, 24)
game.spawnXY("bronze-coin", 56, 24)
game.spawnXY("bronze-coin", 64, 24)
game.spawnXY("bronze-coin", 72, 24)
game.spawnXY("bronze-coin", 24, 32)
game.spawnXY("bronze-coin", 56, 32)
game.spawnXY("bronze-coin", 8, 40)
game.spawnXY("bronze-coin", 16, 40)
game.spawnXY("bronze-coin", 24, 40)
game.spawnXY("bronze-coin", 32, 40)
game.spawnXY("bronze-coin", 40, 40)
game.spawnXY("bronze-coin", 48, 40)
game.spawnXY("bronze-coin", 56, 40)
game.spawnXY("bronze-coin", 64, 40)
game.spawnXY("bronze-coin", 72, 40)
game.spawnXY("bronze-coin", 8, 48)
game.spawnXY("bronze-coin", 24, 48)
game.spawnXY("bronze-coin", 40, 48)
game.spawnXY("bronze-coin", 56, 48)
game.spawnXY("bronze-coin", 72, 48)
game.spawnXY("bronze-coin", 8, 56)
game.spawnXY("bronze-coin", 16, 56)
game.spawnXY("bronze-coin", 24, 56)
game.spawnXY("bronze-coin", 32, 56)
game.spawnXY("bronze-coin", 48, 56)
game.spawnXY("bronze-coin", 56, 56)
game.spawnXY("bronze-coin", 64, 56)
game.spawnXY("bronze-coin", 72, 56)
game.spawnXY("mushroom", 40, 8)
game.spawnXY("mushroom", 8, 32)
game.spawnXY("mushroom", 72, 32)
game.spawnXY("mushroom", 40, 56)
# 游戏设置
# 目标,UI和游戏全局变量
game.score = 1000
game.powerDuration = POWER_DURATION
game.powerTime = 0
game.powerEndTime = 0
ui.track(game, "time")
ui.track(game, "score")
ui.track(game, "powerTime")
game.addCollectGoal()
game.addSurviveGoal();
# 英雄设置
# 玩家,其参数和事件处理程序。
player = game.spawnPlayerXY("knight", 8, 8)
player.maxSpeed = HERO_SPEED
def powerPlayerUp():
    player.scale = 2
    player.attackDamage = 100
    game.powerEndTime = game.time + game.powerDuration
def powerPlayerDown():
    player.scale = 1
    player.attackDamage = 1
def onCollect(event):
    player = event.target
    item = event.other
    if item.type == "bronze-coin":
        game.score += COIN_SCORE
    if item.type == "mushroom":
        game.score += MUSHROOM_SCORE
        powerPlayerUp()
def onCollide(event):
    player = event.target
    other = event.other
    if other.type == "scout" and player.scale == 2:
        other.defeat()
player.on("collect", onCollect)
player.on("collide", onCollide)
# 敌人
# 敌方发生器,敌人事件和参数。
generator = game.spawnXY("generator", 41, 31)
generator.spawnType = "scout"
generator.spawnDelay = SPAWN_DELAY;
def onSpawn(event):
    unit = event.target
    unit.maxSpeed = OGRE_SPEED
    unit.attackDamage = player.maxHealth
    while True:
        if player.scale == 2:
            unit.behavior = "RunsAway"
        else:
            unit.behavior = "AttacksNearest"
def onDefeat(event):
    game.score += DEFEATED_SCORE
game.setActionFor("scout", "spawn", onSpawn)
game.setActionFor("scout", "defeat", onDefeat)
# 游戏循环
# 主要的游戏循环具有基于时间的功能。
def checkTimeScore():
    game.score -= TIME_SCORE
    if game.score < 0:
        game.score = 0
def checkPowerTimer():
    game.powerTime = game.powerEndTime - game.time
    if game.powerTime <= 0:
        game.powerTime = 0
        if player.scale == 2:
            powerPlayerDown()
def checkTimers():
    checkTimeScore()
    checkPowerTimer()
while True:
    checkTimers()
# 赢得游戏胜利!

概览

尝试逐个更改参数,而不是每次迭代更改所有参数。 当你同时改变几个参数时,很难理解游戏参数的影响。

但是有时游戏参数具有协同作用,只有在将它们一起更改时才能看到结果。 没有正确的答案。 只需测试各种参数并分析结果。

硬币游戏第 5 步:平衡 解法

# 游戏测试人员不仅应该发现错误,还要解决平衡问题。
# 游戏参数
# 游戏参数定义游戏难度。
# 改变游戏参数来平衡游戏。
# 强化时间需要多长时间(秒)。
POWER_DURATION = 4 # ?
# 硬币,蘑菇和食人魔的得分值。
COIN_SCORE = 1 # ?
MUSHROOM_SCORE = 5 # ?
DEFEATED_SCORE = 10 # ?
# 每场比赛时间流逝得分减少多少。
TIME_SCORE = 0.5 # ?
# 玩家和食人魔的速度。
HERO_SPEED = 22 # ?
OGRE_SPEED = 12 # ?
# 食人魔产生延迟(秒)。
SPAWN_DELAY = 6 # ?
# 关卡布局
# 障碍和可收集的物品。
game.spawnXY("forest", 16, 16)
game.spawnXY("forest", 32, 16)
game.spawnXY("forest", 48, 16)
game.spawnXY("forest", 64, 16)
game.spawnXY("forest", 16, 32)
game.spawnXY("forest", 32, 32)
game.spawnXY("forest", 48, 32)
game.spawnXY("forest", 64, 32)
game.spawnXY("forest", 16, 48)
game.spawnXY("forest", 32, 48)
game.spawnXY("forest", 48, 48)
game.spawnXY("forest", 64, 48)
game.spawnXY("bronze-coin", 16, 8)
game.spawnXY("bronze-coin", 24, 8)
game.spawnXY("bronze-coin", 32, 8)
game.spawnXY("bronze-coin", 48, 8)
game.spawnXY("bronze-coin", 56, 8)
game.spawnXY("bronze-coin", 64, 8)
game.spawnXY("bronze-coin", 72, 8)
game.spawnXY("bronze-coin", 8, 16)
game.spawnXY("bronze-coin", 24, 16)
game.spawnXY("bronze-coin", 40, 16)
game.spawnXY("bronze-coin", 56, 16)
game.spawnXY("bronze-coin", 72, 16)
game.spawnXY("bronze-coin", 8, 24)
game.spawnXY("bronze-coin", 16, 24)
game.spawnXY("bronze-coin", 24, 24)
game.spawnXY("bronze-coin", 32, 24)
game.spawnXY("bronze-coin", 40, 24)
game.spawnXY("bronze-coin", 48, 24)
game.spawnXY("bronze-coin", 56, 24)
game.spawnXY("bronze-coin", 64, 24)
game.spawnXY("bronze-coin", 72, 24)
game.spawnXY("bronze-coin", 24, 32)
game.spawnXY("bronze-coin", 56, 32)
game.spawnXY("bronze-coin", 8, 40)
game.spawnXY("bronze-coin", 16, 40)
game.spawnXY("bronze-coin", 24, 40)
game.spawnXY("bronze-coin", 32, 40)
game.spawnXY("bronze-coin", 40, 40)
game.spawnXY("bronze-coin", 48, 40)
game.spawnXY("bronze-coin", 56, 40)
game.spawnXY("bronze-coin", 64, 40)
game.spawnXY("bronze-coin", 72, 40)
game.spawnXY("bronze-coin", 8, 48)
game.spawnXY("bronze-coin", 24, 48)
game.spawnXY("bronze-coin", 40, 48)
game.spawnXY("bronze-coin", 56, 48)
game.spawnXY("bronze-coin", 72, 48)
game.spawnXY("bronze-coin", 8, 56)
game.spawnXY("bronze-coin", 16, 56)
game.spawnXY("bronze-coin", 24, 56)
game.spawnXY("bronze-coin", 32, 56)
game.spawnXY("bronze-coin", 48, 56)
game.spawnXY("bronze-coin", 56, 56)
game.spawnXY("bronze-coin", 64, 56)
game.spawnXY("bronze-coin", 72, 56)
game.spawnXY("mushroom", 40, 8)
game.spawnXY("mushroom", 8, 32)
game.spawnXY("mushroom", 72, 32)
game.spawnXY("mushroom", 40, 56)
# 游戏设置
# 目标,UI和游戏全局变量
game.score = 1000
game.powerDuration = POWER_DURATION
game.powerTime = 0
game.powerEndTime = 0
ui.track(game, "time")
ui.track(game, "score")
ui.track(game, "powerTime")
game.addCollectGoal()
game.addSurviveGoal();
# 英雄设置
# 玩家,其参数和事件处理程序。
player = game.spawnPlayerXY("knight", 8, 8)
player.maxSpeed = HERO_SPEED
def powerPlayerUp():
    player.scale = 2
    player.attackDamage = 100
    game.powerEndTime = game.time + game.powerDuration
def powerPlayerDown():
    player.scale = 1
    player.attackDamage = 1
def onCollect(event):
    player = event.target
    item = event.other
    if item.type == "bronze-coin":
        game.score += COIN_SCORE
    if item.type == "mushroom":
        game.score += MUSHROOM_SCORE
        powerPlayerUp()
def onCollide(event):
    player = event.target
    other = event.other
    if other.type == "scout" and player.scale == 2:
        other.defeat()
player.on("collect", onCollect)
player.on("collide", onCollide)
# 敌人
# 敌方发生器,敌人事件和参数。
generator = game.spawnXY("generator", 41, 31)
generator.spawnType = "scout"
generator.spawnDelay = SPAWN_DELAY;
def onSpawn(event):
    unit = event.target
    unit.maxSpeed = OGRE_SPEED
    unit.attackDamage = player.maxHealth
    while True:
        if player.scale == 2:
            unit.behavior = "RunsAway"
        else:
            unit.behavior = "AttacksNearest"
def onDefeat(event):
    game.score += DEFEATED_SCORE
game.setActionFor("scout", "spawn", onSpawn)
game.setActionFor("scout", "defeat", onDefeat)
# 游戏循环
# 主要的游戏循环具有基于时间的功能。
def checkTimeScore():
    game.score -= TIME_SCORE
    if game.score < 0:
        game.score = 0
def checkPowerTimer():
    game.powerTime = game.powerEndTime - game.time
    if game.powerTime <= 0:
        game.powerTime = 0
        if player.scale == 2:
            powerPlayerDown()
def checkTimers():
    checkTimeScore()
    checkPowerTimer()
while True:
    checkTimers()
# 赢得游戏胜利!

 

本攻略发于极客战记官方教学栏目,原文地址为:

https://codecombat.163.com/news/jikezhanji-yingbiyouxipingheng

极客战记——学编程,用玩的!

「网易官方」极客战记(codecombat)攻略-游戏开发2-硬币游戏第 5 步:平衡-game-of-coins-step-5-balance

标签:进入   ext   gre   布局   ref   点击   near   影响   erp   

原文地址:https://www.cnblogs.com/codecombat/p/12859390.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!