Exemple #1
0
int main(int argc, char *argv[])
{
	bool fullscreen = false;
	if (argc == 2)
	{
		if (strcmp(argv[1], "-full") == 0)
		{
			fullscreen = true;
		}
	}
	initWindow(1024, 768, fullscreen, "Space!!! :D");
	load();
	while (!keyInput.ESC)
	{
		clear();
		int i, r, g, b;
		for (i = 0; i < maxStars; i++)
		{
			r = randomNum(0, 255);
			g = randomNum(0, 255);
			b = randomNum(0, 255);
			setColour(r, g, b, 255);
			pixel(stars[i].x, stars[i].y);
		}
		update();
		logic();
		capFrameRate(60);
	}
	return 0;
}
Exemple #2
0
void load()
{
	int i;
	for (i = 0; i < maxStars; i++)
	{
		stars[i].origX = scrWidth/2;
		stars[i].origY = scrHeight/2;
		stars[i].moveRad = randomNum(5, 10);
		stars[i].angle = degreesToRadians(randomNum(0, 360));
		stars[i].moveSpeed = randomNum(2, 6);
	}
}
Exemple #3
0
Ball *initBallRandom(int id)
{
    Ball *ball = (Ball *)malloc(sizeof(Ball));
    ball->id = id;
    ball->tstamp = sim_time;
    ball->px = randomNum(0.1, 0.9); //taking between 10 cm to 90 cm
    ball->py = randomNum(0.1, 0.9); //taking between 10 cm to 90 cm
    ball->vx = randomNum(-0.5, 0.5);
    ball->vy = randomNum(-0.5, 0.5);
    ball->radius = MIN_RADIUS;
    ball->colour = getColour();
    return ball;
}
//Returns a pointer to a string or something
char* generateSom(){
	char op = randomOperator();
	char buff[11];
	char num1buff[3];
	char num2buff[3];
	char* som = malloc(sizeof(char) * 11);

	int firstNum = randomNum(0, 99);
	int secondNum;
	int answer;

	if (op != '-'){
		secondNum = randomNum(0, 99);
	} else {
		secondNum = randomNum(0, (firstNum - 1));
	}

	switch (op){
	case '+':
		answer = firstNum + secondNum;
		break;
	case '-':
		answer = firstNum - secondNum;
		break;
	case '*':
		answer = firstNum * secondNum;
		break;
	case '/':
		//Speciale methode, dank aan Arjan!
		answer = randomNum(1, 99);
		secondNum = randomNum(1, ((int) 100 / answer));
		firstNum = answer * secondNum;
		break;
	}

	if(firstNum < 10){
		sprintf(num1buff, "0%d", firstNum);
	} else {
		sprintf(num1buff, "%d", firstNum);
	}

	if(secondNum < 10){
		sprintf(num2buff, "0%d", secondNum);
	} else {
		sprintf(num2buff, "%d", secondNum);
	}

	sprintf(buff, "%s%c%s=%d", num1buff, op, num2buff, answer);
	strncpy(som, buff, 11);
	return som;
}
int Player::AiMove(){

	int x = randomNum(2);
	int y = randomNum(2);

	int move = this->move(x,y);

	while (move == Game::FIELDTAKEN)
	{	
		x = randomNum(2);
		y = randomNum(2);
		move = this->move(x,y);
	}
	
	return move;
}
void MainWindow::numerousTest(int times)
{
    for (int i = 0; i < times; i++)
    {
        int randNum = randomNum();
        switch (randNum) {
        case 0:
            server.sendPlanHash();
            QTest::qWait(500);
            break;
        case 1:
            server.sendCommandStart();
            QTest::qWait(500);
            break;
        case 2:
            server.sendCommandStop();
            QTest::qWait(500);
            break;
        case 3:
            server.sendCommandPause();
            QTest::qWait(500);
            break;
        case 4:
            server.sendCommandResume();
            QTest::qWait(500);
            break;
        default:
            break;
        }
    }
}
Exemple #7
0
Engine::Engine(QQmlEngine *eng, QObject *parent) : QObject(parent)
{
    m_engine = eng;

    //Random number seed:
    qsrand(time(NULL));

    int flag = randomNum(2);
    m_self = new Player(true, flag == 0, new Hero());
    m_opponent = new Player(false, flag == 1, new Hero());

    m_index = 2; //The summoning queue index of the minions starts from 2. 0 and 1 are for the heros.
}
Exemple #8
0
QString passgenerate::genPass(){
    QString theLetters = "abcdefghijklmnopqrstuvwxyz";
    QString theSymbols = "?+-*/;:{]}[~!@#$%^&()";
    QString StrongPasswordArray ="";

    int capitalise,i;
    srand (time(NULL));
    for ( i = 0; i < 20; i++) {
        capitalise = randomNum(6);
        if (capitalise == 0) {
            StrongPasswordArray += theLetters[randomNum(26)].toUpper();
        }
        else {
            StrongPasswordArray += theLetters[randomNum(26)];
        }
    }
    // adding symbols in password
    int numberOfSym = randomNum(5);
    int positionForSym, theSym;
    for (i = 0; i < numberOfSym; i++) {
        positionForSym = randomNum(20);
        theSym = randomNum(21);
         StrongPasswordArray[positionForSym] = theSymbols[theSym];
    }
    //adding numbers in password
    int numberOfDigits = randomNum(5) +1;
    int positionForNumeric, theNumber;
    for (i = 0; i < numberOfDigits; i++) {
        positionForNumeric = randomNum(20);
        theNumber = randomNum(9);
        theNumber +=48;
         StrongPasswordArray[positionForNumeric] = (char)theNumber;
    }
    return StrongPasswordArray;

}
int main()
{
	srand(time(NULL));
	//Declare Variables
	FILE *fp;
	char *line = NULL;
    size_t len = 0;
    ssize_t read;
	char filename[99];
	char *numLine;
	char *userInput = (char*) malloc(100);
	char *valueLine;
	char buffer[100];
	int n = 0;
	clock_t start, end;
	float elapsed_time;

	//For random generation
	int maxValue = 10000;
	int maxNumOfCoins = 5;
	int maxCoinValue = 50;
	
	//regular variables
	int v[maxNumOfCoins];
	int c[maxNumOfCoins];
	int a, m;	//start value
	
	//prep arrays
	for(int x = 0; x < maxNumOfCoins; x++)
	{
		c[x] = 0;
		v[x] = 0;
	}

	//ask user for file or random generator
	printf("What do you want to run:\n");
	printf("1) Load from File\n");
	printf("2) Random Generator\n");
	
	//Get user input
	scanf ("%[^\n]%*c", userInput);
	
	if (strcmp(userInput,"1") == 0)
	{
		//Run LoadFile
	}
	else if (strcmp(userInput,"2") == 0)
	{
		//Run Random Generator
		randomNum(&v, &a, maxNumOfCoins, maxCoinValue, maxValue);
	}
	
	//start = clock();
	runGreedyAlgorithm(v, a, &c, &m, maxNumOfCoins);
	//end = clock();
	//elapsed_time = (float)(end - start) / (1.0*CLOCKS_PER_SEC);
	printf("%d\n", a);
	//fprintf(fp,"%d %s %f %s",a, "\t", elapsed_time ,"\n");
	printf("\nmaxNumOfCoins=%d\n", maxNumOfCoins);
	printf("maxCoinValue=%d\n", maxCoinValue);
	printf("maxValue=%d\n", maxValue);
	outputResults(v, maxNumOfCoins, a, 'V');
	printf("Elapsed time: %f seconds\n", elapsed_time);
	printf("\nResults:\n");
	outputResults(c, maxNumOfCoins, m, 'C');
	
	// printf("Enter filename: ");
	// fgets(filename, 99, stdin);
	// char *p = strchr(filename, '\n'); // p will point to the newline in filename
	// if(p) *p = 0; // if p is not null, terminate filename at p
	
	// fp = fopen(filename, "r");
	
	// if(!fp)
		// perror("File not found");
	// else
	// {
		// printf("opening file: %s...\n", filename);
		// while ((read = getline(&line, &len, fp)) != -1) {
			// if (n == 1)
			// {
				// numLine = (char *) realloc (numLine, strlen(line)+1);
				// strncpy(numLine, line, strlen(line));
				// *p = strchr(numLine, '\n'); // p will point to the newline in filename
				// if(p) *p = 0; // if p is not null, terminate filename at p
				
			// }
			// if (n == 2)
			// {
				// printf("n=2\n");
				// printf("strlen=%d\n",strlen(line));
				// valueLine = (char *) realloc (valueLine, strlen(line)+1);
				//strncpy(valueLine, line, strlen(line));
			// }
			// n++;
		// }
    // }
 
	// printf("numLine=%s\n", numLine);
	// printf("valueLine=%s\n", valueLine);

 
	/*
    //parse numbers from lines into array
	for (int i = 0; i < line[0].noOfLines; i++)
	{
		line[i].noOfnums = 0;
		//printf("Words[%d]=%s\n", i, line[i].words); //Test Only
		char *pt;
		pt = strtok(line[i].words,",");
		while (pt != NULL) {
			if (pt[0] == '[')
				pt[0] = ' ';
			line[i].num[line[i].noOfnums] = atoi(pt);
			pt = strtok (NULL, ",");
			line[i].noOfnums++;
		}
	}
	*/
	//close file
	//fclose(fp);
	
	//Exit
	printf("\nHave a nice day.\n");
	return 0;
}
char randomOperator(){
	char operators[4] = { '+', '-', '*', '/' };
	return operators[randomNum(0, 3)];
}
Exemple #11
0
/* Function: newGhostDirection
 * Parameters: int ghostNum
 * Randomly picks the direction the ghost specified by ghostNum
 * will move.  Ghosts will not do a 180 degree turn (turn around)
 * if another direction is possible.
 */
