d20 die roll string parser and roller in C#

dickenscider said:
@Plane Sailing, I think you can simplify the code if you like. It outputs a long string when only the actual die roll result is probably most useful. The extra info in the output is just there for display purposes in case you want to show a breakdown of the rolls to the UI or whatever consumer/caller.

Yes, I simplified it to just return an int. For my money a static method is exactly what is needed here - I never need to know the state of the dice at any point, it doesn't have to exist as a distinct entity. It just provides me the die rolling function when I need it.

I'm having fun with Test-Driven Development at the moment, and it is proving more beneficial than I thought it would :)

FWIW my little 'project' is to create a client-server 'dungeon viewer' app which will be like a simplified version of the new thing by electronic arts.

Cheers
 

log in or register to remove this ad

@Plane Sailing,

You like TDD? I just hate writing the tests. But I should use it more often. Definitely is a good practice/habit/method.

Is your 'dungeon viewer' app like MapTools? If so, that would be great..esp one in C# ;)

And, to which "new thing by electronic arts" are you referring? I'm not familiar.

Keep me posted if you ever release the app and/or source. Ever thought about hosting it on CodePlex? I think CP has come a long way since it was first introduced. (I feel like such a M$ whore).
 

I'm only just getting into TDD as a result of an inspirational conference last week. Visual Studio 2008 has some really nice tools for generating test stubs (including using reflection for testing of private methods), and one of the design elements that I'm trying out is typically using lots of small, easily testable methods rather than a few big methods.

My 'Dungeon Viewer' would be like the thing demonstrated in the videos by WotC (and I meant to write 'WotC' when it came out 'electronic arts' for reasons unknown!).

I rather like the idea of having rooms that contain features and creatures, and the DM (server) gets to see all the rooms with a certain level of ambient light and 'public' visibility, while the PC (client) view has light from light sources (torches, spells etc) and only rooms that they have visited have 'public' visibility - rooms that they have not seen yet are marked as 'private' by the DM and don't appear on their client.

It will be an interesting opportunity to use WPF features like 3D support, easy scaling and transformation of graphic primitives, XAML binding to XML data sources and similar stuff.

I'm most at home with OO classes, then XML and XAML/WPF is furthest away from my comfort zone, so that is the rough order that I'm tackling things in :)

I'll certainly let you know how I get on with it!

Cheers
 

dickenscider said:
@azhrei, that sounds more like a model-view-controller pattern (or n-tier)...but really that is a type of observer pattern I suppose.
Actually, it's just model-view, as there's no UI component to act as controller. :)

The DieRoller is the model, providing storage for the data (although it doesn't actually store the data, it generates it on-the-fly) and the DieObserver provides an implementation for the view.

The MVC pattern is much more sophisticated and unnecessary in this case, while having a DieRoller object that can be customized could be quite useful.
 

Plane Sailing said:
I'm only just getting into TDD as a result of an inspirational conference last week. Visual Studio 2008 has some really nice tools for generating test stubs (including using reflection for testing of private methods), and one of the design elements that I'm trying out is typically using lots of small, easily testable methods rather than a few big methods.

My 'Dungeon Viewer' would be like the thing demonstrated in the videos by WotC (and I meant to write 'WotC' when it came out 'electronic arts' for reasons unknown!).

I rather like the idea of having rooms that contain features and creatures, and the DM (server) gets to see all the rooms with a certain level of ambient light and 'public' visibility, while the PC (client) view has light from light sources (torches, spells etc) and only rooms that they have visited have 'public' visibility - rooms that they have not seen yet are marked as 'private' by the DM and don't appear on their client.

It will be an interesting opportunity to use WPF features like 3D support, easy scaling and transformation of graphic primitives, XAML binding to XML data sources and similar stuff.

I'm most at home with OO classes, then XML and XAML/WPF is furthest away from my comfort zone, so that is the rough order that I'm tackling things in :)

I'll certainly let you know how I get on with it!

Cheers
The interesting part of WPF is how much you can actually do in your XAML. I started in a new project 1 1/4 years ago, and looking back, there is so much I (and the others in my team) could have done much more elegant by relying only on XAML, using (Data)Triggers and Setters, or Control & DataTemplates.
My advice:
Try to understand how this stuff works as soon as you notice that you write code-behind that directly changes your visual representation (ranging from adding whole visual elements over setting the content of ItemControls to switching Visibility of elements on or off (Hidden/Collapsed).
Off course, before you do that, you need to understand DataBinding and also Converters.
Oh, and understing Resources and ResourceDictionary is also important. ;)

