Here are two simple suggestions for improving code structure:
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; } }
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:
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; } }
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:
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; } }
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:
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; } // ... }
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:
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; } // ... }
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:
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; } }
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:
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; } // ... }
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.