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
Branches master
No related tags found
No related merge requests found
package no.ntnu.idatt2001.oblig4.cardgame.View; 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.application.Application;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button; 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.paint.Color;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.scene.text.FontWeight; import javafx.scene.text.FontWeight;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.stage.Stage; 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 { public class ApplicationFront extends Application {
...@@ -80,11 +76,22 @@ public class ApplicationFront extends Application { ...@@ -80,11 +76,22 @@ public class ApplicationFront extends Application {
deckField.setLayoutX(365); deckField.setLayoutX(365);
deckField.setLayoutY(90); 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 -> { dealHand.setOnAction(e -> {
hand.setHand(deck.dealHand(NUM_CARDS)); hand.setHand(deck.dealHand(NUM_CARDS));
handField.getChildren().clear(); handField.getChildren().clear();
for (PlayingCard card : hand.getHand()) { 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); ImageView cardFront = new ImageView(image);
cardFront.setFitWidth(75); cardFront.setFitWidth(75);
cardFront.setFitHeight(90); cardFront.setFitHeight(90);
...@@ -92,20 +99,19 @@ public class ApplicationFront extends Application { ...@@ -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, hearts, flush, queen, sum);
Group root = new Group(dealHand, checkHand, handField, deckField);
Scene scene = new Scene(root, 800, 600, Color.DARKSEAGREEN); Scene scene = new Scene(root, 800, 600, Color.DARKSEAGREEN);
stage.setScene(scene); stage.setScene(scene);
return 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) { public Image newImage(String path, int x, int y, int width, int height) {
Image image = new Image(path); Image image = new Image(path);
...@@ -117,6 +123,7 @@ public class ApplicationFront extends Application { ...@@ -117,6 +123,7 @@ public class ApplicationFront extends Application {
imageView.setPreserveRatio(true); imageView.setPreserveRatio(true);
return image; return image;
} }
public Button newGameButton(String text, int x, int y, String borderColor, public Button newGameButton(String text, int x, int y, String borderColor,
String backgroundColor, int width, int height, int fontSize) { String backgroundColor, int width, int height, int fontSize) {
Button button = new Button(text); Button button = new Button(text);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment