#include "IwGx.h"
#include "IwHashString.h"
#include "game.h"
#include "input.h"
#include "audio.h"
#include "PauseMenu.h"
#include "resources.h"
#include "s3eKeyboard.h"
#include "s3eOSReadString.h"
#include "s3eOSExec.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;
#define numBoxes 5
#define FONT_HEIGHT 15
#define FONT_DESIGN_WIDTH 320
#define GRAPHIC_DESIGN_WIDTH 768
#define maxCount 10
Game::~Game()
{
if (checkBoxes != 0)
{
delete[] checkBoxes;
}
if (checkBoxText != 0)
{
delete[] checkBoxText;
}
if (textBoxes != 0)
{
delete[] textBoxes;
}
if (textFeildText != 0)
{
delete[] textFeildText;
}
if (stringValues != 0)
{
delete[] stringValues;
}
if (checkBoxesChecked != 0)
{
delete[] checkBoxesChecked;
}
if (eraseButton != 0)
{
delete[] eraseButton;
}
}
/*void Game::pauseGame()
{
// Switch to pause menu scene
g_pSceneManager->SwitchTo(g_pSceneManager->Find("pausemenu"));
}*/
float inputConverted[15 + (3 * maxCount)];
void Game::resumeGame()
{
}
void Game::newGame()
{
// Reset score
}
void Game::swap(bool ch, int i)
{
//ch false if unchecked
if (!ch)
{
checkBoxesChecked[i]->m_X = checkBoxes[i]->m_X;
checkBoxes[i]->m_X = width * 2;
}
else
{
checkBoxes[i]->m_X = checkBoxesChecked[i]->m_X;
checkBoxesChecked[i]->m_X = width * 2;
}
}
void Game::Move(int upDown)
{
int tempCounter = counter + upDown;
if (tempCounter >= 0 && tempCounter <= maxCount)
{
if (tempCounter == 0)
{
if (eraseButton[0]->m_X > width)
{
eraseButton[0]->m_X = upButton->m_X;
upButton->m_X = width * 2;
}
}
else
{
if (eraseButton[0]->m_X < width)
{
upButton->m_X = eraseButton[0]->m_X;
eraseButton[0]->m_X = width * 2;
}
if (tempCounter == maxCount)
{
if (eraseButton[4]->m_X > width)
{
eraseButton[4]->m_X = downButton->m_X;
downButton->m_X = width * 2;
}
}
else
{
if (eraseButton[4]->m_X < width)
{
downButton->m_X = eraseButton[4]->m_X;
eraseButton[4]->m_X = width * 2;
}
}
}
counter = tempCounter;
for (int q = 3; q < 18; q++)
{
textFeildText[q]->m_Text = stringValues[(q - 3) + (tempCounter * 3)]->m_Text;
}
}
}
void Game::Update(float deltaTime, float alphaMul)
{
if (!m_IsActive)
return;
activeEvent = false;
// Update base scene
Scene::Update(deltaTime, alphaMul);
if ((s3eKeyboardGetState(s3eKeyBack) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyBack) & S3E_KEY_STATE_PRESSED))
{
s3eDeviceRequestQuit();
}
// Detect screen tap
if (m_IsInputActive && m_Manager->GetCurrent() == this && !g_pInput->m_Touched && g_pInput->m_PrevTouched)
{
g_pInput->Reset();
if (iButton->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
PauseMenu* pause = new PauseMenu();
pause->SetName("pausemenu");
pause->Init();
g_pSceneManager->Add(pause);
g_pSceneManager->SwitchTo(g_pSceneManager->Find("pausemenu"));
activeEvent = true;
}
else if (reset->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
if (checkBoxes != 0)
{
delete[] checkBoxes;
}
if (checkBoxText != 0)
{
delete[] checkBoxText;
}
if (textBoxes != 0)
{
delete[] textBoxes;
}
if (textFeildText != 0)
{
delete[] textFeildText;
}
if (stringValues != 0)
{
delete[] stringValues;
}
if (checkBoxesChecked != 0)
{
delete[] checkBoxesChecked;
}
if(eraseButton != 0)
{
delete[] eraseButton;
}
largestInput = 0;
Init();
activeEvent = true;
}
else if (teachPassiv->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
if (s3eOSExecAvailable())
{
s3eOSExecExecute("http://teachpassiv.com", S3E_FALSE);
}
activeEvent = true;
}
else if (upButton->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
Move(-1);
activeEvent = true;
}
else if (downButton->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
Move(1);
activeEvent = true;
}
else if (!heated)
{
if (heatedButton->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
if (!checked[0])
{
heated = !heated;
heatSpriteChecked->m_X = heatedButton->m_X;
heatedButton->m_X = width * 2;
if (largestInput >= 2)
{
if (largestInput % 3 == 1)
{
largestInput -= 2;
}
else if (largestInput % 3 == 0)
{
largestInput--;
}
Calculate();
}
}
activeEvent = true;
}
}
else
{
if (heatSpriteChecked->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
if (!checked[0])
{
heated = !heated;
heatedButton->m_X = heatSpriteChecked->m_X;
heatSpriteChecked->m_X = width * 2;
Calculate();
}
activeEvent = true;
}
}
if (activeEvent == false)
{
for (int i = 0; i < numBoxes; i++)
{
//up to here ok
if (!checked[i])
{
if (checkBoxes[i]->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
swap(checked[i], i);
checked[i] = !checked[i];
activeEvent = true;
if (i == 1)
{
checkBoxText[4]->m_X = checkBoxLabelStorage;
checkBoxes[4]->m_X = checkBoxStorage;
}
else if (i != 4)
{
if (checked[4])
{
swap(checked[4], 4);
checked[4] = !checked[4];
}
checkBoxesChecked[4]->m_X = width * 2;
checkBoxText[4]->m_X = width * 2;
checkBoxes[4]->m_X = width * 2;
if (checked[4])
{
swap(checked[4], 4);
}
}
if (i == 0)
{
heatedText->m_X = width * 2;
heatedTextB->m_X = width * 2;
heatedButton->m_X = width * 2;
heatSpriteChecked->m_X = width * 2;
if (heated)
{
heated = !heated;
}
}
else
{
if (heatedText->m_X = width * 2)
{
heatedText->m_X = heatedTextStorage;
heatedTextB->m_X = heatedTextStorage;
heatedButton->m_X = heatedSpriteStorage;
heatSpriteChecked->m_X = width * 2;
if (heated)
{
heated = !heated;
}
}
}
//up to here working
if (i != 4)
{
for (int k = 0; k < numBoxes - 1; k++)
{
if (k != i && checked[k])
{
//to uncheck pass in false
swap(checked[k], k);
checked[k] = !checked[k];
}
}
if (i == 0 && heated)
{
heated = !heated;
heatedButton->m_X = heatSpriteChecked->m_X;
heatSpriteChecked->m_X = width * 2;
}
}
Calculate();
break;
}
}
else
{
if (checkBoxesChecked[i]->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
if (i == 1)
{
if (checked[4])
{
swap(checked[4], 4);
}
checkBoxesChecked[4]->m_X = width * 2;
checkBoxText[4]->m_X = width * 2;
checkBoxes[4]->m_X = width * 2;
}
else if (i == 0)
{
if (heatedText->m_X = width * 2)
{
heatedText->m_X = heatedTextStorage;
heatedTextB->m_X = heatedTextStorage;
heatedButton->m_X = heatedSpriteStorage;
heatSpriteChecked->m_X = width * 2;
}
}
swap(checked[i], i);
activeEvent = true;
checked[i] = !checked[i];
Calculate();
break;
}
}
}
if (!activeEvent)
{
for (int eraseCheck = 0; eraseCheck < 5; eraseCheck++)
{
if (eraseButton[eraseCheck]->HitTest(g_pInput->m_X, g_pInput->m_Y))
{
//delete text
for (int l = 0; l < 3; l++)
{
textFeildText[(eraseCheck * 3) + 3 + l]->m_Text = "";
stringValues[(eraseCheck * 3) + l + (counter * 3)]->m_Text = "";
}
inputConverted[(eraseCheck * 3) + 1 + (counter * 3)] = 0.0;
inputConverted[(eraseCheck * 3) + 2 + (counter * 3)] = 0.0;
activeEvent = true;
int index = 1;
largestInput = 0;
while (inputConverted[inde
评论0