Results 101 to 111 of 111
Thread: Help with random letters.
- 02-25-2011, 07:52 AM #101
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
- 02-25-2011, 07:53 AM #102
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
- 02-25-2011, 09:02 AM #103
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,395
- Blog Entries
- 7
- Rep Power
- 17
For one thing I would've created to ugly methods:
And have this total lack of arrays or other data structures concentrated in those two little monsters above.Java Code:int getS(int i) { switch (i) { case 1: return s1; case 2: return s2; ... default: throw IllegalArgumentExcept("s"+i+" doesn't exist); } } void setS(int i, int value) { switch(i) { case 1: s1= v; return; case 2: s2= v; return; ... default: throw IllegalArgumentExcept("s"+i+" doesn't exist); } }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-25-2011, 09:07 AM #104
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Yeah, he basically has that now, but he's yet to clean out some cruft he accumulated before he started doing it right.
@jenxin -- how about that moveLetter() method? And the moveValid() method to go with it?
-Gary-
- 02-25-2011, 09:14 AM #105
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
not sure if this is correct but, moveLetter() method:
I'm unsure of how to write the moveValid() method.Java Code:private void moveLetter(char c) { setBoardValueAtSquare(c, ' '); setBoardValueAtSquare(' ', c); }
when i try to just bypass the moveValid, and instead use the moveLetter, it's just gives me an error code with the corresponding int value of a letter... ie. when i put in a ;
*** Invalid index value of: 97 in setBoardValueAtSquare(). Exiting program...
- 02-25-2011, 09:19 AM #106
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
That's not going to work. You're trying to put a space in square 'a' which Java understands is square 97 (the ASCII value of 'a'). You don't have 97 squares -- you only have 25.
You need to get the number of the square where your char is first. You also need to get the number of the square where the space is. Then you need to put the char where the space was, and put the space where the char was. Try again.
-Gary-
- 02-25-2011, 09:41 AM #107
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
I tried but I'm not sure how to do it. I understand what you mean, but I don't know how to accomplish it, :\
- 02-25-2011, 09:45 AM #108
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
also how do I make it not randomize everytime the method is called upon? should i take out the initialize from the while script?
edit:
took it out and its constant now. phew
- 02-25-2011, 10:59 AM #109
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
Thanks guys, I got it working, kinda :[.
It checks for invalid moves, but some moves are.. getting through, idk why.
I ended up using my old moveLetter code(yes the messy one), and also my old moveValid code. Well at least my code isn't 2000 lines anymore. :] Thanks gary!!
- 02-25-2011, 05:13 PM #110
I'm glad you got it working, but you caused yourself much more trouble than you needed to by not taking the time to understand the Magic Squares program. A big part of computer science classes is taking one assignment and building on it to do a more complicated assignment. Get used to that process. Take the time to understand previous assignments before moving on to the next one. You'll save yourself a lot of time and a lot of headaches that way.
Recommended reading: Starting Writing a ProgramHow to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-28-2011, 03:32 PM #111
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
for those who wanted the solution; here it is.
http://logos.cs.uic.edu/107/assignme.../SquareUp.java
Similar Threads
-
generate random letters inbetween a string
By greg677 in forum New To JavaReplies: 1Last Post: 05-04-2010, 05:06 AM -
What does the letters mean?
By mustachMan in forum New To JavaReplies: 3Last Post: 02-11-2010, 09:50 PM -
How do I generate random numbers in a certain range using the random class?
By frasifrasi in forum New To JavaReplies: 8Last Post: 04-19-2009, 05:50 PM -
Generate a random code 4 letters long
By bl00dr3d in forum New To JavaReplies: 9Last Post: 04-06-2009, 05:32 AM -
need block letters??
By dc2acgsr99 in forum New To JavaReplies: 16Last Post: 01-29-2008, 08:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks