DatabaseTester::DatabaseTester() {
	if (testConnect()) {

		// log in players
		int resultCode = db.PlayerLogin("jake", "1234");
		resultCode += db.PlayerLogin("ggg", "1234");
		resultCode += db.PlayerLogin("ender", "abcd1234");
		resultCode += db.PlayerLogin("asus", "abcd1234");
		

		// update stats, be careful!
		//resultCode += db.UpdateTotalKills("jake", 1);
		//resultCode += db.UpdateTotalDeaths("ender", 1);
		//resultCode += db.UpdateTotalAssists("ggg", 1);


		// if result code is still 0, no errors have occurred
		if (!resultCode) {
			printPlayers();
		} else {
			std::cout << "errors" << std::endl;
		}


		// log out players
		resultCode += db.PlayerLogout("jake");
		resultCode += db.PlayerLogout("ggg");
		resultCode += db.PlayerLogout("ender");
		resultCode += db.PlayerLogout("asus");



	}
	testDisconnect();
}
Ejemplo n.º 2
0
void				Graphics::refreshScreen(Map *map)
{
  app->Clear();
  printBackground();
  cleanMap(map);
  highlightCase(map->getHud());
  printRessources(map);
  printEggs(map);
  printPlayers(map);
  printHud(map);
  app->Display();
}
Ejemplo n.º 3
0
// check which player has lost
// if no player is dead we check which one has more life left
const unsigned int Game::checkWhosDead(void) const
{
#ifdef DEBUG
        // print player info
        printPlayers();
#endif

    unsigned int loser = 0;
    
    if ( m_player[0].isDead() )
    {
        std::cout << "Player 1 is dead!" << std::endl
                  << std::endl;
        loser = 1;
    }
    else if ( m_player[1].isDead() )
    {
        std::cout << "Player 2 is dead!" << std::endl
                  << std::endl;
        loser = 2;
    }
    else
    {
        std::cout << "Nonone is dead!" << std::endl;

        // compare players who is better
        loser = comparePlayers();

        if ( 0 != loser )
        {
            std::cout << "But player " << loser << " has lost!"
                      << std::endl;
        }
        std::cout << std::endl;
    }
    
    return loser;
}
Ejemplo n.º 4
0
// do-loop for gaming till one player has lost (starting at 1)
const unsigned int Game::doStart(const bool contest)
{
    do
    {
#ifdef DEBUG
        std::cout << "Player's " << m_currentPlayer+1 << " turn!" << std::endl;
#endif        

        if ( !writeData() )
        {
            break;
        }

#ifdef DEBUG
        // print game field
        m_field.print();
#endif

        if ( !contest )
        {
            std::cout << "Manually save result.dat and hit enter!" << std::endl;
            getchar();
        }
        else
        {
            // call routine for AI
            if ( 0 == m_currentPlayer )
            {
                if ( system ("./fm-ai1.bin") )
                {
                    std::cout << "Game::doStart() error: calling fm-ai1 failed" << std::endl;
                    // this player will loose the contest
                    m_player[m_currentPlayer].looseAllLife();
                    
                    break;
                }
            }
            else
            {
                if ( system ("./fm-ai2.bin") )
                {
                    std::cout << "Game::doStart() error: calling fm-ai2 failed" << std::endl;

                    // this player will loose the contest
                    m_player[m_currentPlayer].looseAllLife();

                    break;
                }
            }
        }
        
        // now we must read the result that has stored to positions
        FieldPos pos1, pos2;
        if ( !readResult(pos1, pos2) )
        {
            // file could not be read
            break;   
        }
        
#ifdef DEBUG
        std::cout << "Game::doStart() info: swap "
                  << pos1.x() << " " << pos1.y() << " with "
                  << pos2.x() << " " << pos2.y() << std::endl;
#endif
        
        // delete files
        deleteFiles();
        
        // switch positions on game field
        if ( m_field.swapTiles(pos1, pos2) )
        {
            // remove all matching tiles
            if ( !cascade(contest) )
            {
                break;
            }

        }
        else
        {
#ifdef DEBUG
            std::cout << "Game::doStart() Illegal move: loose 5 life"
                      << std::endl;
#endif
            m_player[m_currentPlayer].looseLife(5);
            // getchar();
        }

        // set next player (if necessary)
        nextPlayer();

        // check if gamefield is playable and remove lower lines
        // until the game is playable again
        if ( !checkIfPlayable(contest) )
        {
            break;                
        }
        
#ifdef DEBUG
        // print player info
        printPlayers();
#endif
        
        // getchar();
        
    } while ( !isOnePlayerDead() );
    
    return checkWhosDead();
}