Skip to content
Snippets Groups Projects
Commit c63d2a21 authored by Isak Kallestad Mandal's avatar Isak Kallestad Mandal
Browse files

Added functionality to the checkHand button

parent 94cdb39b
No related branches found
No related tags found
No related merge requests found
package no.ntnu.idatt2001.oblig4.cardgame.View;
import javafx.scene.control.TextField;
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Rectangle;
import no.ntnu.idatt2001.oblig4.cardgame.Model.HandOfCards;
import no.ntnu.idatt2001.oblig4.cardgame.Model.PlayingCard;
import no.ntnu.idatt2001.oblig4.cardgame.Model.DeckOfCards;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import no.ntnu.idatt2001.oblig4.cardgame.Model.DeckOfCards;
import no.ntnu.idatt2001.oblig4.cardgame.Model.HandOfCards;
import no.ntnu.idatt2001.oblig4.cardgame.Model.PlayingCard;
public class ApplicationFront extends Application {
......@@ -80,11 +76,22 @@ public class ApplicationFront extends Application {
deckField.setLayoutX(365);
deckField.setLayoutY(90);
TextField hearts = newTextField("", 180, 400, "black", "white", 200, 50, 20);
TextField flush = newTextField("", 425, 400, "black", "white", 200, 50, 20);
TextField queen = newTextField("", 180, 500, "black", "white", 250, 50, 20);
TextField sum = newTextField("", 475, 500, "black", "white", 150, 50, 20);
hearts.setEditable(false);
flush.setEditable(false);
queen.setEditable(false);
sum.setEditable(false);
dealHand.setOnAction(e -> {
hand.setHand(deck.dealHand(NUM_CARDS));
handField.getChildren().clear();
for (PlayingCard card : hand.getHand()) {
Image image = new Image("file:src/main/resources/" + card.getSuit() + card.getFace() + ".png");
Image image = new Image(
"file:src/main/resources/" + card.getSuit() + card.getFace() + ".png");
ImageView cardFront = new ImageView(image);
cardFront.setFitWidth(75);
cardFront.setFitHeight(90);
......@@ -92,20 +99,19 @@ public class ApplicationFront extends Application {
}
});
checkHand.setOnAction(e -> {
hearts.setText(hand.hasHearts());
flush.setText(hand.isFlush());
queen.setText(hand.hasQueenOfSpades());
sum.setText(String.valueOf(hand.calculateSumOfHand()));
});
Group root = new Group(dealHand, checkHand, handField, deckField);
Group root = new Group(dealHand, checkHand, handField, deckField, hearts, flush, queen, sum);
Scene scene = new Scene(root, 800, 600, Color.DARKSEAGREEN);
stage.setScene(scene);
return scene;
}
// Image cardBack = newImage("file:src/main/resources/back1.png", 100, 100, 100, 100);
// Rectangle cardBackRect = new Rectangle(100, 100, 100 , 100);
// ImageInput imageInput = new ImageInput(cardBack, 100, 100);
// cardBackRect.setEffect(imageInput);
public Image newImage(String path, int x, int y, int width, int height) {
Image image = new Image(path);
......@@ -117,6 +123,7 @@ public class ApplicationFront extends Application {
imageView.setPreserveRatio(true);
return image;
}
public Button newGameButton(String text, int x, int y, String borderColor,
String backgroundColor, int width, int height, int fontSize) {
Button button = new Button(text);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment