text adventures -- advanced source code, I can't decide which is cooler/scarier

Started by Darren Dirt, October 31, 2013, 08:57:59 AM

Previous topic - Next topic

Darren Dirt

After a quick skim yesterday of the "TypeScript"-generated JS source for "Candy Box 2", I realized that there's some brilliant elegance in there, and I can definitely learn a lot re. class-like Javascript coding from it (also there's very neat usage of ASCII art -- including* a full weapon/item inventory, along with mouse-move CollisionBox detecting, plus multi-language text localization, "save files", etc.) ...

http://candybox2.net/candybox2_uncompressed.js



But that "code" is already "cracked"; it's nothing like the WOW head-asplode wtf-ness I feel when I try to figure this out ("Colossal Cave Adventure" in DOS Batch)...

http://www.dostips.com/forum/viewtopic.php?f=3&t=4876
https://sites.google.com/site/dbenhamfiles/adventure.bat.txt?attredirects=0

(from "dbenham", definitely one of the smartest and most creative contributors amongst the most popular DOS Batch forums)


Stuff like this almost makes me feel "dumb" relative to these developers -- but that is a good thing, I mean you gotta humble yourself occasionally or you'll never be motivated to improve your skill set!

Thoughts?






* and even a squirrel in a tree!
Spoiler



