-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AMM
committed
Aug 11, 2012
1 parent
9473402
commit 01f6c3b
Showing
45 changed files
with
2,173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>thunderstone</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mehtank.thunderstone.api; | ||
|
||
import com.mehtank.thunderstone.engine.GameEvent; | ||
|
||
public interface GameEventListener { | ||
public void gameEvent(GameEvent event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.mehtank.thunderstone.api; | ||
|
||
import java.util.Random; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
import com.mehtank.thunderstone.engine.GameEvent; | ||
|
||
public interface GameInterface { | ||
public Random getRand(); | ||
|
||
public void trash(Card c); | ||
public void broadcastEvent(GameEvent event); | ||
|
||
public void info(String s); | ||
public void debug(String s); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.mehtank.thunderstone.api; | ||
|
||
public interface LogReader { | ||
void log(String s); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.mehtank.thunderstone.api; | ||
|
||
import com.mehtank.thunderstone.comms.GameQuery; | ||
|
||
public interface PlayHandler { | ||
|
||
String getName(); | ||
GameQuery query(GameQuery p); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.mehtank.thunderstone.api; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
import com.mehtank.thunderstone.engine.SelectCardOptions; | ||
|
||
public interface PlayerInterface { | ||
public String getName(); | ||
|
||
public Card[] getHand(); | ||
public int getHandSize(); | ||
public int getDiscardSize(); | ||
public int getDeckSize(); | ||
|
||
public void gain(Card card); | ||
public void discard(Card card); | ||
public void discardHand(); | ||
|
||
public Card drawFromDeck(); | ||
public void draw(); | ||
public void draw(int numCards); | ||
|
||
public Card pickACard(SelectCardOptions sco, Card[] hand); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.mehtank.thunderstone.cards; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
import com.mehtank.thunderstone.engine.Strings; | ||
|
||
public class CardGroup { | ||
String type; | ||
String name; | ||
String title; | ||
ArrayList<Card> cards = new ArrayList<Card>(); | ||
|
||
public CardGroup(Element e, Cards allCards) { | ||
type = e.getAttribute("type"); | ||
name = e.getAttribute("name"); | ||
title = e.getAttribute("title"); | ||
|
||
NodeList cardNodes = e.getElementsByTagName("card"); | ||
for (int i = 0; i < cardNodes.getLength(); i++) { | ||
Node node = cardNodes.item(i); | ||
if (node.getNodeType() == Node.ELEMENT_NODE) { | ||
Element element = (Element) node; | ||
Card card = allCards.getCard(element.getAttribute("name")); | ||
card.addAttribute("type", type); | ||
card.addAttribute("grouptitle", title); | ||
cards.add(card); | ||
} | ||
} | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public ArrayList<Card> getCards() { | ||
return cards; | ||
} | ||
|
||
public boolean equals(String s) { | ||
String cName = Strings.getCanonicalName(name); | ||
return (cName.equals(Strings.getCanonicalName(s))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package com.mehtank.thunderstone.cards; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.Random; | ||
import java.util.TreeMap; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
|
||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.xml.sax.SAXException; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
import com.mehtank.thunderstone.engine.CardPile; | ||
import com.mehtank.thunderstone.engine.XMLUtils; | ||
|
||
public class Cards { | ||
private String set = ""; | ||
private ArrayList<Card> cards = new ArrayList<Card>(); | ||
private ArrayList<CardGroup> groups = new ArrayList<CardGroup>(); | ||
|
||
public String getSet() { | ||
return set; | ||
} | ||
public Card[] getCards() { | ||
return cards.toArray(new Card[0]); | ||
} | ||
|
||
public Cards() { | ||
loadCards(); | ||
} | ||
|
||
public Card getCard(String name) { | ||
for (Card c : cards) | ||
if (c.equals(name)) | ||
return c.copy(); | ||
return null; | ||
} | ||
|
||
public CardPile getCardPile(String name) { | ||
return getCardPile(name, -1); | ||
} | ||
|
||
public CardPile getCardPile(String name, int count) { | ||
Card c = getCard(name); | ||
if (c == null) | ||
return null; | ||
|
||
if (count < 0) count = c.getCount(); | ||
|
||
CardPile p = new CardPile(name); | ||
for (int i = 0; i < count; i++) | ||
c.copy().moveTo(p); | ||
return p; | ||
} | ||
|
||
public CardPile getHeroPile(String name) { | ||
return getGroupPile(name, "level"); | ||
} | ||
public CardPile getMonsterPile(String name) { | ||
return getGroupPile(name, "xp"); | ||
} | ||
|
||
public CardPile getGroupPile(String name, String sort) { | ||
for (CardGroup g : groups) { | ||
if (g.equals(name)) { | ||
CardPile p = new CardPile(g.getTitle()); | ||
TreeMap<Float, Card> hash = new TreeMap<Float, Card>(); | ||
for (Card c : g.getCards()) | ||
hash.put(c.getInt(sort) + new Random().nextFloat(), c); // XXX is this robust enough? | ||
for (Card c : hash.values()) | ||
for (int i = 0; i < c.getCount() ; i++) | ||
c.copy().moveTo(p); | ||
return p; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private void loadCards() { | ||
InputStream xmlStream = this.getClass().getResourceAsStream("cards.xml"); | ||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder dBuilder; | ||
try { | ||
dBuilder = dbFactory.newDocumentBuilder(); | ||
} catch (ParserConfigurationException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
return; | ||
} | ||
Document doc; | ||
try { | ||
doc = dBuilder.parse(xmlStream); | ||
} catch (SAXException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
return; | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
return; | ||
} | ||
Element root = doc.getDocumentElement(); | ||
root.normalize(); | ||
|
||
String rootname = root.getNodeName(); | ||
|
||
if (!rootname.equals("cards")) | ||
return; | ||
|
||
set = root.getAttribute("set"); | ||
|
||
for (Element e : XMLUtils.getElementListByTagName(root, "card")) | ||
makeCard(e); | ||
for (Element e : XMLUtils.getElementListByTagName(root, "cardgroup")) | ||
groups.add(new CardGroup(e, this)); | ||
} | ||
|
||
private void makeCard(Element element) { | ||
String name = element.getAttribute("name"); | ||
String classname = this.getClass().getPackage().getName() + "." + name; | ||
Class<?> c = null; | ||
try { | ||
c = Class.forName(classname); | ||
} catch (ClassNotFoundException e) { | ||
return; | ||
} | ||
|
||
if (c == null) | ||
return; | ||
|
||
Card card; | ||
try { | ||
card = (Card) c.newInstance(); | ||
} catch (InstantiationException e) { | ||
return; | ||
} catch (IllegalAccessException e) { | ||
return; | ||
} | ||
|
||
card.setXML(element); | ||
cards.add(card); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mehtank.thunderstone.cards.base; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
|
||
public class ArchdukeOfPain extends Card { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mehtank.thunderstone.cards.base; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
import com.mehtank.thunderstone.engine.Context; | ||
import com.mehtank.thunderstone.engine.Effect; | ||
|
||
public class Barkeep extends Card { | ||
public Barkeep() { | ||
super(); | ||
|
||
final Card me = this; | ||
|
||
addEffect("plusbuy", new Effect() { | ||
@Override | ||
public boolean effect(Context context) { | ||
context.addBuys(1); | ||
return true; | ||
}}); | ||
|
||
addEffect("plusgold", new Effect() { | ||
@Override | ||
public boolean effect(Context context) { | ||
context.getGame().trash(me); | ||
context.addGold(2); | ||
return true; | ||
}}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.mehtank.thunderstone.cards.base; | ||
|
||
public class Cards extends com.mehtank.thunderstone.cards.Cards { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mehtank.thunderstone.cards.base; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
|
||
public class Grudgebeast extends Card { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mehtank.thunderstone.cards.base; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
|
||
public class Succubus extends Card { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mehtank.thunderstone.cards.base; | ||
|
||
import com.mehtank.thunderstone.engine.Card; | ||
|
||
public class TheUnchained extends Card { | ||
|
||
} |
Oops, something went wrong.