Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Saturday, March 12, 2016

ShoppyRL day one: "I'm the map, I'm the map..."

So today I made a map! It's similar to the TriQuest map (2013 7DRL) in that it's composed of "danger zones", but this time the danger zones are "fuzzed" a bit so they're not perfectly square. Well, actually they have holes cut out of them!

I've also created some creatures which are placed on the map: 5 heroes and a bunch of monsters. The terrain and the creatures can be edited in data files!

I also made a basic combat system; not sure how balanced it is, but it's similar to the one I used in TriQuest. Hopefully balancing it will require only tweaking creature stats...

Finally, there's a console app which displays the map and simulates some combat (though creatures can attack each other from across the map). I think I'll have to use some other sort of GUI, though, as the console app is way too slow then displaying the map. No idea why the Windows console can't just display a grid of characters... isn't that what it's for?

I think I'm basically on track for today, though I'll be rather busy the rest of the week so I don't really have high hopes of completing this game on time. I would have continued on with tomorrow's goals, but I'd already spent enough time programming for one day! (Even though I borrowed a lot of utility code from other projects of mine...)

Speaking of tomorrow's goals...

  • Create a real GUI
  • Oops, I forgot to finish this... let me go publish it now!

ShoppyRL day 8: "Game over, boys! No, wait, career over..."

So, I wasn't able to complete ShoppyRL this week. I already knew it on day 2 - I just had too much going on, and I was also fed up with trying out different UI frameworks. The Windows console was too slow after all (seriously Microsoft, how hard it is to make a freaking CONSOLE?!) and I tried WPF but I don't know enough about it to make anything happen in the "proper" way without what felt like gigabytes of repetitive view-model code. I could have hacked together a "fake" WPF app, or switched over to WinForms in which that sort of coding style is actually considered acceptable, but at that point I didn't really care anymore; I didn't have time for any more messing around, so I gave up. Sorry folks! Maybe I'll pick this up again someday, but I kind of doubt it... I don't even think I want to be a programmer anymore! Well, I could do it if I didn't have to write user interfaces, but good luck finding a job or open-source project like that...

Friday, March 4, 2016

ShoppyRL day zero: "Once more unto the breach..."

Time for another 7DRL! This time I'll be doing an idea that Nick (my friend who helped me with polishing up Beware of Strange Warp points a few years ago) and I have been discussing.

This one's called "ShoppyRL", and it's inspired by the PC game Recettear as well as the Android game Merchant. In ShoppyRL, you play the role of a shopkeeper by day, and switch over to controlling an adventurer by night to fend off the monster incursion.

As a shopkeeper, you'll be buying, selling, and crafting items with various town citizens, including adventurers, craftsmen, and other such folks. You want to make a decent profit, but be sure not to overcharge the adventurers, as you want them to have enough money to buy more gear later!

As an adventurer, you'll patrol the area outside the town in search of the demon gates, which are spawning the invading monsters. If you destroy the demon gates, you win the game, but of course they are well guarded by monsters, so you'll need to gather loot to improve your adventurers. Wait too long, though, and the monsters will overrun the town!

That's right, "adventurers". There will be several adventurers, and you'll be able to switch between them at any time, with the ones you're not controlling being run by the AI. I'm hoping to get some sort of "hunting pack" mechanic in there that keeps the adventurers close together (stay near the strongest ally, for instance) while also attacking nearby enemies, so they don't run off and get killed too easily. Of course, the monsters will employ this algorithm as well, so prepare for some epic battles!

Stay tuned over the next week as I develop ShoppyRL!

Oh, yeah, goals for tomorrow...
  • Create "creature", "townsperson", "hero", and "monster" classes
  • Create a map, and populate it with terrain, heroes, and monsters
  • Implement basic combat mechanics (not movement yet, just combat)
  • Create unit tests to make sure the map and combat work (since there won't be a GUI yet)

Monday, February 11, 2013

On Error Don't Explode

Everyone in the programming world mocks VB's old On Error Resume Next feature, saying it led to "cowboy coding". But you know what? The old horse had its merits!

The next time you're frustrated by Java's checked exceptions, think what fun it would be if you could write some code and not have to catch every single eventuality that whoever designed your API could think of... seriously, do I really need to catch a MalformedUriException when I'm just passing the constant string "www.wikipedia.org" to the Uri class constructor?

.NET, while it doesn't have checked exceptions like Java, has problems of its own. It's like a crotchety old uncle who is hard of hearing, so if you don't say what you want exactly right, it spews a stream of profanity in your face. It's almost worse than Java, since (although it's easier to code), you live in constant fear of runtime exceptions crashing your production code, so you are forced to spend all your time writing unit tests (not that those are unnecessary in Java, but they're more needed, in my opinion, in .NET).

And then there are the dynamic languages. These are the most flexible of all, so naturally they need tons of unit tests. You can't even assume that a variable you reference actually exists in some of these languages! However they are quite a bit more flexible when it comes to data structures. While Java and .NET will scream at you if you try to add a key to a map/dictionary and the key is already present, or conversely if you try to change the value of one that's not actually there, Perl (for instance) will happily overwrite the existing key when you add, and is glad to insert the one that's not there for you. (This is primarily because there is no distinction between "add" and "change value" for Perl hashes, since both are simply assignments, but that's beside the point.)

So where can we find a happy medium? On Error Resume Next is too lenient, but Java's anal-retentiveness is too strict. .NET and Perl take various stances in the middle, but I don't think either is optimal. What we need, I'd have to say, is actually a rethinking of the whole exception handling mechanic.

Instead of specifying in our code every time we want to handle an exception, why not assume that exceptions are meant to be handled? It's the best practice, so why shouldn't our programming languages adapt to it? The only thing left is to specify how the exceptions are to be handled.

There are several ways to handle an exception:

  • ignore it
  • log it and continue
  • log it and terminate
There are of course more than these, but these are the main ones that are "sane" - sure you could terminate without logging it, but that's not very helpful!

So, the idea is, in each source code file you would specify a default exception handling behavior, which could then be overridden in individual block scopes. For instance (in pseudo-C#):

// This class is very important to the global economy! If it produces incorrect results the world is doomed! We must stop it at once if it errs even slightly!
@Catch(typeof(Exception), CatchMode.LogAndTerminate)
class ImportantBusinessLogic
{
    public static void Main()
    {
        DoImportantBusinessStuff();
        // OK, we can be a little more lenient here; sometimes the web service we are using returns nulls instead of actual data; in that case we just use the cache.
        @Catch(typeof(NullReferenceException), CatchMode.LogAndContinue)
        {
            ComputeSomeInterestRates();
        }
        SaveTheGlobalEconomyFromRuin();
    }
}

Good idea? Bad idea? Anyone care?