Database.addAscii("places/aTree/background", 70, 52, [
    "            |   |",
    "            |   |",
    "  |             |",
    "  |             |",
    "  |             |",
    "                |",
    "                |        _.-'''-,",
    "                |      .'        `\\",
    "                |     /           /",
    "       |        |    /      .--^_^",
    "       |        |    |     /  C ,,\\",
    "                |    |    |   \\  _.)                           ___",
    "                |     \\   |   /  \\                   ____.----'.-'",
    "                |      '-, \\./ \\)\\)               .-' --  __.-'",
    "    |            \\        `-/   );/           ___/  - _.-'",
    "    |             \\_________''--'-'________.-' --    /",
    "    |              -   --        -  -     -     __.-'",
    "                     -    --    -     --   --  /",
    "                   _________________________.-'",
    "                  /",
    "                 /",
    "                |",
    "          |     |",
    "          |     |",
    "          |     |",
    "          |     |",
    "                |",
    "                |",
    "                |",
...




Heck, there's even an "animated" sea snake!


Spoiler


Database.addAscii("places/quests/theSea/seaSnake/9", 101, 10, [
    "",
    "",
    "                                           _  .  -  -  -  .",
    "                                       .-' ('( ( ( ( ( ( ( ( '-.",
    "                                  _. '( ( ( (_( . . ----- . ( ( ('.",
    "    ___//_                     _.( ( ( (_. '                   -( ( (",
    " _.c    ) (-._             _.-( ( ( (.-'                          '(_( '",
    "/__  _ /_( ( ( ( - .....- '( ( (_-'                                  '( ( -",
    "  /.'    '-.( ( ( ( ( ( ( ( ( -'                                         ( (\\",
    "              ' -(.(_(_( - '                                                '|"
]);
Database.addAscii("places/quests/theSea/seaSnake/12", 101, 11, [
    "",
    "",
    "    ___//",
    " _.c    )_                                               _ _ _",
    "/__  _ /_ ( - _                                   _.- '( ( ( ( ('-._",
    "  /.'   _( ( ( (' -. _                     _. _-( ( ( ( (_(_(_( ( ( (-_",
    "         ' -(_( ( ( ( (-._             _.-( (( ( ( (_.- '     '  -.( ( (.",
    "               ' -.(_( ( ( ( - .....- '( ( (_ ( (.-'                '-( ('.",
    "                     '-.( ( ( ( ( ( ( ( ( -' -'                        '-( (.",
    "                          ' -(.(_(_( - '                                  '.(\\",
    "                                                                            '-"
]);
Database.addAscii("places/quests/theSea/seaSnake/11", 111, 10, [
    "",
    "",
    "                                                         _ _ _",
    "    ___//_                                        _.- '( ( ( ( ('-._",
    " _.c    ) ( - _                               _-( ( ( ( (_(_(_( ( ( (-_",
    "/__  _ /_( ( ( (' -. _                     _.( ( ( (_.- '     '  -.( ( (.",
    "  /.'    ' -(_( ( ( ( (-._             _.-( ( ( (.-'                '-( ('.",
    "               ' -.(_( ( ( ( - .....- '( ( (_-'                        '-( (.",
    "                     '-.( ( ( ( ( ( ( ( ( -'                              '.(\\",
    "                          ' -(.(_(_( - '                                    '-"
]);
Database.addAscii("places/quests/theSea/seaSnake/10", 103, 10, [
    "",
    "",
    "                                                 _  .  -  -  -  .",
    "                                             .-' ('( ( ( ( ( ( ( ( (-.",
    "    ___//_                              _. '( ( ( (_( . . ----- . ( ( ('.",
    " _.c    )(' -. _                     _.( ( ( (_. '                '. ( ( (.",
    "/__  _ /( ( ( ( (-._             _.-( ( ( (.-'                        '-( (\\",
    "  /.'    ' -.(_( ( ( ( - .....- '( ( (_-'                                '.(\\",
    "               '-.( ( ( ( ( ( ( ( ( -'                                     \\('",
    "                    ' -(.(_(_( - '                                          \\|"
]);
Database.addAscii("places/quests/theSea/seaSnake/3", 78, 11, [
    "",
    "",
    "             __..__",
    "    ___//_.-( ( ( ( ' -.",
    " _.c    )( ( (_(_( (.( (' -_",
    "/__  _ / _(.('     ' -(_( ( ( -._                                _ .  _",
    "  /.'                   '-.( ( ( ( -._                      _.-( ( ( ( (' -_",
    "                            ' (_( ( ( '- ._             _.-'( ( ( (-(- ' '- .\\",
    "                                '(.( ( ( ( '- . _ _ .-'( ( (_(.-'",
    "                                    '-(_( ( ( ( ( ( ( ( (_('",
    "                                         '--(.(_( ( ( -'"
]);
Database.addAscii("places/quests/theSea/seaSnake/2", 79, 11, [
    "",
    "",
    "    ___//_.__",
    " _.c    )( ( (-( . _",
    "/__  _ /(_(_( (.( ( (-_",
    "  /.'        ' '(_( ( ( -._                                _ .- - . _",
    "                  '(.( ( ( ( -._                      _.-' ( ( ( ( ( (-_",
    "                      ' (_( ( ( '- _              _.-'( ( ( ( (-'-(.(_( '-.",
    "                          '(.( ( ( ( '- . _ _ .-'( ( ( (.-'           '-(_('.",
    "                              '-(_( ( ( ( ( ( ( ( (_(-'                   '(.\\",
    "                                  '--(.(_( ( ( -'"
]);
Database.addAscii("places/quests/theSea/seaSnake/7", 89, 11, [
    "",
    "                                    _ _ . _",
    "                              _.- '( ( ( ( ( ('-.",
    "                          .-(.('( ( ( ( ( ( ( ( ('.",
    "                     _. '( ( ( (.( -'''''''''-(_( (.(-",
    "                  _.( ( ( (_. '                 '( ( ( (_",
    "              _.-( ( ( (.-'                       ' ( ( ( '",
    "    ___//__.-'( ( (_(-'                               -( ( ( (._            _.",
    " _.c    )( ( ( (.('                                     ' (.( ( '- . _ _ .-( /",
    "/__  _ /__( (-'                                             ' ( ( ( ( ( ( (.'",
    "  /.'                                                            ' ( ( (-'"
]);
Database.addAscii("places/quests/theSea/seaSnake/5", 78, 11, [
    "",
    "                          _ _",
    "                   _.-('( ( ( ('-.",
    "               _.-'( ( ( ( ( ( ( ( ' .",
    "           _-'( ( ( (.(- '  '-(_( (.( ( -",
    "    ___//('( ( (_(-'            ' -( ( ( ( '._",
    " _.c    ) (_(.-'                    ' ( ( ( ( ( -._                       _.-/",
    "/__  _ /.-'                               -( ( ( ( '- ._             _.-'( .'",
    "  /.'                                         ' (.( ( ( '- . _ _ .-'( ( (.'",
    "                                                   ' ( ( ( ( ( ( (_(_( '",
    "                                                       '- ( (_(.(-'"
]);
Database.addAscii("places/quests/theSea/seaSnake/4", 78, 11, [
    "",
    "",
    "              _. -'('('- ._",
    "           . '( ( ( ( ( ( (-( . _",
    "    ___//('( ( (.(-'''.(_( (.( ( (-_",
    " _.c    ) ( ( '            '(_( ( ( -._                                  ____",
    "/__  _ /. '                    '(.( ( ( ( -._                      _. - ( (.-'",
    "  /.'                              ' (_( ( ( '- ._             _.-'( ( (.'",
    "                                       '(.( ( ( ( '- . _ _ .-'( ( ( (.'",
    "                                           '-(_( ( ( ( ( ( ( ( (_(-'",
    "                                                '--(.(_( ( ( -'"
]);
Database.addAscii("places/quests/theSea/seaSnake/8", 96, 10, [
    "",
    "",
    "                                     _ . - '( ( (' - . _",
    "                                 .-' ('( ( ( ( ( ( ( ( ( -",
    "                            _. '( ( ( (.(- - ''' - -  ( ( ( (",
    "                         _.( ( ( (_. '                  '( ( ( -",
    "    ___//            _.-( ( ( (.-'                         '( ( ( -",
    " _.c    )( - .._..-' ( ( (_-'                                 -( ( (._",
    "/__  _ /( ( ( ( ( ( ( ( -'                                      '(.( ('- . __",
    "  /.'     ' -(_(_( - '                                              '-( ( ( .'"
]);
Database.addAscii("places/quests/theSea/seaSnake/6", 84, 11, [
    "",
    "                              _ _ . _",
    "                        _.- '( ( ( ( ( ('-.",
    "                    .-(.('( ( ( ( ( ( ( ( ('.",
    "               _. '( ( ( (.( -'''''''''-(_( (.(-",
    "            _.( ( ( (_. '                 '( ( ( (-_",
    "    ___//.-( ( ( (.-'                       ' ( ( ( (-                     /|",
    " _.c    ) ( (_(-'                               -( ( ( (- ._            _.( /",
    "/__  _ /_(.('                                     ' (.( ( ( '- . _ _ .-( (.'",
    "  /.'                                                 ' ( ( ( ( ( ( ( (_-'",
    "                                                           ' - ( ( ( '"
]);
Database.addAscii("places/quests/theSea/seaSnake/1", 78, 11, [
    "",
    "    ___//",
    " _.c    )_",
    "/__  _ /( (-_",
    "  /.' '(.( ( (-_",
    "         '(_( ( ( -._                                _ .- ( -._",
    "            '(.( ( ( ( -._                      _.-( ( ( ( ( ( (-._",
    "                ' (_( ( ( '- ._             _.-'( ( ( ( (-(-(.(_( ('-._",
    "                    '(.( ( ( ( '- . _ _ .-'( ( ( (.-'          '-(_( ('-_",
    "                        '-(_( ( ( ( ( ( ( ( (_(-'                   '-(_('-_",
    "                            '--(.(_( ( ( -'                            ' - ('>"
]);

[close]



AND for some laughs, if you keep clicking "Throw 10 candies on the ground", it's almost like the Infocom HHGG text adventure if you kept swearing, the "narrator" gets increasingly made at you -- search for function CandiesThrown and see for yourself, funny guy.




[close]
_____________________

Strive for progress. Not perfection.
_____________________

Mr. Analog

Man, you may want to take a look at Prototype, you can really start creating JS that simplifies OOP like attributes already present in JS: http://prototypejs.org/learn/class-inheritance

You can also check out TypeScript, which is a typed superset / abstraction of JavaScript that can be compiled into JS for any platform, there's a plugin for Visual Studio 2012 and it's baked into 2013, it certainly makes things easier by creating a more strict world to create things with.

And of course JQuery, Mootools and Twitter Bootstrap for building some robust cross-browser coolness.
By Grabthar's Hammer

Darren Dirt

Quote from: Mr. Analog on October 31, 2013, 09:35:32 AM
You can also check out TypeScript, which is a typed superset / abstraction of JavaScript that can be compiled into JS for any platform, there's a plugin for Visual Studio 2012 and it's baked into 2013, it certainly makes things easier by creating a more strict world to create things with.

The above "candybox2.net" .JS file is produced via TypeScript -- which is why it's so nicely structured and caught my eye.

Unfortunately the work that I do here at my just-over-broke is not very conducive to completely overhauling how stuff is done; not much of it is Javascript anyway ... just know myself that in my free time I sometimes like to build proof-of-concept type of stuff, and seeing the Candy Box script code was like a re-awakening of what I have known for a while but just haven't had much chance/reason to put into practice, in terms of elegant JS'ing. Over the years I've developed my own "way" of throwing stuff together quickly, but God help the guy or gal who might ever have to expand upon my code ;) "It works, don't touch anything!" okay not quite that bad, but compared to the above I definitely feel inspired to increase the Elegance Quotient of my more-than-super-simple code.
_____________________

Strive for progress. Not perfection.
_____________________

Mr. Analog

Eh sometimes it really is easier to just core out the underlying infrastructure of a thing without changing how it looks/feels, at least that's what I found doing support.

Some of this stuff you can pick up in a weekend
By Grabthar's Hammer