diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..9ba41a2 --- /dev/null +++ b/.classpath @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index a37751c..8786d60 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -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: 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 diff --git a/.gitignore b/.gitignore index 2adc7f9..63da651 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ *.class manifest.txt *.jar +target/ +.DS_Store +cards.db \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..adcf102 --- /dev/null +++ b/.project @@ -0,0 +1,34 @@ + + + MTGClone + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + 1600989245301 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..e9441bb --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..d4313d4 --- /dev/null +++ b/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..46235dc --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e0f15db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 6f5feb9..0000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e7b1bd0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,100 @@ + + + + 4.0.0 + + MTGClone + MTGClone + 1.0 + + MTGClone + https://github.com/jordanmason-stleo/MTGClone + + + UTF-8 + 11 + 11 + + + + + junit + junit + 4.11 + test + + + org.xerial + sqlite-jdbc + 3.32.3.2 + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + + true + MTGClone.Driver + + + + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + maven-assembly-plugin + + + + MTGClone.Driver + + + + jar-with-dependencies + + + + + + + diff --git a/src/main/java/MTGClone/App.java b/src/main/java/MTGClone/App.java new file mode 100644 index 0000000..06d6249 --- /dev/null +++ b/src/main/java/MTGClone/App.java @@ -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(); + } + + +} \ No newline at end of file diff --git a/Card.java b/src/main/java/MTGClone/Card.java similarity index 97% rename from Card.java rename to src/main/java/MTGClone/Card.java index 3876e03..a2d0287 100644 --- a/Card.java +++ b/src/main/java/MTGClone/Card.java @@ -1,3 +1,5 @@ +package MTGClone; + public class Card{ protected String cardName; protected int manaCost; @@ -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; diff --git a/Deck.java b/src/main/java/MTGClone/Deck.java similarity index 63% rename from Deck.java rename to src/main/java/MTGClone/Deck.java index 7d3642b..168ebce 100644 --- a/Deck.java +++ b/src/main/java/MTGClone/Deck.java @@ -1,3 +1,5 @@ +package MTGClone; + import java.util.ArrayList; import java.util.Collections; @@ -5,6 +7,7 @@ public class Deck { protected ArrayList topdeck; protected ArrayList discard; protected ArrayList hand; + public Card drawCard(){ if (topdeck.size()<=0) return null; @@ -15,25 +18,15 @@ public class Deck { } public Deck() { - topdeck=new ArrayList(); - discard=new ArrayList(); - hand=new ArrayList(); - 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(); + hand = new ArrayList(); + discard = new ArrayList(); + for (int i = 0; i < 60; i++){ + topdeck.add(d.getRandomCard()); } Shuffle(); - for (int i = 0; i < 7; i++){ drawCard(); } diff --git a/Driver.java b/src/main/java/MTGClone/Driver.java similarity index 89% rename from Driver.java rename to src/main/java/MTGClone/Driver.java index c3e73de..a032575 100644 --- a/Driver.java +++ b/src/main/java/MTGClone/Driver.java @@ -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 { 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(); diff --git a/Game.java b/src/main/java/MTGClone/Game.java similarity index 90% rename from Game.java rename to src/main/java/MTGClone/Game.java index eaa9316..225603b 100644 --- a/Game.java +++ b/src/main/java/MTGClone/Game.java @@ -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 { this.player2Field=new ArrayList(); } - public void Turn(Player player,Player target) { - player.turn(target); + public void Turn(Player player,Player target, Scanner in) { + player.turn(target, in); } } \ No newline at end of file diff --git a/Player.java b/src/main/java/MTGClone/Player.java similarity index 97% rename from Player.java rename to src/main/java/MTGClone/Player.java index a027b83..86a0b62 100644 --- a/Player.java +++ b/src/main/java/MTGClone/Player.java @@ -1,3 +1,4 @@ +package MTGClone; import java.util.Scanner; 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 { else System.out.println("You've selected an invalid card."); } - } @Override diff --git a/src/main/java/MTGClone/SQLDriver.java b/src/main/java/MTGClone/SQLDriver.java new file mode 100644 index 0000000..2371186 --- /dev/null +++ b/src/main/java/MTGClone/SQLDriver.java @@ -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 topdeck = new ArrayList(); + 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; + } +}