Jordan Mason
4 years ago
commit
9c2c38d390
5 changed files with 409 additions and 0 deletions
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
public class Card{ |
||||
protected String cardName; |
||||
protected int manaCost; |
||||
protected int power; |
||||
protected int toughness; |
||||
protected String description; |
||||
protected String image; |
||||
protected String creatureType; |
||||
|
||||
|
||||
|
||||
public String getCardName() { |
||||
return cardName; |
||||
} |
||||
|
||||
public void setCardName(String cardName) { |
||||
this.cardName = cardName; |
||||
} |
||||
|
||||
public int getManaCost() { |
||||
return manaCost; |
||||
} |
||||
|
||||
public void setManaCost(int manaCost) { |
||||
this.manaCost = manaCost; |
||||
} |
||||
|
||||
public int getPower() { |
||||
return power; |
||||
} |
||||
|
||||
public void setPower(int power) { |
||||
this.power = power; |
||||
} |
||||
|
||||
public int getToughness() { |
||||
return toughness; |
||||
} |
||||
|
||||
public void setToughness(int toughness) { |
||||
this.toughness = toughness; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
public String getImage() { |
||||
return image; |
||||
} |
||||
|
||||
public void setImage(String image) { |
||||
this.image = image; |
||||
} |
||||
|
||||
public String getCreatureType() { |
||||
return creatureType; |
||||
} |
||||
|
||||
public void setCreatureType(String creatureType) { |
||||
this.creatureType = creatureType; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "Card [cardName=" + cardName + ", creatureType=" + creatureType + ", description=" + description |
||||
+ ", image=" + image + ", manaCost=" + manaCost + ", power=" + power + ", toughness=" + toughness + "]"; |
||||
} |
||||
|
||||
public Card(String cardName, int manaCost, int power, int toughness, String description, String image, |
||||
String creatureType) { |
||||
this.cardName = cardName; |
||||
this.manaCost = manaCost; |
||||
this.power = power; |
||||
this.toughness = toughness; |
||||
this.description = description; |
||||
this.image = image; |
||||
this.creatureType = creatureType; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
|
||||
public class Deck { |
||||
protected ArrayList<Card> topdeck; |
||||
protected ArrayList<Card> discard; |
||||
protected ArrayList<Card> hand; |
||||
public Card drawCard(){ |
||||
if (topdeck.size()<=0) |
||||
return null; |
||||
Card card=topdeck.get(0); |
||||
topdeck.remove(0); |
||||
hand.add(card); |
||||
return card; |
||||
|
||||
} |
||||
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")); |
||||
} |
||||
Shuffle(); |
||||
|
||||
for (int i = 0; i < 7; i++){ |
||||
drawCard(); |
||||
} |
||||
} |
||||
|
||||
private void Shuffle() { |
||||
Collections.shuffle(topdeck); |
||||
|
||||
} |
||||
|
||||
public ArrayList<Card> getTopdeck() { |
||||
return topdeck; |
||||
} |
||||
|
||||
public void setTopdeck(ArrayList<Card> topdeck) { |
||||
this.topdeck = topdeck; |
||||
} |
||||
|
||||
public ArrayList<Card> getDiscard() { |
||||
return discard; |
||||
} |
||||
|
||||
public void setDiscard(ArrayList<Card> discard) { |
||||
this.discard = discard; |
||||
} |
||||
|
||||
public ArrayList<Card> getHand() { |
||||
return hand; |
||||
} |
||||
|
||||
public void setHand(ArrayList<Card> hand) { |
||||
this.hand = hand; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "Deck [discard=" + discard + ", hand=" + hand + ", topdeck=" + topdeck + "]"; |
||||
} |
||||
|
||||
public void showHand() { |
||||
int maxName = 0; |
||||
int maxType = 0; |
||||
for (Card c : hand) { |
||||
if (c.cardName.length() > maxName) { |
||||
maxName = c.cardName.length(); |
||||
} |
||||
if (c.creatureType.length() > maxType) { |
||||
maxType = c.creatureType.length(); |
||||
} |
||||
} |
||||
for (int i = 0; i < hand.size(); i++) { |
||||
Card c=hand.get(i); |
||||
System.out.print((i+1) + " " + c.cardName); |
||||
for (int ii = c.cardName.length(); ii < maxName; ii++) { |
||||
System.out.print(" "); |
||||
} |
||||
System.out.print(" (" + c.creatureType + ")"); |
||||
for (int ii = c.creatureType.length(); ii < maxType; ii++) { |
||||
System.out.print(" "); |
||||
} |
||||
System.out.print("\t" +(c.manaCost>=0? c.manaCost :0) + "M\t" + c.power + "P\t" + c.toughness + "T\n"); |
||||
} |
||||
System.out.println(""); |
||||
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
import java.util.Scanner; |
||||
public class Driver { |
||||
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); |
||||
System.out.println("------------------------------------------------------------------------------------------------------------------------------"); |
||||
if (game.player2.lifeTotal>0) |
||||
game.Turn(game.player2,game.player1); |
||||
System.out.println("------------------------------------------------------------------------------------------------------------------------------"); |
||||
} |
||||
in.close(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
import java.util.ArrayList; |
||||
public class Game { |
||||
protected Player player1; |
||||
protected Player player2; |
||||
|
||||
protected ArrayList<Card> player1Field; |
||||
protected ArrayList<Card> player2Field; |
||||
|
||||
|
||||
|
||||
public Player getPlayer1() { |
||||
return player1; |
||||
} |
||||
|
||||
public void setPlayer1(Player player1) { |
||||
this.player1 = player1; |
||||
} |
||||
|
||||
public Player getPlayer2() { |
||||
return player2; |
||||
} |
||||
|
||||
public void setPlayer2(Player player2) { |
||||
this.player2 = player2; |
||||
} |
||||
|
||||
public ArrayList<Card> getPlayer1Field() { |
||||
return player1Field; |
||||
} |
||||
|
||||
public void setPlayer1Field(ArrayList<Card> player1Field) { |
||||
this.player1Field = player1Field; |
||||
} |
||||
|
||||
public ArrayList<Card> getPlayer2Field() { |
||||
return player2Field; |
||||
} |
||||
|
||||
public void setPlayer2Field(ArrayList<Card> player2Field) { |
||||
this.player2Field = player2Field; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "Game [player1=" + player1 + ", player1Field=" + player1Field + ", player2=" + player2 |
||||
+ ", player2Field=" + player2Field + "]"; |
||||
} |
||||
|
||||
public Game(Player player1, Player player2) { |
||||
this.player1 = player1; |
||||
this.player2 = player2; |
||||
this.player1Field=new ArrayList<Card>(); |
||||
this.player2Field=new ArrayList<Card>(); |
||||
} |
||||
|
||||
public void Turn(Player player,Player target) { |
||||
player.turn(target); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,130 @@
@@ -0,0 +1,130 @@
|
||||
import java.util.Scanner; |
||||
|
||||
public class Player { |
||||
protected Deck deck; |
||||
protected String name; |
||||
protected int lifeTotal; |
||||
protected int manaTotal; |
||||
protected int armorTotal; |
||||
|
||||
public Deck getDeck() { |
||||
return deck; |
||||
} |
||||
|
||||
public void setDeck(Deck deck) { |
||||
this.deck = deck; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public Player(Deck deck, String name) { |
||||
this.deck = deck; |
||||
this.name = name; |
||||
this.lifeTotal = 20; |
||||
this.manaTotal = 0; |
||||
this.armorTotal = 0; |
||||
} |
||||
|
||||
public boolean playCard(Card card, int currentMana) { |
||||
if (currentMana < card.getManaCost()) |
||||
return false; |
||||
currentMana -= card.getManaCost(); |
||||
if (currentMana > manaTotal) |
||||
manaTotal = currentMana; |
||||
return true; |
||||
|
||||
} |
||||
|
||||
public void turn(Player target) { |
||||
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 |
||||
+ ". Your opponent's health and armor is " + target.lifeTotal + " and " + target.armorTotal + ".\n"); |
||||
|
||||
do { |
||||
deck.showHand(); |
||||
System.out.println("You have " + currentMana + " mana.\n"); |
||||
System.out.print("Play your cards. 0 to skip: "); |
||||
cardUse = Integer.parseInt(in.nextLine()); |
||||
|
||||
if (cardUse > 0 && cardUse <= deck.getHand().size()) { |
||||
Card card = deck.getHand().get(cardUse - 1); |
||||
if (playCard(card, currentMana)) { |
||||
deck.getHand().remove(cardUse - 1); |
||||
currentMana -= card.manaCost; |
||||
armorTotal += card.toughness; |
||||
int damage = card.power; |
||||
int armor = target.armorTotal; |
||||
if (target.armorTotal > 0) { |
||||
target.setArmorTotal(target.getArmorTotal() - damage); |
||||
damage -= armor; |
||||
if (target.armorTotal < 0) |
||||
target.setArmorTotal(0); |
||||
} |
||||
if (damage > 0) |
||||
target.setLifeTotal(target.getLifeTotal() - damage); |
||||
|
||||
if (card.power > 0) { |
||||
System.out.println("Your opponent's health and armor is " + target.lifeTotal + " and " + target.armorTotal + "."); |
||||
} |
||||
} else { |
||||
System.out.println("You do not have enough mana to play that card."); |
||||
} |
||||
} else if (cardUse!=0) { |
||||
System.out.println("Invalid selection."); |
||||
} |
||||
} while (cardUse != 0); |
||||
|
||||
while (deck.getHand().size() > 7) { |
||||
deck.showHand(); |
||||
System.out.print("Discard a card: "); |
||||
cardUse = Integer.parseInt(in.nextLine()); |
||||
|
||||
if (cardUse > 0 && cardUse <= deck.getHand().size()) |
||||
deck.getHand().remove(cardUse - 1); |
||||
else |
||||
System.out.println("You've selected an invalid card."); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "Player [armorTotal=" + armorTotal + ", deck=" + deck + ", lifeTotal=" + lifeTotal + ", manaTotal=" |
||||
+ manaTotal + ", name=" + name + "]"; |
||||
} |
||||
|
||||
public int getLifeTotal() { |
||||
return lifeTotal; |
||||
} |
||||
|
||||
public void setLifeTotal(int lifeTotal) { |
||||
this.lifeTotal = lifeTotal; |
||||
} |
||||
|
||||
public int getManaTotal() { |
||||
return manaTotal; |
||||
} |
||||
|
||||
public void setManaTotal(int manaTotal) { |
||||
this.manaTotal = manaTotal; |
||||
} |
||||
|
||||
public int getArmorTotal() { |
||||
return armorTotal; |
||||
} |
||||
|
||||
public void setArmorTotal(int armorTotal) { |
||||
this.armorTotal = armorTotal; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue