Narutimmy Posted February 28, 2018 Posted February 28, 2018 (edited) Hello good afternoon, I need your help, I want to convert this code created in C to Lua, if someone can help me please. #include <stdio.h> //Variables globales int nmatriz = 0; void generarMatriz(int nmatriz); //Funcion principal int main(){ printf("Inserta el tamaño de la matriz\n"); scanf("%d",&nmatriz); generarMatriz(nmatriz); } //Funcion que generara la matriz en caracol void generarMatriz(nmatriz){ int i,j; int countTotal = 1,tamanioTotal = nmatriz*nmatriz; int fila = 0, check = nmatriz, band = 1; int matrizCaracol[nmatriz][nmatriz]; //Llena matriz while(countTotal<=tamanioTotal){ //Hacia la derecha for(i=band-1; i < check; i++){ matrizCaracol[fila][i] = countTotal; countTotal = countTotal++; } fila = nmatriz - band; check = nmatriz - band; //Hacia abajo for(i=band; i <= check; i++){ matrizCaracol[i][fila] = countTotal; countTotal = countTotal++; } //Hacia la izquierda for(i=check-1; i >= (band-1) ; i--){ matrizCaracol[fila][i] = countTotal; countTotal = countTotal++; } fila = band-1; //Hacia arriba for(i=check-1; i >= band ; i--){ matrizCaracol[i][fila] = countTotal; countTotal = countTotal++; } band++; fila = band-1; } //Imprimir matriz for(i=0; i<nmatriz; i++){ for(j=0; j<nmatriz; j++){ printf("%d \t", matrizCaracol[i][j]); } printf("\n"); } } I have already made several attempts but I get it, help please. This is what the code has to do. sending to print on screen. Edited February 28, 2018 by Narutimmy mtasa://66.85.14.178:22003 Ts3: thezombiworld.com:7777
Saml1er Posted February 28, 2018 Posted February 28, 2018 Please show us your Lua code, where you made attempts.
NeXuS™ Posted March 1, 2018 Posted March 1, 2018 (edited) local sX, sY = guiGetScreenSize() local unitW, unitH = 40, 40 local snakeSize = 0 local snakeTable = {} function setupSnake(_snakeSize) snakeSize = _snakeSize for i = 0, _snakeSize-1 do for j = 1, _snakeSize do snakeTable[i*_snakeSize+j] = i*_snakeSize+j end end addEventHandler("onClientRender", root, drawSnake) end function drawSnake() local snakeW, snakeH = snakeSize*unitW, snakeSize*unitH local snakeX, snakeY = (sX-snakeW)/2, (sY-snakeH)/2 local offsetX, offsetY = 0, 0 for i = 0, snakeSize-1 do for j = 1, snakeSize do dxDrawRectangle(snakeX+offsetX, snakeY+offsetY, unitW, unitH, tocolor(0, 0, 0, 170)) dxDrawText(snakeTable[i*snakeSize+j], snakeX+offsetX, snakeY+offsetY, snakeX+offsetX+unitW, snakeY+offsetY+unitH, tocolor(255, 255, 255, 255), 1, "default-bold", "center", "center") offsetX = offsetX + unitW end offsetY = offsetY + unitH offsetX = 0 end end addCommandHandler("snake", function(_, _snakeSize) if not tonumber(_snakeSize) then outputChatBox("You have to insert a number as the snakesize.") else setupSnake(_snakeSize) end end) Edited March 1, 2018 by NeXuS™ Did I help you? NeXuS™#0001
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now