This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Ok then i had an idea today that i would try and make a card game. Before I start programing the game properly i started experimenting with things. First i got it into my head that i would represent each card in the deck by using two arrays - one for suit and one for the card number.
Then i kind of just started jamming and learning. Here i was trying to make a way so that once the card had been dealt it wouldn't be dealt again. Anyway i'll post the code first before i continue.
There is one other class that has the main method, that starts another method that invokes the dealRandomCard method.
Please just think of this as a rough draft, more like a doodle. Or an experiment to see what is possible using array lists and arrays.
The problem is that when i compile and run the program (either in eclispe or using command promt, the program runs fine, but then one of my processors (i have a quadcore) maxes out to 100%, and then it stays there until i either close eclispse or exit the command prompt.
What an earth is going on? Why is it doing this?
Sorry if the code seems a bit random. Maybe i should add some comments to say what is doing what. Or maybe it will be obvious to a none beginner i don't know.
Joined: Feb 13, 2010
I think i've just worked it out.
it's cause the for loop NEVER ends!
hope someone hasn't gone to the trouble of writing a big long reply!
Yep, that's it. The old infinite loop. Your problem was decrementing the loop index inside the loop. It's generally a bad idea to play around with the loop index like that, and now you know why!
Joined: Feb 13, 2010
Greg Charles wrote:Yep, that's it. The old infinite loop. Your problem was decrementing the loop index inside the loop. It's generally a bad idea to play around with the loop index like that, and now you know why!
haha i can't believe i did that!
If anyone is wondering what the heck i was thinking of. I was thinking that i wanted the for loop to go until i had printed out 52 cards, and if a certain card generated by a random number had already been generated i wanted the for loop to go again like nothing had happend. Oh well i think i would be better off using a while loop and just incrementing a variable everytime a card is printed out.