Lua游戏设计范例2

2019-05-08 14:35:23
收藏数:0
阅读数:75
评论数:0
-- MV
function _shoot(a, b)
    -- model;a 射击 b
    -- 游戏中每个个体,状态迁移
    if a.gun == 'ak47'
        then
        b.blood = b.blood - 20
    elseif a.gun == 'awmh'
        then
        b.blood = b.blood - 10
    else
        b.blood = b.blood - 5
    end
end

function render(a, b)
    -- view
    -- 渲染
    print(string.format('%s 射击 %s', a.name, b.name))
    print('结果:')
    show(a)
    show(b)
end

function show(a)
    -- 显示
    print(string.format('%s(%s), 血量 %d', 
        a.name, a.emoji, a.blood))
end

user={name='之江马化腾', gun='ak47',
blood=100, emoji='^_^', speed=8}
enemy={name='之江刘强东', gun='awmh',
blood=100, emoji='*_*', speed=4}

function shoot(a, b)
    -- 大纲
    _shoot(a,b)  -- model: rules
    render(a,b)  -- view: 让玩家看到效果 
end

shoot(user, enemy)
shoot(enemy, user)