Ejemplo n.º 1
0
void Admin::AddGame(Games& g, int id)
{
	Games empty;
	fstream to_handle("Games.dat", ios_base::in | ios_base::out | ios::binary);
	if (!to_handle.is_open())
	{
		cout << "Could not open file, press any key to exit:" << endl;
		fflush(stdin);
		getchar();
		exit(1);
	}
	to_handle.seekg((id - 1)*sizeof(Games));
	to_handle.read(reinterpret_cast<char*>(&empty), sizeof(Games));
	string Void = empty.getName();
	if (Void == "")
	{
		to_handle.seekp((id - 1)*sizeof(Games));
		to_handle.write(reinterpret_cast<const char*>(&g), sizeof(Games));
		cout << "Data has been written!" << endl;
	}
	else
	{
		cout << "Block no.#" << id << " is not empty" << endl;
	}
	to_handle.close();
}
Ejemplo n.º 2
0
void Settings::on_games_clicked()
{
    close();
    Games game;
    game.setModal(true);
    game.exec();
}
Ejemplo n.º 3
0
void Admin::SeeAllGames()
{
	Games blank; int c = 1;
	string Void;
	fstream to_handle("Games.dat", ios_base::in|ios_base::out|ios::binary);
	if (!to_handle)
	{
		cout << "Could not open file, press any key to exit:" << endl;
		fflush(stdin);
		getchar();
		exit(1);
	}
	to_handle.seekg(0, ios::beg);
	while (to_handle.read(reinterpret_cast<char*>(&blank), sizeof(Games)))
	{
		Void = blank.getName();
		if (Void!= "")
		{
			cout << blank;
			blank.Display();
			cout << "at ID: " << c << endl;
		}
		c++;
	}
	to_handle.close();
}
Ejemplo n.º 4
0
/**
 * Print the capacity and current element count of the specified Games object.
 * @param games A Games object.
 */
void printElementCount( const Games& games ) {
    sleep(1);  // Simulate latency.
    cout << "  { count:" << games.getCount() << ", size:" << games.getSize() << " }" << endl;
}
Ejemplo n.º 5
0
int main(int argc, const char **argv) {
    bool STRtags = false; 
    std::string line;
    //Parser parser;
    if(argc > 1) {
        // Open argument as file
        //parser.parse(std::string(argv[1]));
    
        //games = parser.games();
        Games games;
        games.openFile(std::string(argv[1]));
        games = games.getGamesByType("15|10");
        auto months = games.getMonths();
        for(auto &month : months) {
            std::cout << "Stats for " << month << std::endl;
            Games thismonth = games.getGamesByMonth(month);
            Games wonbyme = thismonth.getGamesWonBy("madsravn");
            Games drawGames = thismonth.getDrawGames();
            Games lostbyme = thismonth.getGamesLostBy("madsravn");
            std::cout << "Amount of games: " << thismonth.getSize() << std::endl;
            std::cout << "Won: " << wonbyme.getSize() << std::endl;
            std::cout << "==> As white: " << wonbyme.wonAsWhite().getSize() << std::endl;
            std::cout << "==> As black: " << wonbyme.wonAsBlack().getSize() << std::endl;
            std::cout << "Lost: " << lostbyme.getSize() << std::endl;
            std::cout << "==> As white: " << lostbyme.lostAsWhite().getSize() << std::endl;
            std::cout << "==> As black: " << lostbyme.lostAsBlack().getSize() << std::endl;
            std::cout << "Draw: " << drawGames.getSize() << std::endl; 
            std::cout << "==> As white: " << drawGames.drawAsWhite("madsravn").getSize() << std::endl;
            std::cout << "==> As black: " << drawGames.drawAsBlack("madsravn").getSize() << std::endl << std::endl;

        }
    } else {
        std::cout << "Takes one argument, the file which needs to be parsed." << std::endl; 
    }

    return 0;
}