moved drawCard functions to new player class structure. Deprecated and redirected the methods in GameAction.java. I will work on changing all source to call the new functions.

This commit is contained in:
jendave
2011-08-06 09:36:49 +00:00
parent 5a4f3b497d
commit 5e1f8c3e02
4 changed files with 141 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
package forge;
import java.util.Random;
public class AIPlayer extends Player{
@@ -34,4 +36,34 @@ public class AIPlayer extends Player{
///
///////////////
////////////////////////////////
///
/// replaces AllZone.GameAction.draw* methods
///
////////////////////////////////
public boolean dredge() {
Random random = new Random();
boolean use = random.nextBoolean();
if(use) {
CardList tmp = getDredge();
tmp.shuffle();
Card c = tmp.get(0);
//rule 702.49a
if(getDredgeNumber(c) <= AllZone.Computer_Library.size() ) {
//dredge library, put card in hand
AllZone.GameAction.moveToHand(c);
//put dredge number in graveyard
for(int i = 0; i < getDredgeNumber(c); i++) {
Card c2 = AllZone.Computer_Library.get(0);
AllZone.GameAction.moveToGraveyard(c2);
}
}
else {
use = false;
}
}
return use;
}
}//end AIPlayer class

View File

@@ -2354,15 +2354,20 @@ public class GameAction {
* @param player target player to draw
* @param numCards the number of cards the player should draw
*/
@Deprecated
public void drawCards(Player player, int numCards) {
if(numCards > 0) {
player.drawCards(numCards);
/*if(numCards > 0) {
for(int i=0; i < numCards; i++) {
drawCard(player);
}
}
*/
}
@Deprecated
public void drawCard(Player player) {
player.drawCard();
/*
PlayerZone library = AllZone.getZone(Constant.Zone.Library, player);
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, player);
@@ -2392,8 +2397,9 @@ public class GameAction {
else {
doDraw(player, library, hand);
}
*/
}
/*
private void doDraw(Player player, PlayerZone library, PlayerZone hand) {
if(library.size() != 0) {
Card c = library.get(0);
@@ -2417,7 +2423,7 @@ public class GameAction {
}
}
}
*
private ArrayList<Card> getDredge() {
ArrayList<Card> dredge = new ArrayList<Card>();
Card c[] = AllZone.Human_Graveyard.getCards();
@@ -2442,6 +2448,7 @@ public class GameAction {
throw new RuntimeException("Input_Draw : getDredgeNumber() card doesn't have dredge - " + c.getName());
}//getDredgeNumber()
*/
//is this card a permanent that is in play?
public boolean isCardInPlay(Card c) {

View File

@@ -12,6 +12,10 @@ public class HumanPlayer extends Player{
super(myName, myLife, myPoisonCounters);
}
public Player getOpponent() {
return AllZone.ComputerPlayer;
}
////////////////
///
/// Methods to ease transition to Abstract Player class
@@ -30,8 +34,30 @@ public class HumanPlayer extends Player{
///
///////////////
public Player getOpponent() {
return AllZone.ComputerPlayer;
public boolean dredge() {
boolean dredged = false;
String choices[] = {"Yes", "No"};
Object o = AllZone.Display.getChoice("Do you want to dredge?", choices);
if(o.equals("Yes")) {
Card c = (Card) AllZone.Display.getChoice("Select card to dredge", getDredge().toArray());
//rule 702.49a
if(getDredgeNumber(c) <= AllZone.Human_Library.size()) {
//might have to make this more sophisticated
//dredge library, put card in hand
AllZone.GameAction.moveToHand(c);
for(int i = 0; i < getDredgeNumber(c); i++) {
Card c2 = AllZone.Human_Library.get(0);
AllZone.GameAction.moveToGraveyard(c2);
}
dredged = true;
}
else {
dredged = false;
}
}
return dredged;
}
}//end HumanPlayer class

View File

@@ -1,6 +1,8 @@
package forge;
import java.util.ArrayList;
public abstract class Player extends MyObservable{
protected String name;
@@ -229,7 +231,75 @@ public abstract class Player extends MyObservable{
return new CardList();
}
////////////////////////////////
///
/// replaces AllZone.GameAction.draw* methods
///
////////////////////////////////
public void drawCard() {
drawCards(1);
}
public void drawCards() {
drawCards(1);
}
public abstract boolean dredge();
public void drawCards(int n) {
PlayerZone library = AllZone.getZone(Constant.Zone.Library, this);
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, this);
for(int i = 0; i < n; i++) {
if(getDredge().size() == 0 || !dredge()) {
doDraw(library, hand);
}
}
}
private void doDraw(PlayerZone library, PlayerZone hand) {
if(library.size() != 0) {
Card c = library.get(0);
library.remove(0);
hand.add(c);
GameActionUtil.executeDrawCardTriggeredEffects(this);
}
//lose:
else if(Constant.Runtime.Mill[0]) {
if(!AllZoneUtil.isCardInPlay("Platinum Angel", this) && !AllZoneUtil.isCardInPlay("Abyssal Persecutor", this.getOpponent())) {
setLife(0);
AllZone.GameAction.checkStateEffects();
}
}
}
protected CardList getDredge() {
CardList dredge = new CardList();
CardList cl = AllZoneUtil.getPlayerGraveyard(this);
for(Card c:cl) {
ArrayList<String> kw = c.getKeyword();
for(int i = 0; i < kw.size(); i++) {
if(kw.get(i).toString().startsWith("Dredge")) {
if(AllZoneUtil.getPlayerCardsInLibrary(this).size() >= getDredgeNumber(c)) dredge.add(c);
}
}
}
return dredge;
}//hasDredge()
protected int getDredgeNumber(Card c) {
ArrayList<String> a = c.getKeyword();
for(int i = 0; i < a.size(); i++)
if(a.get(i).toString().startsWith("Dredge")) {
String s = a.get(i).toString();
return Integer.parseInt("" + s.charAt(s.length() - 1));
}
throw new RuntimeException("Input_Draw : getDredgeNumber() card doesn't have dredge - " + c.getName());
}//getDredgeNumber()
////////////////////////////////
//