ComputerCraft Chris Programs Code
Programs for ComputerCraft mods of Minecraft
Brought to you by:
christophedlr
--Déclaration des variables
--Configuration
length = 1;
width = 1;
space = 1;
pos = "left";
--Dernière configuration
oldlength = 1;
oldwidth = 1;
oldspace = 1;
oldpos = "left";
--Déclaration des fonctions
function clearScreen()
term.clear();
term.setCursorPos(1, 1);
end
--Menu du programme
function menu()
clearScreen();
print("Sugar Canes Farm V1.0 - French version\n");
print("1. Demarrer");
print("2. Configuration");
print("3. Quitter\n");
write("Votre choix: ");
local choice = tonumber( read() );
if choice == 1 then
start();
elseif choice == 2 then
config();
elseif choice == 3 then
print("Fermeture du programme");
end
end
--Configuration of program
function config()
clearScreen();
print("SCF - Utilitaire de configuration\n");
print("1. Longueur: "..length);
print("2. Largeur: "..width);
print("3. Espacement: "..space);
print("4. Direction : "..pos);
print("5. Valider");
print("6. Annuler");
write("Votre choix: ");
local choice = tonumber( read() );
if choice == 1 then
oldlength = length;
write("Longueur en blocs: ");
length = tonumber( read() );
config();
elseif choice == 2 then
oldwidth = width;
write("Largeur en blocs (2 max): ");
width = tonumber( read() );
if width > 2 then
width = 2;
end
config();
elseif choice == 3 then
oldspace = space;
write("Espacement en blocs: ");
space = tonumber( read() );
config();
elseif choice == 4 then
oldpos = pos;
write("Direction (left/right): ");
pos = read();
config();
elseif choice == 5 then
save();
menu();
elseif choice == 6 then
length = oldlength;
width = oldwidth;
space = oldspace;
pos = oldpos;
menu();
end
end
--Starting program
function start()
turtle.up();
for i = 1,width do
for j = 0,length do
turtle.dig();
turtle.forward();
end
if pos == "left" then
turtle.turnLeft();
elseif pos == "right" then
turtle.turnRight();
end
for x = 1,space do
turtle.forward();
end
if pos == "left" then
turtle.turnLeft();
elseif pos == "right" then
turtle.turnRight();
end
end
turtle.down();
end
--Save configuration
function save()
local file = fs.open("scf.cfg", "w");
file.writeLine(length);
file.writeLine(width);
file.writeLine(space);
file.writeLine(pos);
file.close();
end
--Load configuration
function load()
local file = fs.open("scf.cfg", "r");
length = tonumber( file.readLine() );
width = tonumber( file.readLine() );
space = tonumber( file.readLine() );
pos = file.readLine();
file.close();
oldlength = length;
oldwidth = width;
oldspace = space;
oldpos = pos;
end
--Call functions
if fs.exists("scf.cfg") then
load();
end
menu();