start 380 project5
changes to 380 project 4 changes to 350 project 2 Signed-off-by: Amrit Panesar <apanesar@4195tech.com>
This commit is contained in:
1 parent
40ac78074b
commit
39ee821f54
174 files changed
+13356
-80
No files matched your search
@@ -0,0 +1,117 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameReelRandomModel.h"
|
||||
|
||||
#include "..\..\Utils\GkMaths.h"
|
||||
|
||||
|
||||
GkGameReelRandomModel::GkGameReelRandomModel(int numItems, int numSymbols)
|
||||
:GkGameReelModel(numItems)
|
||||
{
|
||||
this->numSymbols = numSymbols;
|
||||
this->symbols = new GameReelRandomModelSymbol[numSymbols];
|
||||
|
||||
for (int i = 0; i < numSymbols; i++)
|
||||
this->SetupSymbol(i, i);
|
||||
}
|
||||
|
||||
|
||||
GkGameReelRandomModel::~GkGameReelRandomModel(void)
|
||||
{
|
||||
delete[] this->symbols;
|
||||
}
|
||||
|
||||
|
||||
void GkGameReelRandomModel::SetupSymbol(int symbolIndex, int symbolValue, int hitProbability, int maxHits)
|
||||
{
|
||||
this->symbols[symbolIndex].value = symbolValue;
|
||||
this->symbols[symbolIndex].hitProbability = hitProbability;
|
||||
this->symbols[symbolIndex].maxHits = maxHits;
|
||||
|
||||
this->overallProbability = 0;
|
||||
for (int i = 0; i < this->numSymbols; i++)
|
||||
this->overallProbability += this->symbols[i].hitProbability;
|
||||
}
|
||||
|
||||
bool GkGameReelRandomModel::ReplaceReelSymbol(int itemIndex, int symbolIndex, bool forceReplace)
|
||||
{
|
||||
bool autoGenerate = symbolIndex == -1;
|
||||
|
||||
do
|
||||
{
|
||||
if (autoGenerate)
|
||||
{
|
||||
symbolIndex = this->GetSymbolIndex();
|
||||
}
|
||||
|
||||
if ((this->symbols[symbolIndex].maxHits == GkGameReelRandomModel::UnlimitedHits) || (this->symbols[symbolIndex].occurances < this->symbols[symbolIndex].maxHits) || forceReplace)
|
||||
{
|
||||
this->symbols[this->items[itemIndex]].occurances--;
|
||||
this->items[itemIndex] = symbolIndex;
|
||||
this->symbols[symbolIndex].occurances++;
|
||||
return true;
|
||||
}
|
||||
} while (autoGenerate);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int GkGameReelRandomModel::GetSymbolIndex()
|
||||
{
|
||||
int p = GkMaths::Random(this->overallProbability);
|
||||
|
||||
int s = 0;
|
||||
for (int i = 0; i < this->numSymbols; i++)
|
||||
{
|
||||
s += this->symbols[i].hitProbability;
|
||||
if (p < s)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GkGameReelRandomModel::GetSymbol()
|
||||
{
|
||||
int symbolIndex = this->GetSymbolIndex();
|
||||
if (symbolIndex == -1)
|
||||
return -1;
|
||||
else
|
||||
return this->symbols[symbolIndex].value;
|
||||
}
|
||||
|
||||
void GkGameReelRandomModel::GenerateReel()
|
||||
{
|
||||
for (int symbolIndex = 0; symbolIndex < this->numSymbols; symbolIndex++)
|
||||
this->symbols[symbolIndex].occurances = 0;
|
||||
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
int symbolIndex = this->GetSymbolIndex();
|
||||
if ((this->symbols[symbolIndex].maxHits == GkGameReelRandomModel::UnlimitedHits) || (this->symbols[symbolIndex].occurances < this->symbols[symbolIndex].maxHits))
|
||||
{
|
||||
this->items[itemIndex] = this->symbols[symbolIndex].value;
|
||||
this->symbols[symbolIndex].occurances++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameReelRandomModel::GenerateReelZero()
|
||||
{
|
||||
this->GenerateReel();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameReelModel.h"
|
||||
|
||||
struct GameReelRandomModelSymbol
|
||||
{
|
||||
int value, hitProbability, maxHits,
|
||||
occurances;
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGameReelRandomModel :
|
||||
public GkGameReelModel
|
||||
{
|
||||
public:
|
||||
static const int UnlimitedHits = -1;
|
||||
|
||||
int numSymbols;
|
||||
GameReelRandomModelSymbol *symbols;
|
||||
|
||||
int overallProbability;
|
||||
|
||||
GkGameReelRandomModel(int numItems, int numSymbols);
|
||||
~GkGameReelRandomModel(void);
|
||||
|
||||
void SetupSymbol(int symbolIndex, int symbolValue, int hitProbability = 1, int maxHits = GkGameReelRandomModel::UnlimitedHits);
|
||||
bool ReplaceReelSymbol(int itemIndex, int symbolIndex, bool forceReplace);
|
||||
int GetSymbolIndex();
|
||||
|
||||
int GetSymbol();
|
||||
void GenerateReel();
|
||||
void GenerateReelZero();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameReelStripModel.h"
|
||||
|
||||
#include "..\..\OSSpecific\GkOSUtils.h"
|
||||
#include "..\..\Utils\GkMaths.h"
|
||||
|
||||
GkGameReelStripModel::GkGameReelStripModel(int numItems, int numSymbols, ...)
|
||||
: GkGameReelModel(numItems)
|
||||
{
|
||||
this->numSymbols = numSymbols;
|
||||
this->symbolStrip = new int[this->numSymbols];
|
||||
|
||||
int *parameters = (int*)((int)&numSymbols + 4);
|
||||
for (int i = 0; i < this->numSymbols; i++)
|
||||
this->symbolStrip[i] = parameters[i];
|
||||
|
||||
this->stripPosition = GkMaths::Random(this->numSymbols);
|
||||
}
|
||||
|
||||
|
||||
GkGameReelStripModel::~GkGameReelStripModel(void)
|
||||
{
|
||||
delete[] this->symbolStrip;
|
||||
}
|
||||
|
||||
int GkGameReelStripModel::GetSymbol()
|
||||
{
|
||||
this->stripPosition = (this->stripPosition + 1) % this->numSymbols;
|
||||
return this->symbolStrip[this->stripPosition];
|
||||
}
|
||||
|
||||
void GkGameReelStripModel::GenerateReel()
|
||||
{
|
||||
this->stripPosition = GkMaths::Random(this->numSymbols);
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
|
||||
{
|
||||
this->items[itemIndex] = this->GetSymbol();
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameReelStripModel::GenerateReelZero()
|
||||
{
|
||||
this->stripPosition = this->numSymbols - this->numItems / 2;
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
|
||||
{
|
||||
this->items[itemIndex] = this->GetSymbol();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameReelModel.h"
|
||||
|
||||
class GKDLLCLASS GkGameReelStripModel :
|
||||
public GkGameReelModel
|
||||
{
|
||||
public:
|
||||
int numSymbols;
|
||||
int *symbolStrip;
|
||||
int stripPosition;
|
||||
|
||||
GkGameReelStripModel(int numItems, int numSymbols, ...);
|
||||
~GkGameReelStripModel(void);
|
||||
|
||||
int GetSymbol();
|
||||
void GenerateReel();
|
||||
void GenerateReelZero();
|
||||
};
|
||||
Reference in new issue
Block a user