@badidea
I thought OOP was to prevent modifications breaking the code? My coding is rather simple much as I coded on the old machines like the c64. I try and break it down into modules that only do one thing.
The reason I deleted the post was it was rubbish (I thought) and I wasn't happy with the coding. As for the game play it was only a appetiser for better things :) The other factor was collecting the diamonds with the least amount of drilling and ladder building which required some strategy thinking. Of course I would be adding other stuff and that is why I decided to rewrite the "engine" part to make it easier to add other things like rolling or falling rocks and other character sprites apart from the miner.
So until the corona virus gets me I will be concentrating on this particular project and hopefully have something to offer for comment or suggestions without feeling the need to delete it :)
A simple miner program
-
- Posts: 3909
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: A simple miner program
I don't know. Maybe if you are good at it. And if you are capable of doing the full design before actual coding. Which I cannot.BasicCoder2 wrote:I thought OOP was to prevent modifications breaking the code?
Maybe for a next project I try without OOP and see what happens. But with 'structs', else I go crazy. Maybe play with namespaces as well to keeps things ordered.
But the problem is not related to OOP. I use a state (waling, climbing, falling, idle, etc) for the miner. Currently I switch to that states without doing all the checks if that state is allowed. I save the previous state and it (later on in the code) turns out that state is not allowed, I switch back to the previous state. That is a bit weird I think. So I would probably implement a requested state and only switch to that state if allowed.
BTW, any code can break by modification. It is very easy. Change 1 single bit and the changes are high the the program does not work any more. Unlike humans which can handle a bit of modification usually, up to a certain level, without completely crashing.
Re: A simple miner program
Just for fun, using some oop but bypassing it back to procedural.
Code: Select all
Enum
up
down
End Enum
type strings
private:
as string original
as string sorted
declare operator cast() as string
as byte direction
declare constructor(as string, as byte,as long,as long)
declare sub sort(as strings,as long,as long)
end type
operator strings.cast() as string
print "Original string: "; original
print "Sorted string: ";sorted
print "Press any key . . ."
return ""
end operator
constructor strings(tosort as string, dirn as byte,l as long,u as long)
original=tosort
sorted=tosort
direction=dirn
sort(this,l,u)
swap sorted,original
end constructor
sub strings.sort(s As strings,begin As Long,Finish As Long)
Dim As Long i=begin,j=finish
Dim As ubyte x =S.original[(I+J)\2]
While I <= J
if direction=down then
While S.original[I] > X:I+=1:Wend
While S.original[J] < X:J-=1:Wend
else
While S.original[I] < X:I+=1:Wend
While S.original[J] > X:J-=1:Wend
end if
If I<=J Then Swap S.original[I],S.original[J]: I+=1:J-=1
wend
If J > begin Then sort(S,begin,J)
If I < Finish Then sort(S,I,Finish)
End sub
'=============================
'get the actual procedures
declare function show alias "_ZN7STRINGScv8FBSTRINGEv"(as strings) as string 'cast()
declare sub construct cdecl alias "_ZN7STRINGSC1ER8FBSTRINGaii"(as strings,as string,as byte,as long,as long)'constructor
dim as string f="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
dim as strings ptr result=callocate(sizeof(strings))
construct(*result,f,down,0,len(f)-1)
show (*result)
deallocate result
sleep
Re: A simple miner program
That code is not funny :-Pdodicat wrote:Just for fun, using some oop but bypassing it back to procedural.
...
Re: A simple miner program
In Linux 32 bit
the constructor alias is "_ZN7STRINGSC1ER8FBSTRINGall"
Don't have 64 bit Linux to test.
You seem in a very bad mood badidea.
the constructor alias is "_ZN7STRINGSC1ER8FBSTRINGall"
Don't have 64 bit Linux to test.
You seem in a very bad mood badidea.
-
- Posts: 3909
- Joined: Jan 01, 2009 7:03
- Location: Australia
Games and OOP
@badidea
Oop does however seem well suited for games which are essentially a collection of interacting objects.
It is not so much I have a problem with classes, which I did learn about when I was programming in C++ using the Dev-C++ compiler, it is just that when I changed to FreeBasic over 10 years ago it didn't support OOP and I kind of forgot about it. I think the enthusiasts for OOP with FreeBASIC are already well practised using it with c++badidea wrote:I don't know. Maybe if you are good at it. And if you are capable of doing the full design before actual coding. Which I cannot.BasicCoder2 wrote:I thought OOP was to prevent modifications breaking the code?
Maybe for a next project I try without OOP and see what happens. But with 'structs', else I go crazy. Maybe play with namespaces as well to keeps things ordered.
Oop does however seem well suited for games which are essentially a collection of interacting objects.
Indeed humans and other living things are examples of a hierarchy of self contained modules as indeed is the whole biosphere. And that collection of processing modules we call the brain uses statistical decision making not hard brittle logic although it is capable of doing logic when required.BTW, any code can break by modification. It is very easy. Change 1 single bit and the changes are high the the program does not work any more. Unlike humans which can handle a bit of modification usually, up to a certain level, without completely crashing.
Re: A simple miner program
Strange, "_ZN7STRINGSC1ER8FBSTRINGaii" works fine here on linux fbc 32 and 64 bit.dodicat wrote:In Linux 32 bit
the constructor alias is "_ZN7STRINGSC1ER8FBSTRINGall"
Don't have 64 bit Linux to test.
Than I must be me with the corona-depression. Maybe I did too many simulations.dodicat wrote:You seem in a very bad mood badidea.
Re: A simple miner program
I was experimenting with things like calling a constructor for example by using alias "_ZN7STRINGSC1ER8FBSTRINGall", in order to overcome the C++ class problem.
It is ugly, but my reasoning is that basically C and C++ (and FreeBASIC) are procedural languages, OOP is just a layer over the basic procedures.
I was hoping to get away with using a type structure and accessing C++ class methods via these names, for the more straightforward dynamic libraries anyway.
It is ugly, but my reasoning is that basically C and C++ (and FreeBASIC) are procedural languages, OOP is just a layer over the basic procedures.
I was hoping to get away with using a type structure and accessing C++ class methods via these names, for the more straightforward dynamic libraries anyway.