Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to use table ?

edited June 2012 in Questions Posts: 12

Hi, i'm new comer in Codea And Lua And i have some troubles with lua tables. Could someone explain me what i'm doing wrong in this attemp of drawing à 10x10 board game?
Thanks

--# Main


function setup()
    -- sens du jeu
    supportedOrientations(PORTRAIT)
    --displayMode(FULLSCREEN)

    -- definition des variables globales
    blanc=color(255, 255, 255, 255)
    noir=color(0, 0, 0, 255)
    vide= color(0, 0, 0, 43)
    nbrCases= 10
    diam=WIDTH/(nbrCases+2)

    -- génération du plateau de jeu
    -- plateau[ligne][colonne]
    cases={}
    for l=1 , nbrCases do
        for i=1 , nbrCases do
        cases[l][i]=vide
        end
    end

    -- placement des billes de départ
    ctr=nbrCases/2
    -- cases[5][5]=blanc
    -- creation du plateau
    jeu = Plateau()
end

function draw()
    background(40, 40, 50)
    jeu:draw()
end
--# Plateau
Plateau = class()

function Plateau:init()
    pimage=image(WIDTH,WIDTH)
    setContext(pimage)
    background(135, 78, 39, 255)

    for i,lig in ipairs(cases) do
        for j=1, nbrCases do
            if lig[j]~=vide then
                fill(lig[j])
                else fill(vide)
            end
            ellipse((diam/2)+diam*i,(diam/2)+diam*j,diam,diam)
            text(i.." "..j,(diam/2)+diam*i,(diam/2)+diam*j)
        end
    end
    setContext()
end

function Plateau:draw()
    sprite(pimage,WIDTH/2,HEIGHT/2)
end
Tagged:

Comments

Sign In or Register to comment.