10-26-2005, 11:11 PM
i've been really busy with school, but i managed a few minutes of coding
here's some code (FreeBASIC .14):
[syntax="qbasic"]'
' Text Adventure game...thing...Oz style
'
ENUM Boolean
True = -1, False = 0
END ENUM
TYPE World
fname as string
lumps as integer
END TYPE
TYPE Scene
offset as integer
length as integer
END TYPE
TYPE Object
' Where are we loading this from?
fname as string
name as string
num_c as integer ' How many associated commands?
assoc_c as any ptr ' Associated command function reference
assoc_f as function() as any ' This will be determined by assoc_c[#]
' We could add attributes such as weight here if we want to...
END TYPE
TYPE ObjCommands
name as string ' Main name of the command ex: "Kick"
aliases as string ptr ' Aliases of the main name, ex: "Take"->"Get", "Steal"
assoc_f as function() as any ' The function (from pointers)
END TYPE
DECLARE FUNCTION Valid_Command(command_ as any ptr) as integer ' Returns index of the command
DECLARE FUNCTION Valid_Obj_Command(this as Object, command as any ptr) as integer ' Returns -1 if the command is not accepted, otherwise it returns the command index
' Our actions to objects
DECLARE FUNCTION Take(this as Object) as Boolean
DECLARE FUNCTION Break(this as Object) as Boolean
DECLARE FUNCTION Push(this as Object) as Boolean
' This controls our world
DECLARE FUNCTION Move(direction as string) as Boolean
' Here are our initializers
DECLARE SUB Init_Commands()
' ***
' Lets make some variables
' ***
REDIM SHARED cmdlst(0) as ObjCommands
Init_Commands()
' ***
' Our code for the main game goes here
' ***
' These are just some tests and examples
dim i as integer
i = Valid_Command(cptr(any ptr, @cmdlst(0).assoc_f)) ' @Take
print i
sleep
end
' ***
' Initializes commands (to make code less messy)
' ***
SUB Init_Commands()
' We have 3 commands:
' Take(), Break(), Push()
REDIM cmdlst(0 to 2) as ObjCommands
cmdlst(0).name = "take"
cmdlst(0).aliases = Callocate(2) ' The number of aliases...right now we have 2 (0, 1)
cmdlst(0).aliases[0] = "grab"
cmdlst(0).aliases[1] = "steal"
cmdlst(0).assoc_f = @Take
cmdlst(1).name = "break"
cmdlst(1).aliases = Callocate(2) ' The number of aliases...right now we have 2 (0, 1)
cmdlst(1).aliases[0] = "smash"
cmdlst(1).aliases[1] = "destroy"
cmdlst(1).assoc_f = @Break
cmdlst(2).name = "push"
cmdlst(2).aliases = Callocate(0) ' The number of aliases...right now, we have 0 (i couldn't think of any)
cmdlst(2).assoc_f = @Push
END SUB
FUNCTION Valid_Command(command_ as any ptr) as integer
dim cmdi as integer ' command index
for cmdi = lbound(cmdlst) to ubound(cmdlst)
if(command_ = @cmdlst(cmdi).assoc_f) then
return 1
end if
next
return 0
END FUNCTION
FUNCTION Take(this as Object) as Boolean
return False
END FUNCTION
FUNCTION Break(this as Object) as Boolean
return False
END FUNCTION
FUNCTION Push(this as Object) as Boolean
return False
END FUNCTION[/syntax]
Oz~
:: Edit ::
I should explain the World and Scene types
If you've ever looked at quake code, you'd see how they save and load levels....through "lumps"
basically, a lump is a chunk of data....it has a starting point, and it has a length
here's a good example:
It's jsut a quicker way of organizing multiple forms of data in one file
Here's how it would work in a file format (each line is a pseudo line in the file):
So, in one file, we could have multiple rooms, with multiple mini-lumps inside, if we wanted
i hope that helps explain how it could work
if there are any other thoughts, please contribute...you can completely trash that base code if you have another idea...
if you don't feel like coding it, i probably can if i have a better idea of what I'm doing
Oz~
here's some code (FreeBASIC .14):
[syntax="qbasic"]'
' Text Adventure game...thing...Oz style

'
ENUM Boolean
True = -1, False = 0
END ENUM
TYPE World
fname as string
lumps as integer
END TYPE
TYPE Scene
offset as integer
length as integer
END TYPE
TYPE Object
' Where are we loading this from?
fname as string
name as string
num_c as integer ' How many associated commands?
assoc_c as any ptr ' Associated command function reference
assoc_f as function() as any ' This will be determined by assoc_c[#]
' We could add attributes such as weight here if we want to...
END TYPE
TYPE ObjCommands
name as string ' Main name of the command ex: "Kick"
aliases as string ptr ' Aliases of the main name, ex: "Take"->"Get", "Steal"
assoc_f as function() as any ' The function (from pointers)
END TYPE
DECLARE FUNCTION Valid_Command(command_ as any ptr) as integer ' Returns index of the command
DECLARE FUNCTION Valid_Obj_Command(this as Object, command as any ptr) as integer ' Returns -1 if the command is not accepted, otherwise it returns the command index
' Our actions to objects
DECLARE FUNCTION Take(this as Object) as Boolean
DECLARE FUNCTION Break(this as Object) as Boolean
DECLARE FUNCTION Push(this as Object) as Boolean
' This controls our world
DECLARE FUNCTION Move(direction as string) as Boolean
' Here are our initializers
DECLARE SUB Init_Commands()
' ***
' Lets make some variables
' ***
REDIM SHARED cmdlst(0) as ObjCommands
Init_Commands()
' ***
' Our code for the main game goes here
' ***
' These are just some tests and examples
dim i as integer
i = Valid_Command(cptr(any ptr, @cmdlst(0).assoc_f)) ' @Take

print i
sleep
end
' ***
' Initializes commands (to make code less messy)
' ***
SUB Init_Commands()
' We have 3 commands:
' Take(), Break(), Push()
REDIM cmdlst(0 to 2) as ObjCommands
cmdlst(0).name = "take"
cmdlst(0).aliases = Callocate(2) ' The number of aliases...right now we have 2 (0, 1)
cmdlst(0).aliases[0] = "grab"
cmdlst(0).aliases[1] = "steal"
cmdlst(0).assoc_f = @Take
cmdlst(1).name = "break"
cmdlst(1).aliases = Callocate(2) ' The number of aliases...right now we have 2 (0, 1)
cmdlst(1).aliases[0] = "smash"
cmdlst(1).aliases[1] = "destroy"
cmdlst(1).assoc_f = @Break
cmdlst(2).name = "push"
cmdlst(2).aliases = Callocate(0) ' The number of aliases...right now, we have 0 (i couldn't think of any)
cmdlst(2).assoc_f = @Push
END SUB
FUNCTION Valid_Command(command_ as any ptr) as integer
dim cmdi as integer ' command index
for cmdi = lbound(cmdlst) to ubound(cmdlst)
if(command_ = @cmdlst(cmdi).assoc_f) then
return 1
end if
next
return 0
END FUNCTION
FUNCTION Take(this as Object) as Boolean
return False
END FUNCTION
FUNCTION Break(this as Object) as Boolean
return False
END FUNCTION
FUNCTION Push(this as Object) as Boolean
return False
END FUNCTION[/syntax]
Oz~
:: Edit ::
I should explain the World and Scene types
If you've ever looked at quake code, you'd see how they save and load levels....through "lumps"
basically, a lump is a chunk of data....it has a starting point, and it has a length
here's a good example:
Code:
mynick$ = "Ozwald Smooth"
lump(1).offset = 1
lump(1).length = 6
' Lump(1) = "Ozwald"
lump(2).offset = 7
lump(2).length = 6
' Lump(2) = "Smooth"
It's jsut a quicker way of organizing multiple forms of data in one file
Here's how it would work in a file format (each line is a pseudo line in the file):
Quote:num_lumps%
lump_1_offset%
lump_2_offset%
(...)
Length_of_Lump_one%
data$
Length_of_Lump_two%
data$
(...)
So, in one file, we could have multiple rooms, with multiple mini-lumps inside, if we wanted
i hope that helps explain how it could work
if there are any other thoughts, please contribute...you can completely trash that base code if you have another idea...
if you don't feel like coding it, i probably can if i have a better idea of what I'm doing
Oz~