Commit b3620f30 authored by Brigitt Gyamfi Bright's avatar Brigitt Gyamfi Bright
Browse files

GUI

parent 08bcc0b5
package edu.IDATT2001.brigittb.Obli3_DeckOfCard.GUI;
import javafx.application.Application;
import javafx.stage.Stage;
import edu.IDATT2001.brigittb.Obli3_DeckOfCard.GameLogic.DeckOfCards;
import edu.IDATT2001.brigittb.Obli3_DeckOfCard.GameLogic.Hand;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
public class Controller extends Application {
public class Controller{
private DeckOfCards deck = new DeckOfCards();
private Hand cardsAtHand = new Hand();
@FXML
public Button dealHandButton;
@FXML
public Label sumDisplay;
@FXML
public Button checkHandButton;
@FXML
public Label cardDisplay;
@FXML
public Label flushDisplay;
@FXML
public static ChoiceBox<String> filterBox;
@FXML
public Label filteringDisplay ;
@FXML Label doYouHavereqCardDisplay;
public void dealHand() {
cardsAtHand.addCardsToHand();
}
public void checkHand() {
sumDisplay.setText(String.valueOf(cardsAtHand.getSumOfCardsAtHand()));
if (cardsAtHand.flush()) flushDisplay.setText("Flush!");
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
public void findCard(String value){
if (cardsAtHand.doYouHaveThisCard(value)) doYouHavereqCardDisplay.setText("Yes");
else doYouHavereqCardDisplay.setText("No");
}
//filterBox.getItems().addAll("H", "S", "D", "C");
}
}
......@@ -32,8 +32,15 @@ public class Hand {
*
*/
public void addCardsToHand() {
if(cardsAtHand.size() == 0) cardsAtHand.addAll(deck.dealHand(5));
else cardsAtHand.addAll(deck.dealHand(2));
if(cardsAtHand.size() == 0){
cardsAtHand.addAll(deck.dealHand(5));
}else if (cardsAtHand.size() == 1) {
cardsAtHand.addAll(deck.dealHand(4));
} else if (cardsAtHand.size() == 2){
cardsAtHand.addAll(deck.dealHand(3));
} else if (cardsAtHand.size() == 3){
cardsAtHand.addAll(deck.dealHand(2));
} else cardsAtHand.addAll(deck.dealHand(1));
for (PlayingCard s : cardsAtHand) {
deck.removeFromDeck(s);
......@@ -59,7 +66,7 @@ public class Hand {
}
/**
* get All cards from hand that matches the requested suit
* Filters out cards from hand that matches the requested suit
* @param ch the requested char as a string
* @return all cards with matching suit
*/
......@@ -78,19 +85,54 @@ public class Hand {
return type;
}
/**
* Checks if you have a spesific card at hand
* @param req the requested card as a string
*
* @return the card
*/
public boolean doYouHaveThisCard(String req){
return cardsAtHand.stream().anyMatch(c -> c.getAsString().equals(req));
}
/**
* Checks if the 5 cards are of the same suit or not
* @return true if they are, false if they are not
*/
public boolean flush(){
List<PlayingCard> suits;
if (cardsAtHand.stream().allMatch(value -> value.getSuit() == 'S')){
suits = cardsAtHand.stream().filter(card -> card.getAsString().startsWith("S")).collect(Collectors.toList());
for (PlayingCard p: suits) {
cardsAtHand.remove(p);
}
return true;
} else if (cardsAtHand.stream().allMatch(value -> value.getSuit() == 'H')){
suits = cardsAtHand.stream().filter(card -> card.getAsString().startsWith("H")).collect(Collectors.toList());
for (PlayingCard p: suits) {
cardsAtHand.remove(p);
}
return true;
} else if (cardsAtHand.stream().allMatch(value -> value.getSuit() == 'C')){
suits = cardsAtHand.stream().filter(card -> card.getAsString().startsWith("C")).collect(Collectors.toList());
for (PlayingCard p: suits) {
cardsAtHand.remove(p);
}
return true;
} else return cardsAtHand.stream().allMatch(value -> value.getSuit() == 'H');
} else if(cardsAtHand.stream().allMatch(value -> value.getSuit() == 'D')) {
suits = cardsAtHand.stream().filter(card -> card.getAsString().startsWith("D")).collect(Collectors.toList());
for (PlayingCard p: suits) {
cardsAtHand.remove(p);
}
return true ;
}
return false;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="Game"
prefHeight="400.0" prefWidth="600.0">
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.IDATT2001.brigittb.Obli3_DeckOfCard.GUI.Controller">
<children>
<SplitPane dividerPositions="0.7904040404040404" prefHeight="400.0" prefWidth="600.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<ImageView id="card3" fitHeight="122.0" fitWidth="82.0" layoutX="194.0" layoutY="138.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@Images/Clubs5.png" />
</image>
</ImageView>
<ImageView id="card1" fitHeight="122.0" fitWidth="82.0" layoutX="14.0" layoutY="224.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@Images/Clubs1.png" />
</image>
</ImageView>
<ImageView fx:id="card5" fitHeight="106.0" fitWidth="82.0" layoutX="371.0" layoutY="227.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@Images/Clubs4.png" />
</image>
</ImageView>
<ImageView id="card2" fitHeight="122.0" fitWidth="82.0" layoutX="104.0" layoutY="161.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@Images/Clubs2.png" />
</image>
</ImageView>
<ImageView id="card4" fitHeight="122.0" fitWidth="82.0" layoutX="282.0" layoutY="161.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@Images/Clubs3.png" />
</image>
</ImageView>
<Label layoutX="166.0" layoutY="61.0" prefHeight="42.0" prefWidth="139.0" text="Flush!">
<font>
<Font name="Hiragino Sans W9" size="37.0" />
</font>
</Label>
<Label layoutX="203.0" layoutY="309.0" prefHeight="18.0" prefWidth="63.0" text="Face sum: ">
<font>
<Font name="Futura Medium" size="13.0" />
</font>
</Label>
<Label id="deal_hand" layoutX="296.0" layoutY="327.0" prefHeight="19.0" prefWidth="55.0" text="y/n">
<font>
<Font name="Avenir Next Bold" size="13.0" />
</font>
</Label>
<Label layoutX="155.0" layoutY="327.0" prefHeight="18.0" prefWidth="139.0" text="Do you have this card: ">
<font>
<Font name="Futura Medium" size="13.0" />
</font>
</Label>
<Label id="deal_hand" layoutX="269.0" layoutY="309.0" prefHeight="19.0" prefWidth="55.0" text="sum">
<font>
<Font name="Avenir Next Bold" size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<ChoiceBox layoutX="20.0" layoutY="216.0" prefHeight="26.0" prefWidth="83.0" />
<Button accessibleText="Deal Hand" layoutX="20.0" layoutY="100.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="83.0" text="Deal Hand" />
<Button layoutX="20.0" layoutY="133.0" mnemonicParsing="false" text="Check hand" />
<Label layoutX="20.0" layoutY="199.0" text="Filter cards:" />
<Label layoutX="9.0" layoutY="260.0" prefHeight="42.0" prefWidth="105.0" text="Do you have this card?">
<font>
<Font size="11.0" />
</font>
</Label>
<TextField layoutX="16.0" layoutY="302.0" prefHeight="26.0" prefWidth="90.0" promptText="Format (H2 or C6..)">
<font>
<Font size="8.0" />
</font>
</TextField>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment