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

Merge branch 'master' into 'main'

Added beginnings of GUI and images

See merge request !2
parents e3224317 2a8f9a82
No related branches found
No related tags found
2 merge requests!2Added beginnings of GUI and images,!1Added classes for PlayingCard and DeckOfCards as well as tesst classes
Showing
with 287 additions and 0 deletions
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA" serialisationVersion="2">
<checkstyleVersion>10.7.0</checkstyleVersion>
<scanScope>JavaOnly</scanScope>
<copyLibs>true</copyLibs>
<option name="thirdPartyClasspath" />
<option name="activeLocationIds" />
<option name="locations">
<list>
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
</list>
</option>
</component>
</project>
\ No newline at end of file
This folder contains libraries copied from the "CardGame" project.
It is managed by the CheckStyle-IDEA IDE plugin.
Do not modify this folder while the IDE is running.
When the IDE is stopped, you may delete this folder at any time. It will be recreated as needed.
In order to prevent the CheckStyle-IDEA IDE plugin from creating this folder,
uncheck the "Copy libraries from project directory" option in the CheckStyle-IDEA settings dialog.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="CardGame" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/../../Arbeidskrav 4/CardGame/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/../../Arbeidskrav 4/CardGame/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/../../Arbeidskrav 4/CardGame/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.ntnu.idatt2001</groupId>
<artifactId>CardGame</artifactId>
<version>0.1</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>edu.ntnu.idatt2001.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>20-ea+9</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package edu.ntnu.idatt2001;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class DeckOfCards {
private final List<PlayingCard> deckOfCards;
public DeckOfCards() {
this.deckOfCards = new ArrayList<>();
char[] suit = {'C', 'D', 'H', 'S'};
for (char c : suit) {
for (int j = 0; j <= 12; j++) {
deckOfCards.add(new PlayingCard(c, j+1));
}
}
}
public PlayingCard[] dealHand(int n) {
PlayingCard[] hand = new PlayingCard[n];
Random random = new Random();
int i;
for (int j = 0; j < n; j++) {
i = random.nextInt(52-j);
hand[j] = deckOfCards.get(i);
deckOfCards.remove(i);
}
return hand;
}
public List<PlayingCard> getDeckOfCards() {
return deckOfCards;
}
}
\ No newline at end of file
package edu.ntnu.idatt2001;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
\ No newline at end of file
package edu.ntnu.idatt2001;
/**
* Represents a playing card. A playing card has a number (face) between
* 1 and 13, where 1 is called an Ace, 11 = Knight, 12 = Queen and 13 = King.
* The card can also be one of 4 suits: Spade, Heart, Diamonds and Clubs.
*
* @author ntnu
* @version 2020-01-10
*/
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
/**
* Creates an instance of a PlayingCard with a given suit and face.
*
* @param suit The suit of the card, as a single character. 'S' for Spades,
* 'H' for Heart, 'D' for Diamonds and 'C' for clubs
* @param face The face value of the card, an integer between 1 and 13
*/
public PlayingCard(char suit, int face) {
this.suit = suit;
this.face = face;
}
/**
* Returns the suit and face of the card as a string.
* A 4 of hearts is returned as the string "H4".
*
* @return the suit and face of the card as a string
*/
public String getAsString() {
return String.format("%s%s", suit, face);
}
/**
* Returns the suit of the card, 'S' for Spades, 'H' for Heart,
* 'D' for Diamonds and 'C' for Clubs.
*
* @return the suit of the card
*/
public char getSuit() {
return suit;
}
/**
* Returns the face of the card (value between 1 and 13).
*
* @return the face of the card
*/
public int getFace() {
return face;
}
}
\ No newline at end of file
package edu.ntnu.idatt2001;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@Nested
class DeckOfCardsTest {
@Test
public void doesCardsHaveRightValue() {
DeckOfCards doc = new DeckOfCards();
List<PlayingCard> deckOfCards = doc.getDeckOfCards();
assertEquals("C1", deckOfCards.get(0).getAsString());
assertNotEquals("C2", deckOfCards.get(0).getAsString());
assertEquals("S13", deckOfCards.get(51).getAsString());
}
@Test
public void dealHandDealsRightAmountOfCards() {
DeckOfCards doc = new DeckOfCards();
assertEquals(5, doc.dealHand(5).length);
}
}
\ No newline at end of file
File added
File added
File added
File added
#Generated by Maven
#Tue Mar 07 12:21:01 CET 2023
groupId=edu.ntnu.idatt2001
artifactId=CardGame
version=0.1
edu\ntnu\idatt2001\Main.class
edu\ntnu\idatt2001\DeckOfCards.class
edu\ntnu\idatt2001\PlayingCard.class
C:\Users\Torbjrn\OneDrive - NTNU\Documents\BIDATA\Vr 2023\IDATT2001\Arbeidskrav 4\CardGame\src\main\java\edu\ntnu\idatt2001\DeckOfCards.java
C:\Users\Torbjrn\OneDrive - NTNU\Documents\BIDATA\Vr 2023\IDATT2001\Arbeidskrav 4\CardGame\src\main\java\edu\ntnu\idatt2001\Main.java
C:\Users\Torbjrn\OneDrive - NTNU\Documents\BIDATA\Vr 2023\IDATT2001\Arbeidskrav 4\CardGame\src\main\java\edu\ntnu\idatt2001\PlayingCard.java
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment