mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-07 07:50:27 +00:00
Lint whitespace during CI
This commit is contained in:
parent
3f98b2785e
commit
0de5969ec1
3
.github/workflows/main-ci.yml
vendored
3
.github/workflows/main-ci.yml
vendored
@ -37,3 +37,6 @@ jobs:
|
|||||||
test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate
|
test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate
|
||||||
chmod +x bin/illuaminate
|
chmod +x bin/illuaminate
|
||||||
bin/illuaminate lint
|
bin/illuaminate lint
|
||||||
|
|
||||||
|
- name: Check whitespace
|
||||||
|
run: python3 tools/check-lines.py
|
||||||
|
@ -1 +1 @@
|
|||||||
adventure is a text adventure game for CraftOS. To navigate around the world of adventure, type simple instructions to the interpreter, for example: "go north", "punch tree", "craft planks", "mine coal with pickaxe", "hit creeper with sword"
|
adventure is a text adventure game for CraftOS. To navigate around the world of adventure, type simple instructions to the interpreter, for example: "go north", "punch tree", "craft planks", "mine coal with pickaxe", "hit creeper with sword"
|
||||||
|
@ -3,4 +3,4 @@ alias assigns shell commands to run other programs.
|
|||||||
ex:
|
ex:
|
||||||
"alias dir ls" will make the "dir" command run the "ls" program
|
"alias dir ls" will make the "dir" command run the "ls" program
|
||||||
"alias dir" will remove the alias set on "dir"
|
"alias dir" will remove the alias set on "dir"
|
||||||
"alias" will list all current aliases.
|
"alias" will list all current aliases.
|
||||||
|
@ -2,4 +2,4 @@ Surf the rednet superhighway with "chat", the networked chat program for CraftOS
|
|||||||
|
|
||||||
ex:
|
ex:
|
||||||
"chat host forgecraft" will create a chatroom with the name "forgecraft"
|
"chat host forgecraft" will create a chatroom with the name "forgecraft"
|
||||||
"chat join forgecraft direwolf20" will connect to the chatroom with the name "forgecraft", using the nickname "direwolf20"
|
"chat join forgecraft direwolf20" will connect to the chatroom with the name "forgecraft", using the nickname "direwolf20"
|
||||||
|
@ -1 +1 @@
|
|||||||
clear clears the screen.
|
clear clears the screen.
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
coroutine is a standard Lua5.1 API.
|
coroutine is a standard Lua5.1 API.
|
||||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||||
|
@ -1 +1 @@
|
|||||||
dance is a program for Turtles. Turtles love to get funky.
|
dance is a program for Turtles. Turtles love to get funky.
|
||||||
|
@ -14,4 +14,4 @@ disk.getID( drive )
|
|||||||
Events fired by the disk API:
|
Events fired by the disk API:
|
||||||
"disk" when a disk or other item is inserted into a disk drive. Argument is the name of the drive
|
"disk" when a disk or other item is inserted into a disk drive. Argument is the name of the drive
|
||||||
"disk_eject" when a disk is removed from a disk drive. Argument is the name of the drive
|
"disk_eject" when a disk is removed from a disk drive. Argument is the name of the drive
|
||||||
Type "help events" to learn about the event system.
|
Type "help events" to learn about the event system.
|
||||||
|
@ -3,4 +3,4 @@ dj plays Music Discs from disk drives attached to the computer.
|
|||||||
ex:
|
ex:
|
||||||
"dj" or "dj play" plays a random disc.
|
"dj" or "dj play" plays a random disc.
|
||||||
"dj play left" plays the disc in the drive on the left of the computer.
|
"dj play left" plays the disc in the drive on the left of the computer.
|
||||||
"dj stop" stops the current disc.
|
"dj stop" stops the current disc.
|
||||||
|
@ -2,4 +2,4 @@ drive tells you which disk drive the current or specified directory is located i
|
|||||||
|
|
||||||
ex:
|
ex:
|
||||||
"drive" tell you the disk drive of the current directory.
|
"drive" tell you the disk drive of the current directory.
|
||||||
"drive foo" tells you the disk drive of the subdirectory "foo"
|
"drive foo" tells you the disk drive of the subdirectory "foo"
|
||||||
|
@ -16,4 +16,4 @@ getDiskID()
|
|||||||
Events fired by the Disk Drive:
|
Events fired by the Disk Drive:
|
||||||
"disk" when a disk or other item is inserted into the drive. Argument is the name of the drive.
|
"disk" when a disk or other item is inserted into the drive. Argument is the name of the drive.
|
||||||
"disk_eject" when a disk is removed from a drive. Argument is the name of the drive.
|
"disk_eject" when a disk is removed from a drive. Argument is the name of the drive.
|
||||||
Type "help events" to learn about the event system.
|
Type "help events" to learn about the event system.
|
||||||
|
@ -1 +1 @@
|
|||||||
Mostly harmless.
|
Mostly harmless.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
edit is a text editor for creating or modifying programs or text files. After creating a program with edit, type its filename in the shell to run it. You can open any of the builtin programs with edit to learn how to program.
|
edit is a text editor for creating or modifying programs or text files. After creating a program with edit, type its filename in the shell to run it. You can open any of the builtin programs with edit to learn how to program.
|
||||||
|
|
||||||
ex:
|
ex:
|
||||||
"edit hello" opens a file called "hello" for editing.
|
"edit hello" opens a file called "hello" for editing.
|
||||||
|
@ -1 +1 @@
|
|||||||
exit will exit the current shell.
|
exit will exit the current shell.
|
||||||
|
@ -4,7 +4,7 @@ Type "help gpsapi" for help using GPS functions in lua programs.
|
|||||||
ex:
|
ex:
|
||||||
"gps locate" will connect to nearby GPS servers, and try to determine the position of the computer or turtle.
|
"gps locate" will connect to nearby GPS servers, and try to determine the position of the computer or turtle.
|
||||||
"gps host" will try to determine the position, and host a GPS server if successful.
|
"gps host" will try to determine the position, and host a GPS server if successful.
|
||||||
"gps host 10 20 30" will host a GPS server, using the manually entered position 10,20,30.
|
"gps host 10 20 30" will host a GPS server, using the manually entered position 10,20,30.
|
||||||
|
|
||||||
Take care when manually entering host positions. If the positions entered into multiple GPS hosts
|
Take care when manually entering host positions. If the positions entered into multiple GPS hosts
|
||||||
are not consistent, the results of locate calls will be incorrect.
|
are not consistent, the results of locate calls will be incorrect.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Functions in the GPS API:
|
Functions in the GPS API:
|
||||||
gps.locate( timeout )
|
gps.locate( timeout )
|
||||||
|
|
||||||
The locate function will send a signal to nearby gps servers, and wait for responses before the timeout. If it receives enough responses to determine this computers position then x, y and z co-ordinates will be returned, otherwise it will return nil. If GPS hosts do not have their positions configured correctly, results will be inaccurate.
|
The locate function will send a signal to nearby gps servers, and wait for responses before the timeout. If it receives enough responses to determine this computers position then x, y and z co-ordinates will be returned, otherwise it will return nil. If GPS hosts do not have their positions configured correctly, results will be inaccurate.
|
||||||
|
@ -1 +1 @@
|
|||||||
hello prints the text "Hello World!" to the screen.
|
hello prints the text "Hello World!" to the screen.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
help is the help tool you're currently using.
|
help is the help tool you're currently using.
|
||||||
Type "help index" to see all help topics.
|
Type "help index" to see all help topics.
|
||||||
Type "help" to see the help intro.
|
Type "help" to see the help intro.
|
||||||
Type "help helpapi" for information on the help Lua API.
|
Type "help helpapi" for information on the help Lua API.
|
||||||
|
@ -2,4 +2,4 @@ id prints the unique identifier of this computer, or a Disk in an attached Disk
|
|||||||
|
|
||||||
ex:
|
ex:
|
||||||
"id" will print this Computers ID and label
|
"id" will print this Computers ID and label
|
||||||
"id left" will print the ID and label of the disk in the Disk Drive on the left
|
"id left" will print the ID and label of the disk in the Disk Drive on the left
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
io is a standard Lua5.1 API, reimplemented for CraftOS. Not all the features are availiable.
|
io is a standard Lua5.1 API, reimplemented for CraftOS. Not all the features are availiable.
|
||||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||||
|
@ -3,7 +3,7 @@ The keys API contains constants for all the key codes that can be returned by th
|
|||||||
Example usage:
|
Example usage:
|
||||||
local sEvent, nKey = os.pullEvent()
|
local sEvent, nKey = os.pullEvent()
|
||||||
if sEvent == "key" and nKey == keys.enter then
|
if sEvent == "key" and nKey == keys.enter then
|
||||||
-- Do something
|
-- Do something
|
||||||
end
|
end
|
||||||
|
|
||||||
See http://www.minecraftwiki.net/wiki/Key_codes, or the source code, for a complete reference.
|
See http://www.minecraftwiki.net/wiki/Key_codes, or the source code, for a complete reference.
|
||||||
|
@ -1 +1 @@
|
|||||||
ls will list all the directories and files in the current location. Use "type" to find out if an item is a file or a directory.
|
ls will list all the directories and files in the current location. Use "type" to find out if an item is a file or a directory.
|
||||||
|
@ -1 +1 @@
|
|||||||
lua is an interactive prompt for the lua programming language. It's a useful tool for learning the language.
|
lua is an interactive prompt for the lua programming language. It's a useful tool for learning the language.
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
math is a standard Lua5.1 API.
|
math is a standard Lua5.1 API.
|
||||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||||
|
@ -2,4 +2,4 @@ mkdir creates a directory in the current location.
|
|||||||
|
|
||||||
ex:
|
ex:
|
||||||
"mkdir foo" creates a directory named "foo".
|
"mkdir foo" creates a directory named "foo".
|
||||||
"mkdir ../foo" creates a directory named "foo" in the directory above the current directory.
|
"mkdir ../foo" creates a directory named "foo" in the directory above the current directory.
|
||||||
|
@ -9,4 +9,4 @@ transmit( channel, replyChannel, message )
|
|||||||
isWireless()
|
isWireless()
|
||||||
|
|
||||||
Events fired by Modems:
|
Events fired by Modems:
|
||||||
"modem_message" when a message is received on an open channel. Arguments are name, channel, replyChannel, message, distance
|
"modem_message" when a message is received on an open channel. Arguments are name, channel, replyChannel, message, distance
|
||||||
|
@ -3,4 +3,4 @@ Type "help monitors" for help using monitors as peripherals in lua programs.
|
|||||||
|
|
||||||
ex:
|
ex:
|
||||||
"monitor left hello" will run the "hello" program on the monitor to the left of the computer.
|
"monitor left hello" will run the "hello" program on the monitor to the left of the computer.
|
||||||
"monitor top edit foo" will run the edit program on the top monitor, editing the file "foo".
|
"monitor top edit foo" will run the edit program on the top monitor, editing the file "foo".
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
multishell is the toplevel program on Advanced Computers which manages background tabs.
|
multishell is the toplevel program on Advanced Computers which manages background tabs.
|
||||||
Type "help shellapi" for information about the shell lua api.
|
Type "help shellapi" for information about the shell lua api.
|
||||||
|
@ -23,4 +23,4 @@ os.reboot()
|
|||||||
Events emitted by the os API:
|
Events emitted by the os API:
|
||||||
"timer" when a timeout started by os.startTimer() completes. Argument is the token returned by os.startTimer().
|
"timer" when a timeout started by os.startTimer() completes. Argument is the token returned by os.startTimer().
|
||||||
"alarm" when a time passed to os.setAlarm() is reached. Argument is the token returned by os.setAlarm().
|
"alarm" when a time passed to os.setAlarm() is reached. Argument is the token returned by os.setAlarm().
|
||||||
Type "help events" to learn about the event system.
|
Type "help events" to learn about the event system.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Functions in the Parallel API:
|
Functions in the Parallel API:
|
||||||
parallel.waitForAny( function1, function2, ... )
|
parallel.waitForAny( function1, function2, ... )
|
||||||
parallel.waitForAll( function1, function2, ... )
|
parallel.waitForAll( function1, function2, ... )
|
||||||
These methods provide an easy way to run multiple lua functions simultaneously.
|
These methods provide an easy way to run multiple lua functions simultaneously.
|
||||||
|
@ -3,4 +3,4 @@ Functions in the pocket API:
|
|||||||
pocket.equipBack()
|
pocket.equipBack()
|
||||||
pocket.unequipBack()
|
pocket.unequipBack()
|
||||||
|
|
||||||
When equipping upgrades, it will search your inventory for a suitable upgrade, starting in the selected slot. If one cannot be found then it will check your offhand.
|
When equipping upgrades, it will search your inventory for a suitable upgrade, starting in the selected slot. If one cannot be found then it will check your offhand.
|
||||||
|
@ -9,4 +9,4 @@ getPageSize()
|
|||||||
setCursorPos( x, y )
|
setCursorPos( x, y )
|
||||||
getCursorPos()
|
getCursorPos()
|
||||||
write( text )
|
write( text )
|
||||||
endPage()
|
endPage()
|
||||||
|
@ -8,4 +8,4 @@ To quickly shutdown a computer, hold Ctrl+S for 1 second.
|
|||||||
To quickly reboot a computer, hold Ctrl+R for 1 second.
|
To quickly reboot a computer, hold Ctrl+R for 1 second.
|
||||||
|
|
||||||
To learn about the programming APIs availiable, type "apis" or "help apis".
|
To learn about the programming APIs availiable, type "apis" or "help apis".
|
||||||
If you get stuck, visit the forums at http://www.computercraft.info/ for advice and tutorials.
|
If you get stuck, visit the forums at http://www.computercraft.info/ for advice and tutorials.
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
reboot will turn the computer off and on again.
|
reboot will turn the computer off and on again.
|
||||||
You can also hold Ctrl+R at any time to quickly reboot.
|
You can also hold Ctrl+R at any time to quickly reboot.
|
||||||
|
@ -6,4 +6,4 @@ ex:
|
|||||||
"redstone set right blue false" turns off the blue wire in the bundled cable on the right redstone output.
|
"redstone set right blue false" turns off the blue wire in the bundled cable on the right redstone output.
|
||||||
"redstone pulse front 10 1" emits 10 one second redstone pulses on the front redstone output.
|
"redstone pulse front 10 1" emits 10 one second redstone pulses on the front redstone output.
|
||||||
|
|
||||||
Type "help redstoneapi" or "help rs" for information on the redstone Lua API.
|
Type "help redstoneapi" or "help rs" for information on the redstone Lua API.
|
||||||
|
@ -3,4 +3,4 @@ refuel is a program for Turtles. Refuel will consume items from the inventory as
|
|||||||
ex:
|
ex:
|
||||||
"refuel" will refuel with at most one fuel item
|
"refuel" will refuel with at most one fuel item
|
||||||
"refuel 10" will refuel with at most 10 fuel items
|
"refuel 10" will refuel with at most 10 fuel items
|
||||||
"refuel all" will refuel with as many fuel items as possible
|
"refuel all" will refuel with as many fuel items as possible
|
||||||
|
@ -1 +1 @@
|
|||||||
repeat is a program for repeating rednet messages across long distances. To use, connect 2 or more modems to a computer and run the "repeat" program; from then on, any rednet message sent from any computer in wireless range or connected by networking cable to either of the modems will be repeated to those on the other side.
|
repeat is a program for repeating rednet messages across long distances. To use, connect 2 or more modems to a computer and run the "repeat" program; from then on, any rednet message sent from any computer in wireless range or connected by networking cable to either of the modems will be repeated to those on the other side.
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
shell is the toplevel program which interprets commands and runs program.
|
shell is the toplevel program which interprets commands and runs program.
|
||||||
Type "help shellapi" for information about the shell lua api.
|
Type "help shellapi" for information about the shell lua api.
|
||||||
|
@ -1 +1 @@
|
|||||||
shutdown will turn off the computer.
|
shutdown will turn off the computer.
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
string is a standard Lua5.1 API.
|
string is a standard Lua5.1 API.
|
||||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
table is a standard Lua5.1 API.
|
table is a standard Lua5.1 API.
|
||||||
Refer to http://www.lua.org/manual/5.1/ for more information.
|
Refer to http://www.lua.org/manual/5.1/ for more information.
|
||||||
|
@ -1 +1 @@
|
|||||||
time prints the current time of day.
|
time prints the current time of day.
|
||||||
|
@ -1 +1 @@
|
|||||||
type determines the type of a file or directory. Prints "file", "directory" or "does not exist".
|
type determines the type of a file or directory. Prints "file", "directory" or "does not exist".
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
--[[
|
--[[
|
||||||
battleship,
|
battleship,
|
||||||
|
|
||||||
by GopherAtl, 2013
|
by GopherAtl, 2013
|
||||||
|
|
||||||
Do whatever you want, just don't judge me by
|
Do whatever you want, just don't judge me by
|
||||||
what a mess this code is.
|
what a mess this code is.
|
||||||
--]]
|
--]]
|
||||||
@ -17,21 +17,21 @@ local myTurn
|
|||||||
local targetX,targetY
|
local targetX,targetY
|
||||||
local shipsLeft=5
|
local shipsLeft=5
|
||||||
local oppShipsLeft=5
|
local oppShipsLeft=5
|
||||||
|
|
||||||
local originalTerm = term.current()
|
local originalTerm = term.current()
|
||||||
|
|
||||||
--bounding box of the target grid
|
--bounding box of the target grid
|
||||||
local targetGridBounds={
|
local targetGridBounds={
|
||||||
minX=16, maxX=25,
|
minX=16, maxX=25,
|
||||||
minY=4, maxY=13
|
minY=4, maxY=13
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local function doColor(text,background)
|
local function doColor(text,background)
|
||||||
term.setTextColor(text)
|
term.setTextColor(text)
|
||||||
term.setBackgroundColor(background)
|
term.setBackgroundColor(background)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function doColor_mono(text,background)
|
local function doColor_mono(text,background)
|
||||||
if text==colors.blue or text==colors.red or text==colors.black or text==colors.lime or background==colors.lightGray then
|
if text==colors.blue or text==colors.red or text==colors.black or text==colors.lime or background==colors.lightGray then
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
@ -39,9 +39,9 @@ local function doColor_mono(text,background)
|
|||||||
else
|
else
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function doScreenColor()
|
local function doScreenColor()
|
||||||
if term.isColor() then
|
if term.isColor() then
|
||||||
doColor(colors.white,colors.lightGray)
|
doColor(colors.white,colors.lightGray)
|
||||||
@ -49,16 +49,16 @@ local function doScreenColor()
|
|||||||
doColor(colors.black,colors.white)
|
doColor(colors.black,colors.white)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function toGridRef(x,y)
|
local function toGridRef(x,y)
|
||||||
return string.sub("ABCDEFGHIJ",x,x)..string.sub("1234567890",y,y)
|
return string.sub("ABCDEFGHIJ",x,x)..string.sub("1234567890",y,y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if not term.isColor() then
|
if not term.isColor() then
|
||||||
doColor=doColor_mono
|
doColor=doColor_mono
|
||||||
end
|
end
|
||||||
|
|
||||||
local function quit()
|
local function quit()
|
||||||
if openedSide then
|
if openedSide then
|
||||||
rednet.close(openedSide)
|
rednet.close(openedSide)
|
||||||
@ -68,7 +68,7 @@ local function quit()
|
|||||||
print()
|
print()
|
||||||
error()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
local foundModem=false
|
local foundModem=false
|
||||||
--find modem
|
--find modem
|
||||||
for k,v in pairs(redstone.getSides()) do
|
for k,v in pairs(redstone.getSides()) do
|
||||||
@ -81,17 +81,17 @@ for k,v in pairs(redstone.getSides()) do
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not foundModem then
|
if not foundModem then
|
||||||
print("You must have a modem to play!")
|
print("You must have a modem to play!")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if action==nil or (action~="join" and action~="host") then
|
if action==nil or (action~="join" and action~="host") then
|
||||||
print("Invalid parameters. Usage:\n> battleship host\nHosts a game, waits for another computer to join\n> battleship join\nLooks for another game to join")
|
print("Invalid parameters. Usage:\n> battleship host\nHosts a game, waits for another computer to join\n> battleship join\nLooks for another game to join")
|
||||||
quit()
|
quit()
|
||||||
end
|
end
|
||||||
|
|
||||||
--get player name
|
--get player name
|
||||||
while true do
|
while true do
|
||||||
doColor(colors.cyan,colors.black)
|
doColor(colors.cyan,colors.black)
|
||||||
@ -108,13 +108,13 @@ while true do
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if action=="join" then
|
if action=="join" then
|
||||||
print("Attempting to join a game...\n(press q to cancel)")
|
print("Attempting to join a game...\n(press q to cancel)")
|
||||||
while true do
|
while true do
|
||||||
local retryTimer=os.startTimer(1);
|
local retryTimer=os.startTimer(1);
|
||||||
rednet.broadcast("bs join "..myName);
|
rednet.broadcast("bs join "..myName);
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local event,p1,p2,p3=os.pullEvent();
|
local event,p1,p2,p3=os.pullEvent();
|
||||||
if event=="rednet_message" then
|
if event=="rednet_message" then
|
||||||
@ -131,7 +131,7 @@ if action=="join" then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local joined=false
|
local joined=false
|
||||||
|
|
||||||
if opponentID then
|
if opponentID then
|
||||||
print("Joining game!")
|
print("Joining game!")
|
||||||
rednet.send(opponentID,"bs start")
|
rednet.send(opponentID,"bs start")
|
||||||
@ -142,7 +142,7 @@ elseif action=="host" then
|
|||||||
print("Waiting for challenger...\n(Press q to cancel)")
|
print("Waiting for challenger...\n(Press q to cancel)")
|
||||||
while true do
|
while true do
|
||||||
while true do
|
while true do
|
||||||
local event,p1,p2=os.pullEvent()
|
local event,p1,p2=os.pullEvent()
|
||||||
if event=="rednet_message" then
|
if event=="rednet_message" then
|
||||||
opponent=string.match(p2,"bs join %s*(.+)%s*") if opponent then
|
opponent=string.match(p2,"bs join %s*(.+)%s*") if opponent then
|
||||||
print("found player, inviting..")
|
print("found player, inviting..")
|
||||||
@ -154,7 +154,7 @@ elseif action=="host" then
|
|||||||
quit()
|
quit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if opponentID then
|
if opponentID then
|
||||||
rednet.send(opponentID,"bs accept "..myName)
|
rednet.send(opponentID,"bs accept "..myName)
|
||||||
local timeout=os.startTimer(1)
|
local timeout=os.startTimer(1)
|
||||||
@ -166,17 +166,17 @@ elseif action=="host" then
|
|||||||
elseif event=="timer" and p1==timeout then
|
elseif event=="timer" and p1==timeout then
|
||||||
print("player joined another game. Waiting for another...")
|
print("player joined another game. Waiting for another...")
|
||||||
opponentID=nil
|
opponentID=nil
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if opponentID then
|
if opponentID then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local ships={
|
local ships={
|
||||||
{pos=nil,dir="h",size=5,name="carrier",hits=0},
|
{pos=nil,dir="h",size=5,name="carrier",hits=0},
|
||||||
{pos=nil,dir="h",size=4,name="battleship",hits=0},
|
{pos=nil,dir="h",size=4,name="battleship",hits=0},
|
||||||
@ -184,12 +184,12 @@ local ships={
|
|||||||
{pos=nil,dir="h",size=3,name="submarine",hits=0},
|
{pos=nil,dir="h",size=3,name="submarine",hits=0},
|
||||||
{pos=nil,dir="h",size=2,name="destroyer",hits=0},
|
{pos=nil,dir="h",size=2,name="destroyer",hits=0},
|
||||||
}
|
}
|
||||||
|
|
||||||
local myShotTable={ {1,1,true},{5,5,false} }
|
local myShotTable={ {1,1,true},{5,5,false} }
|
||||||
local oppShotTable={ }
|
local oppShotTable={ }
|
||||||
|
|
||||||
local myGrid,oppGrid={title=myName},{title=opponent}
|
local myGrid,oppGrid={title=myName},{title=opponent}
|
||||||
|
|
||||||
--setup grids
|
--setup grids
|
||||||
for i=1,10 do
|
for i=1,10 do
|
||||||
myGrid[i]={}
|
myGrid[i]={}
|
||||||
@ -199,8 +199,8 @@ for i=1,10 do
|
|||||||
oppGrid[i][j]={hit=false,ship=false}
|
oppGrid[i][j]={hit=false,ship=false}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawShipsToGrid(ships,grid)
|
local function drawShipsToGrid(ships,grid)
|
||||||
for i=1,#ships do
|
for i=1,#ships do
|
||||||
local x,y=table.unpack(ships[i].pos)
|
local x,y=table.unpack(ships[i].pos)
|
||||||
local stepX=ships[i].dir=="h" and 1 or 0
|
local stepX=ships[i].dir=="h" and 1 or 0
|
||||||
@ -211,18 +211,18 @@ local function drawShipsToGrid(ships,grid)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawShotToGrid(shot,grid)
|
local function drawShotToGrid(shot,grid)
|
||||||
grid[shot[1]][shot[2]].shot=true
|
grid[shot[1]][shot[2]].shot=true
|
||||||
grid[shot[1]][shot[2]].hit=shot[3]
|
grid[shot[1]][shot[2]].hit=shot[3]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function makeShot(x,y,grid)
|
local function makeShot(x,y,grid)
|
||||||
local tile=grid[x][y]
|
local tile=grid[x][y]
|
||||||
if tile.shot==true then
|
if tile.shot==true then
|
||||||
return nil --already shot here!
|
return nil --already shot here!
|
||||||
end
|
end
|
||||||
|
|
||||||
local shot={x,y,tile.ship}
|
local shot={x,y,tile.ship}
|
||||||
drawShotToGrid(shot,grid)
|
drawShotToGrid(shot,grid)
|
||||||
if tile.ship then
|
if tile.ship then
|
||||||
@ -232,12 +232,12 @@ local function makeShot(x,y,grid)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return shot
|
return shot
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function drawTile(scrX,scrY,tile)
|
local function drawTile(scrX,scrY,tile)
|
||||||
term.setCursorPos(scrX,scrY)
|
term.setCursorPos(scrX,scrY)
|
||||||
|
|
||||||
if tile.ship then
|
if tile.ship then
|
||||||
if tile.shot then
|
if tile.shot then
|
||||||
doColor(colors.red,colors.gray)
|
doColor(colors.red,colors.gray)
|
||||||
@ -259,31 +259,31 @@ local function drawTile(scrX,scrY,tile)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawGrid(scrX,scrY,grid)
|
local function drawGrid(scrX,scrY,grid)
|
||||||
doColor(colors.white,colors.black)
|
doColor(colors.white,colors.black)
|
||||||
term.setCursorPos(scrX,scrY+1)
|
term.setCursorPos(scrX,scrY+1)
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
doColor(colors.white,colors.gray)
|
doColor(colors.white,colors.gray)
|
||||||
term.setCursorPos(scrX,scrY)
|
term.setCursorPos(scrX,scrY)
|
||||||
local pad=11-#grid.title
|
local pad=11-#grid.title
|
||||||
term.write(string.rep(" ",math.ceil(pad/2))..grid.title..string.rep(" ",math.floor(pad/2)))
|
term.write(string.rep(" ",math.ceil(pad/2))..grid.title..string.rep(" ",math.floor(pad/2)))
|
||||||
|
|
||||||
for gx=1,10 do
|
for gx=1,10 do
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
term.setCursorPos(scrX+gx,scrY+1)
|
term.setCursorPos(scrX+gx,scrY+1)
|
||||||
term.write(gx==10 and "0" or string.char(string.byte("0")+gx))
|
term.write(gx==10 and "0" or string.char(string.byte("0")+gx))
|
||||||
|
|
||||||
term.setCursorPos(scrX,scrY+gx+1)
|
term.setCursorPos(scrX,scrY+gx+1)
|
||||||
term.write(string.char(string.byte("A")+gx-1))
|
term.write(string.char(string.byte("A")+gx-1))
|
||||||
for gy=1,10 do
|
for gy=1,10 do
|
||||||
drawTile(scrX+gx,scrY+gy+1,grid[gx][gy])
|
drawTile(scrX+gx,scrY+gy+1,grid[gx][gy])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
doColor(colors.white,colors.black)
|
doColor(colors.white,colors.black)
|
||||||
end
|
end
|
||||||
|
|
||||||
function moveTargetIndicator(newX,newY)
|
function moveTargetIndicator(newX,newY)
|
||||||
--if x has changed...
|
--if x has changed...
|
||||||
if targetX and targetY then
|
if targetX and targetY then
|
||||||
@ -303,8 +303,8 @@ function moveTargetIndicator(newX,newY)
|
|||||||
term.write("^")
|
term.write("^")
|
||||||
term.setCursorPos(targetGridBounds.minX+newX-1,targetGridBounds.minY-3)
|
term.setCursorPos(targetGridBounds.minX+newX-1,targetGridBounds.minY-3)
|
||||||
term.write("v")
|
term.write("v")
|
||||||
|
|
||||||
targetX=newX
|
targetX=newX
|
||||||
end
|
end
|
||||||
if newY~=targetY then
|
if newY~=targetY then
|
||||||
--space over old
|
--space over old
|
||||||
@ -319,11 +319,11 @@ function moveTargetIndicator(newX,newY)
|
|||||||
term.write("<")
|
term.write("<")
|
||||||
term.setCursorPos(targetGridBounds.minX-2,targetGridBounds.minY+newY-1)
|
term.setCursorPos(targetGridBounds.minX-2,targetGridBounds.minY+newY-1)
|
||||||
term.write(">")
|
term.write(">")
|
||||||
|
|
||||||
targetY=newY
|
targetY=newY
|
||||||
end
|
end
|
||||||
term.setCursorPos(15,15)
|
term.setCursorPos(15,15)
|
||||||
term.write("Target : "..toGridRef(targetX,targetY))
|
term.write("Target : "..toGridRef(targetX,targetY))
|
||||||
--if the target tile is a valid target, draw a "+"
|
--if the target tile is a valid target, draw a "+"
|
||||||
if not oppGrid[targetX][targetY].shot then
|
if not oppGrid[targetX][targetY].shot then
|
||||||
term.setCursorPos(targetX+targetGridBounds.minX-1,targetY+targetGridBounds.minY-1)
|
term.setCursorPos(targetX+targetGridBounds.minX-1,targetY+targetGridBounds.minY-1)
|
||||||
@ -331,18 +331,18 @@ function moveTargetIndicator(newX,newY)
|
|||||||
term.write("+")
|
term.write("+")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local log={}
|
local log={}
|
||||||
|
|
||||||
local termWidth,termHeight=term.getSize()
|
local termWidth,termHeight=term.getSize()
|
||||||
|
|
||||||
local logHeight=termHeight-3
|
local logHeight=termHeight-3
|
||||||
local logWidth=termWidth-28
|
local logWidth=termWidth-28
|
||||||
|
|
||||||
for i=1,logHeight do
|
for i=1,logHeight do
|
||||||
log[i]=""
|
log[i]=""
|
||||||
end
|
end
|
||||||
|
|
||||||
local function printLog()
|
local function printLog()
|
||||||
doColor(colors.white,colors.black)
|
doColor(colors.white,colors.black)
|
||||||
for i=1,logHeight do
|
for i=1,logHeight do
|
||||||
@ -358,9 +358,9 @@ local function printLog()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--shipX/Y are the position of ship on grid; gridX/Y are the offset of the top-left of grid
|
--shipX/Y are the position of ship on grid; gridX/Y are the offset of the top-left of grid
|
||||||
local function drawShip(size,align,x,y,char)
|
local function drawShip(size,align,x,y,char)
|
||||||
local stepX=align=="h" and 1 or 0
|
local stepX=align=="h" and 1 or 0
|
||||||
@ -371,31 +371,31 @@ local function drawShip(size,align,x,y,char)
|
|||||||
x,y=x+stepX,y+stepY
|
x,y=x+stepX,y+stepY
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setStatusLine(lineNum,text)
|
local function setStatusLine(lineNum,text)
|
||||||
doScreenColor()
|
doScreenColor()
|
||||||
local pad=math.floor((termWidth-#text)/2)
|
local pad=math.floor((termWidth-#text)/2)
|
||||||
term.setCursorPos(1,16+lineNum)
|
term.setCursorPos(1,16+lineNum)
|
||||||
term.write((" "):rep(pad)..text..(" "):rep(termWidth-#text-pad))
|
term.write((" "):rep(pad)..text..(" "):rep(termWidth-#text-pad))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
doScreenColor()
|
doScreenColor()
|
||||||
term.clear()
|
term.clear()
|
||||||
|
|
||||||
drawGrid(2,2,myGrid)
|
drawGrid(2,2,myGrid)
|
||||||
|
|
||||||
setStatusLine(1,"Started game with "..opponent.." at computer #"..(opponentID or "nil"))
|
setStatusLine(1,"Started game with "..opponent.." at computer #"..(opponentID or "nil"))
|
||||||
|
|
||||||
local function getShipBounds(ship)
|
local function getShipBounds(ship)
|
||||||
return {
|
return {
|
||||||
minX=ship.pos[1],
|
minX=ship.pos[1],
|
||||||
minY=ship.pos[2],
|
minY=ship.pos[2],
|
||||||
maxX=ship.pos[1]+(ship.dir=="h" and ship.size-1 or 0),
|
maxX=ship.pos[1]+(ship.dir=="h" and ship.size-1 or 0),
|
||||||
maxY=ship.pos[2]+(ship.dir=="v" and ship.size-1 or 0)
|
maxY=ship.pos[2]+(ship.dir=="v" and ship.size-1 or 0)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getPointBounds(x,y)
|
local function getPointBounds(x,y)
|
||||||
return {
|
return {
|
||||||
minX=x,
|
minX=x,
|
||||||
@ -404,20 +404,20 @@ local function getPointBounds(x,y)
|
|||||||
maxY=y,
|
maxY=y,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function boundsIntersect(boundsA,boundsB)
|
local function boundsIntersect(boundsA,boundsB)
|
||||||
return not (
|
return not (
|
||||||
boundsA.minX>boundsB.maxX or
|
boundsA.minX>boundsB.maxX or
|
||||||
boundsA.maxX<boundsB.minX or
|
boundsA.maxX<boundsB.minX or
|
||||||
boundsA.minY>boundsB.maxY or
|
boundsA.minY>boundsB.maxY or
|
||||||
boundsA.maxY<boundsB.minY
|
boundsA.maxY<boundsB.minY
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function checkShipCollision(shipIndex)
|
local function checkShipCollision(shipIndex)
|
||||||
local myBounds=getShipBounds(ships[shipIndex])
|
local myBounds=getShipBounds(ships[shipIndex])
|
||||||
for i=1,#ships do
|
for i=1,#ships do
|
||||||
if i~=shipIndex and ships[i].pos then
|
if i~=shipIndex and ships[i].pos then
|
||||||
if boundsIntersect(myBounds,getShipBounds(ships[i])) then
|
if boundsIntersect(myBounds,getShipBounds(ships[i])) then
|
||||||
return i
|
return i
|
||||||
@ -426,9 +426,9 @@ local function checkShipCollision(shipIndex)
|
|||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function randomizeShips()
|
local function randomizeShips()
|
||||||
for i=1,5 do
|
for i=1,5 do
|
||||||
ships[i].pos=nil
|
ships[i].pos=nil
|
||||||
@ -447,10 +447,10 @@ local function randomizeShips()
|
|||||||
ship.dir=dir
|
ship.dir=dir
|
||||||
until checkShipCollision(i)==0
|
until checkShipCollision(i)==0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function shipPlacement()
|
local function shipPlacement()
|
||||||
local selection=1
|
local selection=1
|
||||||
local collidesWith=0
|
local collidesWith=0
|
||||||
@ -458,7 +458,7 @@ local function shipPlacement()
|
|||||||
local moveShip=nil
|
local moveShip=nil
|
||||||
local clickedOn=nil
|
local clickedOn=nil
|
||||||
local clickedAt=nil
|
local clickedAt=nil
|
||||||
|
|
||||||
doScreenColor()
|
doScreenColor()
|
||||||
term.setCursorPos(28,3)
|
term.setCursorPos(28,3)
|
||||||
write("use arrows to move ship")
|
write("use arrows to move ship")
|
||||||
@ -480,7 +480,7 @@ local function shipPlacement()
|
|||||||
write('"f" when finished')
|
write('"f" when finished')
|
||||||
randomizeShips()
|
randomizeShips()
|
||||||
setStatusLine(1,"Arrange your ships on the grid")
|
setStatusLine(1,"Arrange your ships on the grid")
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
--local placed=0
|
--local placed=0
|
||||||
--draw sea
|
--draw sea
|
||||||
@ -502,7 +502,7 @@ local function shipPlacement()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local event,p1,p2,p3=os.pullEvent()
|
local event,p1,p2,p3=os.pullEvent()
|
||||||
if event=="key" then
|
if event=="key" then
|
||||||
if not dragging then
|
if not dragging then
|
||||||
@ -533,14 +533,14 @@ local function shipPlacement()
|
|||||||
end
|
end
|
||||||
elseif p1==keys.r then
|
elseif p1==keys.r then
|
||||||
randomizeShips();
|
randomizeShips();
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif event=="mouse_click" then
|
elseif event=="mouse_click" then
|
||||||
clickedOn=nil
|
clickedOn=nil
|
||||||
--click event! figure out what we clicked on
|
--click event! figure out what we clicked on
|
||||||
local clickBounds=getPointBounds(p2,p3)
|
local clickBounds=getPointBounds(p2,p3)
|
||||||
local clickGridBounds=getPointBounds(p2-2,p3-3)
|
local clickGridBounds=getPointBounds(p2-2,p3-3)
|
||||||
|
|
||||||
for i=1,#ships do
|
for i=1,#ships do
|
||||||
if ships[i].pos and boundsIntersect(clickGridBounds,getShipBounds(ships[i])) and
|
if ships[i].pos and boundsIntersect(clickGridBounds,getShipBounds(ships[i])) and
|
||||||
(collidesWith==0 or collidesWith==i or i==selection) then
|
(collidesWith==0 or collidesWith==i or i==selection) then
|
||||||
@ -554,7 +554,7 @@ local function shipPlacement()
|
|||||||
clickedOffset={p2-2-ships[i].pos[1],p3-3-ships[i].pos[2]}
|
clickedOffset={p2-2-ships[i].pos[1],p3-3-ships[i].pos[2]}
|
||||||
selection=i
|
selection=i
|
||||||
break
|
break
|
||||||
--[[else
|
--[[else
|
||||||
local labelBounds={minX=15,maxX=24,minY=2*i,maxY=1+2*i}
|
local labelBounds={minX=15,maxX=24,minY=2*i,maxY=1+2*i}
|
||||||
if boundsIntersect(clickBounds,labelBounds) and
|
if boundsIntersect(clickBounds,labelBounds) and
|
||||||
(collidesWith==0 or collidesWith==i or i==selection) then
|
(collidesWith==0 or collidesWith==i or i==selection) then
|
||||||
@ -583,20 +583,20 @@ local function shipPlacement()
|
|||||||
--can't drag from a right-click!
|
--can't drag from a right-click!
|
||||||
clickedOn=nil
|
clickedOn=nil
|
||||||
if ships[selection].dir=="h" then
|
if ships[selection].dir=="h" then
|
||||||
ships[selection].dir="v"
|
ships[selection].dir="v"
|
||||||
moveShip={p2-2-ships[selection].pos[1],-(p2-2-ships[selection].pos[1])}
|
moveShip={p2-2-ships[selection].pos[1],-(p2-2-ships[selection].pos[1])}
|
||||||
else
|
else
|
||||||
ships[selection].dir="h"
|
ships[selection].dir="h"
|
||||||
moveShip={p3-3-(ships[selection].pos[2]+ships[selection].size-1),p3-3-(ships[selection].pos[2])}
|
moveShip={p3-3-(ships[selection].pos[2]+ships[selection].size-1),p3-3-(ships[selection].pos[2])}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif event=="mouse_drag" and clickedOn~=nil then
|
elseif event=="mouse_drag" and clickedOn~=nil then
|
||||||
--mode="place"
|
--mode="place"
|
||||||
moveShip={
|
moveShip={
|
||||||
p2-2-clickedOffset[1]-ships[selection].pos[1],
|
p2-2-clickedOffset[1]-ships[selection].pos[1],
|
||||||
p3-3-clickedOffset[2]-ships[selection].pos[2]}
|
p3-3-clickedOffset[2]-ships[selection].pos[2]}
|
||||||
end
|
end
|
||||||
|
|
||||||
if moveShip then
|
if moveShip then
|
||||||
local curShip=ships[selection]
|
local curShip=ships[selection]
|
||||||
--calc position limits based on ship size and alignment
|
--calc position limits based on ship size and alignment
|
||||||
@ -610,15 +610,15 @@ local function shipPlacement()
|
|||||||
--place the ship
|
--place the ship
|
||||||
ships[selection].pos=newPos
|
ships[selection].pos=newPos
|
||||||
--check for collisions with other ships
|
--check for collisions with other ships
|
||||||
|
|
||||||
collidesWith=checkShipCollision(selection)
|
collidesWith=checkShipCollision(selection)
|
||||||
moveShip=nil
|
moveShip=nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function displayGameHelp()
|
local function displayGameHelp()
|
||||||
doScreenColor()
|
doScreenColor()
|
||||||
term.setCursorPos(28,3)
|
term.setCursorPos(28,3)
|
||||||
write("arrows to move cursor")
|
write("arrows to move cursor")
|
||||||
term.setCursorPos(28,4)
|
term.setCursorPos(28,4)
|
||||||
@ -626,27 +626,27 @@ local function displayGameHelp()
|
|||||||
if term.isColor() then
|
if term.isColor() then
|
||||||
term.setCursorPos(28,6)
|
term.setCursorPos(28,6)
|
||||||
write("click on grid to fire")
|
write("click on grid to fire")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function hideHelpArea()
|
local function hideHelpArea()
|
||||||
doScreenColor()
|
doScreenColor()
|
||||||
for y=3,13 do
|
for y=3,13 do
|
||||||
term.setCursorPos(28,y)
|
term.setCursorPos(28,y)
|
||||||
write(string.rep(" ",32))
|
write(string.rep(" ",32))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function runGame()
|
local function runGame()
|
||||||
|
|
||||||
--first, ship placement phase!!
|
--first, ship placement phase!!
|
||||||
shipPlacement()
|
shipPlacement()
|
||||||
|
|
||||||
hideHelpArea()
|
hideHelpArea()
|
||||||
|
|
||||||
--hide the old help, draw the new
|
--hide the old help, draw the new
|
||||||
|
|
||||||
--tell the other guy we're done
|
--tell the other guy we're done
|
||||||
rednet.send(opponentID,"bs ready")
|
rednet.send(opponentID,"bs ready")
|
||||||
if not opponentReady then
|
if not opponentReady then
|
||||||
@ -655,17 +655,17 @@ local function runGame()
|
|||||||
os.pullEvent()
|
os.pullEvent()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--now, play the game
|
--now, play the game
|
||||||
--draw my final ship positions intto the grid
|
--draw my final ship positions intto the grid
|
||||||
drawShipsToGrid(ships,myGrid)
|
drawShipsToGrid(ships,myGrid)
|
||||||
|
|
||||||
|
|
||||||
--if I'm host, flip a coin
|
--if I'm host, flip a coin
|
||||||
if action=="host" then
|
if action=="host" then
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
myTurn=math.floor(100*math.random())%2==0
|
myTurn=math.floor(100*math.random())%2==0
|
||||||
rednet.send(opponentID,"bs cointoss "..tostring(not myTurn))
|
rednet.send(opponentID,"bs cointoss "..tostring(not myTurn))
|
||||||
if myTurn then
|
if myTurn then
|
||||||
setStatusLine(2,"Your turn, take your shot!")
|
setStatusLine(2,"Your turn, take your shot!")
|
||||||
else
|
else
|
||||||
@ -678,15 +678,15 @@ local function runGame()
|
|||||||
os.pullEvent()
|
os.pullEvent()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
setStatusLine(1,"")
|
setStatusLine(1,"")
|
||||||
if myTurn then
|
if myTurn then
|
||||||
--I won, I go first
|
--I won, I go first
|
||||||
displayGameHelp()
|
displayGameHelp()
|
||||||
end
|
end
|
||||||
|
|
||||||
--draw a target grid
|
--draw a target grid
|
||||||
drawGrid(2,2,myGrid)
|
drawGrid(2,2,myGrid)
|
||||||
drawGrid(15,2,oppGrid)
|
drawGrid(15,2,oppGrid)
|
||||||
--initialize target indicators
|
--initialize target indicators
|
||||||
@ -719,7 +719,7 @@ local function runGame()
|
|||||||
elseif p1>="0" and p1<="9" then
|
elseif p1>="0" and p1<="9" then
|
||||||
local t=string.byte(p1)-string.byte("0")
|
local t=string.byte(p1)-string.byte("0")
|
||||||
if t==0 then t=10 end
|
if t==0 then t=10 end
|
||||||
moveTargetIndicator(t,targetY)
|
moveTargetIndicator(t,targetY)
|
||||||
end
|
end
|
||||||
elseif e=="key" then
|
elseif e=="key" then
|
||||||
if p1==keys.enter or p1==keys.space and targetX and targetY then
|
if p1==keys.enter or p1==keys.space and targetX and targetY then
|
||||||
@ -736,7 +736,7 @@ local function runGame()
|
|||||||
moveTargetIndicator(math.max(targetX-1,1),targetY)
|
moveTargetIndicator(math.max(targetX-1,1),targetY)
|
||||||
elseif p1==keys.right then
|
elseif p1==keys.right then
|
||||||
moveTargetIndicator(math.min(targetX+1,10),targetY)
|
moveTargetIndicator(math.min(targetX+1,10),targetY)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--shot sent, wait for my turn to resolve (top coroutine will switch turns and draw the hit to the grid)
|
--shot sent, wait for my turn to resolve (top coroutine will switch turns and draw the hit to the grid)
|
||||||
@ -746,12 +746,12 @@ local function runGame()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local gameRoutine=coroutine.create(runGame)
|
local gameRoutine=coroutine.create(runGame)
|
||||||
--if advanced terminal, default focus to chat, can play with mouse
|
--if advanced terminal, default focus to chat, can play with mouse
|
||||||
local inChat=term.isColor()
|
local inChat=term.isColor()
|
||||||
local savedCursorPos={7,19}
|
local savedCursorPos={7,19}
|
||||||
|
|
||||||
--redirect just to block scroll
|
--redirect just to block scroll
|
||||||
local redir={}
|
local redir={}
|
||||||
for k,v in pairs(originalTerm) do
|
for k,v in pairs(originalTerm) do
|
||||||
@ -762,12 +762,12 @@ for k,v in pairs(originalTerm) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
originalTerm = term.redirect(redir)
|
originalTerm = term.redirect(redir)
|
||||||
|
|
||||||
--run the game routine once
|
--run the game routine once
|
||||||
coroutine.resume(gameRoutine)
|
coroutine.resume(gameRoutine)
|
||||||
--hide cursor
|
--hide cursor
|
||||||
term.setCursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local e,p1,p2,p3,p4,p5=os.pullEventRaw()
|
local e,p1,p2,p3,p4,p5=os.pullEventRaw()
|
||||||
if e=="terminate" then
|
if e=="terminate" then
|
||||||
@ -791,7 +791,7 @@ while true do
|
|||||||
opponentReady=true
|
opponentReady=true
|
||||||
os.queueEvent("kickcoroutine")
|
os.queueEvent("kickcoroutine")
|
||||||
elseif cmd=="cointoss" then
|
elseif cmd=="cointoss" then
|
||||||
myTurn=args=="true"
|
myTurn=args=="true"
|
||||||
if myTurn then
|
if myTurn then
|
||||||
setStatusLine(2,"Your turn, take your shot!")
|
setStatusLine(2,"Your turn, take your shot!")
|
||||||
else
|
else
|
||||||
@ -807,11 +807,11 @@ while true do
|
|||||||
local tile=myGrid[tx][ty]
|
local tile=myGrid[tx][ty]
|
||||||
local shot=makeShot(tx,ty,myGrid)
|
local shot=makeShot(tx,ty,myGrid)
|
||||||
rednet.send(opponentID,"bs result "..(shot[3] and "hit" or "miss"))
|
rednet.send(opponentID,"bs result "..(shot[3] and "hit" or "miss"))
|
||||||
drawTile(2+tx,3+ty,tile)
|
drawTile(2+tx,3+ty,tile)
|
||||||
myTurn=true
|
myTurn=true
|
||||||
os.queueEvent("kickcoroutine")
|
os.queueEvent("kickcoroutine")
|
||||||
displayGameHelp()
|
displayGameHelp()
|
||||||
setStatusLine(1,opponent.." fired at "..toGridRef(tx,ty).." and "..(shot[3] and "hit" or "missed"))
|
setStatusLine(1,opponent.." fired at "..toGridRef(tx,ty).." and "..(shot[3] and "hit" or "missed"))
|
||||||
setStatusLine(2,"Your turn, take your shot!")
|
setStatusLine(2,"Your turn, take your shot!")
|
||||||
end
|
end
|
||||||
elseif cmd=="sink" then
|
elseif cmd=="sink" then
|
||||||
@ -838,7 +838,7 @@ while true do
|
|||||||
setStatusLine(2,"Waiting for opponent...")
|
setStatusLine(2,"Waiting for opponent...")
|
||||||
os.queueEvent("kickcoroutine")
|
os.queueEvent("kickcoroutine")
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif cmd=="win" then
|
elseif cmd=="win" then
|
||||||
--we won!
|
--we won!
|
||||||
setStatusLine(3,"You won the game! Congratulations!")
|
setStatusLine(3,"You won the game! Congratulations!")
|
||||||
@ -852,24 +852,24 @@ while true do
|
|||||||
print("game coroutine crashed with the following error: "..err)
|
print("game coroutine crashed with the following error: "..err)
|
||||||
quit()
|
quit()
|
||||||
end
|
end
|
||||||
|
|
||||||
if coroutine.status(gameRoutine)=="dead" then
|
if coroutine.status(gameRoutine)=="dead" then
|
||||||
--game over
|
--game over
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setCursorPos(1,19)
|
term.setCursorPos(1,19)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
term.write(" Press any key to continue...")
|
term.write(" Press any key to continue...")
|
||||||
os.pullEvent("key")
|
os.pullEvent("key")
|
||||||
--if a char event was queued following the key event, this will eat it
|
--if a char event was queued following the key event, this will eat it
|
||||||
os.sleep(0)
|
os.sleep(0)
|
||||||
|
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
term.clear()
|
term.clear()
|
||||||
quit()
|
quit()
|
||||||
--
|
--
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Lua IDE
|
-- Lua IDE
|
||||||
-- Made by GravityScore
|
-- Made by GravityScore
|
||||||
--
|
--
|
||||||
|
|
||||||
|
|
||||||
-- -------- Variables
|
-- -------- Variables
|
||||||
@ -44,7 +44,7 @@ local function isAdvanced() return term.isColor and term.isColor() end
|
|||||||
|
|
||||||
local function modRead(properties)
|
local function modRead(properties)
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil,
|
local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil,
|
||||||
liveUpdates = nil, exitOnKey = nil}
|
liveUpdates = nil, exitOnKey = nil}
|
||||||
if not properties then properties = {} end
|
if not properties then properties = {} end
|
||||||
for k, v in pairs(defaults) do if not properties[k] then properties[k] = v end end
|
for k, v in pairs(defaults) do if not properties[k] then properties[k] = v end end
|
||||||
@ -58,7 +58,7 @@ local function modRead(properties)
|
|||||||
|
|
||||||
local function redraw(repl)
|
local function redraw(repl)
|
||||||
local scroll = 0
|
local scroll = 0
|
||||||
if properties.visibleLength and sx + pos > properties.visibleLength + 1 then
|
if properties.visibleLength and sx + pos > properties.visibleLength + 1 then
|
||||||
scroll = (sx + pos) - (properties.visibleLength + 1)
|
scroll = (sx + pos) - (properties.visibleLength + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -133,9 +133,9 @@ local function modRead(properties)
|
|||||||
elseif (but == keys.up or but == keys.down) and properties.history then
|
elseif (but == keys.up or but == keys.down) and properties.history then
|
||||||
redraw(" ")
|
redraw(" ")
|
||||||
if but == keys.up then
|
if but == keys.up then
|
||||||
if historyPos == nil and #properties.history > 0 then
|
if historyPos == nil and #properties.history > 0 then
|
||||||
historyPos = #properties.history
|
historyPos = #properties.history
|
||||||
elseif historyPos > 1 then
|
elseif historyPos > 1 then
|
||||||
historyPos = historyPos - 1
|
historyPos = historyPos - 1
|
||||||
end
|
end
|
||||||
elseif but == keys.down then
|
elseif but == keys.down then
|
||||||
@ -173,9 +173,9 @@ local function modRead(properties)
|
|||||||
elseif but == keys["end"] then
|
elseif but == keys["end"] then
|
||||||
pos = line:len()
|
pos = line:len()
|
||||||
redraw()
|
redraw()
|
||||||
elseif properties.exitOnKey then
|
elseif properties.exitOnKey then
|
||||||
if but == properties.exitOnKey or (properties.exitOnKey == "control" and
|
if but == properties.exitOnKey or (properties.exitOnKey == "control" and
|
||||||
(but == 29 or but == 157)) then
|
(but == 29 or but == 157)) then
|
||||||
term.setCursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -296,7 +296,7 @@ end
|
|||||||
|
|
||||||
local function centerRead(wid, begt)
|
local function centerRead(wid, begt)
|
||||||
local function liveUpdate(line, e, but, x, y, p4, p5)
|
local function liveUpdate(line, e, but, x, y, p4, p5)
|
||||||
if isAdvanced() and e == "mouse_click" and x >= w/2 - wid/2 and x <= w/2 - wid/2 + 10
|
if isAdvanced() and e == "mouse_click" and x >= w/2 - wid/2 and x <= w/2 - wid/2 + 10
|
||||||
and y >= 13 and y <= 15 then
|
and y >= 13 and y <= 15 then
|
||||||
return true, ""
|
return true, ""
|
||||||
end
|
end
|
||||||
@ -707,7 +707,7 @@ languages.brainfuck.mapLoops = function(code)
|
|||||||
loopLocations[loc] = true
|
loopLocations[loc] = true
|
||||||
elseif let == "]" then
|
elseif let == "]" then
|
||||||
local found = false
|
local found = false
|
||||||
for i = loc, 1, -1 do
|
for i = loc, 1, -1 do
|
||||||
if loopLocations[i] == true then
|
if loopLocations[i] == true then
|
||||||
loopLocations[i] = loc
|
loopLocations[i] = loc
|
||||||
found = true
|
found = true
|
||||||
@ -877,7 +877,7 @@ local function run(path, lines, useArgs)
|
|||||||
local s = centerRead(w - 13, fs.getName(path) .. " ")
|
local s = centerRead(w - 13, fs.getName(path) .. " ")
|
||||||
for m in string.gmatch(s, "[^ \t]+") do ar[#ar + 1] = m:gsub("^%s*(.-)%s*$", "%1") end
|
for m in string.gmatch(s, "[^ \t]+") do ar[#ar + 1] = m:gsub("^%s*(.-)%s*$", "%1") end
|
||||||
end
|
end
|
||||||
|
|
||||||
saveFile(path, lines)
|
saveFile(path, lines)
|
||||||
term.setCursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
@ -949,7 +949,7 @@ local function run(path, lines, useArgs)
|
|||||||
term.setCursorPos(5, 14)
|
term.setCursorPos(5, 14)
|
||||||
term.write(b)
|
term.write(b)
|
||||||
end
|
end
|
||||||
|
|
||||||
local opt = prompt({{"Error Help", w/2 - 15, 17}, {"Go To Line", w/2 + 2, 17}},
|
local opt = prompt({{"Error Help", w/2 - 15, 17}, {"Go To Line", w/2 + 2, 17}},
|
||||||
"horizontal")
|
"horizontal")
|
||||||
if opt == "Error Help" then
|
if opt == "Error Help" then
|
||||||
@ -1459,7 +1459,7 @@ end
|
|||||||
|
|
||||||
local function writeHighlighted(line)
|
local function writeHighlighted(line)
|
||||||
if curLanguage == languages.lua then
|
if curLanguage == languages.lua then
|
||||||
while line:len() > 0 do
|
while line:len() > 0 do
|
||||||
line = attemptToHighlight(line, "^%-%-%[%[.-%]%]", colors[theme.comment]) or
|
line = attemptToHighlight(line, "^%-%-%[%[.-%]%]", colors[theme.comment]) or
|
||||||
attemptToHighlight(line, "^%-%-.*", colors[theme.comment]) or
|
attemptToHighlight(line, "^%-%-.*", colors[theme.comment]) or
|
||||||
attemptToHighlight(line, "^\".*[^\\]\"", colors[theme.string]) or
|
attemptToHighlight(line, "^\".*[^\\]\"", colors[theme.string]) or
|
||||||
@ -1491,7 +1491,7 @@ local function draw()
|
|||||||
for i = 1, edh do
|
for i = 1, edh do
|
||||||
local a = lines[scrolly + i]
|
local a = lines[scrolly + i]
|
||||||
if a then
|
if a then
|
||||||
local ln = string.rep(" ", offx - 1 - tostring(scrolly + i):len()) .. tostring(scrolly + i)
|
local ln = string.rep(" ", offx - 1 - tostring(scrolly + i):len()) .. tostring(scrolly + i)
|
||||||
local l = a:sub(scrollx + 1, edw + scrollx + 1)
|
local l = a:sub(scrollx + 1, edw + scrollx + 1)
|
||||||
ln = ln .. ":"
|
ln = ln .. ":"
|
||||||
|
|
||||||
@ -1541,7 +1541,7 @@ local function drawLine(...)
|
|||||||
for _, ly in pairs(ls) do
|
for _, ly in pairs(ls) do
|
||||||
local a = lines[ly]
|
local a = lines[ly]
|
||||||
if a then
|
if a then
|
||||||
local ln = string.rep(" ", offx - 1 - tostring(ly):len()) .. tostring(ly)
|
local ln = string.rep(" ", offx - 1 - tostring(ly):len()) .. tostring(ly)
|
||||||
local l = a:sub(scrollx + 1, edw + scrollx + 1)
|
local l = a:sub(scrollx + 1, edw + scrollx + 1)
|
||||||
ln = ln .. ":"
|
ln = ln .. ":"
|
||||||
|
|
||||||
@ -1651,7 +1651,7 @@ local function edit(path)
|
|||||||
draw()
|
draw()
|
||||||
term.setCursorPos(x + offx, y + offy)
|
term.setCursorPos(x + offx, y + offy)
|
||||||
term.setCursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
|
|
||||||
-- Main loop
|
-- Main loop
|
||||||
local tid = os.startTimer(3)
|
local tid = os.startTimer(3)
|
||||||
while true do
|
while true do
|
||||||
@ -1692,8 +1692,8 @@ local function edit(path)
|
|||||||
if f then
|
if f then
|
||||||
table.insert(lines, y + 1, string.rep(" ", spaces + 2))
|
table.insert(lines, y + 1, string.rep(" ", spaces + 2))
|
||||||
if not f:find("else", 1, true) and not f:find("elseif", 1, true) then
|
if not f:find("else", 1, true) and not f:find("elseif", 1, true) then
|
||||||
table.insert(lines, y + 2, string.rep(" ", spaces) ..
|
table.insert(lines, y + 2, string.rep(" ", spaces) ..
|
||||||
(f:find("repeat", 1, true) and "until " or f:find("{", 1, true) and "}" or
|
(f:find("repeat", 1, true) and "until " or f:find("{", 1, true) and "}" or
|
||||||
"end"))
|
"end"))
|
||||||
end
|
end
|
||||||
x, y = spaces + 3, y + 1
|
x, y = spaces + 3, y + 1
|
||||||
@ -1771,7 +1771,7 @@ local function edit(path)
|
|||||||
x = math.min(lines[y]:len() + 1, x)
|
x = math.min(lines[y]:len() + 1, x)
|
||||||
cursorLoc(x, y, true)
|
cursorLoc(x, y, true)
|
||||||
end
|
end
|
||||||
elseif e == "char" and allowEditorEvent and (displayCode and true or
|
elseif e == "char" and allowEditorEvent and (displayCode and true or
|
||||||
y + scrolly - 1 == liveErr.line) then
|
y + scrolly - 1 == liveErr.line) then
|
||||||
local shouldIgnore = false
|
local shouldIgnore = false
|
||||||
for k, v in pairs(liveCompletions) do
|
for k, v in pairs(liveCompletions) do
|
||||||
@ -2083,7 +2083,7 @@ local function changeTheme()
|
|||||||
sleep(1.6)
|
sleep(1.6)
|
||||||
return "menu"
|
return "menu"
|
||||||
end
|
end
|
||||||
|
|
||||||
term.write("LuaIDE - Could Not Load Theme!")
|
term.write("LuaIDE - Could Not Load Theme!")
|
||||||
fs.delete("/.LuaIDE_temp_theme_file")
|
fs.delete("/.LuaIDE_temp_theme_file")
|
||||||
sleep(1.6)
|
sleep(1.6)
|
||||||
@ -2100,7 +2100,7 @@ local function settings()
|
|||||||
title("LuaIDE - Settings")
|
title("LuaIDE - Settings")
|
||||||
|
|
||||||
local opt = prompt({{"Change Theme", w/2 - 17, 8}, {"Return to Menu", w/2 - 19, 13},
|
local opt = prompt({{"Change Theme", w/2 - 17, 8}, {"Return to Menu", w/2 - 19, 13},
|
||||||
--[[{"Check for Updates", w/2 + 2, 8},]] {"Exit IDE", w/2 + 2, 13, bg = colors[theme.err],
|
--[[{"Check for Updates", w/2 + 2, 8},]] {"Exit IDE", w/2 + 2, 13, bg = colors[theme.err],
|
||||||
highlight = colors[theme.errHighlight]}}, "vertical", true)
|
highlight = colors[theme.errHighlight]}}, "vertical", true)
|
||||||
if opt == "Change Theme" then return changeTheme()
|
if opt == "Change Theme" then return changeTheme()
|
||||||
-- elseif opt == "Check for Updates" then return update()
|
-- elseif opt == "Check for Updates" then return update()
|
||||||
@ -2189,7 +2189,7 @@ if err and not err:find("Terminated") then
|
|||||||
term.write("Please report this error to")
|
term.write("Please report this error to")
|
||||||
term.setCursorPos(6, cy + 3)
|
term.setCursorPos(6, cy + 3)
|
||||||
term.write("GravityScore! ")
|
term.write("GravityScore! ")
|
||||||
|
|
||||||
term.setBackgroundColor(colors[theme.background])
|
term.setBackgroundColor(colors[theme.background])
|
||||||
if isAdvanced() then centerPrint("Click to Exit...", h - 1)
|
if isAdvanced() then centerPrint("Click to Exit...", h - 1)
|
||||||
else centerPrint("Press Any Key to Exit...", h - 1) end
|
else centerPrint("Press Any Key to Exit...", h - 1) end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
--[[
|
--[[
|
||||||
Project info:
|
Project info:
|
||||||
|
|
||||||
Name: Maze
|
Name: Maze
|
||||||
Creator: Jesusthekiller
|
Creator: Jesusthekiller
|
||||||
Language: Lua (CC)
|
Language: Lua (CC)
|
||||||
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
--[[
|
--[[
|
||||||
LICENSE:
|
LICENSE:
|
||||||
|
|
||||||
Maze
|
Maze
|
||||||
Copyright (c) 2013 Jesusthekiller
|
Copyright (c) 2013 Jesusthekiller
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ repeat
|
|||||||
|
|
||||||
cwrite("Enter maze size (5-99):")
|
cwrite("Enter maze size (5-99):")
|
||||||
size = read()
|
size = read()
|
||||||
|
|
||||||
size = tonumber(size)
|
size = tonumber(size)
|
||||||
if not size then
|
if not size then
|
||||||
size = 0
|
size = 0
|
||||||
@ -82,18 +82,18 @@ until size > 4 and size < 100
|
|||||||
|
|
||||||
-- The generate
|
-- The generate
|
||||||
local function mazeGen(mx, my)
|
local function mazeGen(mx, my)
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Format:
|
Format:
|
||||||
|
|
||||||
maze.x.y.(1/2/3/4) = true/false
|
maze.x.y.(1/2/3/4) = true/false
|
||||||
|
|
||||||
1 - top
|
1 - top
|
||||||
2 - bottom
|
2 - bottom
|
||||||
3 - right
|
3 - right
|
||||||
4 - left
|
4 - left
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
local maze = {}
|
local maze = {}
|
||||||
for i = 1, mx do
|
for i = 1, mx do
|
||||||
maze[i] = {}
|
maze[i] = {}
|
||||||
@ -116,26 +116,26 @@ local function mazeGen(mx, my)
|
|||||||
local intact = {}
|
local intact = {}
|
||||||
local x = curr.x
|
local x = curr.x
|
||||||
local y = curr.y
|
local y = curr.y
|
||||||
|
|
||||||
if x - 1 >= 1 and maze[x-1][y][1] and maze[x-1][y][2] and maze[x-1][y][3] and maze[x-1][y][4] then -- Check for full cells
|
if x - 1 >= 1 and maze[x-1][y][1] and maze[x-1][y][2] and maze[x-1][y][3] and maze[x-1][y][4] then -- Check for full cells
|
||||||
intact[#intact+1] = {x-1, y, 1}
|
intact[#intact+1] = {x-1, y, 1}
|
||||||
end
|
end
|
||||||
|
|
||||||
if x + 1 <= mx and maze[x+1][y][1] and maze[x+1][y][2] and maze[x+1][y][3] and maze[x+1][y][4] then
|
if x + 1 <= mx and maze[x+1][y][1] and maze[x+1][y][2] and maze[x+1][y][3] and maze[x+1][y][4] then
|
||||||
intact[#intact+1] = {x+1, y, 2}
|
intact[#intact+1] = {x+1, y, 2}
|
||||||
end
|
end
|
||||||
|
|
||||||
if y + 1 <= my and maze[x][y+1][1] and maze[x][y+1][2] and maze[x][y+1][3] and maze[x][y+1][4] then
|
if y + 1 <= my and maze[x][y+1][1] and maze[x][y+1][2] and maze[x][y+1][3] and maze[x][y+1][4] then
|
||||||
intact[#intact+1] = {x, y+1, 3}
|
intact[#intact+1] = {x, y+1, 3}
|
||||||
end
|
end
|
||||||
|
|
||||||
if y - 1 >= 1 and maze[x][y-1][1] and maze[x][y-1][2] and maze[x][y-1][3] and maze[x][y-1][4] then
|
if y - 1 >= 1 and maze[x][y-1][1] and maze[x][y-1][2] and maze[x][y-1][3] and maze[x][y-1][4] then
|
||||||
intact[#intact+1] = {x, y-1, 4}
|
intact[#intact+1] = {x, y-1, 4}
|
||||||
end
|
end
|
||||||
|
|
||||||
if #intact > 0 then
|
if #intact > 0 then
|
||||||
local i = math.random(1, #intact) -- Choose random
|
local i = math.random(1, #intact) -- Choose random
|
||||||
|
|
||||||
if intact[i][3] == 1 then -- Set intact's attached wall to false
|
if intact[i][3] == 1 then -- Set intact's attached wall to false
|
||||||
maze[intact[i][1]][intact[i][2]][2] = false
|
maze[intact[i][1]][intact[i][2]][2] = false
|
||||||
elseif intact[i][3] == 2 then
|
elseif intact[i][3] == 2 then
|
||||||
@ -145,11 +145,11 @@ local function mazeGen(mx, my)
|
|||||||
elseif intact[i][3] == 4 then
|
elseif intact[i][3] == 4 then
|
||||||
maze[intact[i][1]][intact[i][2]][3] = false
|
maze[intact[i][1]][intact[i][2]][3] = false
|
||||||
end
|
end
|
||||||
|
|
||||||
maze[x][y][intact[i][3]] = false -- Set attached wall to false
|
maze[x][y][intact[i][3]] = false -- Set attached wall to false
|
||||||
|
|
||||||
vis = vis + 1 -- Increase vis
|
vis = vis + 1 -- Increase vis
|
||||||
|
|
||||||
stack[#stack+1] = intact[i] -- Add to stack
|
stack[#stack+1] = intact[i] -- Add to stack
|
||||||
else
|
else
|
||||||
local tmp = table.remove(stack) -- Get last cell
|
local tmp = table.remove(stack) -- Get last cell
|
||||||
@ -157,7 +157,7 @@ local function mazeGen(mx, my)
|
|||||||
curr.y = tmp[2]
|
curr.y = tmp[2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return maze
|
return maze
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ local tab = {}
|
|||||||
|
|
||||||
for x = 1, size * 2 + 1 do
|
for x = 1, size * 2 + 1 do
|
||||||
tab[x] = {}
|
tab[x] = {}
|
||||||
|
|
||||||
for y = 1, size * 2 + 1 do
|
for y = 1, size * 2 + 1 do
|
||||||
if x % 2 == 0 and y % 2 == 0 then -- Fill cells (empty)
|
if x % 2 == 0 and y % 2 == 0 then -- Fill cells (empty)
|
||||||
tab[x][y] = false
|
tab[x][y] = false
|
||||||
@ -201,7 +201,7 @@ repeat
|
|||||||
-- Print map
|
-- Print map
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
term.clear()
|
term.clear()
|
||||||
|
|
||||||
if posx == 2 and posy == 2 then
|
if posx == 2 and posy == 2 then
|
||||||
term.setCursorPos(1, 1)
|
term.setCursorPos(1, 1)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
@ -211,27 +211,27 @@ repeat
|
|||||||
print("Goal: Step on # (It's on bottom right corner)")
|
print("Goal: Step on # (It's on bottom right corner)")
|
||||||
print("\nGood Luck!")
|
print("\nGood Luck!")
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.setCursorPos(1, 19)
|
term.setCursorPos(1, 19)
|
||||||
write("X: "..posx.." Y: "..posy)
|
write("X: "..posx.." Y: "..posy)
|
||||||
]]
|
]]
|
||||||
|
|
||||||
for x, tV in ipairs(tab) do -- Print the map
|
for x, tV in ipairs(tab) do -- Print the map
|
||||||
for y, v in ipairs(tV) do
|
for y, v in ipairs(tV) do
|
||||||
if offsety+y > 20 then
|
if offsety+y > 20 then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setCursorPos(offsetx+x, offsety+y)
|
term.setCursorPos(offsetx+x, offsety+y)
|
||||||
|
|
||||||
if v then
|
if v then
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
else
|
else
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
end
|
end
|
||||||
|
|
||||||
if offsety+y < 20 and offsety+y > 0 and offsetx+x < 52 and offsetx+x > 0 then
|
if offsety+y < 20 and offsety+y > 0 and offsetx+x < 52 and offsetx+x > 0 then
|
||||||
if x == size*2 and y == size*2 then
|
if x == size*2 and y == size*2 then
|
||||||
if term.isColor() then
|
if term.isColor() then
|
||||||
@ -243,51 +243,51 @@ repeat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if offsetx+x > 51 then
|
if offsetx+x > 51 then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setCursorPos(51/2, 19/2)
|
term.setCursorPos(51/2, 19/2)
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
|
|
||||||
if term.isColor() then
|
if term.isColor() then
|
||||||
term.setTextColor(colors.red)
|
term.setTextColor(colors.red)
|
||||||
else
|
else
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
end
|
end
|
||||||
|
|
||||||
write("X")
|
write("X")
|
||||||
|
|
||||||
-- Wait for key
|
-- Wait for key
|
||||||
|
|
||||||
local e, k = os.pullEvent("char")
|
local e, k = os.pullEvent("char")
|
||||||
|
|
||||||
if k == "a" and (not tab[posx-1][posy]) then
|
if k == "a" and (not tab[posx-1][posy]) then
|
||||||
posx = posx - 1
|
posx = posx - 1
|
||||||
offsetx = offsetx + 1
|
offsetx = offsetx + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if k == "d" and (not tab[posx+1][posy]) then
|
if k == "d" and (not tab[posx+1][posy]) then
|
||||||
posx = posx + 1
|
posx = posx + 1
|
||||||
offsetx = offsetx - 1
|
offsetx = offsetx - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if k == "w" and (not tab[posx][posy-1]) then
|
if k == "w" and (not tab[posx][posy-1]) then
|
||||||
posy = posy - 1
|
posy = posy - 1
|
||||||
offsety = offsety + 1
|
offsety = offsety + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if k == "s" and (not tab[posx][posy+1]) then
|
if k == "s" and (not tab[posx][posy+1]) then
|
||||||
posy = posy + 1
|
posy = posy + 1
|
||||||
offsety = offsety - 1
|
offsety = offsety - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if k == "q" then
|
if k == "q" then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
if k == "r" then
|
if k == "r" then
|
||||||
posx = 2
|
posx = 2
|
||||||
posy = 2
|
posy = 2
|
||||||
@ -324,4 +324,4 @@ term.setBackgroundColor(colors.black)
|
|||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1, 1)
|
term.setCursorPos(1, 1)
|
||||||
cprint(" Maze by JTK. Thanks for playing!")
|
cprint(" Maze by JTK. Thanks for playing!")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
--[[
|
--[[
|
||||||
Project info:
|
Project info:
|
||||||
|
|
||||||
Name: Maze 3D
|
Name: Maze 3D
|
||||||
Creator: Jesusthekiller
|
Creator: Jesusthekiller
|
||||||
Language: Lua (CC)
|
Language: Lua (CC)
|
||||||
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
--[[
|
--[[
|
||||||
LICENSE:
|
LICENSE:
|
||||||
|
|
||||||
Maze 3D
|
Maze 3D
|
||||||
Copyright (c) 2013 Jesusthekiller
|
Copyright (c) 2013 Jesusthekiller
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ repeat
|
|||||||
|
|
||||||
cwrite("Enter maze size (5-99):")
|
cwrite("Enter maze size (5-99):")
|
||||||
size = read()
|
size = read()
|
||||||
|
|
||||||
size = tonumber(size)
|
size = tonumber(size)
|
||||||
if not size then
|
if not size then
|
||||||
size = 0
|
size = 0
|
||||||
@ -87,18 +87,18 @@ until size > 4 and size < 100
|
|||||||
|
|
||||||
-- The generate
|
-- The generate
|
||||||
local function mazeGen(mx, my)
|
local function mazeGen(mx, my)
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Format:
|
Format:
|
||||||
|
|
||||||
maze.x.y.(1/2/3/4) = true/false
|
maze.x.y.(1/2/3/4) = true/false
|
||||||
|
|
||||||
1 - top
|
1 - top
|
||||||
2 - bottom
|
2 - bottom
|
||||||
3 - right
|
3 - right
|
||||||
4 - left
|
4 - left
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
local maze = {}
|
local maze = {}
|
||||||
for i = 1, mx do
|
for i = 1, mx do
|
||||||
maze[i] = {}
|
maze[i] = {}
|
||||||
@ -121,26 +121,26 @@ local function mazeGen(mx, my)
|
|||||||
local intact = {}
|
local intact = {}
|
||||||
local x = curr.x
|
local x = curr.x
|
||||||
local y = curr.y
|
local y = curr.y
|
||||||
|
|
||||||
if x - 1 >= 1 and maze[x-1][y][1] and maze[x-1][y][2] and maze[x-1][y][3] and maze[x-1][y][4] then -- Check for full cells
|
if x - 1 >= 1 and maze[x-1][y][1] and maze[x-1][y][2] and maze[x-1][y][3] and maze[x-1][y][4] then -- Check for full cells
|
||||||
intact[#intact+1] = {x-1, y, 1}
|
intact[#intact+1] = {x-1, y, 1}
|
||||||
end
|
end
|
||||||
|
|
||||||
if x + 1 <= mx and maze[x+1][y][1] and maze[x+1][y][2] and maze[x+1][y][3] and maze[x+1][y][4] then
|
if x + 1 <= mx and maze[x+1][y][1] and maze[x+1][y][2] and maze[x+1][y][3] and maze[x+1][y][4] then
|
||||||
intact[#intact+1] = {x+1, y, 2}
|
intact[#intact+1] = {x+1, y, 2}
|
||||||
end
|
end
|
||||||
|
|
||||||
if y + 1 <= my and maze[x][y+1][1] and maze[x][y+1][2] and maze[x][y+1][3] and maze[x][y+1][4] then
|
if y + 1 <= my and maze[x][y+1][1] and maze[x][y+1][2] and maze[x][y+1][3] and maze[x][y+1][4] then
|
||||||
intact[#intact+1] = {x, y+1, 3}
|
intact[#intact+1] = {x, y+1, 3}
|
||||||
end
|
end
|
||||||
|
|
||||||
if y - 1 >= 1 and maze[x][y-1][1] and maze[x][y-1][2] and maze[x][y-1][3] and maze[x][y-1][4] then
|
if y - 1 >= 1 and maze[x][y-1][1] and maze[x][y-1][2] and maze[x][y-1][3] and maze[x][y-1][4] then
|
||||||
intact[#intact+1] = {x, y-1, 4}
|
intact[#intact+1] = {x, y-1, 4}
|
||||||
end
|
end
|
||||||
|
|
||||||
if #intact > 0 then
|
if #intact > 0 then
|
||||||
local i = math.random(1, #intact) -- Choose random
|
local i = math.random(1, #intact) -- Choose random
|
||||||
|
|
||||||
if intact[i][3] == 1 then -- Set intact's attached wall to false
|
if intact[i][3] == 1 then -- Set intact's attached wall to false
|
||||||
maze[intact[i][1]][intact[i][2]][2] = false
|
maze[intact[i][1]][intact[i][2]][2] = false
|
||||||
elseif intact[i][3] == 2 then
|
elseif intact[i][3] == 2 then
|
||||||
@ -150,11 +150,11 @@ local function mazeGen(mx, my)
|
|||||||
elseif intact[i][3] == 4 then
|
elseif intact[i][3] == 4 then
|
||||||
maze[intact[i][1]][intact[i][2]][3] = false
|
maze[intact[i][1]][intact[i][2]][3] = false
|
||||||
end
|
end
|
||||||
|
|
||||||
maze[x][y][intact[i][3]] = false -- Set attached wall to false
|
maze[x][y][intact[i][3]] = false -- Set attached wall to false
|
||||||
|
|
||||||
vis = vis + 1 -- Increase vis
|
vis = vis + 1 -- Increase vis
|
||||||
|
|
||||||
stack[#stack+1] = intact[i] -- Add to stack
|
stack[#stack+1] = intact[i] -- Add to stack
|
||||||
else
|
else
|
||||||
local tmp = table.remove(stack) -- Get last cell
|
local tmp = table.remove(stack) -- Get last cell
|
||||||
@ -162,7 +162,7 @@ local function mazeGen(mx, my)
|
|||||||
curr.y = tmp[2]
|
curr.y = tmp[2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return maze
|
return maze
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ local tab = {}
|
|||||||
|
|
||||||
for x = 1, size * 2 + 1 do
|
for x = 1, size * 2 + 1 do
|
||||||
tab[x] = {}
|
tab[x] = {}
|
||||||
|
|
||||||
for y = 1, size * 2 + 1 do
|
for y = 1, size * 2 + 1 do
|
||||||
if x % 2 == 0 and y % 2 == 0 then -- Fill cells (empty)
|
if x % 2 == 0 and y % 2 == 0 then -- Fill cells (empty)
|
||||||
tab[x][y] = " "
|
tab[x][y] = " "
|
||||||
@ -263,13 +263,13 @@ if redirect then
|
|||||||
print("redirect API found, using buffer")
|
print("redirect API found, using buffer")
|
||||||
else
|
else
|
||||||
local pe=printError
|
local pe=printError
|
||||||
rawset(_G,"printError",error)
|
rawset(_G,"printError",error)
|
||||||
local ok, err=pcall(os.loadAPI,"redirect")
|
local ok, err=pcall(os.loadAPI,"redirect")
|
||||||
if not ok then
|
if not ok then
|
||||||
print("trying "..shell.dir().."/redirect")
|
print("trying "..shell.dir().."/redirect")
|
||||||
ok,err=pcall(os.loadAPI,shell.dir().."/redirect")
|
ok,err=pcall(os.loadAPI,shell.dir().."/redirect")
|
||||||
end
|
end
|
||||||
if ok then
|
if ok then
|
||||||
print("Loaded redirect API, using buffer")
|
print("Loaded redirect API, using buffer")
|
||||||
buffer=redirect.createRedirectBuffer()
|
buffer=redirect.createRedirectBuffer()
|
||||||
loadedAPI=true
|
loadedAPI=true
|
||||||
@ -277,7 +277,7 @@ else
|
|||||||
print("redirect API not found or could not be loaded, drawing directly; this may cause flickering.")
|
print("redirect API not found or could not be loaded, drawing directly; this may cause flickering.")
|
||||||
end
|
end
|
||||||
rawset(_G,"printError",pe)
|
rawset(_G,"printError",pe)
|
||||||
end
|
end
|
||||||
|
|
||||||
local colorSchemes = {
|
local colorSchemes = {
|
||||||
{0,8}, --white+gray
|
{0,8}, --white+gray
|
||||||
@ -338,10 +338,10 @@ local function cast(cx,cy,angle)
|
|||||||
end
|
end
|
||||||
local wall=map[y]:sub(x,x)
|
local wall=map[y]:sub(x,x)
|
||||||
if wall~=" " then
|
if wall~=" " then
|
||||||
|
|
||||||
return colorSchemes[tonumber(wall)][isX and 1 or 2], hitD
|
return colorSchemes[tonumber(wall)][isX and 1 or 2], hitD
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local w,h=term.getSize()
|
local w,h=term.getSize()
|
||||||
@ -370,7 +370,7 @@ for x=1,w do
|
|||||||
t.angle=math.atan2(x-centerX,screenDist)
|
t.angle=math.atan2(x-centerX,screenDist)
|
||||||
t.dist=((x-centerX)^2+screenDist^2)^.5/screenDist
|
t.dist=((x-centerX)^2+screenDist^2)^.5/screenDist
|
||||||
end
|
end
|
||||||
|
|
||||||
local function redraw()
|
local function redraw()
|
||||||
local oldTerm
|
local oldTerm
|
||||||
if buffer.isBuffer then
|
if buffer.isBuffer then
|
||||||
@ -411,15 +411,15 @@ local function clampCollision(x,y,radius)
|
|||||||
--I am. Complete fail, do nothing.
|
--I am. Complete fail, do nothing.
|
||||||
return x,y
|
return x,y
|
||||||
end
|
end
|
||||||
|
|
||||||
--ok, check the neighbors.
|
--ok, check the neighbors.
|
||||||
local right=math.floor(x+radius)>gx
|
local right=math.floor(x+radius)>gx
|
||||||
local left=math.floor(x-radius)<gx
|
local left=math.floor(x-radius)<gx
|
||||||
local front=math.floor(y-radius)<gy
|
local front=math.floor(y-radius)<gy
|
||||||
local back=math.floor(y+radius)>gy
|
local back=math.floor(y+radius)>gy
|
||||||
|
|
||||||
local pushed=false
|
local pushed=false
|
||||||
|
|
||||||
if right and map[gy]:sub(gx+1,gx+1)~=" " then
|
if right and map[gy]:sub(gx+1,gx+1)~=" " then
|
||||||
--push left
|
--push left
|
||||||
pushed=true
|
pushed=true
|
||||||
@ -429,7 +429,7 @@ local function clampCollision(x,y,radius)
|
|||||||
pushed=true
|
pushed=true
|
||||||
x=gx+radius
|
x=gx+radius
|
||||||
end
|
end
|
||||||
|
|
||||||
if front and map[gy-1]:sub(gx,gx)~=" " then
|
if front and map[gy-1]:sub(gx,gx)~=" " then
|
||||||
--push back
|
--push back
|
||||||
pushed=true
|
pushed=true
|
||||||
@ -442,7 +442,7 @@ local function clampCollision(x,y,radius)
|
|||||||
|
|
||||||
y=gy+1-radius
|
y=gy+1-radius
|
||||||
end
|
end
|
||||||
|
|
||||||
--if I wasn't pushed out on any side, I might be hitting a corner
|
--if I wasn't pushed out on any side, I might be hitting a corner
|
||||||
if not pushed then
|
if not pushed then
|
||||||
--square rad
|
--square rad
|
||||||
@ -482,7 +482,7 @@ local function clampCollision(x,y,radius)
|
|||||||
x=x+pushx
|
x=x+pushx
|
||||||
y=y+pushy
|
y=y+pushy
|
||||||
end
|
end
|
||||||
|
|
||||||
return x,y
|
return x,y
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -533,7 +533,7 @@ while true do
|
|||||||
redraw()
|
redraw()
|
||||||
dirty=false
|
dirty=false
|
||||||
end
|
end
|
||||||
|
|
||||||
local e={os.pullEvent()}
|
local e={os.pullEvent()}
|
||||||
if e[1]=="key" then
|
if e[1]=="key" then
|
||||||
if e[2]==keys.left then
|
if e[2]==keys.left then
|
||||||
@ -565,7 +565,7 @@ while true do
|
|||||||
dir=startdir
|
dir=startdir
|
||||||
dirty=true
|
dirty=true
|
||||||
end
|
end
|
||||||
|
|
||||||
if px >= mapW-1 and py >= mapH-1 then
|
if px >= mapW-1 and py >= mapH-1 then
|
||||||
win = true
|
win = true
|
||||||
break
|
break
|
||||||
|
@ -23,4 +23,4 @@ if fs.exists(args[1]) then
|
|||||||
else
|
else
|
||||||
print("Client rejected file!")
|
print("Client rejected file!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -718,4 +718,4 @@ elseif #args >= 1 then --either no server running or we are the local shell on t
|
|||||||
else
|
else
|
||||||
print("Usage: nsh <serverID> [resume]")
|
print("Usage: nsh <serverID> [resume]")
|
||||||
print(" nsh host [remote [local [name]]]")
|
print(" nsh host [remote [local [name]]]")
|
||||||
end
|
end
|
||||||
|
@ -32,4 +32,4 @@ if message ~= "fileNotFound" then
|
|||||||
else
|
else
|
||||||
print("Empty file not written!")
|
print("Empty file not written!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -124,7 +124,7 @@ end
|
|||||||
local function getAIMove()
|
local function getAIMove()
|
||||||
-- make it seem like the computer actually has to think about its move
|
-- make it seem like the computer actually has to think about its move
|
||||||
sleep(0.8)
|
sleep(0.8)
|
||||||
|
|
||||||
-- check if AI can win and return the 3rd tile to create a win, if it cannot, check for a human attempt at winning and stop it, if there is none, return a random
|
-- check if AI can win and return the 3rd tile to create a win, if it cannot, check for a human attempt at winning and stop it, if there is none, return a random
|
||||||
return (search(currentPlayer) or search(opposites[currentPlayer])) or math.random(1,9)
|
return (search(currentPlayer) or search(opposites[currentPlayer])) or math.random(1,9)
|
||||||
end
|
end
|
||||||
@ -177,7 +177,7 @@ local function modread( _mask, _history, _limit )
|
|||||||
redraw(' ')
|
redraw(' ')
|
||||||
if event[2] == keys.up then
|
if event[2] == keys.up then
|
||||||
if not historyPos then
|
if not historyPos then
|
||||||
historyPos = #_history
|
historyPos = #_history
|
||||||
elseif historyPos > 1 then
|
elseif historyPos > 1 then
|
||||||
historyPos = historyPos - 1
|
historyPos = historyPos - 1
|
||||||
end
|
end
|
||||||
@ -308,14 +308,14 @@ local function render()
|
|||||||
writeAt('+'..string.rep('-', sw-2)..'+', 1, 3)
|
writeAt('+'..string.rep('-', sw-2)..'+', 1, 3)
|
||||||
writeAt('+'..string.rep('-', sw-2)..'+', 1, sh-2)
|
writeAt('+'..string.rep('-', sw-2)..'+', 1, sh-2)
|
||||||
writeAt('+'..string.rep('-', sw-2)..'+', 1, sh)
|
writeAt('+'..string.rep('-', sw-2)..'+', 1, sh)
|
||||||
|
|
||||||
if term.isColor and term.isColor() then
|
if term.isColor and term.isColor() then
|
||||||
term.setCursorPos(sw, 1)
|
term.setCursorPos(sw, 1)
|
||||||
term.setBackgroundColor(colors.red)
|
term.setBackgroundColor(colors.red)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
writeWithFormat('X')
|
writeWithFormat('X')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set our colours
|
-- set our colours
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
@ -359,7 +359,7 @@ local function render()
|
|||||||
writeAt((board[i + 6] == 'x' and '/\\' or '\\/'), 18+((i-1)*7), 14)
|
writeAt((board[i + 6] == 'x' and '/\\' or '\\/'), 18+((i-1)*7), 14)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw the current player
|
-- draw the current player
|
||||||
term.setCursorPos(3, sh - 3)
|
term.setCursorPos(3, sh - 3)
|
||||||
if not winner then
|
if not winner then
|
||||||
@ -441,4 +441,4 @@ cwriteWithFormat('&4Thank you for playing CCTicTacToe v1.0', 1)
|
|||||||
cwriteWithFormat('&4By &8TheOriginal&3BIT\n', 2)
|
cwriteWithFormat('&4By &8TheOriginal&3BIT\n', 2)
|
||||||
|
|
||||||
-- restore the default terminal object
|
-- restore the default terminal object
|
||||||
term.redirect( oldTermObj )
|
term.redirect( oldTermObj )
|
||||||
|
@ -22,7 +22,7 @@ while not bFinished do
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get this every frame incase the monitor resizes
|
-- Get this every frame incase the monitor resizes
|
||||||
local w,h = term.getSize()
|
local w,h = term.getSize()
|
||||||
local startX = math.floor( (w - 65) / 2 )
|
local startX = math.floor( (w - 65) / 2 )
|
||||||
local startY = math.floor( (h - 14) / 2 )
|
local startY = math.floor( (h - 14) / 2 )
|
||||||
|
@ -1 +1 @@
|
|||||||
print( "\"talk\" was removed in ComputerCraft 1.6, use the builtin \"chat\" program instead!" )
|
print( "\"talk\" was removed in ComputerCraft 1.6, use the builtin \"chat\" program instead!" )
|
||||||
|
@ -27,11 +27,11 @@ function initVariables()
|
|||||||
human6x = 85
|
human6x = 85
|
||||||
human6y = 18
|
human6y = 18
|
||||||
human1 = true
|
human1 = true
|
||||||
human2 = true
|
human2 = true
|
||||||
human3 = true
|
human3 = true
|
||||||
human4 = true
|
human4 = true
|
||||||
human5 = true
|
human5 = true
|
||||||
human6 = true
|
human6 = true
|
||||||
human1Abducted=false
|
human1Abducted=false
|
||||||
human2Abducted=false
|
human2Abducted=false
|
||||||
human3Abducted=false
|
human3Abducted=false
|
||||||
@ -245,7 +245,7 @@ function printScore()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function rewriteScores()
|
function rewriteScores()
|
||||||
if newScore > score1 then
|
if newScore > score1 then
|
||||||
name5=name4 score5=score4
|
name5=name4 score5=score4
|
||||||
name4=name3 score4=score3
|
name4=name3 score4=score3
|
||||||
name3=name2 score3=score2
|
name3=name2 score3=score2
|
||||||
@ -264,7 +264,7 @@ function rewriteScores()
|
|||||||
name5=name4 score5=score4
|
name5=name4 score5=score4
|
||||||
name4=newName score4=newScore
|
name4=newName score4=newScore
|
||||||
elseif newScore > score5 then
|
elseif newScore > score5 then
|
||||||
name5=newName score5=newScore
|
name5=newName score5=newScore
|
||||||
end
|
end
|
||||||
local highScoreTable = {{name1, score1}, {name2,score2}, {name3,score3}, {name4,score4}, {name5,score5}}
|
local highScoreTable = {{name1, score1}, {name2,score2}, {name3,score3}, {name4,score4}, {name5,score5}}
|
||||||
local newHighScoreStr = textutils.serialize(highScoreTable)
|
local newHighScoreStr = textutils.serialize(highScoreTable)
|
||||||
@ -289,7 +289,7 @@ function newHighScoreObtained()
|
|||||||
newNameStr=newNameStr..p1
|
newNameStr=newNameStr..p1
|
||||||
newNameStrLen=newNameStrLen+1
|
newNameStrLen=newNameStrLen+1
|
||||||
printCent(14,newNameStr.." ")
|
printCent(14,newNameStr.." ")
|
||||||
|
|
||||||
elseif event=="key" and p1 == 14 and newNameStrLen>0 then
|
elseif event=="key" and p1 == 14 and newNameStrLen>0 then
|
||||||
newNameStr=string.sub(newNameStr,1,string.len(newNameStr)-1)
|
newNameStr=string.sub(newNameStr,1,string.len(newNameStr)-1)
|
||||||
newNameStrLen=newNameStrLen-1
|
newNameStrLen=newNameStrLen-1
|
||||||
@ -303,9 +303,9 @@ function newHighScoreObtained()
|
|||||||
printScore()
|
printScore()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function highScore()
|
function highScore()
|
||||||
@ -327,8 +327,8 @@ function highScore()
|
|||||||
newHighScoreObtained()
|
newHighScoreObtained()
|
||||||
end
|
end
|
||||||
printScore()
|
printScore()
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -351,24 +351,24 @@ function gameOver(gameOverMsg)
|
|||||||
running=false
|
running=false
|
||||||
sleep(1.5)
|
sleep(1.5)
|
||||||
highScore()-- new
|
highScore()-- new
|
||||||
--playAgain
|
--playAgain
|
||||||
end
|
end
|
||||||
|
|
||||||
function playAgain()
|
function playAgain()
|
||||||
sleep(1)
|
sleep(1)
|
||||||
printCent(12,"Play again (Y or N)")
|
printCent(12,"Play again (Y or N)")
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local event,p1,p2,p3 = os.pullEvent()
|
local event,p1,p2,p3 = os.pullEvent()
|
||||||
if event=="char" then
|
if event=="char" then
|
||||||
if string.lower(p1)=="y" then
|
if string.lower(p1)=="y" then
|
||||||
runGame()
|
runGame()
|
||||||
elseif string.lower(p1)=="n" then
|
elseif string.lower(p1)=="n" then
|
||||||
os.shutdown()
|
os.shutdown()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function killPlayer()
|
function killPlayer()
|
||||||
@ -378,7 +378,7 @@ function killPlayer()
|
|||||||
moveDown=false
|
moveDown=false
|
||||||
delShip(shipYPos)
|
delShip(shipYPos)
|
||||||
lives=lives-1
|
lives=lives-1
|
||||||
if lives==0 then
|
if lives==0 then
|
||||||
gameOver("OUT OF LIVES")
|
gameOver("OUT OF LIVES")
|
||||||
end
|
end
|
||||||
killedState=true
|
killedState=true
|
||||||
@ -438,7 +438,7 @@ function right()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function up()
|
function up()
|
||||||
if shipYPos > 2 then
|
if shipYPos > 2 then
|
||||||
delShip(shipYPos)
|
delShip(shipYPos)
|
||||||
shipYPos=shipYPos-1
|
shipYPos=shipYPos-1
|
||||||
checkShipCollision()
|
checkShipCollision()
|
||||||
@ -449,7 +449,7 @@ function up()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function down()
|
function down()
|
||||||
if shipYPos<17 then
|
if shipYPos<17 then
|
||||||
delShip(shipYPos)
|
delShip(shipYPos)
|
||||||
shipYPos=shipYPos+1
|
shipYPos=shipYPos+1
|
||||||
checkShipCollision()
|
checkShipCollision()
|
||||||
@ -480,7 +480,7 @@ function checkShipCollision()
|
|||||||
if human3x >=24 and human3x <= 26 then
|
if human3x >=24 and human3x <= 26 then
|
||||||
human3=false
|
human3=false
|
||||||
humanHitRoutine()
|
humanHitRoutine()
|
||||||
end
|
end
|
||||||
elseif human4==true and human4y==shipYPos then
|
elseif human4==true and human4y==shipYPos then
|
||||||
if human4x >=24 and human4x <= 26 then
|
if human4x >=24 and human4x <= 26 then
|
||||||
human4=false
|
human4=false
|
||||||
@ -495,7 +495,7 @@ function checkShipCollision()
|
|||||||
if human6x >=24 and human6x <= 26 then
|
if human6x >=24 and human6x <= 26 then
|
||||||
human6=false
|
human6=false
|
||||||
humanHitRoutine()
|
humanHitRoutine()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -551,7 +551,7 @@ function alienDown()
|
|||||||
alien1Abduct=true
|
alien1Abduct=true
|
||||||
alien1Carry=true
|
alien1Carry=true
|
||||||
alien1Step=17
|
alien1Step=17
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -564,74 +564,74 @@ function alienRoutine()
|
|||||||
end
|
end
|
||||||
alien1Abduct=false
|
alien1Abduct=false
|
||||||
alien1Carry=false
|
alien1Carry=false
|
||||||
if humansLeft==0 then
|
if humansLeft==0 then
|
||||||
gameOver("NO HUMANS LEFT")
|
gameOver("NO HUMANS LEFT")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function alienUp()
|
function alienUp()
|
||||||
if alien1==true and alien1Abduct==true then
|
if alien1==true and alien1Abduct==true then
|
||||||
if alien1x+1 == human1x then
|
if alien1x+1 == human1x then
|
||||||
human1Abducted=true
|
human1Abducted=true
|
||||||
alien1Step=alien1Step-stepValue
|
alien1Step=alien1Step-stepValue
|
||||||
alien1y=math.floor(alien1Step)
|
alien1y=math.floor(alien1Step)
|
||||||
human1y=math.floor(alien1Step)+1
|
human1y=math.floor(alien1Step)+1
|
||||||
human1x=alien1x+1
|
human1x=alien1x+1
|
||||||
if human1y<=2 then
|
if human1y<=2 then
|
||||||
alienRoutine()
|
alienRoutine()
|
||||||
human1=false
|
human1=false
|
||||||
end
|
end
|
||||||
elseif alien1x+1 == human2x then
|
elseif alien1x+1 == human2x then
|
||||||
human2Abducted=true
|
human2Abducted=true
|
||||||
alien1Step=alien1Step-stepValue
|
alien1Step=alien1Step-stepValue
|
||||||
alien1y=math.floor(alien1Step)
|
alien1y=math.floor(alien1Step)
|
||||||
human2y=math.floor(alien1Step)+1
|
human2y=math.floor(alien1Step)+1
|
||||||
human2x=alien1x+1
|
human2x=alien1x+1
|
||||||
if human2y<=2 then
|
if human2y<=2 then
|
||||||
alienRoutine()
|
alienRoutine()
|
||||||
human2=false
|
human2=false
|
||||||
end
|
end
|
||||||
elseif alien1x+1 == human3x then
|
elseif alien1x+1 == human3x then
|
||||||
human3Abducted=true
|
human3Abducted=true
|
||||||
alien1Step=alien1Step-stepValue
|
alien1Step=alien1Step-stepValue
|
||||||
alien1y=math.floor(alien1Step)
|
alien1y=math.floor(alien1Step)
|
||||||
human3y=math.floor(alien1Step)+1
|
human3y=math.floor(alien1Step)+1
|
||||||
human3x=alien1x+1
|
human3x=alien1x+1
|
||||||
if human3y<=2 then
|
if human3y<=2 then
|
||||||
alienRoutine()
|
alienRoutine()
|
||||||
human3=false
|
human3=false
|
||||||
end
|
end
|
||||||
elseif alien1x+1 == human4x then
|
elseif alien1x+1 == human4x then
|
||||||
human4Abducted=true
|
human4Abducted=true
|
||||||
alien1Step=alien1Step-stepValue
|
alien1Step=alien1Step-stepValue
|
||||||
alien1y=math.floor(alien1Step)
|
alien1y=math.floor(alien1Step)
|
||||||
human4y=math.floor(alien1Step)+1
|
human4y=math.floor(alien1Step)+1
|
||||||
human4x=alien1x+1
|
human4x=alien1x+1
|
||||||
if human4y<=2 then
|
if human4y<=2 then
|
||||||
alienRoutine()
|
alienRoutine()
|
||||||
human4=false
|
human4=false
|
||||||
end
|
end
|
||||||
elseif alien1x+1 == human5x then
|
elseif alien1x+1 == human5x then
|
||||||
human5Abducted=true
|
human5Abducted=true
|
||||||
alien1Step=alien1Step-stepValue
|
alien1Step=alien1Step-stepValue
|
||||||
alien1y=math.floor(alien1Step)
|
alien1y=math.floor(alien1Step)
|
||||||
human5y=math.floor(alien1Step)+1
|
human5y=math.floor(alien1Step)+1
|
||||||
human5x=alien1x+1
|
human5x=alien1x+1
|
||||||
if human5y<=2 then
|
if human5y<=2 then
|
||||||
alienRoutine()
|
alienRoutine()
|
||||||
human5=false
|
human5=false
|
||||||
end
|
end
|
||||||
elseif alien1x+1 == human6x then
|
elseif alien1x+1 == human6x then
|
||||||
human6Abducted=true
|
human6Abducted=true
|
||||||
alien1Step=alien1Step-stepValue
|
alien1Step=alien1Step-stepValue
|
||||||
alien1y=math.floor(alien1Step)
|
alien1y=math.floor(alien1Step)
|
||||||
human6y=math.floor(alien1Step)+1
|
human6y=math.floor(alien1Step)+1
|
||||||
human6x=alien1x+1
|
human6x=alien1x+1
|
||||||
if human6y<=2 then
|
if human6y<=2 then
|
||||||
alienRoutine()
|
alienRoutine()
|
||||||
human6=false
|
human6=false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if alien1==false then alienGen() end
|
if alien1==false then alienGen() end
|
||||||
@ -645,7 +645,7 @@ function keyPress() -- 200 UP, 208 DOWN, 203 LEFT, 205 RIGHT, 57 SPACE, 16 Q
|
|||||||
moveDown=true
|
moveDown=true
|
||||||
moveUp=false
|
moveUp=false
|
||||||
elseif pressedKey==203 or pressedKey == 30 then -- left
|
elseif pressedKey==203 or pressedKey == 30 then -- left
|
||||||
moveLeft=true
|
moveLeft=true
|
||||||
moveRight=false
|
moveRight=false
|
||||||
elseif pressedKey==205 or pressedKey == 32 then -- right
|
elseif pressedKey==205 or pressedKey == 32 then -- right
|
||||||
moveRight=true
|
moveRight=true
|
||||||
@ -654,7 +654,7 @@ function keyPress() -- 200 UP, 208 DOWN, 203 LEFT, 205 RIGHT, 57 SPACE, 16 Q
|
|||||||
if bulletState==false then
|
if bulletState==false then
|
||||||
bulletYPos=shipYPos
|
bulletYPos=shipYPos
|
||||||
bulletState=true
|
bulletState=true
|
||||||
if shipFacingRight==true then
|
if shipFacingRight==true then
|
||||||
bulletXPos=shipXPos+3
|
bulletXPos=shipXPos+3
|
||||||
bulletGoingRight=true
|
bulletGoingRight=true
|
||||||
else
|
else
|
||||||
@ -665,13 +665,13 @@ function keyPress() -- 200 UP, 208 DOWN, 203 LEFT, 205 RIGHT, 57 SPACE, 16 Q
|
|||||||
elseif pressedKey==25 then -- q (use 25 if p for quit)
|
elseif pressedKey==25 then -- q (use 25 if p for quit)
|
||||||
gameOver("YOU QUIT")
|
gameOver("YOU QUIT")
|
||||||
end
|
end
|
||||||
|
|
||||||
--term.setCursorPos(30,1)
|
--term.setCursorPos(30,1)
|
||||||
--write(pressedKey.." ")
|
--write(pressedKey.." ")
|
||||||
end
|
end
|
||||||
|
|
||||||
function removeBullet()
|
function removeBullet()
|
||||||
if bulletGoingRight==true then
|
if bulletGoingRight==true then
|
||||||
bulletXPos = 60
|
bulletXPos = 60
|
||||||
else
|
else
|
||||||
bulletXPos = -10
|
bulletXPos = -10
|
||||||
@ -691,7 +691,7 @@ end
|
|||||||
function humanHitRoutine()
|
function humanHitRoutine()
|
||||||
score=score-50
|
score=score-50
|
||||||
humansLeft=humansLeft-1
|
humansLeft=humansLeft-1
|
||||||
if humansLeft==0 then
|
if humansLeft==0 then
|
||||||
gameOver("NO HUMANS LEFT")
|
gameOver("NO HUMANS LEFT")
|
||||||
end
|
end
|
||||||
if alien1Carry==true then alien1Carry=false end
|
if alien1Carry==true then alien1Carry=false end
|
||||||
@ -699,9 +699,9 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function checkBulletCollision()
|
function checkBulletCollision()
|
||||||
if alien1 == true and bulletYPos == alien1y then
|
if alien1 == true and bulletYPos == alien1y then
|
||||||
if bulletXPos >= alien1x and bulletXPos <= alien1x + 3 then
|
if bulletXPos >= alien1x and bulletXPos <= alien1x + 3 then
|
||||||
alien1Hit()
|
alien1Hit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if human1 == true and bulletYPos == human1y and bulletXPos == human1x then human1=false humanHitRoutine() end
|
if human1 == true and bulletYPos == human1y and bulletXPos == human1x then human1=false humanHitRoutine() end
|
||||||
@ -737,15 +737,15 @@ end
|
|||||||
function gameControl()
|
function gameControl()
|
||||||
|
|
||||||
gameTimer=os.startTimer(0.1)
|
gameTimer=os.startTimer(0.1)
|
||||||
|
|
||||||
while running do
|
while running do
|
||||||
local event,p1,p2,p3 = os.pullEvent()
|
local event,p1,p2,p3 = os.pullEvent()
|
||||||
if score<0 then score=0 end
|
if score<0 then score=0 end
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
term.setBackgroundColour(colours.yellow)
|
term.setBackgroundColour(colours.yellow)
|
||||||
write(string.rep(" ",w))
|
write(string.rep(" ",w))
|
||||||
|
|
||||||
|
|
||||||
term.setTextColour(colours.red)
|
term.setTextColour(colours.red)
|
||||||
term.setCursorPos(5,1)
|
term.setCursorPos(5,1)
|
||||||
write("Score: "..score.." ")
|
write("Score: "..score.." ")
|
||||||
@ -753,15 +753,15 @@ function gameControl()
|
|||||||
write("Humans Left: "..humansLeft.." ")
|
write("Humans Left: "..humansLeft.." ")
|
||||||
term.setCursorPos(40,1)
|
term.setCursorPos(40,1)
|
||||||
write("Lives: "..lives.." ")
|
write("Lives: "..lives.." ")
|
||||||
|
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.setTextColour(colours.white)
|
term.setTextColour(colours.white)
|
||||||
|
|
||||||
local newStepValue = (score+0.1)/1000
|
local newStepValue = (score+0.1)/1000
|
||||||
if newStepValue > stepValue then stepValue= newStepValue end
|
if newStepValue > stepValue then stepValue= newStepValue end
|
||||||
if stepValue>0.4 then stepValue=0.4 end
|
if stepValue>0.4 then stepValue=0.4 end
|
||||||
|
|
||||||
|
|
||||||
--[[DEBUG
|
--[[DEBUG
|
||||||
term.setCursorPos(2,2)
|
term.setCursorPos(2,2)
|
||||||
write("human1x "..human1x.." ")
|
write("human1x "..human1x.." ")
|
||||||
@ -776,10 +776,10 @@ function gameControl()
|
|||||||
term.setCursorPos(2,7)
|
term.setCursorPos(2,7)
|
||||||
write("human6x "..human6x.." ")
|
write("human6x "..human6x.." ")
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
|
||||||
if event=="timer" and gameTimer == p1 then
|
if event=="timer" and gameTimer == p1 then
|
||||||
if killedState==true then
|
if killedState==true then
|
||||||
delShip(shipYPos)
|
delShip(shipYPos)
|
||||||
delHumans()
|
delHumans()
|
||||||
dropHumans()
|
dropHumans()
|
||||||
@ -800,15 +800,15 @@ function gameControl()
|
|||||||
else
|
else
|
||||||
moveLeft=true
|
moveLeft=true
|
||||||
moveRight=false
|
moveRight=false
|
||||||
end
|
end
|
||||||
killedDelay=0
|
killedDelay=0
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
||||||
--alienGen()
|
--alienGen()
|
||||||
drawShip(shipYPos)
|
drawShip(shipYPos)
|
||||||
delAliens()
|
delAliens()
|
||||||
|
|
||||||
delHumans()
|
delHumans()
|
||||||
dropHumans()
|
dropHumans()
|
||||||
alienDown()
|
alienDown()
|
||||||
@ -817,7 +817,7 @@ function gameControl()
|
|||||||
drawHumans()
|
drawHumans()
|
||||||
drawBorder()
|
drawBorder()
|
||||||
end
|
end
|
||||||
|
|
||||||
if bulletState==true then
|
if bulletState==true then
|
||||||
if bulletGoingRight==true then
|
if bulletGoingRight==true then
|
||||||
delBullet()
|
delBullet()
|
||||||
@ -839,7 +839,7 @@ function gameControl()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if moveLeft==true then
|
if moveLeft==true then
|
||||||
left()
|
left()
|
||||||
end
|
end
|
||||||
@ -852,16 +852,16 @@ function gameControl()
|
|||||||
if moveDown==true then
|
if moveDown==true then
|
||||||
down()
|
down()
|
||||||
end
|
end
|
||||||
|
|
||||||
gameTimer=os.startTimer(0.1)
|
gameTimer=os.startTimer(0.1)
|
||||||
|
|
||||||
elseif event=="key" and killedState==false then
|
elseif event=="key" and killedState==false then
|
||||||
pressedKey=p1
|
pressedKey=p1
|
||||||
keyPress()
|
keyPress()
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function runGame()
|
function runGame()
|
||||||
@ -875,7 +875,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function pix(xCo,yCo,text,col)
|
function pix(xCo,yCo,text,col)
|
||||||
if col== nil then term.setBackgroundColour(colours.black)
|
if col== nil then term.setBackgroundColour(colours.black)
|
||||||
elseif col =="white" then term.setBackgroundColour(colours.white)
|
elseif col =="white" then term.setBackgroundColour(colours.white)
|
||||||
elseif col =="green" then term.setBackgroundColour(colours.green)
|
elseif col =="green" then term.setBackgroundColour(colours.green)
|
||||||
elseif col =="pink" then term.setBackgroundColour(colours.pink)
|
elseif col =="pink" then term.setBackgroundColour(colours.pink)
|
||||||
@ -977,7 +977,7 @@ function line2()
|
|||||||
pix(38,5," ","white")
|
pix(38,5," ","white")
|
||||||
pix(40,5," ","white")
|
pix(40,5," ","white")
|
||||||
pix(42,5," ","white")
|
pix(42,5," ","white")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function line3()
|
function line3()
|
||||||
@ -1030,7 +1030,7 @@ function startScreen()
|
|||||||
term.setCursorPos(1,h)
|
term.setCursorPos(1,h)
|
||||||
write(string.rep(" ",w))
|
write(string.rep(" ",w))
|
||||||
local screenStage=0
|
local screenStage=0
|
||||||
|
|
||||||
screenTimer=os.startTimer(0.1)
|
screenTimer=os.startTimer(0.1)
|
||||||
while true do
|
while true do
|
||||||
local event,p1,p2,p3=os.pullEvent()
|
local event,p1,p2,p3=os.pullEvent()
|
||||||
@ -1039,12 +1039,12 @@ function startScreen()
|
|||||||
clear()
|
clear()
|
||||||
runGame()
|
runGame()
|
||||||
elseif event=="timer" and screenTimer == p1 then
|
elseif event=="timer" and screenTimer == p1 then
|
||||||
|
|
||||||
--term.setCursorPos(1,1) write("screenStage: "..screenStage.." ")
|
--term.setCursorPos(1,1) write("screenStage: "..screenStage.." ")
|
||||||
|
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.setCursorPos(35,1) write("SPACE WHEN READY")
|
term.setCursorPos(35,1) write("SPACE WHEN READY")
|
||||||
|
|
||||||
if screenStage>0 and screenStage<0.5 then
|
if screenStage>0 and screenStage<0.5 then
|
||||||
humanPixY = 18
|
humanPixY = 18
|
||||||
drawHumanPix()
|
drawHumanPix()
|
||||||
@ -1055,17 +1055,17 @@ function startScreen()
|
|||||||
alienPixY = -2
|
alienPixY = -2
|
||||||
delAlienPix()
|
delAlienPix()
|
||||||
alienPixY = -1
|
alienPixY = -1
|
||||||
drawAlienPix()
|
drawAlienPix()
|
||||||
elseif screenStage>4 and screenStage<4.9 then
|
elseif screenStage>4 and screenStage<4.9 then
|
||||||
alienPixY = -1
|
alienPixY = -1
|
||||||
delAlienPix()
|
delAlienPix()
|
||||||
alienPixY = 0
|
alienPixY = 0
|
||||||
drawAlienPix()
|
drawAlienPix()
|
||||||
elseif screenStage>5 and screenStage<5.9 then
|
elseif screenStage>5 and screenStage<5.9 then
|
||||||
alienPixY = 0
|
alienPixY = 0
|
||||||
delAlienPix()
|
delAlienPix()
|
||||||
alienPixY = 1
|
alienPixY = 1
|
||||||
drawAlienPix()
|
drawAlienPix()
|
||||||
elseif screenStage>6 and screenStage<6.9 then
|
elseif screenStage>6 and screenStage<6.9 then
|
||||||
alienPixY = 1
|
alienPixY = 1
|
||||||
delAlienPix()
|
delAlienPix()
|
||||||
@ -1080,7 +1080,7 @@ function startScreen()
|
|||||||
alienPixY = 3
|
alienPixY = 3
|
||||||
delAlienPix()
|
delAlienPix()
|
||||||
alienPixY = 4
|
alienPixY = 4
|
||||||
drawAlienPix()
|
drawAlienPix()
|
||||||
elseif screenStage>8 and screenStage<9.9 then
|
elseif screenStage>8 and screenStage<9.9 then
|
||||||
alienPixY = 4
|
alienPixY = 4
|
||||||
delAlienPix()
|
delAlienPix()
|
||||||
@ -1120,7 +1120,7 @@ function startScreen()
|
|||||||
pix(22,17," ","yellow")
|
pix(22,17," ","yellow")
|
||||||
pix(22,18," ","yellow")
|
pix(22,18," ","yellow")
|
||||||
humanPixY = 18
|
humanPixY = 18
|
||||||
drawHumanPix()
|
drawHumanPix()
|
||||||
elseif screenStage>10.8 and screenStage<11 then
|
elseif screenStage>10.8 and screenStage<11 then
|
||||||
pix(25,8," ","yellow")
|
pix(25,8," ","yellow")
|
||||||
pix(24,9," ","yellow")
|
pix(24,9," ","yellow")
|
||||||
@ -1134,7 +1134,7 @@ function startScreen()
|
|||||||
pix(20,17," ","yellow")
|
pix(20,17," ","yellow")
|
||||||
pix(20,18," ","yellow")
|
pix(20,18," ","yellow")
|
||||||
humanPixY = 18
|
humanPixY = 18
|
||||||
drawHumanPix()
|
drawHumanPix()
|
||||||
elseif screenStage>11.9 and screenStage<12 then
|
elseif screenStage>11.9 and screenStage<12 then
|
||||||
pix(1,6," ","yellow")
|
pix(1,6," ","yellow")
|
||||||
elseif screenStage>12 and screenStage<12.1 then
|
elseif screenStage>12 and screenStage<12.1 then
|
||||||
@ -1142,7 +1142,7 @@ function startScreen()
|
|||||||
pix(3,6," ","yellow")
|
pix(3,6," ","yellow")
|
||||||
elseif screenStage>12.1 and screenStage<12.2 then
|
elseif screenStage>12.1 and screenStage<12.2 then
|
||||||
pix(3,6," ")
|
pix(3,6," ")
|
||||||
pix(5,6," ","yellow")
|
pix(5,6," ","yellow")
|
||||||
elseif screenStage>12.2 and screenStage<12.3 then
|
elseif screenStage>12.2 and screenStage<12.3 then
|
||||||
pix(5,6," ")
|
pix(5,6," ")
|
||||||
pix(7,6," ","yellow")
|
pix(7,6," ","yellow")
|
||||||
@ -1166,102 +1166,102 @@ function startScreen()
|
|||||||
end
|
end
|
||||||
humanPixY=18
|
humanPixY=18
|
||||||
drawHumanPix()
|
drawHumanPix()
|
||||||
elseif screenStage>13 and screenStage<13.1 then
|
elseif screenStage>13 and screenStage<13.1 then
|
||||||
shipPixX= -16
|
shipPixX= -16
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13 and screenStage<13.1 then
|
elseif screenStage>13 and screenStage<13.1 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= -15
|
shipPixX= -15
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13.1 and screenStage<13.2 then
|
elseif screenStage>13.1 and screenStage<13.2 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= -12
|
shipPixX= -12
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13.2 and screenStage<13.3 then
|
elseif screenStage>13.2 and screenStage<13.3 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= -9
|
shipPixX= -9
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13.2 and screenStage<13.3 then
|
elseif screenStage>13.2 and screenStage<13.3 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= -6
|
shipPixX= -6
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13.3 and screenStage<13.4 then
|
elseif screenStage>13.3 and screenStage<13.4 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= -3
|
shipPixX= -3
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13.4 and screenStage<13.5 then
|
elseif screenStage>13.4 and screenStage<13.5 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 0
|
shipPixX= 0
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13.6 and screenStage<13.7 then
|
elseif screenStage>13.6 and screenStage<13.7 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 3
|
shipPixX= 3
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13.8 and screenStage<13.9 then
|
elseif screenStage>13.8 and screenStage<13.9 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 6
|
shipPixX= 6
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>13.9 and screenStage<14 then
|
elseif screenStage>13.9 and screenStage<14 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 9
|
shipPixX= 9
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.1 and screenStage<14.2 then
|
elseif screenStage>14.1 and screenStage<14.2 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 12
|
shipPixX= 12
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.2 and screenStage<14.3 then
|
elseif screenStage>14.2 and screenStage<14.3 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 15
|
shipPixX= 15
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.3 and screenStage<14.4 then
|
elseif screenStage>14.3 and screenStage<14.4 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 18
|
shipPixX= 18
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.4 and screenStage<14.5 then
|
elseif screenStage>14.4 and screenStage<14.5 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 21
|
shipPixX= 21
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.5 and screenStage<14.6 then
|
elseif screenStage>14.5 and screenStage<14.6 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 24
|
shipPixX= 24
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.6 and screenStage<14.7 then
|
elseif screenStage>14.6 and screenStage<14.7 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 27
|
shipPixX= 27
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.7 and screenStage<14.8 then
|
elseif screenStage>14.7 and screenStage<14.8 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 30
|
shipPixX= 30
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.8 and screenStage<14.9 then
|
elseif screenStage>14.8 and screenStage<14.9 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 33
|
shipPixX= 33
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>14.9 and screenStage<15 then
|
elseif screenStage>14.9 and screenStage<15 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 36
|
shipPixX= 36
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>15 and screenStage<15.1 then
|
elseif screenStage>15 and screenStage<15.1 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 39
|
shipPixX= 39
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>15.1 and screenStage<15.2 then
|
elseif screenStage>15.1 and screenStage<15.2 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 41
|
shipPixX= 41
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>15.2 and screenStage<15.3 then
|
elseif screenStage>15.2 and screenStage<15.3 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 44
|
shipPixX= 44
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>15.3 and screenStage<15.4 then
|
elseif screenStage>15.3 and screenStage<15.4 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 47
|
shipPixX= 47
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>15.4 and screenStage<15.5 then
|
elseif screenStage>15.4 and screenStage<15.5 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
shipPixX= 50
|
shipPixX= 50
|
||||||
drawShipPix()
|
drawShipPix()
|
||||||
elseif screenStage>15.5 and screenStage<15.6 then
|
elseif screenStage>15.5 and screenStage<15.6 then
|
||||||
delShipPix()
|
delShipPix()
|
||||||
elseif screenStage>16 and screenStage<16.9 then
|
elseif screenStage>16 and screenStage<16.9 then
|
||||||
humanPixY=18
|
humanPixY=18
|
||||||
@ -1284,7 +1284,7 @@ function startScreen()
|
|||||||
write("Fire when ready")
|
write("Fire when ready")
|
||||||
elseif screenStage>22.1 and screenStage <27 then
|
elseif screenStage>22.1 and screenStage <27 then
|
||||||
introHighScoreTable()
|
introHighScoreTable()
|
||||||
elseif screenStage>27 then
|
elseif screenStage>27 then
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
for i = 2,h-1 do
|
for i = 2,h-1 do
|
||||||
term.setCursorPos(1,i)
|
term.setCursorPos(1,i)
|
||||||
@ -1292,7 +1292,7 @@ function startScreen()
|
|||||||
end
|
end
|
||||||
screenStage=0
|
screenStage=0
|
||||||
end
|
end
|
||||||
|
|
||||||
screenStage=screenStage+0.1
|
screenStage=screenStage+0.1
|
||||||
screenTimer=os.startTimer(0.025)
|
screenTimer=os.startTimer(0.025)
|
||||||
end
|
end
|
||||||
@ -1308,4 +1308,4 @@ else
|
|||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
print("I'm sorry, Protector requires an Advanced Computer to run")
|
print("I'm sorry, Protector requires an Advanced Computer to run")
|
||||||
print(" ")
|
print(" ")
|
||||||
end
|
end
|
||||||
|
@ -89,7 +89,7 @@ local titleLevel = {
|
|||||||
local function parseValue(x, y, lchar)
|
local function parseValue(x, y, lchar)
|
||||||
if tonumber(lchar, 16) then
|
if tonumber(lchar, 16) then
|
||||||
lchar = math.pow(2, tonumber(lchar,16))
|
lchar = math.pow(2, tonumber(lchar,16))
|
||||||
|
|
||||||
if lchar == colours.blue then
|
if lchar == colours.blue then
|
||||||
map[y][x] = 0
|
map[y][x] = 0
|
||||||
elseif lchar == colours.brown then
|
elseif lchar == colours.brown then
|
||||||
@ -146,7 +146,7 @@ local function loadMap(_sPath)
|
|||||||
goldMap = {}
|
goldMap = {}
|
||||||
monks = {}
|
monks = {}
|
||||||
goldCount = 0
|
goldCount = 0
|
||||||
|
|
||||||
local file = fs.open(_sPath, "r")
|
local file = fs.open(_sPath, "r")
|
||||||
local line = file:readLine()
|
local line = file:readLine()
|
||||||
while line do
|
while line do
|
||||||
@ -279,14 +279,14 @@ local function resetMap()
|
|||||||
monk.x = monk.spawnX
|
monk.x = monk.spawnX
|
||||||
monk.y = monk.spawnY
|
monk.y = monk.spawnY
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,timer in pairs(blockTimers) do
|
for _,timer in pairs(blockTimers) do
|
||||||
map[timer.y][timer.x] = 0
|
map[timer.y][timer.x] = 0
|
||||||
end
|
end
|
||||||
blockTimers = {}
|
blockTimers = {}
|
||||||
plX = plspawnX
|
plX = plspawnX
|
||||||
plY = plspawnY
|
plY = plspawnY
|
||||||
|
|
||||||
moveTimer = -1
|
moveTimer = -1
|
||||||
shootTimer = -1
|
shootTimer = -1
|
||||||
spawnTimer = -1
|
spawnTimer = -1
|
||||||
@ -320,27 +320,27 @@ end
|
|||||||
local function drawLevelList()
|
local function drawLevelList()
|
||||||
local minLev = ((levelLot-1) * 10 + 1)
|
local minLev = ((levelLot-1) * 10 + 1)
|
||||||
local maxLev = minLev + math.min(10, #levelList - (levelLot-1) * 10) - 1
|
local maxLev = minLev + math.min(10, #levelList - (levelLot-1) * 10) - 1
|
||||||
|
|
||||||
term.setCursorPos(7, 2)
|
term.setCursorPos(7, 2)
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
for j = 1,49 do updateMap(j,2) end
|
for j = 1,49 do updateMap(j,2) end
|
||||||
|
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.setTextColour(colours.white)
|
term.setTextColour(colours.white)
|
||||||
term.setCursorPos(7, 2)
|
term.setCursorPos(7, 2)
|
||||||
local msg = "Levels "..minLev.." to "..maxLev.." of "..#levelList
|
local msg = "Levels "..minLev.." to "..maxLev.." of "..#levelList
|
||||||
term.write(msg)
|
term.write(msg)
|
||||||
|
|
||||||
term.setTextColour(colours.yellow)
|
term.setTextColour(colours.yellow)
|
||||||
term.setCursorPos(4, 2)
|
term.setCursorPos(4, 2)
|
||||||
if levelLot > 1 then term.write("<-")
|
if levelLot > 1 then term.write("<-")
|
||||||
else term.write(" ") end
|
else term.write(" ") end
|
||||||
|
|
||||||
term.setCursorPos(8 + #msg, 2)
|
term.setCursorPos(8 + #msg, 2)
|
||||||
if maxLev < #levelList then term.write("->")
|
if maxLev < #levelList then term.write("->")
|
||||||
else term.write(" ") end
|
else term.write(" ") end
|
||||||
|
|
||||||
for i = 1,10 do
|
for i = 1,10 do
|
||||||
term.setCursorPos(1, 3+i)
|
term.setCursorPos(1, 3+i)
|
||||||
for j = 1,49 do updateMap(j,3+i) end
|
for j = 1,49 do updateMap(j,3+i) end
|
||||||
@ -371,12 +371,12 @@ local function loadTitleScreen()
|
|||||||
if #map == 18 then break end
|
if #map == 18 then break end
|
||||||
end
|
end
|
||||||
maxGoldCount = goldCount
|
maxGoldCount = goldCount
|
||||||
|
|
||||||
drawMap()
|
drawMap()
|
||||||
term.setCursorPos(1,19)
|
term.setCursorPos(1,19)
|
||||||
term.setBackgroundColour(colours.blue)
|
term.setBackgroundColour(colours.blue)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
|
|
||||||
menIndex = 1
|
menIndex = 1
|
||||||
titleLoaded = true
|
titleLoaded = true
|
||||||
end
|
end
|
||||||
@ -384,22 +384,22 @@ end
|
|||||||
--Opens an in-game menu to display a series of options.
|
--Opens an in-game menu to display a series of options.
|
||||||
local function inGameMenu(menuList)
|
local function inGameMenu(menuList)
|
||||||
menIndex = 1
|
menIndex = 1
|
||||||
|
|
||||||
local squareTop,squareBottom = 4,6 + #menuList * 2
|
local squareTop,squareBottom = 4,6 + #menuList * 2
|
||||||
local squareSize = 0
|
local squareSize = 0
|
||||||
for i=1,#menuList do squareSize = math.max(squareSize, #menuList[i] + 6) end
|
for i=1,#menuList do squareSize = math.max(squareSize, #menuList[i] + 6) end
|
||||||
|
|
||||||
for y=squareTop,squareBottom do
|
for y=squareTop,squareBottom do
|
||||||
term.setCursorPos(w/2 - squareSize/2, y)
|
term.setCursorPos(w/2 - squareSize/2, y)
|
||||||
term.setBackgroundColour(colours.lightBlue)
|
term.setBackgroundColour(colours.lightBlue)
|
||||||
term.write(string.rep(" ", squareSize))
|
term.write(string.rep(" ", squareSize))
|
||||||
|
|
||||||
if y ~= squareTop and y ~= squareBottom then
|
if y ~= squareTop and y ~= squareBottom then
|
||||||
term.setCursorPos(w/2 - squareSize/2 + 1, y)
|
term.setCursorPos(w/2 - squareSize/2 + 1, y)
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.write(string.rep(" ", squareSize - 2))
|
term.write(string.rep(" ", squareSize - 2))
|
||||||
end
|
end
|
||||||
|
|
||||||
if y ~= squareTop and y ~= squareBottom and y % 2 == 0 then
|
if y ~= squareTop and y ~= squareBottom and y % 2 == 0 then
|
||||||
local opt = menuList[(y - squareTop) / 2]
|
local opt = menuList[(y - squareTop) / 2]
|
||||||
term.setCursorPos(w/2 - #opt/2, y)
|
term.setCursorPos(w/2 - #opt/2, y)
|
||||||
@ -407,7 +407,7 @@ local function inGameMenu(menuList)
|
|||||||
term.write(opt)
|
term.write(opt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local p1 = nil
|
local p1 = nil
|
||||||
repeat
|
repeat
|
||||||
for i=1,#menuList do
|
for i=1,#menuList do
|
||||||
@ -426,20 +426,20 @@ local function inGameMenu(menuList)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
_,p1 = os.pullEvent("key")
|
_,p1 = os.pullEvent("key")
|
||||||
|
|
||||||
if p1 == keys.up and menIndex > 1 then menIndex = menIndex - 1
|
if p1 == keys.up and menIndex > 1 then menIndex = menIndex - 1
|
||||||
elseif p1 == keys.down and menIndex < #menuList then menIndex = menIndex + 1 end
|
elseif p1 == keys.down and menIndex < #menuList then menIndex = menIndex + 1 end
|
||||||
until p1 == keys.enter
|
until p1 == keys.enter
|
||||||
|
|
||||||
return menuList[menIndex]
|
return menuList[menIndex]
|
||||||
end
|
end
|
||||||
|
|
||||||
--Checks to see if any given desired move is legal. Monks and players both use this.
|
--Checks to see if any given desired move is legal. Monks and players both use this.
|
||||||
local function isLegalMove(initX,initY,finX,finY)
|
local function isLegalMove(initX,initY,finX,finY)
|
||||||
if finY < 1 or finY > #map or finX < 1 or finX > 49 then
|
if finY < 1 or finY > #map or finX < 1 or finX > 49 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if map[finY][finX] ~= 0 and map[finY][finX] ~= '#' then
|
if map[finY][finX] ~= 0 and map[finY][finX] ~= '#' then
|
||||||
--This reports 'self moves' as being illegal, but that's fine
|
--This reports 'self moves' as being illegal, but that's fine
|
||||||
for _,monk in pairs(monks) do
|
for _,monk in pairs(monks) do
|
||||||
@ -450,10 +450,10 @@ local function isLegalMove(initX,initY,finX,finY)
|
|||||||
then return true
|
then return true
|
||||||
elseif finY == initY+1 and (map[finY][finX] == "H" or (map[finY][finX] == "h" and goldCount == 0)
|
elseif finY == initY+1 and (map[finY][finX] == "H" or (map[finY][finX] == "h" and goldCount == 0)
|
||||||
or (type(map[finY][finX]) == "number" and map[finY][finX] > 0) or map[finY][finX] == nil or
|
or (type(map[finY][finX]) == "number" and map[finY][finX] > 0) or map[finY][finX] == nil or
|
||||||
map[finY][finX] == "V" or map[finY][finX] == "-" or (map[finY][finX] == 'h' and goldCount ~= 0))
|
map[finY][finX] == "V" or map[finY][finX] == "-" or (map[finY][finX] == 'h' and goldCount ~= 0))
|
||||||
then return true
|
then return true
|
||||||
elseif finX == initX-1 or finX == initX+1 then
|
elseif finX == initX-1 or finX == initX+1 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -461,12 +461,12 @@ end
|
|||||||
--Moves the player to a given step.
|
--Moves the player to a given step.
|
||||||
local function movePlayer(x,y,ignoreLegal)
|
local function movePlayer(x,y,ignoreLegal)
|
||||||
if not ignoreLegal and not isLegalMove(plX,plY,x,y) then return false end
|
if not ignoreLegal and not isLegalMove(plX,plY,x,y) then return false end
|
||||||
|
|
||||||
local ox = plX
|
local ox = plX
|
||||||
local oy = plY
|
local oy = plY
|
||||||
plX = x
|
plX = x
|
||||||
plY = y
|
plY = y
|
||||||
|
|
||||||
updateMap(ox,oy)
|
updateMap(ox,oy)
|
||||||
updateMap(x,y)
|
updateMap(x,y)
|
||||||
if goldMap[y][x] == 1 then
|
if goldMap[y][x] == 1 then
|
||||||
@ -481,14 +481,14 @@ local function movePlayer(x,y,ignoreLegal)
|
|||||||
started = false
|
started = false
|
||||||
nextLevel = true
|
nextLevel = true
|
||||||
end
|
end
|
||||||
|
|
||||||
pfalling = (y < #map and map[y][x] ~= '-' and map[y][x] ~= 'H' and not (map[y][x] == 'h' and goldCount == 0)
|
pfalling = (y < #map and map[y][x] ~= '-' and map[y][x] ~= 'H' and not (map[y][x] == 'h' and goldCount == 0)
|
||||||
and (map[y+1][x] == nil or map[y+1][x] == "V" or map[y+1][x] == 2 or map[y+1][x] == '-'))
|
and (map[y+1][x] == nil or map[y+1][x] == "V" or map[y+1][x] == 2 or map[y+1][x] == '-'))
|
||||||
if (y < #map and map[y+1][x] == 'h' and goldCount ~= 0) then pfalling = true end
|
if (y < #map and map[y+1][x] == 'h' and goldCount ~= 0) then pfalling = true end
|
||||||
for _,monk in pairs(monks) do
|
for _,monk in pairs(monks) do
|
||||||
if monk.x == plX and monk.y == plY + 1 then pfalling = false break end
|
if monk.x == plX and monk.y == plY + 1 then pfalling = false break end
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -634,7 +634,7 @@ local function updateMonks()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not (monk.trapped or monk.dead) then
|
if not (monk.trapped or monk.dead) then
|
||||||
--Has the monk decided on moving left or right? If so we try to move him
|
--Has the monk decided on moving left or right? If so we try to move him
|
||||||
if monk.desX and not monk.falling then
|
if monk.desX and not monk.falling then
|
||||||
@ -708,7 +708,7 @@ local function updateBlockTimer(tid)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function shootBlock(x,y)
|
local function shootBlock(x,y)
|
||||||
if y <= #map and map[y][x] == 0 and (map[y-1][x] == nil
|
if y <= #map and map[y][x] == 0 and (map[y-1][x] == nil
|
||||||
or map[y-1][x] == 2 or (map[y-1][x] == 'h' and goldCount > 0)) then
|
or map[y-1][x] == 2 or (map[y-1][x] == 'h' and goldCount > 0)) then
|
||||||
map[y][x] = 3
|
map[y][x] = 3
|
||||||
table.insert(blockTimers, {x = x; y = y; timer = os.startTimer(0.1);} )
|
table.insert(blockTimers, {x = x; y = y; timer = os.startTimer(0.1);} )
|
||||||
@ -718,14 +718,14 @@ end
|
|||||||
|
|
||||||
local function handleEvents()
|
local function handleEvents()
|
||||||
local id,p1,p2,p3 = os.pullEvent()
|
local id,p1,p2,p3 = os.pullEvent()
|
||||||
|
|
||||||
if id == "key" then
|
if id == "key" then
|
||||||
--Menu Handling
|
--Menu Handling
|
||||||
if p1 == keys.up then
|
if p1 == keys.up then
|
||||||
if menIndex > 1 then menIndex = menIndex - 1 end
|
if menIndex > 1 then menIndex = menIndex - 1 end
|
||||||
elseif p1 == keys.down then
|
elseif p1 == keys.down then
|
||||||
if inLevelSelect then
|
if inLevelSelect then
|
||||||
if menIndex < math.min(10, #levelList - (levelLot-1)*10) then
|
if menIndex < math.min(10, #levelList - (levelLot-1)*10) then
|
||||||
menIndex = menIndex + 1
|
menIndex = menIndex + 1
|
||||||
end
|
end
|
||||||
elseif menIndex < #titleOptions then menIndex = menIndex + 1 end
|
elseif menIndex < #titleOptions then menIndex = menIndex + 1 end
|
||||||
@ -736,7 +736,7 @@ local function handleEvents()
|
|||||||
levelLot = levelLot + 1
|
levelLot = levelLot + 1
|
||||||
drawLevelList()
|
drawLevelList()
|
||||||
end
|
end
|
||||||
|
|
||||||
--Game Handling
|
--Game Handling
|
||||||
if p1 == keys.a and moveTimer == -1 and spawnTimer == -1 then
|
if p1 == keys.a and moveTimer == -1 and spawnTimer == -1 then
|
||||||
movePlayer(plX-1,plY)
|
movePlayer(plX-1,plY)
|
||||||
@ -811,7 +811,7 @@ local function handleEvents()
|
|||||||
monk.trapped = nil
|
monk.trapped = nil
|
||||||
monk.behaviour = "none"
|
monk.behaviour = "none"
|
||||||
monk.justEscaped = true
|
monk.justEscaped = true
|
||||||
|
|
||||||
updateMap(monk.x, monk.y+1)
|
updateMap(monk.x, monk.y+1)
|
||||||
drawMonk(monk)
|
drawMonk(monk)
|
||||||
end
|
end
|
||||||
@ -859,12 +859,12 @@ local pallette = { { t = colours.black, b = colours.blue, s = " ", n = "Solid G
|
|||||||
local brushType = 1
|
local brushType = 1
|
||||||
|
|
||||||
local function getHexOf(colour)
|
local function getHexOf(colour)
|
||||||
if not colour or not tonumber(colour) then
|
if not colour or not tonumber(colour) then
|
||||||
return " "
|
return " "
|
||||||
end
|
end
|
||||||
local value = math.log(colour)/math.log(2)
|
local value = math.log(colour)/math.log(2)
|
||||||
if value > 9 then
|
if value > 9 then
|
||||||
value = hexnums[value]
|
value = hexnums[value]
|
||||||
end
|
end
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
@ -878,7 +878,7 @@ local function drawFooter()
|
|||||||
term.setCursorPos(w,i)
|
term.setCursorPos(w,i)
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.setTextColour(colours.blue)
|
term.setTextColour(colours.blue)
|
||||||
term.setCursorPos(2,h)
|
term.setCursorPos(2,h)
|
||||||
@ -904,7 +904,7 @@ local function drawPallette(xpos,ypos)
|
|||||||
local top = ypos
|
local top = ypos
|
||||||
if xpos + xdim > w then left = left + (w - xpos - xdim) end
|
if xpos + xdim > w then left = left + (w - xpos - xdim) end
|
||||||
if ypos + ydim > h then top = top + (h - ypos - ydim) end
|
if ypos + ydim > h then top = top + (h - ypos - ydim) end
|
||||||
|
|
||||||
--There's no easy way to do this... so we draw it manually :(
|
--There's no easy way to do this... so we draw it manually :(
|
||||||
for i=0,4 do
|
for i=0,4 do
|
||||||
term.setCursorPos(left, top + i)
|
term.setCursorPos(left, top + i)
|
||||||
@ -913,25 +913,25 @@ local function drawPallette(xpos,ypos)
|
|||||||
if i == 0 or i == 4 then term.write("*-----*")
|
if i == 0 or i == 4 then term.write("*-----*")
|
||||||
else term.write("* *") end
|
else term.write("* *") end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i=1,#pallette-1 do
|
for i=1,#pallette-1 do
|
||||||
local ypl = 1
|
local ypl = 1
|
||||||
local xmv = i
|
local xmv = i
|
||||||
if i > 5 then ypl = 2 xmv = i - 5 end
|
if i > 5 then ypl = 2 xmv = i - 5 end
|
||||||
|
|
||||||
term.setCursorPos(left + xmv, top+ypl)
|
term.setCursorPos(left + xmv, top+ypl)
|
||||||
term.setBackgroundColour(pallette[i].b)
|
term.setBackgroundColour(pallette[i].b)
|
||||||
term.setTextColour(pallette[i].t)
|
term.setTextColour(pallette[i].t)
|
||||||
term.write(pallette[i].s)
|
term.write(pallette[i].s)
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setCursorPos(left + 1, top + 3)
|
term.setCursorPos(left + 1, top + 3)
|
||||||
term.setBackgroundColour(colours.red)
|
term.setBackgroundColour(colours.red)
|
||||||
term.setTextColour(colours.black)
|
term.setTextColour(colours.black)
|
||||||
term.write("ERASE")
|
term.write("ERASE")
|
||||||
|
|
||||||
local _,button,x,y = os.pullEvent("mouse_click")
|
local _,button,x,y = os.pullEvent("mouse_click")
|
||||||
|
|
||||||
if button == 1 then
|
if button == 1 then
|
||||||
if y == top + 1 and x > left and x < left + 6 then
|
if y == top + 1 and x > left and x < left + 6 then
|
||||||
brushType = x-left
|
brushType = x-left
|
||||||
@ -941,9 +941,9 @@ local function drawPallette(xpos,ypos)
|
|||||||
brushType = 11
|
brushType = 11
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for y = top,top+ydim do
|
for y = top,top+ydim do
|
||||||
for x = left,left+xdim do
|
for x = left,left+xdim do
|
||||||
--Not sure why the -2 is necessary
|
--Not sure why the -2 is necessary
|
||||||
if map[y+drawOffsetY] then updateMap(x-2,y+drawOffsetY) end
|
if map[y+drawOffsetY] then updateMap(x-2,y+drawOffsetY) end
|
||||||
end
|
end
|
||||||
@ -955,7 +955,7 @@ end
|
|||||||
local function saveCurrentMap(path)
|
local function saveCurrentMap(path)
|
||||||
local file = io.open(shell.resolve(".").."/levels/"..path, "w")
|
local file = io.open(shell.resolve(".").."/levels/"..path, "w")
|
||||||
if not file then return false end
|
if not file then return false end
|
||||||
|
|
||||||
drawMap()
|
drawMap()
|
||||||
drawFooter()
|
drawFooter()
|
||||||
local msg = "Saving.."
|
local msg = "Saving.."
|
||||||
@ -968,7 +968,7 @@ local function saveCurrentMap(path)
|
|||||||
term.write(string.rep(" ", 18))
|
term.write(string.rep(" ", 18))
|
||||||
term.setCursorPos(w/2-9,6)
|
term.setCursorPos(w/2-9,6)
|
||||||
term.setBackgroundColour(colours.lime)
|
term.setBackgroundColour(colours.lime)
|
||||||
|
|
||||||
for y=1,#map do
|
for y=1,#map do
|
||||||
local xstr = ""
|
local xstr = ""
|
||||||
for x=1,49 do
|
for x=1,49 do
|
||||||
@ -1016,14 +1016,14 @@ local function runLevelEditor()
|
|||||||
end
|
end
|
||||||
monks = {}
|
monks = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
drawMap()
|
drawMap()
|
||||||
drawFooter()
|
drawFooter()
|
||||||
|
|
||||||
while inLevelEditor do
|
while inLevelEditor do
|
||||||
local id,button,x,y = os.pullEvent()
|
local id,button,x,y = os.pullEvent()
|
||||||
if id == "mouse_click" or id == "mouse_drag" then
|
if id == "mouse_click" or id == "mouse_drag" then
|
||||||
if button == 2 then
|
if button == 2 then
|
||||||
drawPallette(x,y)
|
drawPallette(x,y)
|
||||||
elseif x > drawOffsetX and x <= 49 + drawOffsetX and y > drawOffsetY and y <= 18 + drawOffsetY then
|
elseif x > drawOffsetX and x <= 49 + drawOffsetX and y > drawOffsetY and y <= 18 + drawOffsetY then
|
||||||
if pallette[brushType].v == "player" then
|
if pallette[brushType].v == "player" then
|
||||||
@ -1095,7 +1095,7 @@ local function runLevelSelect()
|
|||||||
if not titleLoaded then
|
if not titleLoaded then
|
||||||
loadTitleScreen()
|
loadTitleScreen()
|
||||||
monkTimer = os.startTimer(moveIntv * 1.5)
|
monkTimer = os.startTimer(moveIntv * 1.5)
|
||||||
else
|
else
|
||||||
drawMap()
|
drawMap()
|
||||||
drawEndgameMap()
|
drawEndgameMap()
|
||||||
term.setCursorPos(1,19)
|
term.setCursorPos(1,19)
|
||||||
@ -1103,11 +1103,11 @@ local function runLevelSelect()
|
|||||||
term.clearLine()
|
term.clearLine()
|
||||||
end
|
end
|
||||||
drawLevelList()
|
drawLevelList()
|
||||||
|
|
||||||
menSel = "none"
|
menSel = "none"
|
||||||
repeat
|
repeat
|
||||||
handleEvents()
|
handleEvents()
|
||||||
|
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.setTextColour(colours.yellow)
|
term.setTextColour(colours.yellow)
|
||||||
for i=1,10 do
|
for i=1,10 do
|
||||||
@ -1131,23 +1131,23 @@ local function runTitle()
|
|||||||
term.write("Gold Runner")
|
term.write("Gold Runner")
|
||||||
term.setCursorPos(16,4)
|
term.setCursorPos(16,4)
|
||||||
term.write("By Nitrogen Fingers")
|
term.write("By Nitrogen Fingers")
|
||||||
|
|
||||||
term.setTextColour(colours.white)
|
term.setTextColour(colours.white)
|
||||||
for i=1,#titleOptions do
|
for i=1,#titleOptions do
|
||||||
term.setCursorPos(19, 5 + (i*2))
|
term.setCursorPos(19, 5 + (i*2))
|
||||||
term.write(titleOptions[i])
|
term.write(titleOptions[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
term.setCursorPos(16, 7)
|
term.setCursorPos(16, 7)
|
||||||
term.setTextColour(colours.yellow)
|
term.setTextColour(colours.yellow)
|
||||||
term.write("->")
|
term.write("->")
|
||||||
|
|
||||||
menSel = "none"
|
menSel = "none"
|
||||||
monkTimer = os.startTimer(moveIntv * 1.5)
|
monkTimer = os.startTimer(moveIntv * 1.5)
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
handleEvents()
|
handleEvents()
|
||||||
|
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.setTextColour(colours.yellow)
|
term.setTextColour(colours.yellow)
|
||||||
for i=1,#titleOptions do
|
for i=1,#titleOptions do
|
||||||
@ -1166,25 +1166,25 @@ local function playLevel()
|
|||||||
drawHUD()
|
drawHUD()
|
||||||
os.pullEvent("key")
|
os.pullEvent("key")
|
||||||
movePlayer(plX,plY,true)
|
movePlayer(plX,plY,true)
|
||||||
|
|
||||||
monkTimer = os.startTimer(moveIntv * 1.5)
|
monkTimer = os.startTimer(moveIntv * 1.5)
|
||||||
moveTimer = os.startTimer(moveIntv)
|
moveTimer = os.startTimer(moveIntv)
|
||||||
shootTimer = -1
|
shootTimer = -1
|
||||||
spawnTimer = -1
|
spawnTimer = -1
|
||||||
|
|
||||||
started = true
|
started = true
|
||||||
while started do
|
while started do
|
||||||
handleEvents()
|
handleEvents()
|
||||||
end
|
end
|
||||||
|
|
||||||
if menSel == "Quit" or menSel == "Back to Title" or menSel == "Edit Level" then
|
if menSel == "Quit" or menSel == "Back to Title" or menSel == "Edit Level" then
|
||||||
running = false
|
running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
menSel = "none"
|
menSel = "none"
|
||||||
|
|
||||||
if nextLevel then
|
if nextLevel then
|
||||||
if currentLevel == #levelList then
|
if currentLevel == #levelList then
|
||||||
started = false
|
started = false
|
||||||
running = false
|
running = false
|
||||||
break
|
break
|
||||||
@ -1198,12 +1198,12 @@ local function playLevel()
|
|||||||
else
|
else
|
||||||
playerLives = playerLives-1
|
playerLives = playerLives-1
|
||||||
if playerLives > 0 then resetMap()
|
if playerLives > 0 then resetMap()
|
||||||
else
|
else
|
||||||
running = false
|
running = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if nextLevel then
|
if nextLevel then
|
||||||
local msg = "All levels defeated, Gold Runner!"
|
local msg = "All levels defeated, Gold Runner!"
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
@ -1247,7 +1247,7 @@ while menSel ~= "Quit" do
|
|||||||
term.setCursorPos(1,19)
|
term.setCursorPos(1,19)
|
||||||
term.setBackgroundColour(colours.blue)
|
term.setBackgroundColour(colours.blue)
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
|
|
||||||
term.setCursorPos(16,10)
|
term.setCursorPos(16,10)
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.setTextColour(colours.white)
|
term.setTextColour(colours.white)
|
||||||
@ -1256,13 +1256,13 @@ while menSel ~= "Quit" do
|
|||||||
term.setCursorPos(17,11)
|
term.setCursorPos(17,11)
|
||||||
term.setCursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
local levelName = ""
|
local levelName = ""
|
||||||
|
|
||||||
local id,p1
|
local id,p1
|
||||||
repeat
|
repeat
|
||||||
id,p1 = os.pullEvent()
|
id,p1 = os.pullEvent()
|
||||||
if id == "key" and p1 == keys.backspace then
|
if id == "key" and p1 == keys.backspace then
|
||||||
levelName = string.sub(levelName, 1, #levelName - 1)
|
levelName = string.sub(levelName, 1, #levelName - 1)
|
||||||
elseif id == "timer" and p1 == monkTimer then
|
elseif id == "timer" and p1 == monkTimer then
|
||||||
updateMonks()
|
updateMonks()
|
||||||
monkTimer = os.startTimer(moveIntv * 2)
|
monkTimer = os.startTimer(moveIntv * 2)
|
||||||
elseif id == "char" and #levelName < 14 then
|
elseif id == "char" and #levelName < 14 then
|
||||||
@ -1273,15 +1273,15 @@ while menSel ~= "Quit" do
|
|||||||
term.write(levelName..string.rep(" ",14 - #levelName))
|
term.write(levelName..string.rep(" ",14 - #levelName))
|
||||||
term.setCursorPos(17 + #levelName ,11)
|
term.setCursorPos(17 + #levelName ,11)
|
||||||
until id == "key" and p1 == keys.enter and #levelName > 0
|
until id == "key" and p1 == keys.enter and #levelName > 0
|
||||||
|
|
||||||
term.setCursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
levelEditName = levelName
|
levelEditName = levelName
|
||||||
runLevelEditor()
|
runLevelEditor()
|
||||||
|
|
||||||
if menSel == "Play Level" then
|
if menSel == "Play Level" then
|
||||||
currentLevel = nil
|
currentLevel = nil
|
||||||
levelList = fs.list(shell.resolve(".").."/levels")
|
levelList = fs.list(shell.resolve(".").."/levels")
|
||||||
for num,name in pairs(levelList) do
|
for num,name in pairs(levelList) do
|
||||||
if name == levelName then
|
if name == levelName then
|
||||||
currentLevel = num
|
currentLevel = num
|
||||||
break
|
break
|
||||||
@ -1296,7 +1296,7 @@ while menSel ~= "Quit" do
|
|||||||
runLevelEditor()
|
runLevelEditor()
|
||||||
term.setBackgroundColour(colours.black)
|
term.setBackgroundColour(colours.black)
|
||||||
term.clear()
|
term.clear()
|
||||||
|
|
||||||
if menSel == "Play Level" then
|
if menSel == "Play Level" then
|
||||||
menSel = "New Game"
|
menSel = "New Game"
|
||||||
else
|
else
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
--[[
|
--[[
|
||||||
3D Print
|
3D Print
|
||||||
A printing program for use with NPaintPro
|
A printing program for use with NPaintPro
|
||||||
|
|
||||||
By NitrogenFingers
|
By NitrogenFingers
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ local commandList = {
|
|||||||
["DE"] = endPrint;
|
["DE"] = endPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
--Splits a string according to a pattern into a table
|
--Splits a string according to a pattern into a table
|
||||||
local function split(str, pattern)
|
local function split(str, pattern)
|
||||||
local t = { }
|
local t = { }
|
||||||
local fpat = "(.-)" .. pattern
|
local fpat = "(.-)" .. pattern
|
||||||
@ -56,11 +56,11 @@ local function respondToQuery()
|
|||||||
print("Listening for ACT/ID query")
|
print("Listening for ACT/ID query")
|
||||||
local id,key = rednet.receive()
|
local id,key = rednet.receive()
|
||||||
print("Received : "..key)
|
print("Received : "..key)
|
||||||
|
|
||||||
if key == "$3DPRINT IDENTIFY" then
|
if key == "$3DPRINT IDENTIFY" then
|
||||||
print("Requested Identification")
|
print("Requested Identification")
|
||||||
rednet.send(id, "$3DPRINT IDACK "..os.getComputerLabel())
|
rednet.send(id, "$3DPRINT IDACK "..os.getComputerLabel())
|
||||||
|
|
||||||
elseif key == "$3DPRINT ACTIVATE" then
|
elseif key == "$3DPRINT ACTIVATE" then
|
||||||
print("Requested Activation")
|
print("Requested Activation")
|
||||||
activeCommander = id
|
activeCommander = id
|
||||||
@ -76,10 +76,10 @@ local function performPrint()
|
|||||||
while operatingPrint do
|
while operatingPrint do
|
||||||
local id,msg = rednet.receive()
|
local id,msg = rednet.receive()
|
||||||
print("Command : "..msg)
|
print("Command : "..msg)
|
||||||
|
|
||||||
if id == activeCommander and string.find(msg, "$PC") == 1 then
|
if id == activeCommander and string.find(msg, "$PC") == 1 then
|
||||||
local cmds = split(msg, " ")
|
local cmds = split(msg, " ")
|
||||||
|
|
||||||
--It's a bit of a hack, but those are the 2 methods required for a refuel
|
--It's a bit of a hack, but those are the 2 methods required for a refuel
|
||||||
if turtle.getFuelLevel() == 0 and cmds[2] ~= "SS" and cmds[2] ~= "RF" then
|
if turtle.getFuelLevel() == 0 and cmds[2] ~= "SS" and cmds[2] ~= "RF" then
|
||||||
rednet.send(id, "$3DPRINT OOF")
|
rednet.send(id, "$3DPRINT OOF")
|
||||||
@ -95,7 +95,7 @@ local function performPrint()
|
|||||||
commandList[cmds[2]][i](tonumber(cmds[3]))
|
commandList[cmds[2]][i](tonumber(cmds[3]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rednet.send(activeCommander, "$3DPRINT ACK")
|
rednet.send(activeCommander, "$3DPRINT ACK")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -116,4 +116,4 @@ while true do
|
|||||||
respondToQuery()
|
respondToQuery()
|
||||||
--Perform the print
|
--Perform the print
|
||||||
performPrint()
|
performPrint()
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ function initializeBuffer(terminal)
|
|||||||
if not terminal.isColour() then
|
if not terminal.isColour() then
|
||||||
error("Parameter does not represent an advanced computer.")
|
error("Parameter does not represent an advanced computer.")
|
||||||
end
|
end
|
||||||
|
|
||||||
tw,th = terminal.getSize()
|
tw,th = terminal.getSize()
|
||||||
backbuffer = { }
|
backbuffer = { }
|
||||||
for y=1,th do
|
for y=1,th do
|
||||||
@ -41,8 +41,8 @@ end
|
|||||||
function clearBuffer(colour)
|
function clearBuffer(colour)
|
||||||
if not backbuffer then
|
if not backbuffer then
|
||||||
error("Back buffer not yet initialized!")
|
error("Back buffer not yet initialized!")
|
||||||
end
|
end
|
||||||
|
|
||||||
for y=1,#backbuffer do
|
for y=1,#backbuffer do
|
||||||
backbuffer[y] = { }
|
backbuffer[y] = { }
|
||||||
if colour then
|
if colour then
|
||||||
@ -60,26 +60,26 @@ end
|
|||||||
function writeToBuffer(entity)
|
function writeToBuffer(entity)
|
||||||
if not backbuffer then
|
if not backbuffer then
|
||||||
error("Back buffer not yet initialized!")
|
error("Back buffer not yet initialized!")
|
||||||
end
|
end
|
||||||
|
|
||||||
local image = nil
|
local image = nil
|
||||||
if entity.type == "animation" then
|
if entity.type == "animation" then
|
||||||
image = entity.frames[entity.currentFrame]
|
image = entity.frames[entity.currentFrame]
|
||||||
else
|
else
|
||||||
image = entity.image
|
image = entity.image
|
||||||
end
|
end
|
||||||
|
|
||||||
for y=1,image.dimensions.height do
|
for y=1,image.dimensions.height do
|
||||||
for x=1,image.dimensions.width do
|
for x=1,image.dimensions.width do
|
||||||
if image[y][x] then
|
if image[y][x] then
|
||||||
local xpos,ypos = x,y
|
local xpos,ypos = x,y
|
||||||
if entity.mirror.x then xpos = image.dimensions.width - x + 1 end
|
if entity.mirror.x then xpos = image.dimensions.width - x + 1 end
|
||||||
if entity.mirror.y then ypos = image.dimensions.height - y + 1 end
|
if entity.mirror.y then ypos = image.dimensions.height - y + 1 end
|
||||||
|
|
||||||
--If the YPos doesn't exist, no need to loop through the rest of X!
|
--If the YPos doesn't exist, no need to loop through the rest of X!
|
||||||
--Don't you love optimization?
|
--Don't you love optimization?
|
||||||
if not backbuffer[entity.y + ypos - 1] then break end
|
if not backbuffer[entity.y + ypos - 1] then break end
|
||||||
|
|
||||||
backbuffer[entity.y + ypos - 1][entity.x + xpos - 1] = image[y][x]
|
backbuffer[entity.y + ypos - 1][entity.x + xpos - 1] = image[y][x]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -93,7 +93,7 @@ end
|
|||||||
function drawBuffer(terminal)
|
function drawBuffer(terminal)
|
||||||
if not backbuffer then
|
if not backbuffer then
|
||||||
error("Back buffer not yet initialized!")
|
error("Back buffer not yet initialized!")
|
||||||
end
|
end
|
||||||
if not terminal then terminal = term end
|
if not terminal then terminal = term end
|
||||||
if not terminal.setCursorPos or not terminal.setBackgroundColour or not terminal.write then
|
if not terminal.setCursorPos or not terminal.setBackgroundColour or not terminal.write then
|
||||||
error("Parameter cannot be used to initialize the backbuffer.")
|
error("Parameter cannot be used to initialize the backbuffer.")
|
||||||
@ -101,7 +101,7 @@ function drawBuffer(terminal)
|
|||||||
if not terminal.isColour() then
|
if not terminal.isColour() then
|
||||||
error("Parameter does not represent an advanced computer.")
|
error("Parameter does not represent an advanced computer.")
|
||||||
end
|
end
|
||||||
|
|
||||||
for y=1,math.min(#backbuffer, th) do
|
for y=1,math.min(#backbuffer, th) do
|
||||||
for x=1,tw do
|
for x=1,tw do
|
||||||
if backbuffer[y][x] then
|
if backbuffer[y][x] then
|
||||||
@ -167,14 +167,14 @@ end
|
|||||||
]]--
|
]]--
|
||||||
local function drawS(self)
|
local function drawS(self)
|
||||||
local image = self.image
|
local image = self.image
|
||||||
|
|
||||||
for y=1,image.dimensions.height do
|
for y=1,image.dimensions.height do
|
||||||
for x=1,image.dimensions.width do
|
for x=1,image.dimensions.width do
|
||||||
if image[y][x] then
|
if image[y][x] then
|
||||||
local xpos,ypos = x,y
|
local xpos,ypos = x,y
|
||||||
if self.mirror.x then xpos = image.dimensions.width - x + 1 end
|
if self.mirror.x then xpos = image.dimensions.width - x + 1 end
|
||||||
if self.mirror.y then ypos = image.dimensions.height - y + 1 end
|
if self.mirror.y then ypos = image.dimensions.height - y + 1 end
|
||||||
|
|
||||||
term.setBackgroundColour(image[y][x])
|
term.setBackgroundColour(image[y][x])
|
||||||
term.setCursorPos(self.x + xpos - 1, self.y + ypos - 1)
|
term.setCursorPos(self.x + xpos - 1, self.y + ypos - 1)
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
@ -198,7 +198,7 @@ local function drawA(self, frame)
|
|||||||
local xpos,ypos = x,y
|
local xpos,ypos = x,y
|
||||||
if self.mirror.x then xpos = image.dimensions.width - x + 1 end
|
if self.mirror.x then xpos = image.dimensions.width - x + 1 end
|
||||||
if self.mirror.y then ypos = image.dimensions.height - y + 1 end
|
if self.mirror.y then ypos = image.dimensions.height - y + 1 end
|
||||||
|
|
||||||
term.setBackgroundColour(image[y][x])
|
term.setBackgroundColour(image[y][x])
|
||||||
term.setCursorPos(self.x + xpos - 1, self.y + ypos - 1)
|
term.setCursorPos(self.x + xpos - 1, self.y + ypos - 1)
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
@ -259,16 +259,16 @@ local function drawBounds(entity, colour)
|
|||||||
local image = nil
|
local image = nil
|
||||||
if entity.type == "animation" then image = entity.frames[entity.currentFrame]
|
if entity.type == "animation" then image = entity.frames[entity.currentFrame]
|
||||||
else image = entity.image end
|
else image = entity.image end
|
||||||
|
|
||||||
term.setBackgroundColour(colour)
|
term.setBackgroundColour(colour)
|
||||||
|
|
||||||
corners = {
|
corners = {
|
||||||
topleft = { x = entity.x + image.bounds.x - 1, y = entity.y + image.bounds.y - 1 };
|
topleft = { x = entity.x + image.bounds.x - 1, y = entity.y + image.bounds.y - 1 };
|
||||||
topright = { x = entity.x + image.bounds.x + image.bounds.width - 2, y = entity.y + image.bounds.y - 1 };
|
topright = { x = entity.x + image.bounds.x + image.bounds.width - 2, y = entity.y + image.bounds.y - 1 };
|
||||||
botleft = { x = entity.x + image.bounds.x - 1, y = entity.y + image.bounds.y + image.bounds.height - 2 };
|
botleft = { x = entity.x + image.bounds.x - 1, y = entity.y + image.bounds.y + image.bounds.height - 2 };
|
||||||
botright = { x = entity.x + image.bounds.x + image.bounds.width - 2, y = entity.y + image.bounds.y + image.bounds.height - 2 };
|
botright = { x = entity.x + image.bounds.x + image.bounds.width - 2, y = entity.y + image.bounds.y + image.bounds.height - 2 };
|
||||||
}
|
}
|
||||||
|
|
||||||
term.setCursorPos(corners.topleft.x, corners.topleft.y)
|
term.setCursorPos(corners.topleft.x, corners.topleft.y)
|
||||||
term.write(" ")
|
term.write(" ")
|
||||||
term.setCursorPos(corners.topright.x, corners.topright.y)
|
term.setCursorPos(corners.topright.x, corners.topright.y)
|
||||||
@ -308,7 +308,7 @@ end
|
|||||||
local function rCollidesWith(self, other)
|
local function rCollidesWith(self, other)
|
||||||
--First we construct the rectangles
|
--First we construct the rectangles
|
||||||
local img1C, img2C = createRectangle(self), createRectangle(other)
|
local img1C, img2C = createRectangle(self), createRectangle(other)
|
||||||
|
|
||||||
--We then determine the "relative position" , in terms of which is farther left or right
|
--We then determine the "relative position" , in terms of which is farther left or right
|
||||||
leftmost,rightmost,topmost,botmost = nil,nil,nil,nil
|
leftmost,rightmost,topmost,botmost = nil,nil,nil,nil
|
||||||
if img1C.left < img2C.left then
|
if img1C.left < img2C.left then
|
||||||
@ -325,13 +325,13 @@ local function rCollidesWith(self, other)
|
|||||||
topmost = img2C
|
topmost = img2C
|
||||||
botmost = img1C
|
botmost = img1C
|
||||||
end
|
end
|
||||||
|
|
||||||
--Then we determine the distance between the "extreme" edges-
|
--Then we determine the distance between the "extreme" edges-
|
||||||
--distance between leftmost/right edge and rightmost/left edge
|
--distance between leftmost/right edge and rightmost/left edge
|
||||||
--distance between topmost/bottom edge and bottommost/top edge
|
--distance between topmost/bottom edge and bottommost/top edge
|
||||||
local xdist = rightmost.left - leftmost.right
|
local xdist = rightmost.left - leftmost.right
|
||||||
local ydist = botmost.top - topmost.bottom
|
local ydist = botmost.top - topmost.bottom
|
||||||
|
|
||||||
--If both are negative, our rectangles intersect!
|
--If both are negative, our rectangles intersect!
|
||||||
return xdist <= 0 and ydist <= 0
|
return xdist <= 0 and ydist <= 0
|
||||||
end
|
end
|
||||||
@ -352,13 +352,13 @@ local function pCollidesWith(self, other)
|
|||||||
else img1 = self.image end
|
else img1 = self.image end
|
||||||
if other.type == "animation" then img2 = other.frames[other.currentFrame]
|
if other.type == "animation" then img2 = other.frames[other.currentFrame]
|
||||||
else img2 = other.image end
|
else img2 = other.image end
|
||||||
|
|
||||||
--...then we position them...
|
--...then we position them...
|
||||||
leftmost,rightmost,topmost,botmost = nil,nil,nil,nil
|
leftmost,rightmost,topmost,botmost = nil,nil,nil,nil
|
||||||
--We also keep track of which is left and which is right- it doesn't matter in a rectangle
|
--We also keep track of which is left and which is right- it doesn't matter in a rectangle
|
||||||
--collision but it does in a pixel collision.
|
--collision but it does in a pixel collision.
|
||||||
img1T,img2T = {},{}
|
img1T,img2T = {},{}
|
||||||
|
|
||||||
if img1C.left < img2C.left then
|
if img1C.left < img2C.left then
|
||||||
leftmost = img1C
|
leftmost = img1C
|
||||||
rightmost = img2C
|
rightmost = img2C
|
||||||
@ -377,15 +377,15 @@ local function pCollidesWith(self, other)
|
|||||||
botmost = img1C
|
botmost = img1C
|
||||||
img2T.top = true
|
img2T.top = true
|
||||||
end
|
end
|
||||||
|
|
||||||
--...and we again find the distances between the extreme edges.
|
--...and we again find the distances between the extreme edges.
|
||||||
local xdist = rightmost.left - leftmost.right
|
local xdist = rightmost.left - leftmost.right
|
||||||
local ydist = botmost.top - topmost.bottom
|
local ydist = botmost.top - topmost.bottom
|
||||||
|
|
||||||
--If these distances are > 0 then we stop- no need to go any farther.
|
--If these distances are > 0 then we stop- no need to go any farther.
|
||||||
if xdist > 0 or ydist > 0 then return false end
|
if xdist > 0 or ydist > 0 then return false end
|
||||||
|
|
||||||
|
|
||||||
for x = rightmost.left, rightmost.left + math.abs(xdist) do
|
for x = rightmost.left, rightmost.left + math.abs(xdist) do
|
||||||
for y = botmost.top, botmost.top + math.abs(ydist) do
|
for y = botmost.top, botmost.top + math.abs(ydist) do
|
||||||
--We know a collision has occurred if a pixel is occupied by both images. We do this by
|
--We know a collision has occurred if a pixel is occupied by both images. We do this by
|
||||||
@ -398,16 +398,16 @@ local function pCollidesWith(self, other)
|
|||||||
else testX = x - img1C.left + 1 end
|
else testX = x - img1C.left + 1 end
|
||||||
if img1T.top then testY = y - img1C.top + 1
|
if img1T.top then testY = y - img1C.top + 1
|
||||||
else testY = y - img1C.top + 1 end
|
else testY = y - img1C.top + 1 end
|
||||||
|
|
||||||
local occupy1 = img1[testY + img1.bounds.y-1][testX + img1.bounds.x-1] ~= nil
|
local occupy1 = img1[testY + img1.bounds.y-1][testX + img1.bounds.x-1] ~= nil
|
||||||
|
|
||||||
if img2T.left then testX = x - img2C.left + 1
|
if img2T.left then testX = x - img2C.left + 1
|
||||||
else testX = x - img2C.left + 1 end
|
else testX = x - img2C.left + 1 end
|
||||||
if img2T.top then testY = y - img2C.top + 1
|
if img2T.top then testY = y - img2C.top + 1
|
||||||
else testY = y - img2C.top + 1 end
|
else testY = y - img2C.top + 1 end
|
||||||
|
|
||||||
local occupy2 = img2[testY + img2.bounds.y-1][testX + img2.bounds.x-1] ~= nil
|
local occupy2 = img2[testY + img2.bounds.y-1][testX + img2.bounds.x-1] ~= nil
|
||||||
|
|
||||||
if occupy1 and occupy2 then return true end
|
if occupy1 and occupy2 then return true end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -429,7 +429,7 @@ local function moveTo(self, x, y)
|
|||||||
else
|
else
|
||||||
image = self.image
|
image = self.image
|
||||||
end
|
end
|
||||||
|
|
||||||
self.x = x - image.bounds.x + 1
|
self.x = x - image.bounds.x + 1
|
||||||
self.y = y - image.bounds.y + 1
|
self.y = y - image.bounds.y + 1
|
||||||
end
|
end
|
||||||
@ -448,7 +448,7 @@ image:table = a table of the image. Indexed by height, a series of sub-tables, e
|
|||||||
dimensions:table =
|
dimensions:table =
|
||||||
width = the width of the entire image in pixels
|
width = the width of the entire image in pixels
|
||||||
height = the height of the entire image in pixels
|
height = the height of the entire image in pixels
|
||||||
|
|
||||||
mirror:table =
|
mirror:table =
|
||||||
x:bool = whether or not the image is mirrored on the X axis
|
x:bool = whether or not the image is mirrored on the X axis
|
||||||
y:bool = whether or not the image is mirrored on the Y axis
|
y:bool = whether or not the image is mirrored on the Y axis
|
||||||
@ -464,19 +464,19 @@ draw:function = see drawS (above)
|
|||||||
y:number = the initial Y position of the sprite
|
y:number = the initial Y position of the sprite
|
||||||
]]--
|
]]--
|
||||||
function loadSprite(path, x, y)
|
function loadSprite(path, x, y)
|
||||||
local sprite = {
|
local sprite = {
|
||||||
type = "sprite",
|
type = "sprite",
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
image = { },
|
image = { },
|
||||||
mirror = { x = false, y = false }
|
mirror = { x = false, y = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
if fs.exists(path) then
|
if fs.exists(path) then
|
||||||
local file = io.open(path, "r" )
|
local file = io.open(path, "r" )
|
||||||
local leftX, rightX = math.huge, 0
|
local leftX, rightX = math.huge, 0
|
||||||
local topY, botY = nil,nil
|
local topY, botY = nil,nil
|
||||||
|
|
||||||
local lcount = 0
|
local lcount = 0
|
||||||
for line in file:lines() do
|
for line in file:lines() do
|
||||||
lcount = lcount+1
|
lcount = lcount+1
|
||||||
@ -492,7 +492,7 @@ function loadSprite(path, x, y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
sprite.image.bounds = {
|
sprite.image.bounds = {
|
||||||
x = leftX,
|
x = leftX,
|
||||||
width = rightX - leftX + 1,
|
width = rightX - leftX + 1,
|
||||||
@ -503,10 +503,10 @@ function loadSprite(path, x, y)
|
|||||||
width = rightX,
|
width = rightX,
|
||||||
height = botY
|
height = botY
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite.x = sprite.x - leftX + 1
|
sprite.x = sprite.x - leftX + 1
|
||||||
sprite.y = sprite.y - topY + 1
|
sprite.y = sprite.y - topY + 1
|
||||||
|
|
||||||
sprite.repaint = repaintS
|
sprite.repaint = repaintS
|
||||||
sprite.rCollidesWith = rCollidesWith
|
sprite.rCollidesWith = rCollidesWith
|
||||||
sprite.pCollidesWith = pCollidesWith
|
sprite.pCollidesWith = pCollidesWith
|
||||||
@ -536,13 +536,13 @@ function loadAnimation(path, x, y, currentFrame)
|
|||||||
mirror = { x = false, y = false },
|
mirror = { x = false, y = false },
|
||||||
currentFrame = currentFrame
|
currentFrame = currentFrame
|
||||||
}
|
}
|
||||||
|
|
||||||
table.insert(anim.frames, { })
|
table.insert(anim.frames, { })
|
||||||
if fs.exists(path) then
|
if fs.exists(path) then
|
||||||
local file = io.open(path, "r")
|
local file = io.open(path, "r")
|
||||||
local leftX, rightX = math.huge, 0
|
local leftX, rightX = math.huge, 0
|
||||||
local topY, botY = nil,nil
|
local topY, botY = nil,nil
|
||||||
|
|
||||||
local lcount = 0
|
local lcount = 0
|
||||||
for line in file:lines() do
|
for line in file:lines() do
|
||||||
lcount = lcount+1
|
lcount = lcount+1
|
||||||
@ -589,17 +589,17 @@ function loadAnimation(path, x, y, currentFrame)
|
|||||||
}
|
}
|
||||||
anim.x = anim.x - leftX + 1
|
anim.x = anim.x - leftX + 1
|
||||||
anim.y = anim.y - topY + 1
|
anim.y = anim.y - topY + 1
|
||||||
|
|
||||||
if not currentFrame or type(currentFrame) ~= "number" or currentFrame < 1 or
|
if not currentFrame or type(currentFrame) ~= "number" or currentFrame < 1 or
|
||||||
currentFrame > #anim.frames then
|
currentFrame > #anim.frames then
|
||||||
anim.currentFrame = 1
|
anim.currentFrame = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
anim.timerID = nil
|
anim.timerID = nil
|
||||||
anim.lowerBound = 1
|
anim.lowerBound = 1
|
||||||
anim.upperBound = #anim.frames
|
anim.upperBound = #anim.frames
|
||||||
anim.updating = false
|
anim.updating = false
|
||||||
|
|
||||||
anim.repaint = repaintA
|
anim.repaint = repaintA
|
||||||
anim.rCollidesWith = rCollidesWith
|
anim.rCollidesWith = rCollidesWith
|
||||||
anim.pCollidesWith = pCollidesWith
|
anim.pCollidesWith = pCollidesWith
|
||||||
@ -612,4 +612,4 @@ function loadAnimation(path, x, y, currentFrame)
|
|||||||
else
|
else
|
||||||
error(path.." not found!")
|
error(path.." not found!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -175,4 +175,4 @@ drawScreen()
|
|||||||
while true do
|
while true do
|
||||||
loop()
|
loop()
|
||||||
parallel.waitForAny(loop, compute)
|
parallel.waitForAny(loop, compute)
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
--
|
--
|
||||||
-- @tparam string func The function's name
|
-- @tparam string func The function's name
|
||||||
-- @tparam int idx The argument index to this function
|
-- @tparam int idx The argument index to this function
|
||||||
-- @tparam string ty The type this argument should have. May be 'value' for
|
-- @tparam string ty The type this argument should have. May be 'value' for
|
||||||
-- any non-nil value.
|
-- any non-nil value.
|
||||||
-- @param val val The value to check
|
-- @param val val The value to check
|
||||||
-- @throws If this value doesn't match the expected type.
|
-- @throws If this value doesn't match the expected type.
|
||||||
|
@ -39,7 +39,7 @@ describe("The rm program", function()
|
|||||||
expect(capture(stub, "rm"))
|
expect(capture(stub, "rm"))
|
||||||
:matches { ok = true, output = "Usage: rm <paths>\n", error = "" }
|
:matches { ok = true, output = "Usage: rm <paths>\n", error = "" }
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("errors when trying to delete a read-only file", function()
|
it("errors when trying to delete a read-only file", function()
|
||||||
expect(capture(stub, "rm /rom/startup.lua"))
|
expect(capture(stub, "rm /rom/startup.lua"))
|
||||||
:matches { ok = true, output = "", error = "/rom/startup.lua: Access denied\n" }
|
:matches { ok = true, output = "", error = "/rom/startup.lua: Access denied\n" }
|
||||||
|
@ -2,7 +2,7 @@ local capture = require "test_helpers".capture_program
|
|||||||
|
|
||||||
describe("The edit program", function()
|
describe("The edit program", function()
|
||||||
|
|
||||||
it("displays its usage when given no argument", function()
|
it("displays its usage when given no argument", function()
|
||||||
expect(capture(stub, "edit"))
|
expect(capture(stub, "edit"))
|
||||||
:matches { ok = true, output = "Usage: edit <path>\n", error = "" }
|
:matches { ok = true, output = "Usage: edit <path>\n", error = "" }
|
||||||
end)
|
end)
|
||||||
|
@ -51,7 +51,7 @@ describe("The pastebin program", function()
|
|||||||
|
|
||||||
local file = fs.open( "testup", "w" )
|
local file = fs.open( "testup", "w" )
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
expect(capture(stub, "pastebin", "put", "testup" ))
|
expect(capture(stub, "pastebin", "put", "testup" ))
|
||||||
:matches { ok = true, output = "Connecting to pastebin.com... Success.\nUploaded as https://pastebin.com/abcde\nRun \"pastebin get abcde\" to download anywhere\n", error = "" }
|
:matches { ok = true, output = "Connecting to pastebin.com... Success.\nUploaded as https://pastebin.com/abcde\nRun \"pastebin get abcde\" to download anywhere\n", error = "" }
|
||||||
end)
|
end)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
local capture = require "test_helpers".capture_program
|
local capture = require "test_helpers".capture_program
|
||||||
|
|
||||||
describe("The id program", function()
|
describe("The id program", function()
|
||||||
|
|
||||||
it("displays computer id", function()
|
it("displays computer id", function()
|
||||||
local id = os.getComputerID()
|
local id = os.getComputerID()
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ describe("The motd program", function()
|
|||||||
file.write("Hello World!")
|
file.write("Hello World!")
|
||||||
file.close()
|
file.close()
|
||||||
settings.set("motd.path", "/modt_check.txt")
|
settings.set("motd.path", "/modt_check.txt")
|
||||||
|
|
||||||
expect(capture(stub, "motd"))
|
expect(capture(stub, "motd"))
|
||||||
:matches { ok = true, output = "Hello World!\n", error = "" }
|
:matches { ok = true, output = "Hello World!\n", error = "" }
|
||||||
end)
|
end)
|
||||||
|
@ -6,7 +6,7 @@ describe("The set program", function()
|
|||||||
settings.clear()
|
settings.clear()
|
||||||
settings.set("Test", "Hello World!")
|
settings.set("Test", "Hello World!")
|
||||||
settings.set("123", 456)
|
settings.set("123", 456)
|
||||||
|
|
||||||
expect(capture(stub, "set"))
|
expect(capture(stub, "set"))
|
||||||
:matches { ok = true, output = '"123" is 456\n"Test" is "Hello World!"\n', error = "" }
|
:matches { ok = true, output = '"123" is 456\n"Test" is "Hello World!"\n', error = "" }
|
||||||
end)
|
end)
|
||||||
@ -15,12 +15,12 @@ describe("The set program", function()
|
|||||||
settings.clear()
|
settings.clear()
|
||||||
settings.set("Test", "Hello World!")
|
settings.set("Test", "Hello World!")
|
||||||
settings.set("123", 456)
|
settings.set("123", 456)
|
||||||
|
|
||||||
expect(capture(stub, "set Test"))
|
expect(capture(stub, "set Test"))
|
||||||
:matches { ok = true, output = '"Test" is "Hello World!"\n', error = "" }
|
:matches { ok = true, output = '"Test" is "Hello World!"\n', error = "" }
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("set a setting", function()
|
it("set a setting", function()
|
||||||
expect(capture(stub, "set Test Hello"))
|
expect(capture(stub, "set Test Hello"))
|
||||||
:matches { ok = true, output = '"Test" set to "Hello"\n', error = "" }
|
:matches { ok = true, output = '"Test" set to "Hello"\n', error = "" }
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ describe("The time program", function()
|
|||||||
it("displays time", function()
|
it("displays time", function()
|
||||||
local time = textutils.formatTime(os.time())
|
local time = textutils.formatTime(os.time())
|
||||||
local day = os.day()
|
local day = os.day()
|
||||||
|
|
||||||
expect(capture(stub, "time"))
|
expect(capture(stub, "time"))
|
||||||
:matches { ok = true, output = "The time is " .. time .. " on Day " .. day .. "\n", error = "" }
|
:matches { ok = true, output = "The time is " .. time .. " on Day " .. day .. "\n", error = "" }
|
||||||
end)
|
end)
|
||||||
|
28
tools/check-lines.py
Normal file
28
tools/check-lines.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import pathlib, sys
|
||||||
|
|
||||||
|
problems = False
|
||||||
|
|
||||||
|
# Skip images and files without extensions
|
||||||
|
exclude = [ ".png", "" ]
|
||||||
|
|
||||||
|
for path in pathlib.Path(".").glob("src/**/*"):
|
||||||
|
if path.is_dir() or path.suffix in exclude:
|
||||||
|
continue
|
||||||
|
|
||||||
|
with path.open(encoding="utf-8") as file:
|
||||||
|
has_dos, has_trailing, needs_final = False, False, False
|
||||||
|
for i, line in enumerate(file):
|
||||||
|
if len(line) >= 2 and line[-2] == "\r" and line[-1] == "\n" and not has_line:
|
||||||
|
print("%s has contains '\\r\\n' on line %d" % (path, i + 1))
|
||||||
|
problems = has_dos = True
|
||||||
|
|
||||||
|
if len(line) >= 2 and line[-2] in " \t" and line[-1] == "\n" and not has_trailing:
|
||||||
|
print("%s has trailing whitespace on line %d" % (path, i + 1))
|
||||||
|
problems = has_trailing = True
|
||||||
|
|
||||||
|
if line is not None and len(line) >= 1 and line[-1] != "\n":
|
||||||
|
print("%s should end with '\\n'" % path)
|
||||||
|
problems = True
|
||||||
|
|
||||||
|
if problems:
|
||||||
|
sys.exit(1)
|
Loading…
Reference in New Issue
Block a user