jordanmason-stleo
4 years ago
committed by
GitHub
18 changed files with 397 additions and 61 deletions
@ -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> |
@ -1,3 +1,6 @@ |
|||||||
*.class |
*.class |
||||||
manifest.txt |
manifest.txt |
||||||
*.jar |
*.jar |
||||||
|
target/ |
||||||
|
.DS_Store |
||||||
|
cards.db |
@ -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> |
@ -0,0 +1,3 @@ |
|||||||
|
eclipse.preferences.version=1 |
||||||
|
encoding//src/main/java=UTF-8 |
||||||
|
encoding/<project>=UTF-8 |
@ -0,0 +1,2 @@ |
|||||||
|
eclipse.preferences.version=1 |
||||||
|
org.eclipse.jdt.apt.aptEnabled=false |
@ -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 |
@ -0,0 +1,4 @@ |
|||||||
|
activeProfiles= |
||||||
|
eclipse.preferences.version=1 |
||||||
|
resolveWorkspaceProjects=true |
||||||
|
version=1 |
@ -0,0 +1,3 @@ |
|||||||
|
{ |
||||||
|
"java.configuration.updateBuildConfiguration": "automatic" |
||||||
|
} |
@ -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 |
|
@ -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> |
@ -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(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -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…
Reference in new issue