Skip to main content
Code Review

Return to Answer

Bounty Awarded with 25 reputation awarded by Community Bot
edited body
Source Link
Andrej
  • 394
  • 1
  • 5

Here are two simple suggestions for improving code structure:

  1. Create base class for chess pieces abstract class Piece and subclasses for each of the pieces (e.g. class King extends Piece). Each class can then contain code that applies to the piece it represents. This will make it easier to maintain game logic in smaller self-contained chunks of code.

     class Position { /* ... */ }
     abstract class Piece
     {
     abstract boolean canMove(Position from, Position to);
     protected List<Piece> attackedBy() { return null; } // shared code example
     }
     class King extends Piece
     {
     boolean canMove(Position from, Position to) { return false; }
     }
    
  2. Separate UI code from game logic. Put UI code into View classes. Make a view object for each piece on the board. Make game Controller class for working with both view objects and game state. Keep game state in modelModel class. Search for MVC to get further details about this approach.

Here are two simple suggestions for improving code structure:

  1. Create base class for chess pieces abstract class Piece and subclasses for each of the pieces (e.g. class King extends Piece). Each class can then contain code that applies to the piece it represents. This will make it easier to maintain game logic in smaller self-contained chunks of code.

     class Position { /* ... */ }
     abstract class Piece
     {
     abstract boolean canMove(Position from, Position to);
     protected List<Piece> attackedBy() { return null; } // shared code example
     }
     class King extends Piece
     {
     boolean canMove(Position from, Position to) { return false; }
     }
    
  2. Separate UI code from game logic. Put UI code into View classes. Make a view object for each piece on the board. Make game Controller class for working with both view objects and game state. Keep game state in model class. Search for MVC to get further details about this approach.

Here are two simple suggestions for improving code structure:

  1. Create base class for chess pieces abstract class Piece and subclasses for each of the pieces (e.g. class King extends Piece). Each class can then contain code that applies to the piece it represents. This will make it easier to maintain game logic in smaller self-contained chunks of code.

     class Position { /* ... */ }
     abstract class Piece
     {
     abstract boolean canMove(Position from, Position to);
     protected List<Piece> attackedBy() { return null; } // shared code example
     }
     class King extends Piece
     {
     boolean canMove(Position from, Position to) { return false; }
     }
    
  2. Separate UI code from game logic. Put UI code into View classes. Make a view object for each piece on the board. Make game Controller class for working with both view objects and game state. Keep game state in Model class. Search for MVC to get further details about this approach.

added 76 characters in body
Source Link
Andrej
  • 394
  • 1
  • 5

Here are two simple suggestions for improving code structure:

  1. Create base class for chess pieces abstract class Piece and subclasses for each of the pieces (e.g. class King extends Piece). Each class can then contain code that applies to the piece it represents. This will make it easier to maintain game logic in smaller self-contained chunks of code.

     class Position { /* ... */ }
     abstract class Piece
     {
     abstract boolean canMove(Position from, Position to);
     protected List<Piece> attackedBy() { return null; } // ...shared code example
     }
     class King extends Piece
     {
     boolean canMove(Position from, Position to) { return false; } // ...
     }
    
  2. Separate UI code from game logic. Put UI code into View classes. Make a view object for each piece on the board. Make game Controller class for working with both view objects and game state. Keep game state in model class. Search for MVC to get further details about this approach.

Here are two simple suggestions for improving code structure:

  1. Create base class for chess pieces abstract class Piece and subclasses for each of the pieces (e.g. class King extends Piece). Each class can then contain code that applies to the piece it represents. This will make it easier to maintain game logic in smaller self-contained chunks of code.

     class Position { /* ... */ }
     abstract class Piece
     {
     abstract boolean canMove(Position from, Position to); // ...
     }
     class King extends Piece
     {
     boolean canMove(Position from, Position to) { return false; } // ...
     }
    
  2. Separate UI code from game logic. Put UI code into View classes. Make a view object for each piece on the board. Make game Controller class for working with both view objects and game state. Keep game state in model class. Search for MVC to get further details about this approach.

Here are two simple suggestions for improving code structure:

  1. Create base class for chess pieces abstract class Piece and subclasses for each of the pieces (e.g. class King extends Piece). Each class can then contain code that applies to the piece it represents. This will make it easier to maintain game logic in smaller self-contained chunks of code.

     class Position { /* ... */ }
     abstract class Piece
     {
     abstract boolean canMove(Position from, Position to);
     protected List<Piece> attackedBy() { return null; } // shared code example
     }
     class King extends Piece
     {
     boolean canMove(Position from, Position to) { return false; }
     }
    
  2. Separate UI code from game logic. Put UI code into View classes. Make a view object for each piece on the board. Make game Controller class for working with both view objects and game state. Keep game state in model class. Search for MVC to get further details about this approach.

Source Link
Andrej
  • 394
  • 1
  • 5

Here are two simple suggestions for improving code structure:

  1. Create base class for chess pieces abstract class Piece and subclasses for each of the pieces (e.g. class King extends Piece). Each class can then contain code that applies to the piece it represents. This will make it easier to maintain game logic in smaller self-contained chunks of code.

     class Position { /* ... */ }
     abstract class Piece
     {
     abstract boolean canMove(Position from, Position to); // ...
     }
     class King extends Piece
     {
     boolean canMove(Position from, Position to) { return false; } // ...
     }
    
  2. Separate UI code from game logic. Put UI code into View classes. Make a view object for each piece on the board. Make game Controller class for working with both view objects and game state. Keep game state in model class. Search for MVC to get further details about this approach.

lang-java

AltStyle によって変換されたページ (->オリジナル) /