Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw_handkerchief: new game #82

Merged
merged 3 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions games/ecard/mygame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,31 @@ class MainStage : public MainGameStage<TargetStage, RoundStage>
if (reason == CheckoutReason::BY_TIMEOUT || reason == CheckoutReason::BY_LEAVE) {
return;
}
auto &point = table.playerPoint;
auto &target = table.targetScore;
auto &att = table.attacker;
auto &def = table.defender;
// 游戏结束判定
int game_end = (GAME_OPTION(模式) == 0 && round_ % 2 == 0 && (table.playerPoint[0] >= GAME_OPTION(目标) || table.playerPoint[1] >= GAME_OPTION(目标))) || // [经典]偶数回合提前达到目标分
(GAME_OPTION(模式) == 0 && round_ % 2 == 1 && table.playerPoint[0] >= GAME_OPTION(目标) && table.playerPoint[0] > table.playerPoint[1] + 1) || // [经典]奇数回合提前达到目标分0
(GAME_OPTION(模式) == 0 && round_ % 2 == 1 && table.playerPoint[1] >= GAME_OPTION(目标) && table.playerPoint[1] > table.playerPoint[0] + 1) || // [经典]奇数回合提前达到目标分1
(GAME_OPTION(模式) == 1 && round_ < 10 && table.playerPoint[0] > table.playerPoint[1] + table.GetPlayerLeftRound(1)) || // [点球]提前获胜0
(GAME_OPTION(模式) == 1 && round_ < 10 && table.playerPoint[1] > table.playerPoint[0] + table.GetPlayerLeftRound(0)) || // [点球]提前获胜1
(GAME_OPTION(模式) == 1 && round_ >= 10 && round_ % 2 == 0 && table.playerPoint[0] != table.playerPoint[1]) || // [点球]10回合后加赛
(GAME_OPTION(模式) == 2 && table.playerPoint[table.attacker] <= 0) || // [人生]进攻方血量归零
(GAME_OPTION(模式) == 2 && table.playerPoint[table.defender] >= table.targetScore[table.attacker] && table.playerPoint[table.attacker] > 12 - round_); // [人生]进攻方达到目标且血量充足
bool game_end = (GAME_OPTION(模式) == 0 && round_ % 2 == 0 && (point[0] >= GAME_OPTION(目标) || point[1] >= GAME_OPTION(目标))) || // [经典]偶数回合提前达到目标分
(GAME_OPTION(模式) == 0 && round_ % 2 == 1 && point[0] >= GAME_OPTION(目标) && point[0] > point[1] + 1) || // [经典]奇数回合提前达到目标分0
(GAME_OPTION(模式) == 0 && round_ % 2 == 1 && point[1] >= GAME_OPTION(目标) && point[1] > point[0] + 1) || // [经典]奇数回合提前达到目标分1
(GAME_OPTION(模式) == 1 && round_ < 10 && point[0] > point[1] + table.GetPlayerLeftRound(1)) || // [点球]提前获胜0
(GAME_OPTION(模式) == 1 && round_ < 10 && point[1] > point[0] + table.GetPlayerLeftRound(0)) || // [点球]提前获胜1
(GAME_OPTION(模式) == 1 && round_ >= 10 && round_ % 2 == 0 && point[0] != point[1]) || // [点球]10回合后加赛
(GAME_OPTION(模式) == 2 && point[att] <= 0) || // [人生]进攻方血量归零
(GAME_OPTION(模式) == 2 && point[def] >= target[att] && point[att] > 12 - round_ && Global().PlayerName(1) != "机器人0号"); // [人生]进攻方达到目标且血量充足
if ((++round_) <= GAME_OPTION(回合数) && !game_end) {
setter.Emplace<RoundStage>(*this, round_);
return;
}

