Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 60 61 [62] 63 64 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886770 times)

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #915 on: January 26, 2012, 06:07:23 pm »

Done with version beta2 of my Juggling game,
download link:
http://www.mediafire.com/?gc1accuti1u8b62

try it and tell me what you think / if you find any bugs?

left and right arrow move the right hand, A and D move the left hand, space drops a ball,
20 combo give 2x score, 40 combo gives 3x score and 60 combo gives 4x score,
still only one ball so it's super easy.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #916 on: January 26, 2012, 06:21:28 pm »

Done with version beta2 of my Juggling game,
download link:
http://www.mediafire.com/?gc1accuti1u8b62

All works fine for me.  I'd suggest adding a notification for when you run out of balls, and a Retry/Quit? option.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #917 on: January 26, 2012, 06:32:26 pm »

it's on the list of stuff to do.
cleaning up the code right now / rewriting parts of it as functions / getting it ready for the other balls.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #918 on: January 26, 2012, 07:44:58 pm »

This is a small recursive descent parser I have written in c# using concepts from programming language and compiler design. The only difference between this and what I use on my dice roller web app is that I have removed the copyright notice and namespace as it contains my real name and contact info.

Spoiler: Class:DiceExpression (click to show/hide)
« Last Edit: January 26, 2012, 07:59:40 pm by Nadaka »
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #919 on: January 26, 2012, 08:03:05 pm »

Rest of the library:

On a mildly related note: The only copy of code for my web app that I have? is not the code that is running on the site. So I have no idea what is broken, just a pile of heavilly modified code that I have not looked at in a year.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #920 on: January 26, 2012, 08:14:31 pm »

However, some of you who looked at my code mentioned that ConsoleKey data can be used in a switch statement?  Compiler says otherwise, that switches can only interpret primitives, which I recall is why I made a separate Interface to contain the gigantic if-else ladder I built to reinterpret ConsoleKey data as a byte to be passed to a switch statement.  Which is certainly duplication of effort, but with the Interface turned static I can use it anywhere and make some applications with it.

Are you sure you were doing it right? To refer to the lesson back on page 55, I was using the Shirt class. Here was the source.
Spoiler (click to show/hide)

Now if I want to use that in a switch statement, I use it like this.
Spoiler (click to show/hide)

Enums are treated pretty much like primitives. That also means that when you pass them into a method, their value is copied over, not the location like when working with classes.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #921 on: January 26, 2012, 08:34:35 pm »

Yeah, trying it again, I was using the terms incorrectly.  When a statement is composed of "if (info.Key == ConsoleKey.B && info.Modifiers == ConsoleModifiers.Shift)" it gets a little confusing, because I was trying to pass the ConsoleKey enumerator itself into the switch, rather than its .Key extension.

It is worth noting that, as far as I know, I can only make a switch operate on one value, correct?  Which means I'd still have to have an if/else inside the case for any key that I wanted modifiers for, like B and Shift+B.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #922 on: January 26, 2012, 08:39:33 pm »

That is an interesting concept, not one that I have ever played with, but I would assume yes, you are correct, one value per switch statement. Still, I'll be back after a little research and playing around.

EDIT: Nope, couldn't find a way to make it work. Even with some cheating it just would not agree with me.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #923 on: January 26, 2012, 09:41:55 pm »

That is an interesting concept, not one that I have ever played with, but I would assume yes, you are correct, one value per switch statement. Still, I'll be back after a little research and playing around.

EDIT: Nope, couldn't find a way to make it work. Even with some cheating it just would not agree with me.

If you really want to use a switch, you can get creative.  Assign every enum a specific number.  You should be able to choose numbers such that the combinations you care about have sums that are unique.  Then switch on that sum.  Or use cascading ifs instead of a switch.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #924 on: January 26, 2012, 09:44:22 pm »

Yea, either would work, but it still isn't doing it natively. Also, trying to remember what int value corresponds to what enum sort of defeats the purpose.
Easiest way would be to have two case statements nested inside an if, I guess.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #925 on: January 26, 2012, 09:50:39 pm »

In Java, you can assign properties to Enums...you can give them both a private int and a getter method to grab it for you...can you not do that in C#?  I know it isn't native and I agree that it defeats the purpose, but it'd be really easy.  The system remembers the numbers for you.  Still hackish and probably a bad idea, though...

Two case statements nested inside an if...how would that work?  Wouldn't you need a second switch embedded in the first...otherwise it won't check for both cases, it'd fallthrough...unless C# doesn't have fallthrough.  I won't claim to know whether or not it does.
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
« Last Edit: January 26, 2012, 09:59:36 pm by Nadaka »
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #927 on: January 26, 2012, 09:58:40 pm »

Oh yea, you can do that in C#, but like you said, it is sort of hackish... Anyway, a switch inside an if would work for an int and bool,  but not an int and int.

And na, they removed the fallthough. It was causing too many issues with people in Java when they would want A to fall to B, and B to fall to C, but not A to fall to C, and they didn't think about what they were doing, so just had A drop alll the way to the end.
Best practice is to move the code from A, B and C into separate methods, and just have A call the A and B methods.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #928 on: January 26, 2012, 10:10:41 pm »

many issues with [...] Java.

I agree. Also not having fallthrough because users of a silly language can't do it properly is silly.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #929 on: January 26, 2012, 10:14:45 pm »

Eh, if it forces people to do it right...
I sort of see where you are coming from, that the language is a tool, not a baby sitter, and if we want to fuck shit up that is our right, but C# was designed to be used to produce business applications, and fast. If your boss knew that there was one less thing you could get wrong, he would agree with it, and he often gets final choice of language.
Pages: 1 ... 60 61 [62] 63 64 ... 796