And then - note that 3D in WPF isn't exactly... the fastest. We were a bit disappointed in that area - looks nice, but performance is not great. (Though we still have some ideas how to optimize it. And with "we" I mean my colleague, since I did little - or rather nothing - in that area.)
 

Plane Sailing said:
I'm only just getting into TDD as a result of an inspirational conference last week. Visual Studio 2008 has some really nice tools for generating test stubs (including using reflection for testing of private methods), and one of the design elements that I'm trying out is typically using lots of small, easily testable methods rather than a few big methods.

If you're just starting out, you might want to read Test Driven Development: By Example. It's pretty good for learning the basics of TDD.

I use NUnit and I love it! I don't do "true" TDD because I work in a production environment. But, I still do love it.

AFAIK NUnit doesn't work with 3.x yet, though. :(
 

@ThirdWizard, have you any experience with the new built in unit testing in VS2008? Or do you know of any comparison of it with NUnit? I don't think there has been a whole lot of new development with NUnit and, like you said, I don't think it explicitly supports .NET 3.x. (although I'm sure it works fine or as normal).

I was just wondering what the word is on whether built-in VS2008 unit testing is up to snuff.

Thanks,
 

dickenscider said:
@ThirdWizard, have you any experience with the new built in unit testing in VS2008? Or do you know of any comparison of it with NUnit? I don't think there has been a whole lot of new development with NUnit and, like you said, I don't think it explicitly supports .NET 3.x. (although I'm sure it works fine or as normal).

I was just wondering what the word is on whether built-in VS2008 unit testing is up to snuff.

Thanks,

Little late...

I haven't done any unit testing with VS2008, unfortunately. I haven't worked on any production-level projects under 2008 as of yet, since while I'm all about the new and shiny, nobody else (especially my manager!) seems to be wanting to take the plunge on it. I don't guess I can blame them. ;)

I haven't even read about it on a blog! Usually that's where I wait to read about things before trying them myself. Nobody seems to be jumping head first into VS2008 either...
 

True. If I was a manger, I'd be trying to figure out the justification for the cost expenditure. Unless your doing some WPF/3.5 stuff there really is no reason, and even then you could get around with other things I suppose. Does VS05 support C#3.0 and LINQ? Can't remember.

But, I've played a little bit with the unit testing in VS08. I like how it generates the tests for you. Thats nice, but might need a little polishing. Should be really rock solid in the next version. But if you write your tests first (as they say you should) then the test generation isn't so helpful.

All in all, I like VS08, but unless there is a specific reason to pay for it, its kind of like Vista (but not that bad)....its nice, but do you REALLY need it...type of thing.
 

dickenscider said:
True. If I was a manger, I'd be trying to figure out the justification for the cost expenditure. Unless your doing some WPF/3.5 stuff there really is no reason, and even then you could get around with other things I suppose. Does VS05 support C#3.0 and LINQ? Can't remember.

Oh, LINQ is amazing. We do a lot with databases at my job and we've decided that our internal APIs would be aided a lot with LINQ. Especially since VS2008 allows you to browse our databases without having to use other applications. So, I won't have to have Query Analyzer and SQL Management Studio open while I'm doing my programming nearly as often. Plus, those LINQ statements are so much easier to read.

Still not enough leverage to go to 3.0, though. ;)

Well, we actually have one program that we needed WPF for, however, while it is "super important" to the heads, its just a frivolous little application in reality.

But, I've played a little bit with the unit testing in VS08. I like how it generates the tests for you. Thats nice, but might need a little polishing. Should be really rock solid in the next version. But if you write your tests first (as they say you should) then the test generation isn't so helpful.

I'll have to give it a try. We have VS2008 from our MSDN account that we play with to keep up to date.

All in all, I like VS08, but unless there is a specific reason to pay for it, its kind of like Vista (but not that bad)....its nice, but do you REALLY need it...type of thing.

Until that's what everone wants to see on resumes. ;) Although 2.0 isn't nearly as bad as 1.1.
 

Remove ads

Top