Results 1 to 7 of 7
  1. #1
    michail is offline Member
    Join Date
    Dec 2009
    Posts
    31
    Rep Power
    0

    Default Chess, Variable Loosing it.s Value

    messed up code
    Last edited by michail; 01-28-2010 at 05:17 PM.
    For a world of science and reason

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

    Default

    Quote Originally Posted by michail View Post
    Java Code:
                if (Mydisplay == "Pawn 0,1")
    Not that it answers your question but this is not the way to compare two Strings for equality. Use the .equals( ... ) method for that.

    kind regards,

    Jos

  3. #3
    michail is offline Member
    Join Date
    Dec 2009
    Posts
    31
    Rep Power
    0

    Default

    thanks for that. I will do it that way, still don.t know how to get the "myDisplay" to be updated every time the player selects the piece.
    For a world of science and reason

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    It's a bit of unusual code to say the least, but if I were your instructor, I'd ask you to start completely over, to get rid of everything that's static except for the main method, and to make it use more standard OOPs techniques. You may in fact want to discuss this assignment with your instructor a bit.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm sorry to be blunt, but it really is ugly code. I think that your best option truly is to begin again. Again, I'm sincerely sorry to say this.

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

    Default

    Quote Originally Posted by Fubarable View Post
    I'm sorry to be blunt, but it really is ugly code. I think that your best option truly is to begin again. Again, I'm sincerely sorry to say this.
    The politically correct term is 'convoluted' here, as in: the classes and program logic are very convoluted. @OP: think of abstract things that do things: a chess board, a move evaluator (check for legality etc.) chess pieces etc. Those thIngs all have to cooperate in order to play a game of chess, or to at least make the pieces move in a sensible way on the board; the term here is CRC: Classes, Responsibility and Collaboration. All three aspects need to be defined, e.g. don't stick functionality where it doesn't belong (Classes and Responsibility) and don't make classes do things that other classes can't handle (Collaboration).

    kind regards,

    Jos

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    For one thing, in real life, a chess board is not a grid of chess pieces, but rather a 2-dimensional grid of cells, that may or may not hold a single chess piece. Thus if this were my program, I'd create an object, say Square, or Cell, that has a rank and file, and can either be empty or hold a chess piece, and create a board that is a 2-D array of these Cells.

Similar Threads

  1. chess game
    By michail in forum New To Java
    Replies: 13
    Last Post: 01-12-2010, 08:24 AM
  2. Chess game
    By michail in forum New To Java
    Replies: 4
    Last Post: 12-23-2009, 07:51 PM
  3. New Chess-Like game
    By jSarK0Y in forum Reviews / Advertising
    Replies: 3
    Last Post: 06-10-2009, 04:28 AM
  4. Loosing TableCellEditor Component Focus
    By sandeepsai39 in forum AWT / Swing
    Replies: 0
    Last Post: 03-24-2009, 07:39 AM
  5. Loosing TableCellEditor Component Focus
    By sandeepsai39 in forum New To Java
    Replies: 0
    Last Post: 03-23-2009, 06:42 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
  •