示例#1
0
int Universe::splitString(std::string sSplitInp)
{
	char primaryLimiter = ';';
	char secondLimiter = ':';
	std::string sTemp;
	std::vector<int> vTemp;

	for (size_t p = 0, q = 0; p != sSplitInp.npos; p = q)
	{
		sTemp = sSplitInp.substr(p + (p != 0), (q = sSplitInp.find(primaryLimiter, p + 1)) - p - (p != 0));
		std::cout << sTemp << ' ';
		if (p == 0)
		{
			std::string sNew;
			size_t j = 0, k = 0;
			for (unsigned i = 0; i <= 2; i++)
			{
				sNew = sTemp.substr(j + (j != 0), (k = sTemp.find(secondLimiter, j + 1)) - j - (j != 0));
				vTemp.push_back(atoi(sNew.c_str()));
				j = k;
			}
		}
		else
		{
			vTemp.push_back(atoi(sTemp.c_str()));
		}
	}
	addPlanet(Planet(vTemp[0], vTemp[1], vTemp[2], vTemp[3], vTemp[4], vTemp[5], vTemp[6], vTemp[7], vTemp[8])); // ugly

	return 0;
}
示例#2
0
void Star::generate(int seed)
{
    srand(seed);
    int q = rand() % 6 +3; //random int betweeen 3 and 6
    for(int i = 0; i < q; i++)
    {
        int r = rand() % 1 + 5;
        int pathrad = rand() % 100 + 100;
        int theta = rand() % 6;
        int ospeed = rand() % 45;
        Planet x = Planet(r,pathrad,theta,ospeed,*this,sf::Color(rand() % 255,rand() % 255,rand() % 255));
        addPlanet(x);
    }
}
示例#3
0
void Window::applyChangedSettings()
{
    const Settings& settings = Settings::getInstance();
    QList<Settings::PlanetAddress> planets = settings.getPlanets();
    //removing planets from planetList that are not presentes in settings
    //and removing planets in settings that are already presented in the PlanetList
    for (Planet* p1 : planetList) {
        int i;
        bool found = false;
        for (i = 0; i < planets.size(); i ++) {
            found = p1->getAddress() == planets.at(i).address && p1->getPort() == planets.at(i).port;
            if (found) {
                break;
            }
        }
        if (found) {
            planets.removeAt(i);
        } else {
            removePlanet(p1);
            delete p1;
        }
    }
    //planets now contains all new planets
    for (const Settings::PlanetAddress& p2 : planets) {
        addPlanet(new Planet(p2.address, p2.port));
    }

    const QList<bool>& hideColumn = settings.getHideColumn();
    for (int i = 0; i < hideColumn.size(); i ++) {
        bool wasHidden = planetTreeView->isColumnHidden(i);
        planetTreeView->setColumnHidden(i, hideColumn.at(i));
        if (!hideColumn.at(i) && wasHidden && i != 0) {
            planetTreeView->resizeColumnToContents(i-1);
        }
    }

    if (settings.getAutoRefresh()) {
        autoRefreshTimer->start(settings.getAutoRefreshIntervalSec() * 1000);
    } else {
        autoRefreshTimer->stop();
    }

    if (!settings.getPullPlayers()) {
        removeAllPlayers();
    }

    planetTreeProxyModel->invalidate();
}
示例#4
0
void World::addPlanets(int enemiesCase)
{
    addPlanet(Planet::AsteroidAverage, -200.f, 800);
	addPlanet(Planet::Earth, 0.f, 900.f);
	addPlanet(Planet::AsteroidAverage, -200.f, 800);
	addPlanet(Planet::AsteroidLittle, +350.f, 900);
	addPlanet(Planet::AsteroidGreate, +300.f, 1100);
	addPlanet(Planet::Pluton, -100.f, 1500);
	addPlanet(Planet::AsteroidAverage, -250.f, 1300);
	addPlanet(Planet::Earth, -100.f, 2200);
	addPlanet(Planet::AsteroidLittle, +280.f, 1700);
	addPlanet(Planet::AsteroidGreate, +355.f, 2000);
	addPlanet(Planet::Pluton, +180.f, 2900);
	addPlanet(Planet::AsteroidAverage, -500.f, 2500);
	addPlanet(Planet::AsteroidLittle, +280.f, 3200);
	addPlanet(Planet::AsteroidLittle, +350.f, 3350);
 
	std::sort(mPlanetSpawnPoints.begin(), mPlanetSpawnPoints.end(), [](SpawnPoint lhs, SpawnPoint rhs)
	{
		return lhs.y < rhs.y;
	});
}
示例#5
0
int main()
{
    Sleep(1000);
    char * filename  = "saves.bin";
    char check[50];
    int memSize = 20;
    int numOfPl = 0;
    Planet * planets;
    planets = (Planet *)malloc(memSize*(sizeof(Planet)));
    memSize++;
    planets = realloc (planets, memSize*sizeof(Planet));
    deserialization(planets, &numOfPl, filename);
    while(1)
    {
        printPlanets(planets, &numOfPl);
        putCursor(50, 1);
        puts("Enter your command");
        putCursor(50, 2);
        printf(">>");
        scanf("%s", check);
        if (!strcmp(check, "addPl"))
            addPlanet(planets, &numOfPl, &memSize);
            else
        if (!strcmp(check, "addSp"))
            addSputnik(planets, &numOfPl);
            else
        if (!strcmp(check, "removePl"))
            removePlanet(planets, &numOfPl);
            else
        if (!strcmp(check, "removeSp"))
            removeSputnik(planets, &numOfPl);
            else
        if (!strcmp(check, "changePl"))
            changePlanet(planets, &numOfPl);
            else
        if (!strcmp(check, "changeSp"))
            changeSputnik(planets, &numOfPl);
            else
        if (!strcmp(check, "help"))
        {
            putCursor(50, 3);
            puts("List of commands :");
            putCursor(50, 4);
            puts("addPl - Adding a new planet");
            putCursor(50, 5);
            puts("addPl - Adding a new sputnik");
            putCursor(50, 6);
            puts("removePl - Removing some planet");
            putCursor(50, 7);
            puts("removeSp - Removing some sputnik");
            putCursor(50, 8);
            puts("changePl - Changing parameter of some planet");
            putCursor(50, 9);
            puts("changeSp - Changing parameter of some sputnik");
            putCursor(50, 10);
            puts("exit - Stop the program");
            getch();
        }
            else
        if (!strcmp(check, "exit"))
            {
                freeAll(planets, &numOfPl);
                exit(EXIT_SUCCESS);
            }
            else
            {
                putCursor(120, 3);
                puts("ERROR, enter correct command");
            }
        save(planets, &numOfPl, filename);
        system("cls");
        }


        freeAll(planets, &numOfPl);
        return 0;

    }
