| Summary: | NullPointerException on snakemove field in UIPainting.java after refactoring | ||
|---|---|---|---|
| Product: | CS3343 2021/22 Group16 Greedy Snake | Reporter: | WANG Yiwen <ywang2528-c> |
| Component: | Action Package | Assignee: | Baron Qu <zhiyanqu2-c> |
| Status: | RESOLVED FIXED | ||
| Severity: | critical | CC: | ruoxinli3-c |
| Priority: | --- | ||
| Version: | Ver 3.0 | ||
| Hardware: | PC | ||
| OS: | Windows | ||
|
Description
WANG Yiwen
2021-12-06 17:57:05 HKT
The bug is due to we forgot to consider the situation where the snakemove field is not yet set.
The below modification is done and the game now woks well.
//modified actionPerformed in UIPainting.java
public void actionPerformed(ActionEvent e) {
keyLock = SConstant.SC_UPDATED_KEYBOARD_LOCK;
timer.start();
if (!SConstant.SC_GAME_MODE_DEFAULT.equals(game.getMode())) {
if (SConstant.SC_GAME_MODE_AI.equals(game.getMode())) {
MapStatement.getInstance().initRecord();
game.getSnake().updateMapStatus();
game.getBean().updateMapStatus();
game.getSnake().setDirection(SnakeSelfAutoMove.thinkAndMove(((AISnake) game.getSnake()), game.getBean(),
game.getSnake().getDirection()));
}
setSnakemove(game.getSnake().getDirection());
if(snakemove!=null) { // This if else statement is added
snakemove.move(game.getSnake());
}
}
repaint();
}
|