메뉴 건너뛰기

창작에 관련된 질문이나 간단한 팁, 예제를 올리는 곳

------------------------ stairs.lua ------------------------


Stairs = {}


function Stairs:new(x, y, floor, direction, locked)

local newStairs = {x = x, y = y, floor = floor, direction = direction, locked = locked}

self.__index = self

return setmetatable(newStairs, self)

end


function Stairs:draw()

print("Stairs - X:" .. self.x .. " Y:" .. self.y .. " floor: " .. self.floor .. " direction: " .. self.direction .. " locked: " .. tostring(self.locked))

end


------------------------ main.lua ------------------------


require "stairs"


game = {}

game.stairs = {}

table.insert(game.stairs, Stairs:new(2, 6, 1, "up", false))

table.insert(game.stairs, Stairs:new(18, 9, 1, "down", false))

table.insert(game.stairs, Stairs:new(6, 2, 2, "up", false))

table.insert(game.stairs, Stairs:new(7, 12, 2, "down", false))

table.insert(game.stairs, Stairs:new(5, 5, 1, "up", true))


for a = 1, #game.stairs do

game.stairs[a]:draw() --same with game.stairs[a].draw(game.stairs[a])

end


print("Is game.stairs[1] locked? - " .. tostring(game.stairs[1].locked))


------------------------

분류 :
조회 수 :
27
등록일 :
2020.11.06
21:53:00 (*.127.102.18)
엮인글 :
게시글 주소 :
https://hondoom.com/zbxe/index.php?mid=study&document_srl=818619
List of Articles