Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void initGameScreen() {
- PropertiesManager props = PropertiesManager.getPropertiesManager();
- // THE GUESS HISTORY GOES IN THE CENTER, WHICH WE'LL DISPLAY
- // USING HTML IN A JEditorPane
- gamePane = new JEditorPane();
- // gamePane.addKeyListener(cheatKeyHandler);
- gamePane.setEditable(false);
- gamePane.setContentType("text/html");
- //gamePane.setSize( new Dimension( 300, 300) );
- //gamePane.setPreferredSize( new Dimension( 300, 300 ) );
- JScrollPane jScrollPane = new JScrollPane(gamePane);
- jScrollPane.setMaximumSize(new Dimension(500,425));
- jScrollPane.setMinimumSize(new Dimension(500,425));
- // LET'S LOAD THE INITIAL HTML INTO THE STATS EDITOR PAGE
- this.loadPage(gamePane, HangManPropertyType.GAME_FILE_NAME);
- HTMLDocument gameDoc = (HTMLDocument) gamePane.getDocument();
- docManager.setGameDoc(gameDoc);
- //embed swing into javafx
- final SwingNode swingNode = new SwingNode();
- swingNode.setContent(jScrollPane);
- //ScrollPane guessesScrollPane = new ScrollPane();
- //guessesScrollPane.setContent(swingNode);
- //guessesScrollPane.setPannable(true);
- //guessesScrollPane.setPrefSize(400, 400);
- //guessesScrollPane.autosize();
- // LOAD THE HangMan PICTURE AT ZERO STAGE
- String HangMan = props
- .getProperty(HangManPropertyType.HANGMAN0_IMG_NAME);
- Image HangManImg = loadImage(HangMan);
- ImageView image = new ImageView(HangManImg);
- HangManLabel = new Label();
- HangManLabel.setGraphic(image);
- hmPane = new BorderPane();
- hmPane.setCenter(HangManLabel);
- //hmPanel.validate();
- // THE SOUTH GAME PANEL WILL BE DIVIDED IN TWO
- BorderPane southGamePane = new BorderPane();
- //southGamePanel.addKeyListener(cheatKeyHandler);
- //southGamePanel.setLayout(new BorderLayout());
- // WE'LL PUT THE GUESSING CONTROLS IN THE NORTH OF THE SOUTH
- HBox guessingPane = new HBox();
- guessingPane.setStyle("-fx-background-color:lightgray");
- guessingPane.setAlignment(Pos.CENTER);
- //guessingPane.addKeyListener(cheatKeyHandler);
- // WHEN USE CHEAT,SHOW SECRET WORD
- guessingPane.setOnKeyPressed(new EventHandler<KeyEvent>(){
- @Override
- public void handle(KeyEvent ke) {
- // TODO Auto-generated method stub
- cheatKeyHandler.keyPressed(ke);
- }
- });
- // THE NEW GAME BUTTON IS LAST CONTROL FOR THE NORTH OF THE SOUTH
- newGameButton = new Button();
- String imageName = props.getProperty(HangManPropertyType.NEW_GAME_IMG_NAME);
- Image newGameButtonImage = loadImage(imageName);
- ImageView newGameButtonImageView = new ImageView(newGameButtonImage);
- newGameButton.setGraphic(newGameButtonImageView);
- setTooltip(newGameButton, HangManPropertyType.NEW_GAME_TOOLTIP);
- newGameButton.setOnAction(new EventHandler<ActionEvent>(){
- @Override
- public void handle(ActionEvent event) {
- // TODO Auto-generated method stub
- eventHandler.respondToNewGameRequest();
- }
- });
- guessingPane.getChildren().add(newGameButton);
- // WE'LL PUT THE LETTER BUTTONS IN THE SOUTH OF THE SOUTH
- letterButtonsPane = new HBox();
- letterButtonsPane.setStyle("-fx-background-color: grey");
- letterButtonsPane.setPadding(marginlessInsets);
- letterButtonsPane.setSpacing(3.0);
- ArrayList<String> letters = props
- .getPropertyOptionsList(HangManPropertyType.LETTER_OPTIONS);
- // WE'LL STORE THE ALPHABET LETTERS IN A NICE EASY TO ACCESS HASH TABLE
- letterButtons = new HashMap();
- String fontFamily = props
- .getProperty(HangManPropertyType.LETTERS_FONT_FAMILY);
- int fontSize = Integer.parseInt(props
- .getProperty(HangManPropertyType.LETTERS_FONT_SIZE));
- //Font lettersFont = new Font(fontFamily, Font.BOLD, fontSize);
- Font lettersFont = new Font(fontSize);
- Font.font(fontFamily, FontWeight.BOLD, fontSize);
- for (int i = 0; i < letters.size(); i++) {
- // MAKE A BUTTON FOR EACH CHARACTER
- Character c = letters.get(i).charAt(0);
- Button letterButton = new Button("" + c);
- letterButton.setFont(lettersFont);
- letterButtons.put(c, letterButton);
- letterButton.setPadding(marginlessInsets);
- letterButton.setBorder(null);
- letterButtonsPane.getChildren().add(letterButton);
- final String guess;
- guess = c.toString();
- // LET THE EVENT HANDLER DEAL WITH WHEN SOMEONE PRESSES THIS BUTTON
- // THE RIGHT LETTER IN SECRET WORD WILL SHOW AS GREEN, WRONG WILL
- // SHOW AS RED
- // AND THEY WOULD BE DISABLED IF CHOSEN.
- letterButton.setOnAction(new EventHandler<ActionEvent>(){
- @Override
- public void handle(ActionEvent event) {
- // TODO Auto-generated method stub
- eventHandler.respondToGuessWordRequest(event.getSource(),
- guess);
- }
- });
- }
- // RESET ALL THE LETTER BUTTONS
- resetLetterButtonColors();
- // NOW LAY EVERYTHING OUT IN THE GAME PANEL
- //gamePanel.setLayout(new BorderLayout());
- southGamePane.setTop(guessingPane);
- southGamePane.setBottom(letterButtonsPane);
- letterButtonsPane.setAlignment(Pos.CENTER);
- letterButtonsPane.setPrefWidth(800);
- letterButtonsPane.autosize();
- gamePanel.setCenter(swingNode);
- gamePanel.setBottom(southGamePane);
- gamePanel.setRight(hmPane);
- //gamePanel.setPrefSize(500, 500);
- gamePanel.autosize();
- // NOW MAKE THIS PANEL PART OF THE WORKSPACE, WHICH MEANS WE
- // CAN EASILY SWITCH TO IT AT ANY TIME
- //workspace.add(gamePanel, HangManUIState.PLAY_GAME_STATE.toString());
- //workspace.getChildren().add(gamePanel);
- System.out.println("in the initgamePane");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement