174 lines
6.6 KiB
C++
174 lines
6.6 KiB
C++
#include "PlayerAreaModel.h"
|
|
|
|
PlayerAreaModel::PlayerAreaModel(QObject *parent)
|
|
{
|
|
Player defaultValues;
|
|
|
|
for(int i = 0; i < 8; i++){
|
|
players.append(defaultValues);
|
|
}
|
|
}
|
|
|
|
uint PlayerAreaModel::focusedPlayer()
|
|
{
|
|
return focusedPlayer_;
|
|
}
|
|
|
|
void PlayerAreaModel::setFocusedPlayer(int n)
|
|
{
|
|
focusedPlayer_ = n;
|
|
Player player = players.at(n);
|
|
BetType b1 = player.bet1.betType;
|
|
BetType b2 = player.bet2.betType;
|
|
uint n1 = player.bet1.betSpot;
|
|
uint n2 = player.bet2.betSpot;
|
|
emit focusedPlayerChanged(b1, n1, b2, n2);
|
|
}
|
|
|
|
QString PlayerAreaModel::getPlayerName(int n)
|
|
{
|
|
return players.at(n).playerName;
|
|
}
|
|
|
|
void PlayerAreaModel::setPlayerName(QString s, int n)
|
|
{
|
|
players[n].playerName = s;
|
|
}
|
|
|
|
void PlayerAreaModel::bet(BetType b, int n, int bet)
|
|
{
|
|
Player *player = &players[focusedPlayer_];
|
|
|
|
if (player->bet1.betType == NONE) {
|
|
player->bet1.betType = b;
|
|
player->bet1.betValue = bet;
|
|
player->bet1.betSpot = n;
|
|
if (b == 9 && n <= 35) {
|
|
n = 35 - n;
|
|
}
|
|
emit betChanged(b, n, bet);
|
|
} else if (player->bet2.betType == NONE) {
|
|
player->bet2.betType = b;
|
|
player->bet2.betValue = bet;
|
|
player->bet2.betSpot = n;
|
|
if (b == 9 && n <= 35) {
|
|
n = 35 - n;
|
|
}
|
|
emit betChanged(b, n, bet);
|
|
}
|
|
}
|
|
|
|
void PlayerAreaModel::removeBet(BetType b, int n)
|
|
{
|
|
Player *player = &players[focusedPlayer_];
|
|
if (player->bet1.betType != NONE) {
|
|
player->bet1.betType = NONE;
|
|
if (b == 9 && n <= 35) {
|
|
n = 35 - n;
|
|
}
|
|
emit betRemoved(b, n);
|
|
} else {
|
|
player->bet2.betType = NONE;
|
|
if (b == 9 && n <= 35) {
|
|
n = 35 - n;
|
|
}
|
|
emit betRemoved(b, n);
|
|
}
|
|
}
|
|
|
|
void PlayerAreaModel::cancelBet(BetType b, int n)
|
|
{
|
|
emit betCanceled(b, n);
|
|
}
|
|
|
|
void PlayerAreaModel::payout()
|
|
{
|
|
if (players.at(0).bet1.betType == NONE) {
|
|
printf("Select where the ball landed\n");
|
|
} else {
|
|
int rollSpot = 36 - players.at(0).bet1.betSpot;
|
|
|
|
for (int i = 1; i < 8; i++) {
|
|
int betType = players.at(i).bet1.betType;
|
|
int betSpot;
|
|
if (betType == SINGLE) {
|
|
betSpot = 36 - players.at(i).bet1.betSpot;
|
|
} else {
|
|
betSpot = players.at(i).bet1.betSpot + 1;
|
|
}
|
|
players[i].payout = 0;
|
|
printf("%d %d\n", betSpot, rollSpot);
|
|
|
|
if (betType == SINGLE && betSpot == rollSpot) {
|
|
players[i].payout += players.at(i).bet1.betValue * 21;
|
|
} else if (betType == RED && ((1 << (rollSpot - 1)) & redNumbers)) {
|
|
players[i].payout += players.at(i).bet1.betValue * 2;
|
|
} else if (betType == BLACK && !((1 << (rollSpot - 1)) & redNumbers)) {
|
|
players[i].payout += players.at(i).bet1.betValue * 2;
|
|
} else if (betType == ODD && (rollSpot % 2)) {
|
|
players[i].payout += players.at(i).bet1.betValue * 2;
|
|
} else if (betType == EVEN && !(rollSpot % 2)) {
|
|
players[i].payout += players.at(i).bet1.betValue * 2;
|
|
} else if (betType == LOW && rollSpot <= 18 ) {
|
|
players[i].payout += players.at(i).bet1.betValue * 2;
|
|
} else if (betType == HIGH && rollSpot >= 19 && rollSpot < 37) {
|
|
players[i].payout += players.at(i).bet1.betValue * 2;
|
|
} else if (betType == DOZEN) {
|
|
if (rollSpot <= 12 * betSpot && rollSpot >= (12 * (betSpot - 1)) + 1) {
|
|
players[i].payout += players.at(i).bet1.betValue * 3;
|
|
}
|
|
} else if (betType == STREET) {
|
|
if (rollSpot <= 3 * betSpot && rollSpot >= (3 * (betSpot - 1)) + 1) {
|
|
players[i].payout += players.at(i).bet1.betValue * 6;
|
|
}
|
|
} else if (betType == COLUMN) {
|
|
if (betSpot == 1 && ((1 << (rollSpot - 1)) & column1)) {
|
|
players[i].payout += players.at(i).bet1.betValue * 3;
|
|
} else if (betSpot == 2 && ((1 << (rollSpot - 1)) & column2)) {
|
|
players[i].payout += players.at(i).bet1.betValue * 3;
|
|
} else if (betSpot == 3 && ((1 << (rollSpot - 1)) & column3)) {
|
|
players[i].payout += players.at(i).bet1.betValue * 3;
|
|
}
|
|
}
|
|
|
|
betType = players.at(i).bet2.betType;
|
|
if (betType == SINGLE) {
|
|
betSpot = 36 - players.at(i).bet1.betSpot;
|
|
} else {
|
|
betSpot = players.at(i).bet1.betSpot + 1;
|
|
}
|
|
if (betType == SINGLE && betSpot == rollSpot) {
|
|
players[i].payout += players.at(i).bet2.betValue * 21;
|
|
} else if (betType == RED && ((1 << (rollSpot - 1)) & redNumbers)) {
|
|
players[i].payout += players.at(i).bet2.betValue * 2;
|
|
} else if (betType == BLACK && !((1 << (rollSpot - 1)) & redNumbers)) {
|
|
players[i].payout += players.at(i).bet2.betValue * 2;
|
|
} else if (betType == ODD && (rollSpot % 2)) {
|
|
players[i].payout += players.at(i).bet2.betValue * 2;
|
|
} else if (betType == EVEN && !(rollSpot % 2)) {
|
|
players[i].payout += players.at(i).bet2.betValue * 2;
|
|
} else if (betType == LOW && rollSpot <= 18 ) {
|
|
players[i].payout += players.at(i).bet2.betValue * 2;
|
|
} else if (betType == HIGH && rollSpot >= 19 && rollSpot < 37) {
|
|
players[i].payout += players.at(i).bet2.betValue * 2;
|
|
} else if (betType == DOZEN) {
|
|
if (rollSpot <= 12 * betSpot && rollSpot >= (12 * (betSpot - 1)) + 1) {
|
|
players[i].payout += players.at(i).bet2.betValue * 3;
|
|
}
|
|
} else if (betType == STREET) {
|
|
if (rollSpot <= 3 * betSpot && rollSpot >= (3 * (betSpot - 1)) + 1) {
|
|
players[i].payout += players.at(i).bet2.betValue * 6;
|
|
}
|
|
} else if (betType == COLUMN) {
|
|
if (betSpot == 1 && ((1 << (rollSpot - 1)) & column1)) {
|
|
players[i].payout += players.at(i).bet2.betValue * 3;
|
|
} else if (betSpot == 2 && ((1 << (rollSpot - 1)) & column2)) {
|
|
players[i].payout += players.at(i).bet2.betValue * 3;
|
|
} else if (betSpot == 3 && ((1 << (rollSpot - 1)) & column3)) {
|
|
players[i].payout += players.at(i).bet2.betValue * 3;
|
|
}
|
|
}
|
|
printf("Player %s got %d gil\n", players.at(i).playerName.toLocal8Bit().data(), players.at(i).payout);
|
|
}
|
|
}
|
|
}
|