Re: goto's, and loops
- Posted by Jason Gade <jgade at PCEZ.COM> Jul 29, 1999
- 537 views
Although I haven't worked on the program for awhile, I wondered about goto's when trying to port the Rogue role-playing game from C to Euphoria as an exercise. Here is the original code: main(argc, argv) int argc; char *argv[]; { /* Save the setuid we have got, then turn back into the player */ saved_uid=geteuid(); setuid(true_uid=getuid()); if (init(argc, argv)) { /* restored game */ goto PL; } for (;;) { clear_level(); make_level(); put_objects(); put_stairs(); add_traps(); put_mons(); put_player(party_room); print_stats(STAT_ALL); PL: play_level(); free_stuff(&level_objects); free_stuff(&level_monsters); } } Notice the goto jumping into the middle of the loop so that the program can handle a new game or a resumed game. Now, here is the Euphoria. Although it took me some figuring out, I think that it is clearer than the C version. If anyone has a better way of doing it, though, I am willing to learn. -- main() if init(command_line()) then -- restored game play_level() free_stuff(&level_objects) -- Note: didn't translate this yet! free_stuff(&level_monsters) -- Ditto! end if while TRUE do -- main loop BEGIN clear_level() make_level() put_objects() put_stairs() add_traps() put_mons() put_player(party_room) print_stats(STAT_ALL) play_level() free_stuff(&level_objects) -- didn't translate free_stuff(&level_monsters) -- ditto end while -- main loop END -- end main() Gee, I need to get back to work on this . . . The hardest part is figuring out all of the dependencies so that I can include stuff in the right order. I guess that I just have to make a chart by hand, but if anyone has any other useful tips they will be welcome.