Browse Source

Merge pull request #3 from Rudi9719/master

Converted project to Maven and fixed GH Action for AutoBuild
pull/4/head
jordanmason-stleo 4 years ago committed by GitHub
parent
commit
d344649f51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 44
      .classpath
  2. 21
      .github/workflows/c-cpp.yml
  3. 3
      .gitignore
  4. 34
      .project
  5. 3
      .settings/org.eclipse.core.resources.prefs
  6. 2
      .settings/org.eclipse.jdt.apt.core.prefs
  7. 9
      .settings/org.eclipse.jdt.core.prefs
  8. 4
      .settings/org.eclipse.m2e.core.prefs
  9. 3
      .vscode/settings.json
  10. 29
      Makefile
  11. 100
      pom.xml
  12. 31
      src/main/java/MTGClone/App.java
  13. 5
      src/main/java/MTGClone/Card.java
  14. 27
      src/main/java/MTGClone/Deck.java
  15. 5
      src/main/java/MTGClone/Driver.java
  16. 8
      src/main/java/MTGClone/Game.java
  17. 5
      src/main/java/MTGClone/Player.java
  18. 125
      src/main/java/MTGClone/SQLDriver.java

44
.classpath

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

21
.github/workflows/c-cpp.yml

@ -1,4 +1,7 @@ @@ -1,4 +1,7 @@
name: Java CI
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
@ -13,10 +16,14 @@ jobs: @@ -13,10 +16,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: make
run: make jar
- name: Upload Artifact
uses: actions/upload-artifact@v1.0.0
- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Build with Maven
run: mvn clean compile assembly:single
- name: Upload build Artifact
uses: actions/upload-artifact@v2.1.4
with:
name: MTGClone.jar
path: MTGClone.jar
name: MTGClone-1.0-jar-with-dependencies.jar
path: target/MTGClone-1.0-jar-with-dependencies.jar

3
.gitignore vendored

@ -1,3 +1,6 @@ @@ -1,3 +1,6 @@
*.class
manifest.txt
*.jar
target/
.DS_Store
cards.db

34
.project

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MTGClone</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1600989245301</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

3
.settings/org.eclipse.core.resources.prefs

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

2
.settings/org.eclipse.jdt.apt.core.prefs

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false

9
.settings/org.eclipse.jdt.core.prefs

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=11

4
.settings/org.eclipse.m2e.core.prefs

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

3
.vscode/settings.json vendored

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}

29
Makefile

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
JCC = javac
JFLAGS = -g
default:
@echo \"make build\" to compile Java classes
@echo \"make run\" to run Driver class
@echo \"make jar\" to compile executable jar
@echo \"make clean\" to clean up artifacts
build:
$(JCC) $(JFLAGS) Driver.java
run: jar
java -jar MTGClone.jar
jar: build
@echo "Manifest-Version: 1.0" > manifest.txt
@echo "Class-Path: ." >> manifest.txt
@echo "Main-Class: Driver" >> manifest.txt
@echo "" >> manifest.txt
jar -cmf manifest.txt MTGClone.jar *.class
$(RM) manifest.txt
$(RM) *.class
clean:
$(RM) *.class
$(RM) manifest.txt
$(RM) MTGClone.jar

100
pom.xml

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
<?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>MTGClone</groupId>
<artifactId>MTGClone</artifactId>
<version>1.0</version>
<name>MTGClone</name>
<url>https://github.com/jordanmason-stleo/MTGClone</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.32.3.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>MTGClone.Driver</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>MTGClone.Driver</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

31
src/main/java/MTGClone/App.java

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
package MTGClone;
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Player One's name: ");
String player1Name = in.nextLine();
System.out.print("Enter Player Two's name: ");
String player2Name = in.nextLine();
Deck deck=new Deck();
Deck deck2=new Deck();
Player player1= new Player(deck, player1Name);
Player player2= new Player(deck2, player2Name);
Game game= new Game(player1, player2);
while(player1.lifeTotal>=0&&player2.lifeTotal>=0){
if (game.player1.lifeTotal>0)
game.Turn(game.player1,game.player2,in);
System.out.println("------------------------------------------------------------------------------------------------------------------------------");
if (game.player2.lifeTotal>0)
game.Turn(game.player2,game.player1,in);
System.out.println("------------------------------------------------------------------------------------------------------------------------------");
}
in.close();
}
}

