I'm looking for suggestions on how best to port some very old sequential BASIC code. It looks like something like this:
var=1
print "what now?"
input q
if q=2 then goto 500
if q=3 then var=var+1
print "that's nice, now what?"
input q
if q=1 then gosub 700
var2=var+var*2
goto 300
etc.
I flow-charted the program and it's pretty nutty with subroutines and goto statements. I can rewrite alot of it, but would rather just try to preserve the logic to make it easier.
So what I did was to put each of the response lines (the print statements) into a list. I rewrite the list in response to the input from the user (the input statements). I use a regular While Not KeyDown(KEY_ESCAPE) loop to refresh the graphics window. The only thing moving on the screen is the input command line (my code for "input q"). You enter a command, hit enter, and based on what you entered, I refresh the list and the screen gets refreshed (the output "print" stuff).
What I'm not sure about is how get the sequential flow control logic (if then, goto gosub etc.) to fit in the context of the continuous While loop.
What I'm thinking is that I need to write a command parser and then just jump out to a function depending on what the input command is. So the original code (minus the input and output parts) just gets mapped to a series of functions. Then I'd have to write some code to determine where in the original program logic I am at any given time.
I don't see a need to oopify this.
Is there a standard approach for something like this?
-pmc
var=1
print "what now?"
input q
if q=2 then goto 500
if q=3 then var=var+1
print "that's nice, now what?"
input q
if q=1 then gosub 700
var2=var+var*2
goto 300
etc.
I flow-charted the program and it's pretty nutty with subroutines and goto statements. I can rewrite alot of it, but would rather just try to preserve the logic to make it easier.
So what I did was to put each of the response lines (the print statements) into a list. I rewrite the list in response to the input from the user (the input statements). I use a regular While Not KeyDown(KEY_ESCAPE) loop to refresh the graphics window. The only thing moving on the screen is the input command line (my code for "input q"). You enter a command, hit enter, and based on what you entered, I refresh the list and the screen gets refreshed (the output "print" stuff).
What I'm not sure about is how get the sequential flow control logic (if then, goto gosub etc.) to fit in the context of the continuous While loop.
What I'm thinking is that I need to write a command parser and then just jump out to a function depending on what the input command is. So the original code (minus the input and output parts) just gets mapped to a series of functions. Then I'd have to write some code to determine where in the original program logic I am at any given time.
I don't see a need to oopify this.
Is there a standard approach for something like this?
-pmc