Erwan
- Adding external rules mechanism. It is very crude for the moment, but I hope it will grow. Have a look at Rules/mtg.txt for basic usage
This commit is contained in:
@@ -62,7 +62,7 @@ class GameApp: public JApp
|
||||
GameState* mGameStates[MAX_STATE];
|
||||
|
||||
public:
|
||||
int players[2];
|
||||
|
||||
|
||||
int gameType;
|
||||
CardEffect *effect;
|
||||
@@ -85,6 +85,7 @@ class GameApp: public JApp
|
||||
static string systemError;
|
||||
static JMusic* music;
|
||||
static MTGAllCards * collection;
|
||||
static int players[2];
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class MTGCardInstance;
|
||||
struct CardGui;
|
||||
class Player;
|
||||
class TargetChooser;
|
||||
class Rules;
|
||||
using namespace std;
|
||||
|
||||
class GameObserver{
|
||||
@@ -70,7 +71,7 @@ class GameObserver{
|
||||
void eventOccured();
|
||||
void addObserver(MTGAbility * observer);
|
||||
void removeObserver(ActionElement * observer);
|
||||
void startGame(int shuffle = 1, int draw = 1);
|
||||
void startGame(Rules * rules);
|
||||
void untapPhase();
|
||||
void draw();
|
||||
int isInPlay(MTGCardInstance * card);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
class TestSuite;
|
||||
#endif
|
||||
class Credits;
|
||||
class Rules;
|
||||
|
||||
|
||||
class GameStateDuel: public GameState, public JGuiListener
|
||||
@@ -33,11 +34,11 @@ class GameStateDuel: public GameState, public JGuiListener
|
||||
bool premadeDeck;
|
||||
int OpponentsDeckid;
|
||||
string musictrack;
|
||||
Rules * rules;
|
||||
|
||||
bool MusicExist(string FileName);
|
||||
void loadPlayer(int playerId, int decknb = 0, int isAI = 0);
|
||||
void loadPlayerMomir(int playerId, int isAI);
|
||||
void loadPlayerRandom(int playerId, int isAI, int mode);
|
||||
|
||||
|
||||
public:
|
||||
GameStateDuel(GameApp* parent);
|
||||
|
||||
@@ -140,6 +140,8 @@ class MTGCardInstance: public MTGCard, public Damageable {
|
||||
static MTGCardInstance AnyCard;
|
||||
static MTGCardInstance NoCard;
|
||||
|
||||
static MTGCardInstance ExtraRules[2];
|
||||
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream&, const MTGCardInstance&);
|
||||
|
||||
@@ -149,16 +149,16 @@ class MTGPlayerCards {
|
||||
MTGGameZone * garbage;
|
||||
MTGGameZone * temp;
|
||||
|
||||
MTGAllCards * collection;
|
||||
|
||||
MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize);
|
||||
MTGPlayerCards(MTGAllCards * _collection, MTGDeck * deck);
|
||||
MTGPlayerCards(int * idList, int idListSize);
|
||||
MTGPlayerCards(MTGDeck * deck);
|
||||
~MTGPlayerCards();
|
||||
void initGame(int shuffle = 1, int draw = 1);
|
||||
void setOwner(Player * player);
|
||||
void discardRandom(MTGGameZone * from);
|
||||
void drawFromLibrary();
|
||||
void showHand();
|
||||
void resetLibrary();
|
||||
void initDeck(MTGDeck * deck);
|
||||
MTGCardInstance * putInGraveyard(MTGCardInstance * card);
|
||||
MTGCardInstance * putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to);
|
||||
int isInPlay(MTGCardInstance * card);
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#define _PHASERING_H_
|
||||
|
||||
#include <list>
|
||||
using std::list;
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
The class that handles the phases of a turn
|
||||
@@ -33,6 +34,7 @@ private:
|
||||
int addPhaseBefore(int id, Player* player,int after_id, Player * after_player, int allOccurences = 1);
|
||||
int removePhase (int id, Player * player, int allOccurences = 1);
|
||||
static const char * phaseName(int id);
|
||||
static int phaseStrToInt(string s);
|
||||
|
||||
};
|
||||
|
||||
|
||||
74
projects/mtg/include/Rules.h
Normal file
74
projects/mtg/include/Rules.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef _RULES_H_
|
||||
#define _RULES_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
class ManaCost;
|
||||
class Player;
|
||||
class MTGPlayerCards;
|
||||
class MTGDeck;
|
||||
class MTGCardInstance;
|
||||
|
||||
#define MAX_RULES_CARDS 4096;
|
||||
|
||||
class RulesPlayerZone{
|
||||
public:
|
||||
vector<int> cards;
|
||||
void add(int cardid);
|
||||
RulesPlayerZone();
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
class RulesPlayerData{
|
||||
public:
|
||||
vector <string> extraRules;
|
||||
int life;
|
||||
ManaCost * manapool;
|
||||
RulesPlayerZone zones[5];
|
||||
RulesPlayerData();
|
||||
~RulesPlayerData();
|
||||
void cleanup();
|
||||
|
||||
};
|
||||
|
||||
class RulesState{
|
||||
public:
|
||||
int phase;
|
||||
void parsePlayerState(int playerId, string s);
|
||||
RulesState();
|
||||
RulesPlayerData playerData[2];
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
|
||||
class Rules{
|
||||
protected:
|
||||
Player * loadPlayerMomir(int isAI);
|
||||
Player * loadPlayerRandom(int isAI, int mode);
|
||||
Player * initPlayer(int playerId);
|
||||
MTGDeck * buildDeck( int playerId);
|
||||
int strToGameMode(string s);
|
||||
public:
|
||||
enum {
|
||||
PARSE_UNDEFINED,
|
||||
PARSE_INIT,
|
||||
PARSE_PLAYER1,
|
||||
PARSE_PLAYER2,
|
||||
PARSE_PLAYERS
|
||||
};
|
||||
Rules(string filename);
|
||||
int load(string filename);
|
||||
int gamemode;
|
||||
void initPlayers();
|
||||
void addExtraRules();
|
||||
void initGame();
|
||||
void cleanup();
|
||||
vector <string> extraRules;
|
||||
RulesState initState;
|
||||
static int getMTGId(string name);
|
||||
static MTGCardInstance * getCardByMTGId(int mtgid);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -41,7 +41,7 @@ class TestSuite;
|
||||
class TestSuiteState{
|
||||
public:
|
||||
int phase;
|
||||
void parsePlayerState(int playerId, string s,TestSuite * suite);
|
||||
void parsePlayerState(int playerId, string s);
|
||||
TestSuiteState();
|
||||
TestSuitePlayerData playerData[2];
|
||||
void cleanup();
|
||||
@@ -70,13 +70,10 @@ class TestSuite{
|
||||
int assertGame();
|
||||
MTGPlayerCards * buildDeck(int playerId);
|
||||
string getNextAction();
|
||||
int phaseStrToInt(string s);
|
||||
MTGCardInstance * getCardByMTGId(int mtgid);
|
||||
Interruptible * getActionByMTGId(int mtgid);
|
||||
int loadNext();
|
||||
void cleanup();
|
||||
int Log(const char * text);
|
||||
int getMTGId(string name);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user