pwnable之blackjack
经典的21点游戏(黑杰克),然而本人并没有玩过,还要看看规则(┬_┬)。
从题目给的源代码网址(点击打开链接)下载它的代码,对它分析
int k;//发的牌的值
int l;//玩家增加的点数
int d;//电脑增加的点数
int won//赢的次数
int loss;//输的次数
int cash = 500;//初始现金
int bet;//你押的注
int random_card;
int player_total=0;//玩家当前点数
int dealer_total;//电脑的点数
以上都是程序开头设的全局变量,我把它们的功能列出来了
开始想弯了,想着写个脚本来赢个几百万,然而发牌是随机的,要赢靠信仰。其实没有必要分析的那么详细,知道cash和bet就好,找到处理他
们的函数。
if(player_total>=dealer_total) //If player's total is more than dealer's total, win
{
printf("\nUnbelievable! You Win!\n");
won = won+1;
cash = cash+bet;
printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
dealer_total=0;
askover();
}
if(player_total<dealer_total) //If player's total is less than dealer's total, loss
{
printf("\nDealer Has the Better Hand. You Lose.\n");
loss = loss+1;
cash = cash - bet;
printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
dealer_total=0;
askover();
}
以及
int betting() //Asks user amount to bet
{
printf("\n\nEnter Bet: $");
scanf("%d", &bet);
if (bet > cash) //If player tries to bet more money than player has
{
printf("\nYou cannot bet more money than you have.");
printf("\nEnter Bet: ");
scanf("%d", &bet);
return bet;
}
else return bet;
} // End Function