OSDN Git Service

[Refactor] #3733 optional 型の値取得処理 value() を撤廃した その3
[hengbandforosx/hengbandosx.git] / src / market / play-gamble.cpp
1 #include "market/play-gamble.h"
2 #include "avatar/avatar.h"
3 #include "core/asking-player.h"
4 #include "core/show-file.h"
5 #include "io/input-key-acceptor.h"
6 #include "market/building-actions-table.h"
7 #include "market/building-util.h"
8 #include "market/poker.h"
9 #include "system/player-type-definition.h"
10 #include "term/screen-processor.h"
11 #include "term/term-color-types.h"
12 #include "term/z-form.h"
13 #include "util/string-processor.h"
14 #include "view/display-fruit.h"
15 #include "view/display-messages.h"
16
17 /*!
18  * @brief カジノ1プレイごとのメインルーチン / gamble_comm
19  * @param player_ptr プレイヤーへの参照ポインタ
20  * @param cmd プレイするゲームID
21  */
22 void gamble_comm(PlayerType *player_ptr, int cmd)
23 {
24     screen_save();
25     if (cmd == BACT_GAMBLE_RULES) {
26         (void)show_file(player_ptr, true, _("jgambling.txt", "gambling.txt"), 0, 0);
27         screen_load();
28         return;
29     }
30
31     if (player_ptr->au < 1) {
32         msg_print(_("おい!おまえ一文なしじゃないか!こっから出ていけ!", "Hey! You don't have gold - get out of here!"));
33         msg_print(nullptr);
34         screen_load();
35         return;
36     }
37
38     clear_bldg(5, 23);
39     auto maxbet = player_ptr->lev * 200;
40     maxbet = std::min(maxbet, player_ptr->au);
41     constexpr auto prompt = _("賭け金?", "Your wager ?");
42     const auto wager_opt = input_integer(prompt, 1, maxbet, 1);
43     if (!wager_opt) {
44         msg_print(nullptr);
45         screen_load();
46         return;
47     }
48
49     auto wager = wager_opt.value();
50     if (wager > player_ptr->au) {
51         msg_print(_("おい!金が足りないじゃないか!出ていけ!", "Hey! You don't have the gold - get out of here!"));
52         msg_print(nullptr);
53         screen_load();
54         return;
55     }
56
57     msg_print(nullptr);
58     auto win = 0;
59     auto odds = 0;
60     auto oldgold = player_ptr->au;
61     prt(format(_("ゲーム前の所持金: %9d", "Gold before game: %9d"), oldgold), 20, 2);
62     prt(format(_("現在の掛け金:     %9d", "Current Wager:    %9d"), wager), 21, 2);
63     while (true) {
64         player_ptr->au -= wager;
65         switch (cmd) {
66         case BACT_IN_BETWEEN: {
67             c_put_str(TERM_GREEN, _("イン・ビトイーン", "In Between"), 5, 2);
68             odds = 4;
69             win = 0;
70             auto roll1 = randint1(10);
71             auto roll2 = randint1(10);
72             auto choice = randint1(10);
73             prt(format(_("黒ダイス: %d        黒ダイス: %d", "Black die: %d       Black Die: %d"), roll1, roll2), 8, 3);
74             prt(format(_("赤ダイス: %d", "Red die: %d"), choice), 11, 14);
75             if (((choice > roll1) && (choice < roll2)) || ((choice < roll1) && (choice > roll2))) {
76                 win = 1;
77             }
78
79             break;
80         }
81         case BACT_CRAPS: {
82             c_put_str(TERM_GREEN, _("クラップス", "Craps"), 5, 2);
83             win = 3;
84             odds = 2;
85             auto roll1 = randint1(6);
86             auto roll2 = randint1(6);
87             auto roll3 = roll1 + roll2;
88             auto choice = roll3;
89             prt(format(_("1振りめ: %d %d      Total: %d", "First roll: %d %d    Total: %d"), roll1, roll2, roll3), 7, 5);
90             if ((roll3 == 7) || (roll3 == 11)) {
91                 win = 1;
92                 break;
93             }
94
95             if ((roll3 == 2) || (roll3 == 3) || (roll3 == 12)) {
96                 win = 0;
97                 break;
98             }
99
100             do {
101                 msg_print(_("なにかキーを押すともう一回振ります。", "Hit any key to roll again"));
102
103                 msg_print(nullptr);
104                 roll1 = randint1(6);
105                 roll2 = randint1(6);
106                 roll3 = roll1 + roll2;
107                 prt(format(_("出目: %d %d          合計:      %d", "Roll result: %d %d   Total:     %d"), roll1, roll2, roll3), 8, 5);
108                 if (roll3 == choice) {
109                     win = 1;
110                 } else if (roll3 == 7) {
111                     win = 0;
112                 }
113             } while ((win != 1) && (win != 0));
114             break;
115         }
116         case BACT_SPIN_WHEEL: {
117             win = 0;
118             odds = 9;
119             c_put_str(TERM_GREEN, _("ルーレット", "Wheel"), 5, 2);
120             prt("0  1  2  3  4  5  6  7  8  9", 7, 5);
121             prt("--------------------------------", 8, 3);
122             while (true) {
123                 const auto choice_opt = input_integer(_("何番?", "Pick a number"), 0, 9);
124                 if (!choice_opt) {
125                     continue;
126                 }
127
128                 auto choice = choice_opt.value();
129                 msg_print(nullptr);
130                 auto roll1 = randint0(10);
131                 prt(format(_("ルーレットは回り、止まった。勝者は %d番だ。", "The wheel spins to a stop and the winner is %d"), roll1), 13, 3);
132                 prt("", 9, 0);
133                 prt("*", 9, (3 * roll1 + 5));
134                 if (roll1 == choice) {
135                     win = 1;
136                 }
137
138                 break;
139             }
140
141             break;
142         }
143         case BACT_DICE_SLOTS: {
144             c_put_str(TERM_GREEN, _("ダイス・スロット", "Dice Slots"), 5, 2);
145             c_put_str(TERM_YELLOW, _("レモン   レモン            2", "Lemon    Lemon             2"), 6, 37);
146             c_put_str(TERM_YELLOW, _("レモン   レモン   レモン   5", "Lemon    Lemon    Lemon    5"), 7, 37);
147             c_put_str(TERM_ORANGE, _("オレンジ オレンジ オレンジ 10", "Orange   Orange   Orange   10"), 8, 37);
148             c_put_str(TERM_UMBER, _("剣       剣       剣       20", "Sword    Sword    Sword    20"), 9, 37);
149             c_put_str(TERM_SLATE, _("盾       盾       盾       50", "Shield   Shield   Shield   50"), 10, 37);
150             c_put_str(TERM_VIOLET, _("プラム   プラム   プラム   200", "Plum     Plum     Plum     200"), 11, 37);
151             c_put_str(TERM_RED, _("チェリー チェリー チェリー 1000", "Cherry   Cherry   Cherry   1000"), 12, 37);
152
153             win = 0;
154             auto roll1 = randint1(21);
155             for (auto i = 6; i > 0; i--) {
156                 if ((roll1 - i) < 1) {
157                     roll1 = 7 - i;
158                     break;
159                 }
160                 roll1 -= i;
161             }
162
163             auto roll2 = randint1(21);
164             for (auto i = 6; i > 0; i--) {
165                 if ((roll2 - i) < 1) {
166                     roll2 = 7 - i;
167                     break;
168                 }
169                 roll2 -= i;
170             }
171
172             auto choice = randint1(21);
173             for (auto i = 6; i > 0; i--) {
174                 if ((choice - i) < 1) {
175                     choice = 7 - i;
176                     break;
177                 }
178                 choice -= i;
179             }
180
181             put_str("/--------------------------\\", 7, 2);
182             prt("\\--------------------------/", 17, 2);
183             display_fruit(8, 3, roll1 - 1);
184             display_fruit(8, 12, roll2 - 1);
185             display_fruit(8, 21, choice - 1);
186             if ((roll1 == roll2) && (roll2 == choice)) {
187                 win = 1;
188                 switch (roll1) {
189                 case 1:
190                     odds = 5;
191                     break;
192                 case 2:
193                     odds = 10;
194                     break;
195                 case 3:
196                     odds = 20;
197                     break;
198                 case 4:
199                     odds = 50;
200                     break;
201                 case 5:
202                     odds = 200;
203                     break;
204                 case 6:
205                     odds = 1000;
206                     break;
207                 }
208
209                 break;
210             }
211
212             if ((roll1 == 1) && (roll2 == 1)) {
213                 win = 1;
214                 odds = 2;
215             }
216
217             break;
218         }
219         case BACT_POKER:
220             win = 0;
221             odds = do_poker();
222             if (odds) {
223                 win = 1;
224             }
225
226             break;
227         }
228
229         if (win) {
230             prt(_("あなたの勝ち", "YOU WON"), 16, 37);
231             player_ptr->au += odds * wager;
232             prt(format(_("倍率: %d", "Payoff: %d"), odds), 17, 37);
233         } else {
234             prt(_("あなたの負け", "You Lost"), 16, 37);
235             prt("", 17, 37);
236         }
237
238         prt(format(_("現在の所持金:     %9d", "Current Gold:     %9d"), player_ptr->au), 22, 2);
239         prt(_("もう一度(Y/N)?", "Again(Y/N)?"), 18, 37);
240         move_cursor(18, 52);
241         auto again = inkey();
242         prt("", 16, 37);
243         prt("", 17, 37);
244         prt("", 18, 37);
245         if (wager > player_ptr->au) {
246             msg_print(_("おい!金が足りないじゃないか!ここから出て行け!", "Hey! You don't have the gold - get out of here!"));
247             msg_print(nullptr);
248             break;
249         }
250
251         if ((again == 'y') || (again == 'Y')) {
252             continue;
253         }
254
255         break;
256     }
257
258     prt("", 18, 37);
259     if (player_ptr->au >= oldgold) {
260         msg_print(_("「今回は儲けたな!でも次はこっちが勝ってやるからな、絶対に!」", "You came out a winner! We'll win next time, I'm sure."));
261         chg_virtue(player_ptr, Virtue::CHANCE, 3);
262     } else {
263         msg_print(_("「金をスッてしまったな、わはは!うちに帰った方がいいぜ。」", "You lost gold! Haha, better head home."));
264         chg_virtue(player_ptr, Virtue::CHANCE, -3);
265     }
266
267     msg_print(nullptr);
268     screen_load();
269 }