void newGhostDirection(int ghostNum) {
	int ghostMoves[4] = {0, 0, 0, 0};
	int count = 0;
	int i;
	int randNum;

	/* Check possible movement directions */
	if (canMove(ghosts[ghostNum].x, ghosts[ghostNum].y + 1.0, ghostNum)) {
		count++;
		ghostMoves[0] = 1;
	}
	if (canMove(ghosts[ghostNum].x, ghosts[ghostNum].y - 1.0, ghostNum)) {
		count++;
		ghostMoves[1] = 1;
	}
	if (canMove(ghosts[ghostNum].x - 1.0, ghosts[ghostNum].y, ghostNum)) {
		count++;
		ghostMoves[2] = 1;
	}
	if (canMove(ghosts[ghostNum].x + 1.0, ghosts[ghostNum].y, ghostNum)) {
		count++;
		ghostMoves[3] = 1;
	}

	/* Make sure the ghost doesn't just turn around if another
	   direction is possible */
	if (count > 1) {
		switch (ghosts[ghostNum].direction) {
		case up:
			ghostMoves[1] = 0;
			break;
		case down:
			ghostMoves[0] = 0;
			break;
		case left:
			ghostMoves[3] = 0;
			break;
		case right:
			ghostMoves[2] = 0;
			break;
		}
	}

	/* Pick a direction */
	if (count == 1) {
		/* Only one direction possible */
		for (i = 0; i < 4; i++) {
			if (ghostMoves[i] == 1) {
				ghosts[ghostNum].direction = i;
				ghosts[ghostNum].nextDirection = i;
				break;
			}
		}
	} else {
		/* Multiple directions possible - randomly pick one */
		while (1) {
			randNum = randomNum(4);
			if (ghostMoves[randNum] == 1) {
				ghosts[ghostNum].direction = randNum;
				ghosts[ghostNum].nextDirection = randNum;
				break;
			}
		}
	}
}
Exemple #12
0
void Ability::attack(Character& attacker, Character& defender) {
	int damage = randomNum() % 3 + attacker.getLevel();
	defender.setHealth(defender.getHealth() - damage);
}
Exemple #13
0
void Ability::heal(Character& character) {
	int heal = randomNum() % 2 + character.getLevel();
	character.setHealth(character.getHealth() + heal);
}