// Anything after // is a comment not actual C++ code
// Comments are important and I use them to explain things
// Why not read the comments in this code

// These "include" code from the C++ library and SFML too
//#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include <vector>
using std::vector;
#include <string>;
using std::string;
#include <random>
using std::mt19937;
#include <iostream>
using std::cout;

mt19937 mt_rand(time(0));

// initialize everything
void setup(vector<sf::Text>& CS, sf::Font& font) {

	char chems[48][3] = {
		"he", "ac", "al", "am", "ar", "as", "at", "ba", "be", "bi", "br", "ca", "ce",
		"cl", "co", "es", "er", "fr", "ga", "ge", "au", "ha", "he", "ho", "in", "ir",
		"fe", "la", "li", "mo", "ne", "ni", "no", "po", "pr", "pa", "ra", "re", "se",
		"si", "ag", "na", "ta", "te", "th", "ti", "te", "sc"
	};

	for (unsigned int i = 0; i < 48; ++i) {
		CS[i].setFont(font);
		CS[i].setString(chems[i]);
		cout << chems[i] << "  ";
		CS[i].setCharacterSize(100);
		CS[i].setFillColor(sf::Color::White);

	}
}

// This is the main C++ program- Duh!
// It is where our game starts from
int main() {
	sf::Font font;
	font.loadFromFile("28 Days Later.ttf");
	// Make a window that is 800 by 800 pixels
	// And has the title "Chem Strings"
	sf::RenderWindow window(sf::VideoMode(800, 800), "Chem Strings");

	// Create a vector of Chem Strings
	vector<sf::Text> ChemStrings(48);
	setup(ChemStrings, font);

	// SLow this puppy down! (1 frame per second)
	window.setFramerateLimit(10);

	vector<sf::Text> threeby3;
	for (unsigned int i = 0; i < 9; ++i) {
		threeby3.push_back(ChemStrings[mt_rand() % 48]);

		threeby3[i].setOrigin(50, 50);
		threeby3[i].setPosition(250 + 100 * (i % 3), 250 + 100 * (i / 3));
	}

	// This "while" loop goes round and round- perhaps forever
	while (window.isOpen())
	{
		// The next 6 lines of code detect if the window is closed
		// And then shuts down the program
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				// Someone closed the window- bye
				window.close();
		}

		// Clear everything from the last run of the while loop
		window.clear();

		// Draw the 3x3 grid
		//window.draw(message);
		for (sf::Text t : threeby3) {
			t.rotate(10);
			window.draw(t);
		}
		// Show everything we just drew
		window.display();
	} // while

	return 0;
}