Page 6 of 6 FirstFirst ... 456
Results 101 to 111 of 111
  1. #101
    jenxin is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

    Default

    If I was able to use an array, I wouldhv learned it in these past 14 hours.. =[
    Comeback Gary~ lol!

  2. #102
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by JosAH View Post
    That preposterous blob of code won't fit on one screen. I personally find it completely lunatic not to use a simple array for this little problem.

    kind regards,

    Jos
    I agree completely. I don't know how I got myself hooked into this thread.

    -Gary-

  3. #103
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by gcalvin View Post
    I agree completely. I don't know how I got myself hooked into this thread.
    For one thing I would've created to ugly methods:

    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);
       }
    }
    And have this total lack of arrays or other data structures concentrated in those two little monsters above.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #104
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    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-

  5. #105
    jenxin is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

    Default

    not sure if this is correct but, moveLetter() method:

    Java Code:
        private void moveLetter(char c) {
        	setBoardValueAtSquare(c, ' '); 
        	setBoardValueAtSquare(' ', c);
    
    	}
    I'm unsure of how to write the moveValid() method.

    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...

  6. #106
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    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-

  7. #107
    jenxin is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

    Default

    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, :\

  8. #108
    jenxin is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

    Default

    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

  9. #109
    jenxin is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

    Default

    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!!

  10. #110
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,016
    Rep Power
    10

    Default

    Quote Originally Posted by jenxin View Post
    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!!
    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 Program
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #111
    jenxin is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

Page 6 of 6 FirstFirst ... 456

Similar Threads

  1. generate random letters inbetween a string
    By greg677 in forum New To Java
    Replies: 1
    Last Post: 05-04-2010, 06:06 AM
  2. What does the letters mean?
    By mustachMan in forum New To Java
    Replies: 3
    Last Post: 02-11-2010, 10:50 PM
  3. Replies: 8
    Last Post: 04-19-2009, 06:50 PM
  4. Generate a random code 4 letters long
    By bl00dr3d in forum New To Java
    Replies: 9
    Last Post: 04-06-2009, 06:32 AM
  5. need block letters??
    By dc2acgsr99 in forum New To Java
    Replies: 16
    Last Post: 01-29-2008, 09:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •