我目前正在制作一个单臂强盗游戏,这就是它应该做的:
- 用户应该能够将钱放入机器中,50、100 或 500
- 用户应该能够为每场比赛下注
- 用户下注后,货币符号应随机出现在如下字段中:
[ o ] [ p ] [ x ]
[ x ] [ x ] [ x ]
[ x ] [ o ] [ x ]
(1 列/行赢 2x 钱,2 列/行赢 4x 钱等)
这个字段每次都应该用字母随机化,也应该用一个二维数组来表示游戏区域。
我遇到了一些问题,基本上是在我赌了一些钱之后游戏关闭并且我看不到任何错误等,任何澄清这个问题的帮助将不胜感激,以及我可以对我的代码做的任何改进等。
这是我的代码:
#include <iostream>
#include <ctime>
using namespace std;
int main(int args, const char* argv[])
{
int svar = 0;
int bokstav = 0;
int insert;
int build;
int bet;
int credit;
int array;
int jackpot;
int tal;
int spin_1x = 0;
int spin_1y = 0;
int spin_2x = 0;
int spin_2y = 0;
cout << "Welcome to the one-armed bandit!" << endl;
cout << endl;
cout << "To play start by betting some money!" << endl;
cout << endl;
cout << "Insert 50/ 100/ 500 kr to your account!" << endl;
cout << endl;
cin >> insert;
while (insert < 50 || insert > 500)
{
cout << "You either inserted to little or to much" << endl;
cin >> insert;
}
cout << "You inserted" << insert;
cout << endl;
while (insert > 50)
{
cout << "Bet some money to play!" << endl;
cout << endl;
cin >> bet;
cout << endl;
while (bet !=50 && bet !=100 && bet !=500)
{
if (bet == 50) return 1;
{
cout << "You have betted 50 kr!" << endl;
}
{
if (bet == 100) return 2;
{
cout << "You have betted 100 kr!" << endl;
}
{
if (bet == 500)
{
cout << "You have betted 500 kr!" << endl;
}
char a = '£';
char b = '$';
char c = '*';
char build [4][4] = {
{ ' ', 'A', 'B', 'C',},
{ '1', ' ', ' ', ' ',},
{ '2', ' ', ' ', ' ',},
{ '3', ' ', ' ', ' ',},
};
int array();
cout << build[0][1] << " " << build[0][2] <<" "<< build[0][3] <<" " << endl;
cout << build[1][0] <<"|_|" <<"|_|" << "|_|" << endl
<< build[2][0] <<"|_|" <<"|_|" << "|_|" << endl
<< build[3][0] <<"|_|" <<"|_|" << "|_|" << endl;
return 0;
srand(time(0));
spin_1x=rand() % 4 + 1;
spin_1y=rand() % 4 + 1;
spin_2x=rand() % 4 + 1;
spin_2y=rand() % 4 + 1;
int y = 0;
int x = 0;
if (x == spin_1x && y == spin_1y)
{
build[x][y]='0';
cout << "Congrats you won!" << endl;
}
else if (x == spin_2x && y == spin_2y)
cout << "Congrats you won!" << endl;
cout << endl;
cout << "JACKPOT!" << endl;
{
if (insert <= 0)
{
cout << "You dont have any money left! Game's over!" << endl;
}
int insert;
if ((a == 7 && b == 7 && c == 7))
{
cout << "You have won x2 your bet!($" << ( bet*2) << ")" << endl;
credit = credit + (bet*2);
}
else if ((a == b == c) && ! (a == 7 && b == 7 && c == 7))
{
cout << "You have won x4 your bet!($" << (bet*4) << ")" << endl;
credit = credit + (bet*4);
}
else if ((a == b || a == c || b == c) && !(a == b == c) && !(a == 7 && b == 7 && c == 7))
{
credit = credit + (bet*8);
cout << "You have won x8 your bet!($" << (bet*8) << ")" << endl;
}
else if ((a == b || a == c || b == c) && ! (a == b == c) && ! (a == 7 && b == 7 && c == 7))
{
credit = credit + (bet*16);
cout << "You have won x16 your bet!($" << (bet*16) << ")" << endl;
}
else if (( a == b || a == c || b == c) && ! (a == b == c) && ! (a == 7 && b == 7 && c == 7))
{
credit = credit + (bet*128);
cout << "You have won x128 your bet!($" << (bet*128) << ")" << endl;
}
else
{
cout << "You have lost your betting!($-" << bet << ")" << endl;
credit = credit - bet;
}
return credit;
}
}
return 0;
}
}
}
}