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:
Amrit Panesar committed 2015-05-06 10:18:39 -07:00
1 parent 40ac78074b
commit 39ee821f54
174 files changed
+13356 -80

No files matched your search

@@ -0,0 +1,25 @@
#include "CustomGame.h"
#include "Pages\MainPage.h"
const wchar_t *CustomGame::settingsFileName = L"..\\Settings.dat";
const wchar_t *CustomGame::screenShotsFileExp = L"..\\Logging\\Plays\\play{0}.jpg";
CustomGame::CustomGame(GkGraphicsDevice *graphicsDevice, GkSoundDevice *soundDevice) :
GkGame(graphicsDevice, soundDevice)
{
this->logGamePlay = new GkLogFile<LogRecordGamePlay>(L"..\\Logging\\GamePlay.log");
//this->settings = new Settings(CustomGame::settingsFileName, this);
this->AddGamePage(new MainPage(this));
}
CustomGame::~CustomGame(void)
{
delete this->logGamePlay;
//delete this->settings;
}
@@ -0,0 +1,39 @@
#pragma once
#include "..\Engine\GambleKit.h"
//#include "Settings.h"
//#include "Dictionary.h"
struct LogRecordGamePlay
{
DateTime time;
int bet;
int winning;
};
class MainPage;
class MainMenuPage;
class CustomGame :
public GkGame
{
public:
static const wchar_t *dataFileName, *settingsFileName;
static const wchar_t *screenShotsFileExp;
bool isPayingCredits;
int creditsPayed;
//Settings *settings;
GkLogFile<LogRecordGamePlay> *logGamePlay;
MainPage *mainPage;
MainMenuPage *mainMenuPage;
CustomGame(GkGraphicsDevice *graphicsDevice, GkSoundDevice *soundDevice);
~CustomGame(void);
};
@@ -0,0 +1,78 @@
#include "MainWindow.h"
#include "Pages\MainPage.h"
MainWindow::MainWindow(void)
{
if (this->deviceContext == 0)
GkOSUtils::ShowMessage("Error creating device context", this->handle);
if (this->renderContext == 0)
GkOSUtils::ShowMessage("Error creating rendering context", this->handle);
this->graphicsDevice = new GkGraphicsDevice();
if (this->graphicsDevice->maxTextureSize < 2048)
GkOSUtils::ShowMessage(GkStrings::ToShort(GkStrings::Format(L"Graphics device does not suport textures with dimensions of size at least 2048 pixels.\r\nMaxium supported size is {0}.\r\nSome textures may not be rendered.", GkStrings::IntToString(this->graphicsDevice->maxTextureSize).c_str()).c_str()).c_str());
if (!this->graphicsDevice->nonPower2Textures)
GkOSUtils::ShowMessage("Graphics device does not support textures of arbitraty dimensions. Application will require more video memory than normal.");
this->soundDevice = new GkSoundDevice();
GkFileSystem::SetSource(L"..\\GameData\\", FileSystemMode_Physical);
this->game = new CustomGame(this->graphicsDevice, this->soundDevice);
this->SetPosition(0, 0);
this->SetSize(800, 600);
this->SetActive();
}
MainWindow::~MainWindow(void)
{
}
bool MainWindow::Close()
{
delete this->game;
delete this->soundDevice;
delete this->graphicsDevice;
return true;
}
void MainWindow::MainLoop()
{
//TODO: timed rendering (main or custom thread, Sleep(frameInterval - renderTime). VSync
this->game->NewFrame();
this->MakeCurrent();
this->game->Process();
this->game->Render();
this->Present();
// If thre are changes to the settings data, they will automatically be written to disk
//this->game->settings->WriteChanges();
}
void MainWindow::MouseDown(int x, int y, int mouseButtons)
{
this->game->MouseDown(x, y);
};
void MainWindow::MouseUp(int x, int y, int mouseButtons)
{
this->game->MouseUp(x, y);
}
void MainWindow::Resize(int width, int height)
{
this->graphicsDevice->SetViewport(0, 0, width, height);
}
void MainWindow::KeyDown(int keyCode)
{
if (keyCode == VK_ESCAPE)
this->DestroyFormWindow();
}
@@ -0,0 +1,26 @@
#pragma once
#include "..\Engine\GambleKit.h"
#include "CustomGame.h"
class MainWindow :
public GkOpenGLWindowsForm
{
public:
GkGraphicsDevice *graphicsDevice;
GkSoundDevice *soundDevice;
CustomGame *game;
MainWindow::MainWindow(void);
MainWindow::~MainWindow(void);
bool MainWindow::Close();
void MainWindow::MainLoop();
void MainWindow::MouseDown(int x, int y, int mouseButtons);
void MainWindow::MouseUp(int x, int y, int mouseButtons);
void MainWindow::Resize(int width, int height);
void MainWindow::KeyDown(int keyCode);
};
@@ -0,0 +1,159 @@
#include "MainPage.h"
#include "..\..\Engine\GambleKit.h"
MainPage::MainPage(CustomGame *game)
: GkGamePage()
{
// Initialize the variables
this->bet = 10;
this->lines = 5;
this->winning = 0;
this->credits = 100;
// Add the background
this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"Background.png")));
// Create the Bet, Lines and Start buttons
this->btnBet = (GkGameClickButton*)this->AddEntity(new GkGameClickButton(
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_bet_default.png"), 354, 528),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_bet_down.png"), 354, 528),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_bet_disabled.png"), 354, 528)));
this->btnLines = (GkGameClickButton*)this->AddEntity(new GkGameClickButton(
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_lines_default.png"), 524, 528),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_lines_down.png"), 524, 528),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_lines_disabled.png"), 524, 528)));
this->btnStart = (GkGameClickButton*)this->AddEntity(new GkGameClickButton(
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_start_default.png"), 687, 503),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_start_down.png"), 687, 503),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_start_disabled.png"), 687, 503)));
// Create a special counter for the credits, to make them appear to increase gradually for better visual experience
GkGameWinningCounter *creditsCounter = (GkGameWinningCounter*)this->AddEntity(new GkGameWinningCounter(&this->credits, 500.0f, 2.0f));
// Create the Credits, Winning, Bet and Lines text counters and bind them to their respective values. Note that credits is bound to the "creditsCounter"
this->AddEntity(new GkGameTextsIntBinding(&creditsCounter->intDisplayValue, 1, this->AddEntity(new GkGameText(game->AcquireAnimatedFontFromMultipleFiles(L"font_main_{0}.png", L"0123456789,.-"), 80, 496, -3, GkGameText::GameTextAlignment_Center))));
this->AddEntity(new GkGameTextsIntBinding(&this->winning, 1, this->AddEntity(new GkGameText(game->AcquireAnimatedFontFromMultipleFiles(L"font_main_{0}.png", L"0123456789,.-"), 250, 496, -3, GkGameText::GameTextAlignment_Center))));
this->AddEntity(new GkGameTextsIntBinding(&this->bet, 1, this->AddEntity(new GkGameText(game->AcquireAnimatedFontFromMultipleFiles(L"font_main_{0}.png", L"0123456789,.-"), 420, 496, -3, GkGameText::GameTextAlignment_Center))));
this->AddEntity(new GkGameTextsIntBinding(&this->lines, 1, this->AddEntity(new GkGameText(game->AcquireAnimatedFontFromMultipleFiles(L"font_main_{0}.png", L"0123456789,.-"), 590, 496, -3, GkGameText::GameTextAlignment_Center))));
// Create the combinations generator. The combinations generator represents a model of collection of reels. Each of its reels can have a different model
// The GkGameReelStripModel is a GkGameReelModel, representing a reel with a fixed sequence of finite number of items. Here, it is used for all the reels of the combination generator.
this->combinationsGenerator = new GkGameReelsCombinationGenerator(5, 3);
this->combinationsGenerator->SetReelModel(0, new GkGameReelStripModel(3, 6, ReelItem_Cherry, ReelItem_Melon, ReelItem_Cherry, ReelItem_Bell, ReelItem_Cherry, ReelItem_Melon));
this->combinationsGenerator->SetReelModel(1, new GkGameReelStripModel(3, 6, ReelItem_Bell, ReelItem_Melon, ReelItem_Bell, ReelItem_Melon, ReelItem_Melon, ReelItem_Cherry));
this->combinationsGenerator->SetReelModel(2, new GkGameReelStripModel(3, 6, ReelItem_Cherry, ReelItem_7, ReelItem_Melon, ReelItem_Cherry, ReelItem_7, ReelItem_Bell));
this->combinationsGenerator->SetReelModel(3, new GkGameReelStripModel(3, 6, ReelItem_Cherry, ReelItem_Bell, ReelItem_Melon, ReelItem_Bell, ReelItem_Cherry, ReelItem_Bell));
this->combinationsGenerator->SetReelModel(4, new GkGameReelStripModel(3, 6, ReelItem_Cherry, ReelItem_Melon, ReelItem_Bell, ReelItem_Cherry, ReelItem_Melon, ReelItem_Bell));
// Create the visual object for the reels
this->reels = (GkGameReels*)this->AddEntity(new GkGameReels(5, 3, 4, 670, 331));
this->reels->symbols[ReelItem_Cherry] = game->AcquireAnimatedTexture(L"symbol_cherry.png");
this->reels->symbols[ReelItem_Melon ] = game->AcquireAnimatedTexture(L"symbol_melon.png");
this->reels->symbols[ReelItem_Bell ] = game->AcquireAnimatedTexture(L"symbol_bell.png");
this->reels->symbols[ReelItem_7 ] = game->AcquireAnimatedTexture(L"symbol_7.png");
this->reels->x = 62;
this->reels->y = 90;
this->reels->ApplyReelMap();// (this->game->settings->playerSettings->currentMap);
this->reels->SetItemGenerator(this->combinationsGenerator);
// Load the images used to show a winning line
this->lineAnimations[0] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line123.png"), 112, 255));
this->lineAnimations[1] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line123.png"), 112, 139));
this->lineAnimations[2] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line123.png"), 112, 371));
this->lineAnimations[3] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line45.png"), 112, 139));
this->lineAnimations[4] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line45.png"), 112, 139, true, true, true, false, true));
// The winnings model defines two things. One is the properties of the symbols - their coefficients and special behaviour. Second - the shape of the winning lines.
this->winningsModel = new GkGameWinningsModel(5, 3, 5, 4, 0);
this->winningsModel->SetupSymbol(ReelItem_Cherry, 0, GkGameWinningsModel::SymbolFlag_Default, GkGameWinningsModel::SymbolFlag_None, 0, 0, 10, 20, 80);
this->winningsModel->SetupSymbol(ReelItem_Melon , 0, GkGameWinningsModel::SymbolFlag_Default, GkGameWinningsModel::SymbolFlag_None, 0, 0, 20, 40, 200);
this->winningsModel->SetupSymbol(ReelItem_Bell , 0, GkGameWinningsModel::SymbolFlag_Default, GkGameWinningsModel::SymbolFlag_None, 0, 0, 50, 100, 500);
this->winningsModel->SetupSymbol(ReelItem_7 , 0, GkGameWinningsModel::SymbolFlag_Wild, GkGameWinningsModel::SymbolFlag_None, 0, 0, 0, 0, 0);
this->winningsModel->SetupLine(0, 1, 1, 1, 1, 1);
this->winningsModel->SetupLine(1, 0, 0, 0, 0, 0);
this->winningsModel->SetupLine(2, 2, 2, 2, 2, 2);
this->winningsModel->SetupLine(3, 0, 1, 2, 1, 0);
this->winningsModel->SetupLine(4, 2, 1, 0, 1, 2);
// The winnings analyzer is used to analyze a combination for winnings, based on a winning model. After an analisys, it holds all the winnings, if any, and detailed information on them.
this->winningsAnalyzer = new GkGameWinningsAnalyzer(this->winningsModel);
this->sndReels = game->AcquireSoundSource(L"reels.wav");
this->sndReelStop = game->AcquireSoundSource(L"reel.wav");
}
MainPage::~MainPage(void)
{
delete this->combinationsGenerator;
delete this->winningsAnalyzer;
delete this->winningsModel;
}
void MainPage::Process(GkGame *game)
{
if (this->reels->state == Idle)
{
// Start button - hide the lines, generate a random combination, set it to appear on the reels after spinning, analyze its winning and start the reels
if (this->btnStart->IsClicked())
{
for (int lineIndex = 0; lineIndex < this->winningsModel->numLines; lineIndex++)
this->lineAnimations[lineIndex]->visible = false;
this->credits -= this->bet * this->lines;
this->combinationsGenerator->GenerateCombination();
this->reels->SetItems(this->combinationsGenerator);
this->winningsAnalyzer->AnalyzeWinnings(this->combinationsGenerator);
this->winningsAnalyzer->MultiplyWinnings(this->bet);
this->reels->Start();
game->soundDevice->PlaySourceLooping(this->sndReels);
}
// Bet button - change the bet
if (this->btnBet->IsClicked())
{
this->bet = this->bet % 10 + 1;
}
// Lines button - set which lines in the winnings model are active
if (this->btnLines->IsClicked())
{
this->lines = this->lines % 5 + 1;
for (int lineIndex = 0; lineIndex < this->winningsModel->numLines; lineIndex++)
this->winningsModel->lines[lineIndex].active = lineIndex < this->lines;
}
}
// Stop the spinning reels when the button is pressed
if (this->reels->state == Spinning)
{
if (this->btnStart->IsClicked())
this->reels->Stop();
}
// When reels' state HAS JUST CHANGED to Idle, then show any winning lines, if any, and update combination winning and credits
if (this->reels->stateChange == Idle)
{
for (int winIndex = 0; winIndex < this->winningsAnalyzer->winnings.count; winIndex++)
this->lineAnimations[this->winningsAnalyzer->winnings.win[winIndex].lineIndex]->visible = true;
this->winning = this->winningsAnalyzer->totalWinning;
this->credits += this->winning;
game->soundDevice->PauseSource(this->sndReels);
}
// Sound on every reel stop
for (int reelIndex = 0; reelIndex < this->reels->numReels; reelIndex++)
if (this->reels->reels[reelIndex].stateChange == PostStopping)
game->soundDevice->PlaySource(this->sndReelStop);
GkGamePage::Process(game);
}
@@ -0,0 +1,37 @@
#pragma once
#include "..\CustomGame.h"
class MainPage :
public GkGamePage
{
public:
static const int ReelItem_Cherry = 0,
ReelItem_Melon = 1,
ReelItem_Bell = 2,
ReelItem_7 = 3;
GkGameClickButton *btnStart, *btnBet, *btnLines;
GkGameText *textCredits, *textWinning, *textBet, *textLines;
GkGameAnimation *lineAnimations[5];
GkGameReels *reels;
GkGameReelsCombinationGenerator *combinationsGenerator;
GkGameWinningsModel *winningsModel;
GkGameWinningsAnalyzer *winningsAnalyzer;
int bet, lines, winning, credits;
GkSoundSource *sndReels, *sndReelStop;
MainPage(CustomGame *game);
~MainPage(void);
void Process(GkGame *game);
};
@@ -0,0 +1,30 @@
//#define _CRTDBG_MAP_ALLOC
//#include <stdlib.h>
//#include <crtdbg.h>
#include <vld\vld.h>
#include "MainWindow.h"
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show)
{
//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
GkMaths::Randomize();
//Dictionary::Initialize();
GkImage::Initialize();
GkGraphicsDevice::Initialize();
GkSoundDevice::Initialize();
MainWindow mainWindow;
GkWindowsForm::PerformFormLoop();
GkSoundDevice::Close();
//Dictionary::Close();
//_CrtDumpMemoryLeaks();
return 0;
}