!!! WARNING !!! i dont use comments, but instead try to make my code make as much sense as possible through the use of good variable names and sensible function names though some of it may not make sense 'cause im not completely done
String Conversion.h
#include <iostream>
#include <sstream>
#include <string>
std::string Convert(int number)
{
std::stringstream converter;
converter << number;
return converter.str();
}
Jeopardy.h
#include "SFML/Quickstart.h"
#include "SFML/String Conversion.h"
int ScreenWidth;
int ScreenHeight;
int CheckCategories[6];
int CheckMoney[30];
std::string Path;
sf::Sprite Other[6];
sf::Sprite Categories[6];
sf::Sprite Money[30];
sf::Sprite Question;
sf::Sprite Answer;
sf::Image other[6];
sf::Image categories[6];
sf::Image money[5];
sf::Image question;
sf::Image answer;
sf::Music Music[4];
void GetDesktopMode()
{
sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
ScreenWidth = DesktopMode.Width;
ScreenHeight = DesktopMode.Height;
}
std::string GetExeD()
{
GetModuleFileName(NULL, L"Path", 100);
return Path;
}
int LoadImages()
{
std::string base = "C:/Jeopardy/";
std::string end = ".bmp";
std::string middle;
std::string image;
for(int i = 0; i < 6; i++)
{
middle = Convert((i + 1));
image = base + "Other/Slide" + middle + end;
if (!other[i].LoadFromFile(image))
return -1;
image = base + "Categories/Slide" + middle + end;
if (!categories[i].LoadFromFile(image))
return -1;
};
for(int i = 0; i < 5; i++)
{
middle = Convert((i + 1));
image = base + "Money/Slide" + middle + end;
if (!money[i].LoadFromFile(image))
return -1;
};
return 1;
}
void LoadSprites()
{
for (int i = 0; i < 6; i++)
{
Other[i].SetImage(other[i]);
Categories[i].SetImage(categories[i]);
};
for (int i = 0; i < 5; i++)
{
Money[i].SetImage(money[i]);
Money[(i + 5)].SetImage(money[i]);
Money[(i + 10)].SetImage(money[i]);
Money[(i + 15)].SetImage(money[i]);
Money[(i + 20)].SetImage(money[i]);
Money[(i + 25)].SetImage(money[i]);
};
}
void ScaleSprites()
{
float ImageWidth;
float ImageHeight;
for (int i = 0; i < 6; i++)
{
ImageWidth = other[i].GetWidth();
ImageHeight = other[i].GetHeight();
ImageWidth = (ScreenWidth / ImageWidth);
ImageHeight = (ScreenHeight / ImageHeight);
Other[i].Scale(ImageWidth, ImageHeight);
ImageWidth = categories[i].GetWidth();
ImageHeight = categories[i].GetHeight();
ImageWidth = ((ScreenWidth/6) / ImageWidth);
ImageHeight = ((ScreenHeight/6) / ImageHeight);
Categories[i].Scale(ImageWidth, ImageHeight);
};
for (int i = 0; i < 30; i++)
{
ImageWidth = money[i].GetWidth();
ImageHeight = money[i].GetHeight();
ImageWidth = ((ScreenWidth/6) / ImageWidth);
ImageHeight = ((ScreenHeight/6) / ImageHeight);
Money[i].Scale(ImageWidth, ImageHeight);
};
}
void PositionSprites()
{
float xpos = (ScreenWidth/6);
float ypos = (ScreenHeight/6);
float x = 0;
float y = ypos;
for(int i = 0; i < 6; i++)
{
Categories[i].SetPosition(x, 0.0f);
x = x + xpos;
};
for(int i = 0; i < 5; i++)
{
Money[i].SetPosition(0, y);
Money[(i + 5)].SetPosition(xpos, y);
Money[(i + 10)].SetPosition((xpos * 2), y);
Money[(i + 15)].SetPosition((xpos * 3), y);
Money[(i + 20)].SetPosition((xpos * 4), y);
Money[(i + 25)].SetPosition((xpos * 5), y);
y = y + ypos;
};
}
int LoadMusic()
{
if (!Music[0].OpenFromFile("C:/Jeopardy/Music/Opening.wav"))
return -1;
if (!Music[1].OpenFromFile("C:/Jeopardy/Music/Question.wav"))
return -1;
if (!Music[2].OpenFromFile("C:/Jeopardy/Music/Daily Double.wav"))
return -1;
if (!Music[3].OpenFromFile("C:/Jeopardy/Music/Final Jeopardy.wav"))
return -1;
return 1;
}
void InitChecks()
{
for(int i = 0; i < 6; i++)
CheckCategories[i] = 1;
for(int i = 0; i < 30; i++)
CheckMoney[i] = 1;
}
int Load()
{
GetExeD();
GetDesktopMode();
LoadImages();
LoadSprites();
ScaleSprites();
PositionSprites();
LoadMusic();
InitChecks();
Music[0].Play();
return 1;
}
Main.cpp
#include "Jeopardy.h"
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Jeopardy!");
Load();
int stage = 1;
while(App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
if ((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left) && (stage < 3))
stage = stage + 1;
};
App.Clear(sf::Color(17, 86, 178));
if (stage == 1)
App.Draw(Other[0]);
if (stage == 2)
App.Draw(Other[1]);
if (stage == 3)
{
for(int i = 0; i < 6; i++)
{
if(CheckCategories[i] == 1)
App.Draw(Categories[i]);
};
for(int i = 0; i < 30; i++)
{
if(CheckMoney[i] == 1)
App.Draw(Money[i]);
};
};
App.Display();
};
return EXIT_SUCCESS;
}