minor changes, implemented 'doesn't untap' and facedown cards

This commit is contained in:
Max-Wilhelm Bruker 2009-04-07 21:37:57 +02:00
parent e6d6162426
commit a429a4a004
37 changed files with 198 additions and 101 deletions

View file

@ -19,8 +19,8 @@
***************************************************************************/
#include "playerzone.h"
PlayerZone::PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _id_access)
: name(_name), has_coords(_has_coords), is_public(_is_public), id_access(_id_access)
PlayerZone::PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access)
: name(_name), has_coords(_has_coords), is_public(_is_public), is_private(_is_private), id_access(_id_access)
{
}

View file

@ -28,7 +28,8 @@ class PlayerZone {
private:
QString name;
bool has_coords;
bool is_public; // Contents of the zone are visible for anyone
bool is_public; // Contents of the zone are always visible to anyone
bool is_private; // Contents of the zone are always visible to the owner
bool id_access; // getCard() finds by id, not by list index
// Example: When moving a card from the library to the table,
// the card has to be found by list index because the client
@ -36,12 +37,13 @@ private:
// to the table, the card can be found by id because the client
// knows the id and the hand does not need to have a specific order.
public:
PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _id_access);
PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access);
~PlayerZone();
TestCard *getCard(int id, bool remove, int *position = NULL);
bool isPublic() { return is_public; }
bool isPrivate() { return is_private; }
bool hasCoords() { return has_coords; }
bool hasIdAccess() { return id_access; }
QString getName() { return name; }

View file

@ -20,7 +20,7 @@
#include "testcard.h"
TestCard::TestCard(QString _name, int _id, int _coord_x, int _coord_y)
: id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), counters(0), tapped(false), attacking(false)
: id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), counters(0), tapped(false), attacking(false), facedown(false), annotation(QString()), doesntUntap(false)
{
}
@ -36,10 +36,11 @@ void TestCard::resetState()
setTapped(false);
setAttacking(false);
setFaceDown(false);
setAnnotation("");
setAnnotation(QString());
setDoesntUntap(false);
}
bool TestCard::setAttribute(const QString &aname, const QString &avalue)
bool TestCard::setAttribute(const QString &aname, const QString &avalue, bool allCards)
{
if (!aname.compare("counters")) {
bool ok;
@ -48,13 +49,17 @@ bool TestCard::setAttribute(const QString &aname, const QString &avalue)
return false;
setCounters(tmp_int);
} else if (!aname.compare("tapped")) {
setTapped(!avalue.compare("1"));
bool value = !avalue.compare("1");
if (!(!value && allCards && doesntUntap))
setTapped(value);
} else if (!aname.compare("attacking")) {
setAttacking(!avalue.compare("1"));
} else if (!aname.compare("facedown")) {
setFaceDown(!avalue.compare("1"));
} else if (!aname.compare("annotation")) {
setAnnotation(avalue);
} else if (!aname.compare("doesnt_untap")) {
setDoesntUntap(!avalue.compare("1"));
} else
return false;

View file

@ -21,9 +21,7 @@
#define TESTCARD_H
#include <QString>
/**
@author Max-Wilhelm Bruker <brukie@laptop>
*/
class TestCard {
private:
int id;
@ -34,6 +32,7 @@ private:
bool attacking;
bool facedown;
QString annotation;
bool doesntUntap;
public:
TestCard(QString _name, int _id, int _coord_x, int _coord_y);
~TestCard();
@ -47,7 +46,9 @@ public:
bool getAttacking() { return attacking; }
bool getFaceDown() { return facedown; }
QString getAnnotation() { return annotation; }
bool getDoesntUntap() { return doesntUntap; }
void setId(int _id) { id = _id; }
void setCoords(int x, int y) { coord_x = x; coord_y = y; }
void setName(const QString &_name) { name = _name; }
void setCounters(int _counters) { counters = _counters; }
@ -55,9 +56,10 @@ public:
void setAttacking(bool _attacking) { attacking = _attacking; }
void setFaceDown(bool _facedown) { facedown = _facedown; }
void setAnnotation(const QString &_annotation) { annotation = _annotation; }
void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; }
void resetState();
bool setAttribute(const QString &aname, const QString &avalue);
bool setAttribute(const QString &aname, const QString &avalue, bool allCards);
};
#endif

View file

@ -42,6 +42,11 @@ TestServerSocket::~TestServerSocket()
game->removePlayer(this);
}
int TestServerSocket::newCardId()
{
return nextCardId++;
}
void TestServerSocket::setName(const QString &name)
{
emit broadcastEvent(QString("name|%1|%2").arg(PlayerName).arg(name), this);
@ -79,14 +84,14 @@ void TestServerSocket::setupZones()
// ------------------------------------------------------------------
// Create zones
PlayerZone *deck = new PlayerZone("deck", false, false, false);
PlayerZone *deck = new PlayerZone("deck", false, false, false, false);
zones << deck;
PlayerZone *sb = new PlayerZone("sb", false, false, false);
PlayerZone *sb = new PlayerZone("sb", false, false, false, false);
zones << sb;
zones << new PlayerZone("table", true, true, true);
zones << new PlayerZone("hand", false, false, true);
zones << new PlayerZone("grave", false, true, true);
zones << new PlayerZone("rfg", false, true, true);
zones << new PlayerZone("table", true, true, false, true);
zones << new PlayerZone("hand", false, false, true, true);
zones << new PlayerZone("grave", false, true, false, true);
zones << new PlayerZone("rfg", false, true, false, true);
// Create life counter
Counter *life = new Counter("life", 20);
@ -301,8 +306,8 @@ bool TestServerSocket::parseCommand(QString line)
emit broadcastEvent(QString("draw|%1").arg(number), this);
} else if (!cmd.compare("move_card", Qt::CaseInsensitive)) {
// ID Karte, Startzone, Zielzone, Koordinaten X, Y
if (params.size() != 5)
// ID Karte, Startzone, Zielzone, Koordinaten X, Y, Facedown
if (params.size() != 6)
return remsg->send("syntax", false);
bool ok;
int cardid = params[0].toInt(&ok);
@ -326,26 +331,43 @@ bool TestServerSocket::parseCommand(QString line)
if (!ok)
return remsg->send("syntax", false);
}
targetzone->insertCard(card, x, y);
bool facedown = params[5].toInt(&ok);
if (!ok)
return remsg->send("syntax", false);
remsg->send();
msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7").arg(card->getId())
.arg(card->getName())
targetzone->insertCard(card, x, y);
QString privateCardName, publicCardName;
if (facedown)
card->setId(newCardId());
if ((!facedown && !card->getFaceDown())
|| (card->getFaceDown() && !facedown && startzone->isPublic() && targetzone->isPublic()))
publicCardName = card->getName();
if ((!facedown && !card->getFaceDown())
|| (card->getFaceDown() && !facedown && startzone->isPublic() && targetzone->isPublic())
|| (!facedown && targetzone->isPrivate()))
privateCardName = card->getName();
card->setFaceDown(facedown);
msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
.arg(privateCardName)
.arg(startzone->getName())
.arg(position)
.arg(targetzone->getName())
.arg(x)
.arg(y));
// Was ist mit Facedown-Karten?
.arg(y)
.arg(facedown ? 1 : 0));
if ((startzone->isPublic()) || (targetzone->isPublic()))
emit broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7").arg(card->getId())
.arg(card->getName())
emit broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
.arg(publicCardName)
.arg(startzone->getName())
.arg(position)
.arg(targetzone->getName())
.arg(x)
.arg(y), this);
.arg(y)
.arg(facedown ? 1 : 0), this);
else
emit broadcastEvent(QString("move_card|||%1|%2|%3|%4|%5").arg(startzone->getName())
emit broadcastEvent(QString("move_card|||%1|%2|%3|%4|%5|0").arg(startzone->getName())
.arg(position)
.arg(targetzone->getName())
.arg(x)
@ -361,7 +383,7 @@ bool TestServerSocket::parseCommand(QString line)
QString cardname = params[1];
int x = params[3].toInt();
int y = params[4].toInt();
int cardid = nextCardId++;
int cardid = newCardId();
QString powtough = params[2];
remsg->send();
@ -389,13 +411,13 @@ bool TestServerSocket::parseCommand(QString line)
if (cardid == -1) {
QListIterator<TestCard *> CardIterator(zone->cards);
while (CardIterator.hasNext())
if (!CardIterator.next()->setAttribute(params[2], params[3]))
if (!CardIterator.next()->setAttribute(params[2], params[3], true))
return remsg->send("syntax", false);
} else {
TestCard *card = zone->getCard(cardid, false);
if (!card)
return remsg->send("game_state", false);
if (!card->setAttribute(params[2], params[3]))
if (!card->setAttribute(params[2], params[3], false))
return remsg->send("syntax", false);
}
remsg->send();

View file

@ -54,6 +54,7 @@ private:
QList<Counter *> counters;
int PlayerId;
int nextCardId;
int newCardId();
PlayerZone *getZone(const QString &name);
Counter *getCounter(const QString &name);
void setName(const QString &name);

View file

@ -18,4 +18,4 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
const char *VERSION_STRING = "Testserver 0.20090304";
const char *VERSION_STRING = "Testserver 0.20090407";