The title pretty much says it all.
I am learning C++ at the moment and decided to try to make a game. My friend who also wants to learn C++, but does not have VS installed tried to run it, and it crashed on start up.
It was fine when I ran it from outside VS, and I sent it to him in a ZIP file with all the DLLs and in a release build. Unsure why this is happening, anyone have any ideas?
Here is the code, its fairly badly written and the readability is poor (Sorry.)
#include "stdafx.h"
#include <SFML/Graphics.hpp>
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
int main()
{
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
bool gameover(1);
sf::RenderWindow window(sf::VideoMode(240, 500), "Hangman but not very good.");
sf::Text text;
sf::Font font;
sf::Sprite sprite;
sf::Texture texture;
texture.loadFromFile("0.png");
sprite.setTexture(texture);
char uInput[11] = {0};
char displayed[11] = {0};
bool setup = false;
int charCount(0);
int iii(0);
bool correct(0);
long long wrongGuesses(0);
int wordlength(0);
long long gameoverCounter(0);
char currentGuess = 0;
bool bypass = true;
char pngC = '1';
char IOarray[] = "x.png";
bool firstSetup = true;
int correctCounter = 0;
font.loadFromFile("Xefus.ttf");
text.setColor(sf::Color::Yellow);
text.setCharacterSize(24);
text.setFont(font);
text.setString("Please enter the word to guess, press enter to stop");
while(window.isOpen())
{
sf::Event event;
while(gameover)
{
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
if(event.type == sf::Event::TextEntered)
{
bypass = true;
if(iii < 10 && !setup)
if(event.text.unicode < 128 && event.text.unicode > 96)
{
uInput[iii] = static_cast<char>(event.text.unicode);
++iii;
++wordlength;
}
{
for(int i = 0; i < wordlength; ++i)
if(event.text.unicode == uInput[i] && !firstSetup)
{
displayed[i] = uInput[i];
bypass = false;
++correctCounter;
}
else if(bypass = true)
++wrongGuesses;
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
setup = true;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::BackSpace))
{
uInput[iii] = 0;
iii -= 1;
}
}
if(!setup)
{
text.setString(uInput);
displayed[wordlength - 1] = ('*');
setup = false;
}
else
{
text.setString(displayed);
bypass = false;
if(firstSetup)
{
firstSetup = false;
gameoverCounter = 0;
wrongGuesses = 0;
correctCounter = 0;
}
if(wrongGuesses >= wordlength)
{
++gameoverCounter;
wrongGuesses = 0;
IOarray[0] = static_cast<char>(gameoverCounter + 48);
texture.loadFromFile(IOarray);
}
if(gameoverCounter >= 9)
{
return 0;
window.clear();
window.draw(sprite);
window.draw(text);
window.display();
}
if(correctCounter >= wordlength)
{
return 0;
window.clear();
window.draw(sprite);
window.draw(text);
window.display();
}
wrongGuesses = 0;
}
window.clear();
window.draw(sprite);
window.draw(text);
window.display();
}
}
}