// [经典模式]胜负判定
if (GAME_OPTION(模式) == 0) {
player_scores_[0] = table.playerPoint[0];
player_scores_[1] = table.playerPoint[1];
player_scores_[0] = point[0];
player_scores_[1] = point[1];
if (round_ > GAME_OPTION(回合数)) {
Global().Boardcast() << "回合数到达上限,游戏结束\n"
<< "最终比分: " << table.playerPoint[0] << " : " << table.playerPoint[1];
<< "最终比分: " << point[0] << " : " << point[1];
} else {
if (player_scores_[0] >= GAME_OPTION(目标)) {
Global().Boardcast() << At(PlayerID(0)) << " 奴隶胜利次数达到目标,获得胜利!";
Expand All @@ -160,8 +164,8 @@ class MainStage : public MainGameStage<TargetStage, RoundStage>
// [点球模式]胜负判定
if (GAME_OPTION(模式) == 1) {
Global().Boardcast() << Markdown(table.GetShootoutModeTable(round_ < 10 ? round_ : round_ - 1));
player_scores_[0] = table.playerPoint[0];
player_scores_[1] = table.playerPoint[1];
player_scores_[0] = point[0];
player_scores_[1] = point[1];
if (player_scores_[0] == player_scores_[1]) {
Global().Boardcast() << "回合数到达上限,双方平局!";
} else {
Expand All @@ -175,20 +179,20 @@ class MainStage : public MainGameStage<TargetStage, RoundStage>
// [人生模式]胜负判定
if (GAME_OPTION(模式) == 2) {
Global().Boardcast() << Markdown(table.GetLiveModeTable());
if (table.playerPoint[table.attacker] <= 0) {
player_scores_[table.defender] = 1;
Global().Boardcast() << "游戏结束,防守方 " << At(table.defender) << " 获胜!";
if (point[att] <= 0) {
player_scores_[def] = 1;
Global().Boardcast() << "游戏结束,防守方 " << At(def) << " 获胜!";
} else {
if (table.playerPoint[table.defender] >= table.targetScore[table.attacker]) {
player_scores_[table.attacker] = 1;
if (point[def] >= target[att]) {
player_scores_[att] = 1;
if (round_ <= 12) {
Global().Boardcast() << "进攻方 " << At(table.attacker) << " 达到了目标分且生命大于剩余回合数,提前获得胜利!";
Global().Boardcast() << "进攻方 " << At(att) << " 达到了目标分且生命大于剩余回合数,提前获得胜利!";
} else {
Global().Boardcast() << "游戏结束,进攻方 " << At(table.attacker) << " 达到了目标分,获得胜利!";
Global().Boardcast() << "游戏结束,进攻方 " << At(att) << " 达到了目标分,获得胜利!";
}
} else {
player_scores_[table.defender] = 1;
Global().Boardcast() << "游戏结束,进攻方未达到目标分,防守方 " << At(table.defender) << " 获胜!";
player_scores_[def] = 1;
Global().Boardcast() << "游戏结束,进攻方未达到目标分,防守方 " << At(def) << " 获胜!";
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions games/ecard/unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ GAME_TEST(2, LiveMode_TargetStageTimeout_test)
ASSERT_PRI_MSG(OK, 0, "500");
ASSERT_TIMEOUT(CHECKOUT);

ASSERT_SCORE(0,-1);
ASSERT_SCORE(0, -1);
}

GAME_TEST(2, LiveMode_BidStageTimeout_test)
Expand All @@ -112,7 +112,7 @@ GAME_TEST(2, LiveMode_BidStageTimeout_test)

ASSERT_TIMEOUT(CHECKOUT);

ASSERT_SCORE(0,-1);
ASSERT_SCORE(0, -1);
}

GAME_TEST(2, LiveMode_GameStageLeave_test)
Expand Down
8 changes: 5 additions & 3 deletions games/gold_coins/mygame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ template <typename... SubStages> using MainGameStage = StageFsm<void, SubStages.

const std::string k_game_name = "爆金币"; // the game name which should be unique among all the games
uint64_t MaxPlayerNum(const MyGameOptions& options) { return 0; } // 0 indicates no max-player limits
uint32_t Multiple(const MyGameOptions& options) { return 0; } // the default score multiple for the game, 0 for a testing game, 1 for a formal game, 2 or 3 for a long formal game
uint32_t Multiple(const MyGameOptions& options) { return 1; } // the default score multiple for the game, 0 for a testing game, 1 for a formal game, 2 or 3 for a long formal game
const std::string k_developer = "铁蛋";
const std::string k_description = "选择行动,与他人博弈抢夺金币的游戏";
const MutableGenericOptions k_default_generic_options;
const MutableGenericOptions k_default_generic_options{
.is_formal_{false},
};

const char* const settlement_details[7] = {
R"EOF(· 完整判定顺序为:
Expand Down Expand Up @@ -146,7 +148,7 @@ class MainStage : public MainGameStage<RoundStage>
const string takehp_success_color = "FFD4F3"; // 夺血条成功颜色
const string leave_color = "E5E5E5"; // 撤离颜色

const int image_width = Global().PlayerNum() < 8 ? Global().PlayerNum() * 80 + 90 : (Global().PlayerNum() < 16 ? Global().PlayerNum() * 60 + 70 : Global().PlayerNum() * 40 + 50);
const int image_width = Global().PlayerNum() < 8 ? Global().PlayerNum() * 80 + 90 : (Global().PlayerNum() < 16 ? Global().PlayerNum() * 70 + 70 : Global().PlayerNum() * 40 + 50);

string GetName(std::string x);
string GetStatusBoard();
Expand Down
Empty file.
Binary file added games/throw_handkerchief/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading