// ボタンのアクションを定義
const buttonActions = {
hit: () => {//ヒットボタンを押したとき
console.log(“Hit button clicked”);
let lastCard = playerHand.length > 0 ? playerHand[playerHand.length – 1] : null;
//プレイヤーの手札の一番最後のカードを取る(無ければnull)
//playerHand[playerHand.length – 1]プレイヤーの手札の最後の一枚
//条件 ? A : B
//条件がtrue → A
//false → B
//if (条件) {
// A;
//} else {
// B;
//}
let newX = lastCard ? lastCard.x + 30 : 10;
//if (lastCard) {
// newX = lastCard.x + 30;
//} else {
// newX = 10;
//}
//指定した位置にカードを1枚引いて、プレイヤーの手札に追加している
drawCard(newX, 180, 0, true, playerHand);//newX 上記の値
player_total = calculateHandValue(playerHand);//playerの手札の値の合計
player_totalLabel.text = “P: ” + player_total;//それをラベル用の変数へ
if (player_total > 21) {//21より大きい つまりバースト
console.log(“You Lose! (Busted)”);
disableButtons();//ボタンを使えなくする
player_totalLabel.text = “P: ” + player_total + ” (Busted)”;
// 勝敗決定後にネクストゲームボタンを表示
nextButton.opacity = 1;//ボタンを表示
nextButton.ontouchend = buttonActions.next;//イベントが起きるようにする
}
},
stand: () => {//スタンドボタンを押したとき
console.log(“Stand button clicked”);
disableButtons();//ボタンを使えないようにする
dealerHand[1].frame = enchant.TCard.OPEN;//ディーラーの二枚目オープン
dealer_total = calculateHandValue(dealerHand);//ディーラーの点数計算
while (dealer_total < 17) {//ディーラーの点数が17より小さい場合
let lastCard = dealerHand.length > 0 ? dealerHand[dealerHand.length – 1] : null;
//手札があるなら「一番最後のカード」を取る
//なければ null
let newX = lastCard ? lastCard.x + 30 : 10;
//最後のカードがあればその右に30ずらす
//なければ最初の位置(10)
drawCard(newX, 80, 0, true, dealerHand);
//drawCard(x_posi, y_posi, c_rotate, isFaceUp, hand = [])
dealer_total = calculateHandValue(dealerHand);//ディーラーの点数を計算
}
player_totalLabel.text = “P: ” + player_total;
dealer_totalLabel.text = “D: ” + dealer_total;
determineWinner(player_total, dealer_total);//勝敗判定
},
next: () => {//nextボタンを押したとき
console.log(“Next Game button clicked”);
initializeGame(core.rootScene);//初期化
enableButtons();//ボタンつかえるようにする
},
cheat: () => {//チートボタンを押したとき のち実装予定
console.log(“Cheat!!”);
}
};
定
。