5
Card.java → src/main/java/MTGClone/Card.java

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
package MTGClone;
public class Card{
protected String cardName;
protected int manaCost;
@ -70,7 +72,8 @@ public class Card{ @@ -70,7 +72,8 @@ public class Card{
return "Card [cardName=" + cardName + ", creatureType=" + creatureType + ", description=" + description
+ ", image=" + image + ", manaCost=" + manaCost + ", power=" + power + ", toughness=" + toughness + "]";
}
public Card() {}
public Card(String cardName, int manaCost, int power, int toughness, String description, String image,
String creatureType) {
this.cardName = cardName;

27
Deck.java → src/main/java/MTGClone/Deck.java

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
package MTGClone;
import java.util.ArrayList;
import java.util.Collections;
@ -5,6 +7,7 @@ public class Deck { @@ -5,6 +7,7 @@ public class Deck {
protected ArrayList<Card> topdeck;
protected ArrayList<Card> discard;
protected ArrayList<Card> hand;
public Card drawCard(){
if (topdeck.size()<=0)
return null;
@ -15,25 +18,15 @@ public class Deck { @@ -15,25 +18,15 @@ public class Deck {
}
public Deck() {
topdeck=new ArrayList<Card>();
discard=new ArrayList<Card>();
hand=new ArrayList<Card>();
for (int i = 0; i < 4; i++){
topdeck.add(new Card("Devouring Dragon", 5, 5, 6, "He does to people what Greg does to booty.", "", "Dragon"));
topdeck.add(new Card("Dragon Worshipper", 1, 1, 1, "He spends his days praying to dragons.", "", "Human"));
topdeck.add(new Card("Dragon Whelp", 2, 3, 2, "He'll get there.", "", "Dragon"));
topdeck.add(new Card("Dragon Egg", 1, 0, 2, "Close to hatching!", "", "Egg"));
topdeck.add(new Card("Lingering Flame", 3, 4, 3, "He lives among the dragons.", "", "Elemental"));
topdeck.add(new Card("Dragonguard Sentry", 1, 1, 2, "Devoted to the protection of the dragonflight.", "", "Human"));
topdeck.add(new Card("Withering Flamewitch", 2, 4, 2, "Her flame bites deep.", "", "Human"));
topdeck.add(new Card("Final Examination", 6, 9000, 0, "Oh dear, Greg.", "", "Parchment"));
topdeck.add(new Card("Drunken Dragon", 3, 4, 1, "He's trying.", "", "Dragon"));
}
for (int i = 0; i < 24; i++){
topdeck.add(new Card("Isle of Power", -1, 0, 0, "Invoke this for mana.", "", "Land"));
SQLDriver d = new SQLDriver();
d.setupTable();
topdeck = new ArrayList<Card>();
hand = new ArrayList<Card>();
discard = new ArrayList<Card>();
for (int i = 0; i < 60; i++){
topdeck.add(d.getRandomCard());
}
Shuffle();
for (int i = 0; i < 7; i++){
drawCard();
}

5
Driver.java → src/main/java/MTGClone/Driver.java

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
package MTGClone;
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
@ -17,10 +18,10 @@ public class Driver { @@ -17,10 +18,10 @@ public class Driver {
while(player1.lifeTotal>=0&&player2.lifeTotal>=0){
if (game.player1.lifeTotal>0)
game.Turn(game.player1,game.player2);
game.Turn(game.player1,game.player2,in);
System.out.println("------------------------------------------------------------------------------------------------------------------------------");
if (game.player2.lifeTotal>0)
game.Turn(game.player2,game.player1);
game.Turn(game.player2,game.player1,in);
System.out.println("------------------------------------------------------------------------------------------------------------------------------");
}
in.close();

8
Game.java → src/main/java/MTGClone/Game.java

@ -1,4 +1,8 @@ @@ -1,4 +1,8 @@
package MTGClone;
import java.util.ArrayList;
import java.util.Scanner;
public class Game {
protected Player player1;
protected Player player2;
@ -53,8 +57,8 @@ public class Game { @@ -53,8 +57,8 @@ public class Game {
this.player2Field=new ArrayList<Card>();
}
public void Turn(Player player,Player target) {
player.turn(target);
public void Turn(Player player,Player target, Scanner in) {
player.turn(target, in);
}
}

5
Player.java → src/main/java/MTGClone/Player.java

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
package MTGClone;
import java.util.Scanner;
public class Player {
@ -41,10 +42,9 @@ public class Player { @@ -41,10 +42,9 @@ public class Player {
}
public void turn(Player target) {
public void turn(Player target, Scanner in) {
int currentMana = manaTotal;
int cardUse = 0;
Scanner in = new Scanner(System.in);
System.out.println("\n\n\tIt is " + name + "'s turn.");
deck.drawCard();
System.out.println("Your health and armor is " + lifeTotal + " and " + armorTotal
@ -94,7 +94,6 @@ public class Player { @@ -94,7 +94,6 @@ public class Player {
else
System.out.println("You've selected an invalid card.");
}
}
@Override

125
src/main/java/MTGClone/SQLDriver.java

@ -0,0 +1,125 @@ @@ -0,0 +1,125 @@
package MTGClone;
import java.sql.*;
import java.util.*;
public class SQLDriver {
protected Connection c = null;
public boolean tryConnect() {
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:cards.db");
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
return false;
}
return true;
}
public Card getRandomCard() {
try {
c = DriverManager.getConnection("jdbc:sqlite:cards.db");
c.setAutoCommit(false);
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM CARDS ORDER BY RANDOM() LIMIT 1;");
String cardName = "";
int manaCost = 0;
int power = 0;
int toughness = 0;
String description = "";
String image = "";
String creatureType = "";
while (rs.next()) {
cardName = rs.getString("CARDNAME");
manaCost = rs.getInt("MANACOST");
power = rs.getInt("POWER");
toughness = rs.getInt("TOUGHNESS");
description = rs.getString("DESCRIPTION");
image = rs.getString("IMAGE");
creatureType = rs.getString("CREATURETYPE");
}
rs.close();
stmt.close();
c.close();
Card card = new Card(cardName, manaCost, power, toughness, description, image, creatureType);
return card;
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.err.println("Returning null.");
return null;
}
public boolean insertCard(Card card) {
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:cards.db");
c.setAutoCommit(false);
String baseStmt = "INSERT INTO CARDS (CARDNAME,MANACOST,POWER,TOUGHNESS,DESCRIPTION,IMAGE,CREATURETYPE) VALUES ";
stmt = c.createStatement();
String sql = "(\'" + card.cardName + "\'," + card.manaCost + "," + card.power + "," + card.toughness + ", \'"
+ card.description + "\',\'" + card.image + "\',\'" + card.creatureType + "\');";
stmt.executeUpdate(baseStmt + sql);
stmt.close();
c.commit();
c.close();
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
return false;
}
return true;
}
public boolean setupCards() {
ArrayList<Card> topdeck = new ArrayList<Card>();
topdeck.add(new Card("Devouring Dragon", 5, 5, 6, "He does to people what Greg does to booty.", "", "Dragon"));
topdeck.add(new Card("Dragon Worshipper", 1, 1, 1, "He spends his days praying to dragons.", "", "Human"));
topdeck.add(new Card("Dragon Whelp", 2, 3, 2, "He will get there.", "", "Dragon"));
topdeck.add(new Card("Dragon Egg", 1, 0, 2, "Close to hatching!", "", "Egg"));
topdeck.add(new Card("Lingering Flame", 3, 4, 3, "He lives among the dragons.", "", "Elemental"));
topdeck.add(
new Card("Dragonguard Sentry", 1, 1, 2, "Devoted to the protection of the dragonflight.", "", "Human"));
topdeck.add(new Card("Withering Flamewitch", 2, 4, 2, "Her flame bites deep.", "", "Human"));
topdeck.add(new Card("Final Examination", 6, 9000, 0, "Oh dear, Greg.", "", "Parchment"));
topdeck.add(new Card("Drunken Dragon", 3, 4, 1, "He is trying.", "", "Dragon"));
topdeck.add(new Card("Isle of Power", -1, 0, 0, "Invoke this for mana.", "", "Land"));
for (Card card : topdeck) {
if (!insertCard(card)) {
return false;
}
}
return true;
}
public boolean setupTable() {
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:cards.db");
stmt = c.createStatement();
String sql = "CREATE TABLE CARDS " + "(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ " CARDNAME TEXT NOT NULL, " + " MANACOST INT NOT NULL, "
+ " POWER INT NOT NULL, " + " TOUGHNESS INT NOT NULL, "
+ " DESCRIPTION TEXT NOT NULL, " + " IMAGE TEXT NOT NULL, "
+ " CREATURETYPE TEXT NOT NULL)";
stmt.executeUpdate(sql);
stmt.close();
c.close();
if (!setupCards()) {
System.exit(-1);
}
} catch (Exception e) {
if (!e.getMessage().contains("(table CARDS already exists)"))
System.err.println(e.getClass().getName() + ": " + e.getMessage());
return false;
}
return true;
}
}
Loading…
Cancel
Save