reset password
Author Message
jgarc629
Posts: 76
Posted 19:13 Nov 06, 2017 |

Do you need to create a new Scene when they press an arrow key in the Event Handler? Do you have to do something outside of the EventHander as well so it actually effects the GUI like when you press F10? 

 

If so, I typed scene.setOnKeyPressed(key); in my start(Stage PrimaryStage) method in order to have the Event Handler key actually work so it can start a New Game. How can I set my Event Handlers for the arrows to work on the GUI? 

Last edited by jgarc629 at 00:35 Nov 07, 2017.
jingchao
Posts: 25
Posted 22:37 Nov 06, 2017 |

Create different if statements under the same key event handler.

jgarc629
Posts: 76
Posted 23:33 Nov 06, 2017 |
jingchao wrote:

Create different if statements under the same key event handler.

The should I put F10 and the arrow keys under the same Event Handler's anonymous class then?

jingchao
Posts: 25
Posted 23:50 Nov 06, 2017 |

It should be

jgarc629
Posts: 76
Posted 00:34 Nov 07, 2017 |

My if statement for pressing the F10 key has this in the if statement if it's pressed:

if (key.getCode() == KeyCode.F10) {

                    primaryStage.hide();
                    Stage newStage = new Stage();
                    start(newStage);

  }

This works fine to start a new game.

What should I put in the if statement for the other keys. This is what I have for my UP event:

if (key.getCode() == KeyCode.DOWN) {

                    if (game.getMap()[guard.getRow()][guard.getColumn() + 1].getValue() != 'W') {
                        
                        if(guard.getRow() == 1 && guard.getColumn() == 1){
                            game.getMap()[guard.getRow()][guard.getColumn()].setValue('S');    
                        }
                        
                        else{
                            game.getMap()[guard.getRow()][guard.getColumn()].setValue(' ');    
                        }
                        
                        guard.setColumn(guard.getColumn() + 1);
                        game.getMap()[guard.getRow()][guard.getColumn()].setValue('P');    
                        
                    
                    }

}

game is an AsylumMap, Map is the 2D array, Guard is the player represented as a Coordinate btw

jingchao
Posts: 25
Posted 01:53 Nov 07, 2017 |

I don't know your logic here, I implemented it in a very different way. You should figure this out. 😂

jgarc629
Posts: 76
Posted 01:58 Nov 07, 2017 |

Alright cool thanks anyways dude