示例#6
0
DWORD WINAPI mailThread(LPVOID arg) {

	char buffer[1024];
	DWORD bytesRead;
	static int posY = 0;
	int flag = 0;
	HANDLE mailbox;
							/* create a mailslot that clients can use to pass requests through   */
							/* (the clients use the name below to get contact with the mailslot) */
							/* NOTE: The name of a mailslot must start with "\\\\.\\mailslot\\"  */

	
	mailbox = mailslotCreate ("\\\\.\\mailslot\\mailbox");

	InitializeCriticalSection(&criticalSection);
	for(;;) {				
							/* (ordinary file manipulating functions are used to read from mailslots) */
							/* in this example the server receives strings from the client side and   */
							/* displays them in the presentation window                               */
							/* NOTE: binary data can also be sent and received, e.g. planet structures*/
		
		bytesRead = mailslotRead (mailbox, &buffer, strlen(buffer)); 
		//TESTING PLANETS
		//if(flag==0)
		//{
		//	planet_type p1 = { "p1", 300, 300, 0, 0, 1000000000, NULL, 1000, NULL };
		//	planet_type p2 = { "p2", 200, 300, 0, 0.008, 1000, NULL, 1000, NULL};
		//	planet_type p3 = { "p3", 210, 300, 0.008, 0.008, 5000000, NULL, 1000, NULL };
		//	planet_type *p11 = malloc(sizeof(planet_type));
		//	memcpy(p11, &p1, sizeof(planet_type));
		//	p11->next = NULL;
		//	planet_type *p22 = malloc(sizeof(planet_type));
		//	memcpy(p22, &p2, sizeof(planet_type));
		//	p22->next = NULL;
		//	planet_type *p33 = malloc(sizeof(planet_type));
		//	memcpy(p33, &p3, sizeof(planet_type));
		//	p33->next = NULL;
		//	addPlanet(p11);
		//	addPlanet(p22);
		//	addPlanet(p33);
		//	threadCreate((LPTHREAD_START_ROUTINE)planetThread, p11);
		//	threadCreate((LPTHREAD_START_ROUTINE)planetThread, p22);
		//	threadCreate((LPTHREAD_START_ROUTINE)planetThread, p33);
		//	flag = 1;
		//}
		//Create planet
		if (bytesRead != 0) {
			planet_type *p = malloc(sizeof(planet_type));
			memcpy(p, buffer, sizeof(planet_type));
			p->next = NULL;
			addPlanet(p);
			threadCreate((LPTHREAD_START_ROUTINE)planetThread, p);
			
		

							/* NOTE: It is appropriate to replace this code with something */
							/*       that match your needs here.                           */
		posY++;  
							/* (hDC is used reference the previously created window) */	
		TextOut(hDC, 10, 50+posY%200, p->name, sizeof(strlen(p->name)));

		
		}
		else {
								/* failed reading from mailslot                              */
								/* (in this example we ignore this, and happily continue...) */
		}
	}
	DeleteCriticalSection(&criticalSection);
  return 0;
}