Skip to content
Snippets Groups Projects
Commit f04db152 authored by Torbjørn Antonsen's avatar Torbjørn Antonsen
Browse files

Merge branch 'feat/GUI' into 'main'

Feat/gui

See merge request !3
parents d568485b bae079e8
No related branches found
No related tags found
1 merge request!3Feat/gui
Showing
with 153 additions and 6 deletions
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="CheckStyle-IDEA-Module" serialisationVersion="2">
<option name="activeLocationsIds" />
</component>
</module>
\ No newline at end of file
package edu.ntnu.idatt2001;
public class Main {
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.util.ArrayList;
public class Main extends Application {
private final Color DARKGRAY = Color.rgb(54, 69, 79).deriveColor(
0.0, 1.0, 0.4, 1.0);
public static void main(String[] args) {
System.out.println("Hello world!");
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Text handText = new Text("Hand");
GridPane root = new GridPane();
root.setPrefSize(1280, 800);
root.setPadding(new Insets(10, 10, 10, 10));
root.setHgap(20);
root.setVgap(20);
root.setBackground(new Background(new BackgroundFill(DARKGRAY,
new CornerRadii(0), new Insets(0))));
root.setAlignment(Pos.CENTER);
BorderPane hand = new BorderPane(handText);
DialogPane handTitle = new DialogPane();
GridPane handImages = createHandImageViews(5);
handTitle.setHeader(handText);
hand.setTop(handTitle);
hand.setCenter(handImages);
root.add(hand, 0,0);
root.add(createTextsAndTextFields(), 0, 1);
root.add(createButtons(), 1, 0);
Scene scene = new Scene(root,1280, 800, DARKGRAY);
primaryStage.setTitle("CardGame");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
ImageView imageView = new ImageView();
Image icon = new Image("card_icon.png");
imageView.setImage(icon);
primaryStage.getIcons().add(icon);
primaryStage.show();
}
public VBox createButtons() {
Button dealHand = new Button("Deal hand");
dealHand.setPrefSize(100,40);
Button checkHand = new Button("Check hand");
checkHand.setPrefSize(100,40);
VBox vBox = new VBox(dealHand, checkHand);
vBox.setSpacing(20);
vBox.setAlignment(Pos.CENTER);
return vBox;
}
public GridPane createTextsAndTextFields() {
GridPane gridPane = new GridPane();
gridPane.setHgap(5);
gridPane.setVgap(5);
ArrayList<Text> texts = new ArrayList<>();
texts.add(new Text("Sum of the faces: "));
texts.add(new Text("Cards of hearts: "));
texts.add(new Text("Flush: "));
texts.add(new Text("Queen of spades: "));
for (Text text : texts) {
text.setFill(Color.WHITE);
}
TextField textField1 = new TextField();
TextField textField2 = new TextField();
TextField textField3 = new TextField();
TextField textField4 = new TextField();
HBox hBox1 = new HBox(texts.get(0), textField1);
HBox hBox2 = new HBox(texts.get(1), textField2);
HBox hBox3 = new HBox(texts.get(2), textField3);
HBox hBox4 = new HBox(texts.get(3), textField4);
hBox1.setAlignment(Pos.CENTER);
gridPane.add(hBox1, 0,0);
gridPane.add(hBox2, 1,0);
gridPane.add(hBox3, 0,1);
gridPane.add(hBox4, 1,1);
gridPane.setAlignment(Pos.CENTER);
return gridPane;
}
public GridPane createHandImageViews(int n) {
GridPane gridPane = new GridPane();
for (int i = 0; i < n; i++) {
String path = "cardImages/0" + (i + 1) + "c.png";
Image image = new Image(path);
ImageView imageView = new ImageView(image);
imageView.setFitHeight(100);
imageView.setPreserveRatio(true);
gridPane.add(imageView, i, 0);
}
gridPane.setAlignment(Pos.CENTER);
gridPane.setHgap(5);
gridPane.setVgap(5);
gridPane.setBackground(new Background(new BackgroundFill(DARKGRAY.darker(),
new CornerRadii(0), new Insets(0))));
return gridPane;
}
@Override
public void init() throws Exception {
super.init();
}
@Override
public void stop() throws Exception{
super.stop();
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ public class PlayingCard {
private final char suit; // 'S'=spade, 'H'=heart, 'D'=diamonds, 'C'=clubs
private final int face; // a number between 1 and 13
private final String imagePath;
/**
* Creates an instance of a PlayingCard with a given suit and face.
......@@ -23,6 +24,7 @@ public class PlayingCard {
public PlayingCard(char suit, int face) {
this.suit = suit;
this.face = face;
this.imagePath = face + suit + ".png";
}
/**
......@@ -32,7 +34,7 @@ public class PlayingCard {
* @return the suit and face of the card as a string
*/
public String getAsString() {
return String.format("%s%s", suit, face);
return String.format("%s%s", this.suit, this.face);
}
/**
......@@ -42,7 +44,7 @@ public class PlayingCard {
* @return the suit of the card
*/
public char getSuit() {
return suit;
return this.suit;
}
/**
......@@ -51,6 +53,10 @@ public class PlayingCard {
* @return the face of the card
*/
public int getFace() {
return face;
return this.face;
}
public String getImagePath() {
return this.imagePath;
}
}
\ No newline at end of file
src/main/resources/cardBackImage.png

174 KiB

src/main/resources/cardImages/01c.png

41.5 KiB

src/main/resources/cardImages/01d.png

35.9 KiB

src/main/resources/cardImages/01h.png

43.1 KiB

src/main/resources/cardImages/01s.png

59.6 KiB

src/main/resources/cardImages/02c.png

23 KiB

src/main/resources/cardImages/02d.png

19.4 KiB

src/main/resources/cardImages/02h.png

19.7 KiB

src/main/resources/cardImages/02s.png

21.4 KiB

src/main/resources/cardImages/03c.png

28.5 KiB

src/main/resources/cardImages/03d.png

23.7 KiB

src/main/resources/cardImages/03h.png

24.2 KiB

src/main/resources/cardImages/03s.png

26.3 KiB

src/main/resources/cardImages/04c.png

28 KiB

src/main/resources/cardImages/04d.png

23.6 KiB

src/main/resources/cardImages/04h.png

24.1 KiB

src/main/resources/cardImages/04s.png

25.8 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment