more plumbing
This commit is contained in:
parent
e58fc9c38f
commit
b5de19437f
@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
Chess::ChessInstance::ChessInstance(
|
Chess::ChessInstance::ChessInstance(
|
||||||
Chess& game_type_static,
|
Chess& game_type_static,
|
||||||
|
uint32_t opponent,
|
||||||
uint32_t game_id
|
uint32_t game_id
|
||||||
) : _game_type_static(game_type_static) {
|
) : _game_type_static(game_type_static), _opponent(opponent) {
|
||||||
_id = game_id;
|
_id = game_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,6 +18,41 @@ bool Chess::ChessInstance::allInvitesAccepted(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Chess::ChessInstance::onPacket(uint32_t from, const uint8_t* data, const uint32_t data_size) {
|
void Chess::ChessInstance::onPacket(uint32_t from, const uint8_t* data, const uint32_t data_size) {
|
||||||
|
// test, auto resign
|
||||||
|
sendResign();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Chess::ChessInstance::sendResign(void) {
|
||||||
|
std::vector<uint8_t> pkg;
|
||||||
|
|
||||||
|
// resign (chess specific)
|
||||||
|
pkg.push_back(0xff);
|
||||||
|
return _game_type_static._tg.sendPacket(
|
||||||
|
static_cast<Contact3>(_opponent),
|
||||||
|
_game_type_static.getGameType(),
|
||||||
|
_id,
|
||||||
|
pkg.data(), pkg.size()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Chess::ChessInstance::sendMove(ChessCoords p0, ChessCoords p1) {
|
||||||
|
std::vector<uint8_t> pkg;
|
||||||
|
|
||||||
|
// move piece (chess specific)
|
||||||
|
pkg.push_back(0xfe);
|
||||||
|
|
||||||
|
pkg.push_back(p0.L);
|
||||||
|
pkg.push_back(p0.N);
|
||||||
|
|
||||||
|
pkg.push_back(p1.L);
|
||||||
|
pkg.push_back(p1.N);
|
||||||
|
|
||||||
|
return _game_type_static._tg.sendPacket(
|
||||||
|
static_cast<Contact3>(_opponent),
|
||||||
|
_game_type_static.getGameType(),
|
||||||
|
_id,
|
||||||
|
pkg.data(), pkg.size()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Chess::Chess(ToxicGames& tg) : ToxicGameI(tg) {
|
Chess::Chess(ToxicGames& tg) : ToxicGameI(tg) {
|
||||||
@ -32,7 +68,7 @@ std::unique_ptr<Chess::InstanceI> Chess::createGame(std::vector<uint32_t> with)
|
|||||||
std::unique_ptr<Chess::InstanceI> Chess::acceptInvite(uint32_t from, uint32_t game_id) {
|
std::unique_ptr<Chess::InstanceI> Chess::acceptInvite(uint32_t from, uint32_t game_id) {
|
||||||
sendAcceptInvite(from, game_id);
|
sendAcceptInvite(from, game_id);
|
||||||
|
|
||||||
auto new_instance = std::make_unique<ChessInstance>(*this, game_id);
|
auto new_instance = std::make_unique<ChessInstance>(*this, from, game_id);
|
||||||
|
|
||||||
return new_instance;
|
return new_instance;
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,17 @@ struct Chess final : public ToxicGameI {
|
|||||||
Chess(ToxicGames& tg);
|
Chess(ToxicGames& tg);
|
||||||
~Chess(void);
|
~Chess(void);
|
||||||
|
|
||||||
|
struct ChessCoords {
|
||||||
|
char L;
|
||||||
|
uint8_t N;
|
||||||
|
};
|
||||||
|
|
||||||
struct ChessInstance final : public ToxicGameI::InstanceI {
|
struct ChessInstance final : public ToxicGameI::InstanceI {
|
||||||
Chess& _game_type_static;
|
Chess& _game_type_static;
|
||||||
|
|
||||||
ChessInstance(Chess& game_type_static, uint32_t game_id);
|
const uint32_t _opponent;
|
||||||
|
|
||||||
|
ChessInstance(Chess& game_type_static, uint32_t opponent, uint32_t game_id);
|
||||||
~ChessInstance(void) {}
|
~ChessInstance(void) {}
|
||||||
|
|
||||||
// TODO: just destructor?
|
// TODO: just destructor?
|
||||||
@ -24,6 +30,9 @@ struct Chess final : public ToxicGameI {
|
|||||||
// ??
|
// ??
|
||||||
//virtual void tick();
|
//virtual void tick();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool sendResign(void);
|
||||||
|
bool sendMove(ChessCoords p0, ChessCoords p1);
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t getGameType(void) const override { return 1; };
|
uint8_t getGameType(void) const override { return 1; };
|
||||||
|
Loading…
Reference in New Issue
Block a user