Exemple #1
0
/*
 * The main()
 */
int main(int argc, char* argv[]){

	char* prog_name;

	if(argc != 2){
		printf("===================================\n| usage: scoreboard [Program file] |\n===================================\n");
		exit(-1);
	} else {
		prog_name = argv[1];
	}

	printf("Initializing the Scoreboard Parameters ... ...\n");
	init();
	printf("Finished initialization \n");
	loadProgram(prog_name);

#ifdef DEBUG
	printInstrStatus();
#endif /* DEBUG */

	scoreboard();
	printScoreboardResult();

	return 0;
}
Exemple #2
0
void loadgame() {
	clrscr();
	printf("Loading\n");	
	int i,j;
 	for(i = 0;i < 10;i++) {
    		for(j = 0;j <= 100000000;j++);
    	printf(".");
	}    	
	printf("\nGame is loaded,press enter to play\n");	
	int snakeXY[2][MAX_SIZE];	
	int snakelength = 4;
	int dir = LEFT;
	int foodXY[0];
	int score = 0;
	int consolewidth = 80;
	int consoleheight = 25;
	int speed = getgamespeed();
	snakeXY[0][0] = 40;
	snakeXY[1][0] = 10;
	border(consolewidth, consoleheight);
	initsnake(snakeXY, snakelength);
	loadsnake(snakeXY,snakelength);	
	foodcreate(foodXY,consolewidth,consoleheight,snakeXY,snakelength);
	scoreboard(score,speed);
	startgame(snakeXY, foodXY, consolewidth, consoleheight, snakelength, dir, score, speed);
}
Exemple #3
0
//This game starts the game the setting of speed is done by using the clock() function
void startgame(int snakeXY[][MAX_SIZE], int foodXY[], int consolewidth, int consoleheight, int snakelength, int dir, int score, int speed) {
	int isgameover = 0;
	clock_t endwait;
	int waittime = CLOCKS_PER_SEC-(speed)*(CLOCKS_PER_SEC/10);
	waittime = waittime / 2.5;	
	int tempscore = 10 * speed;
	int olddir;
	int newdir = 1;
	endwait = clock() + waittime;
	do {
		if(newdir) {
			olddir = dir;
			dir = checkkey(dir);
		}
		if(olddir != dir) 
			newdir = 0;
		if(clock() >= endwait) {
			displaymovement(snakeXY,snakelength,dir);
			newdir = 1;
			if(checkeatfood(snakeXY, foodXY)) {
				foodcreate(foodXY, consolewidth, consoleheight, snakeXY, snakelength);
				snakelength++;
				score = score + speed; // I have incremented the score with the speed ( 9 gets the most score)
				 if( score >= 10*speed+tempscore) {
                    			speed = speed * 2;
                    			tempscore = score;
 					if(speed <= 9)
                        			waittime = waittime - (CLOCKS_PER_SEC);
                    			else if(waittime >= 40)
                            			waittime = waittime - (CLOCKS_PER_SEC);
                         			
                   		}
				scoreboard(score, speed);			
			}
			endwait = clock() + waittime;	
		}
		isgameover = collides(snakeXY, consolewidth, consoleheight, snakelength);
		 
		if(snakelength >= MAX_SIZE-5) {
            		isgameover = 2;
            		score+=1500; 
        	}	

	
	} while(!isgameover);
	
	switch(isgameover) {
		case 1: 
			gameoverscreen();
			break;
		default: ;
			break;
	}		
	
	
}
Exemple #4
0
int main(int argc, char** argv) {

    int size_of_board; //BOARD'IN BUYUKLUGU
    char cells[21][21]; //CHAR TIPINDE 2D ARRAY
    int check_player_move=1; // PLAYERIN ANLAMLI HAREKETINI KONTROL
    int player_can_move=1;//Playerin hamlesinin olup olmadigi kontrol edilir
    int computer_can_move=1;//Computerin hamlesinin olup olmadigi kontrol edilir
    
    //Gecerli bir size of board degeri girilene kadar,
    //kullanicidan size of board degeri istenir.
    size_of_board=board_size();
    
    //Hucrelerin oyun basi degerleri verilir
    first_view(size_of_board, cells);
    
    //Guncel board ekrana cizilir.
    paint_board(size_of_board, cells);
    
    //Eger player veya computer hamle yapabiliyorsa 
    while(player_can_move==1 || computer_can_move==1)
    {
        computer_can_move=1;
        
        //Player yapacak hamleye sahip mi degil mi
        player_can_move=does_player_have_move(size_of_board, cells);
        
        //Eger Player Hamle yapabiliyorsa
        if(player_can_move)  
        {
            while(check_player_move)
            {
                //Player Hareketi
                //Legal bir hareket girilene kadar donguden cikmaz
                check_player_move=for_player_move(size_of_board, cells);              
            }
            check_player_move=1;
        
            //Guncel board ekrana cizilir.
            paint_board(size_of_board, cells);
        }
        
        //Computer Hareketi
        for_computer_move(size_of_board, cells, &computer_can_move);
    
        //Guncel board ekrana cizilir.
        paint_board(size_of_board, cells);
        
        cout <<"\n";
    }
    
    //Skor Yazilir
    scoreboard(size_of_board, cells);
    
    return 0;
}
Exemple #5
0
/**
 * createWorker() is called once in each of the worker threads.
 * It creates the actual worker threads, then waits for all of the other
 * threads to create their workers before returning.
 *
 * It holds a lock, so that the threads call monitor_->newScoreBoard() and
 * workerFactory_->newWorker() serially, and the Monitor and WorkerFactory
 * classes don't have to worry about locking.
 *
 * This is performed in the worker threads rather than the main thread, just to
 * ensure that memory allocation for the workers is performed in their
 * respective threads.  Allocating the memory in the main thread can lead to
 * false sharing in some cases, hurting performance.  (i.e., scoreboard data
 * for two different workers may be placed on the same cache line, forcing it
 * to be continually evicted as two different CPUs try to access it very
 * frequently.)  Performing the allocation in the individual threads helps
 * let smarter malloc implementations avoid false sharing.
 */
shared_ptr<WorkerIf> Controller::createWorker() {
  Synchronized s(initMonitor_);

  // Create the worker
  int id = workers_.size();
  shared_ptr<ScoreBoard> scoreboard(monitor_->newScoreBoard(id));
  shared_ptr<WorkerIf> worker(workerFactory_->newWorker(id, scoreboard,
                                                        &intervalTimer_));

  // Add the worker to the workers_ array,
  // and notify anyone waiting that we have updated workers_
  workers_.push_back(worker);
  initMonitor_.notifyAll();

  // Wait on all of the other workers to be created
  while (workers_.size() != numThreads_) {
    initMonitor_.wait();
  }

  return worker;
}
Exemple #6
0
std::shared_ptr<ScoreBoard> QpsMonitor::newScoreBoard(int /* id */) {
  std::shared_ptr<QpsScoreBoard> scoreboard(
      new QpsScoreBoard(config_->getNumOpTypes()));
  scoreboards_.push_back(scoreboard);
  return scoreboard;
}
Exemple #7
0
int main(){

	HANDLE  hConsole;
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hConsole, 6);

	int game_count = 0;
	bool repeat = true;
	string answer;
	string difficulty;
	string message = "\nWould you like to play a game of hangman? ";

	cout << "Loading word list...\n";
	// Set seed for random number generation
	srand(time(0));
	// Load up dictionary from "words.txt"
	vector<string> dictionary = loader();

	cout << "The list contains ";

	SetConsoleTextAttribute(hConsole, 2);
	cout << dictionary.size();
	SetConsoleTextAttribute(hConsole, 6);

	cout << " words.\n";
	cout << "\nWelcome. ";

	// Until player selects no
	while (repeat){
		// Check if first round or not
		if (game_count > 0){
			message = "\nWould you like to play another game of hangman? ";
		}

		cout << message;    // COLOR:OFF
		cout << "(";
		SetConsoleTextAttribute(hConsole, 6);
		cout << "y";
		SetConsoleTextAttribute(hConsole, 6);
		cout << "/";
		SetConsoleTextAttribute(hConsole, 6);
		cout << "n";
		SetConsoleTextAttribute(hConsole, 6);
		cout << ") (enter 'scores' to view scoreboard)\n";
		cin >> answer;

		// If player chooses yes, (1) run hangman (2) print score
		// and, if player wins, (3) run scoreboard
		if (answer == "y" || answer == "Y" || answer == "yes" || answer == "Yes"){
			game_count++;
			int score = hangman(dictionary, 6); // RUN
			cout << "Your score was: ";
			if (score == 0){
				SetConsoleTextAttribute(hConsole, 4); // COLOR::RED
				cout << score << endl;
				SetConsoleTextAttribute(hConsole, 6); // COLOR::YELLOW
			}
			else{
				SetConsoleTextAttribute(hConsole, 2); // COLOR::GREEN
				cout << score << endl;
				SetConsoleTextAttribute(hConsole, 6); // COLOR::YELLOW
			}
			// Check whether game was won
			if (score > 0){
				scoreboard(score);
			}
		}
		// If player chooses no, exit game
		else if (answer == "n" || answer == "N" || answer == "no" || answer == "No"){
			repeat = false;
			string goodbye = "Goodbye!";

			for (int i = 0; i < 80; i++){
				SetConsoleTextAttribute(hConsole, i); // COLOR::i
				goodbye = goodbye.insert(0,"         ");
				cout << goodbye << endl;
			}
		}
		// If player enters p, print contents of "words.txt"
		else if (answer == "p"){
			print_vector(dictionary);
		}
		// If player enters scores, print scoreboard
		else if (answer == "scores"){
			print_scoreboard();
			cout << "\n";
		}
		// Else show error
		else{
			cout << "Invalid command.\n";
		}
	}
	
	return 0;
}
int main()
{
	// Print instructions for user
	printf("Asteroid!\nTry to collect as many colored circles as you can.\nThe game is simple. Use the arrow keys to navigate your rocket.\nUp accelerates\nDown brakes immediately\nLeft and Right turn your rocket.\n\nHave fun!!\n");	

	// Define variables
	int xSize=800, ySize=600;
	char c;
	int stillgoing=1;
	float xc=xSize/2, yc=ySize/2, *pxc=&xc, *pyc=&yc;
	float dr=.1;			// rotation increment
	int sign = 1;			// rotation sign
	int r = 15;			// box radius
	int i;				// box counter
	int j;				// triangle counter
	double rotatea=0;		// rotation angle of rocket
	float dx=0, dy=0;		// chane in position of rocket
	float dt=0;			// change in time for acceleration
	float accel=.07;		// acceleration of rocket
	srand(time(NULL));
	int rCir=0;			// radius of circle
	int xCir=xc,yCir=yc;		// position of circle's center
	int rC=255,gC=255,bC=255;	// circle color
	int cirCount=-1;		// number of circles collected(starts at -1 because initial circle is created at center, then random placement begins. Fisrt circle placed at center does not count towards total.
	int isaccel=0;
	double rotatet=rotatea;
	double yRotate=0, xRotate=0;
	float xB, yB;			//  position of fired shot

	gfx_open(xSize,ySize,"Rocketship!");
	
	startGame(xSize, ySize);
	while(stillgoing==1)
	{
		gfx_clear();
		drawAsteroid(xCir,yCir,rCir,rC,gC,bC);	
		drawRocket(xc,yc,rotatet,r);	// uses rotatet, because this will draw the rocket as turning when the left/right arrows are pressed

		scoreboard(cirCount);
		gfx_flush();
		usleep(2000);

		if(gfx_event_waiting()){
			c=gfx_wait();
			switch(c){
				case 'R':	// Accelerate
					dt+=.01;
					dx+=accel*dt;	// increases speed dx by increasing the time and adding to dx
					if(dx>.8) dx=.8;	// this caps dx and dy at 1. Thus the maximum speed is dx=dy=1
					dy=dx;
					isaccel=1;	// the rocket is currently accelerating
					break;
				case 'Q':	// Turn left
					rotatet-=dr;	// decreases angle of rotation
					break;
				case 'S':	// Turn right
//printf("ROTATET: %lf\n",rotatet);
					rotatet+=dr;	// increases angle of rotation
//printf("ROTATET: %lf\n",rotatet);
					break;
				case 'T':	// Brake
					dx=0;		// sets speed dx and dy to 0
					dy=0;
					rotatea=rotatet;
					yRotate=0;
					xRotate=0;
					break;
				case ' ':
					
					fire(rotatet, xc, yc, r);
					break;
				case 'q':	// Quit
					stillgoing=0;
					printf("\nYou collected %i circles!\n",cirCount);
					break;
				default:
					break;
			}
		}
		if(isaccel==1){
		printf("ROTATEA: %lf\n",rotatea);
			if(sin(rotatea)<sin(rotatet)){
				yRotate-=fabs(sin(rotatea+.1));
		printf("check1\n");
			}else if(sin(rotatea)>sin(rotatet)){
				yRotate+=fabs(sin(rotatea-.1));
		printf("check2\n");
			}//else direction of acceleration is equal to direction rocket is facing
			if(cos(rotatea)>cos(rotatet)){
				xRotate-=fabs(cos(rotatea+.1));
		printf("check3\n");
			}else if(cos(rotatea)<cos(rotatet)){
				xRotate+=fabs(cos(rotatea-.1));
		printf("check4\n");
			}
			if(xRotate!=0) rotatea=atan(yRotate/xRotate);
		printf("yRotate: %lf\nxRotate: %lf\nrotatea: %lf\nrotatet: %lf\n",yRotate,xRotate,rotatea,rotatet);
		}

		xc+=dx*cos(rotatea);	// implements x and y speed(dx and dy) by changing position(xc,yc) of rocket at varying rate
		yc+=dy*sin(rotatea);	// why i use rotatea, not rotatet: the rocket will only update the angle of movement, if the rocket is accelerating. This way, you can turn the rocket while it is moving in another direction
		isaccel=0;
		// Transports rocket from one side of screen to other
		wormhole(pxc,pyc,xSize,ySize);
		// Creates new circle if rocket comes too close
		if(sqrt(pow((xc-xCir),2)+pow((yc-yCir),2))<1.6*r+rCir){
			cirCount++;
			rCir=10+rand()%20;
			do{
				xCir=rand()%xSize;
				yCir=rand()%ySize;
				rC=100+rand()%155;
				gC=100+rand()%155;
				bC=100+rand()%155;
			}while(sqrt(pow((xc-xCir),2)+pow((yc-yCir),2))<50);
		}
	}
}
/*
* ディスプレイ関数
*/
static void display(void)
{
	const static GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };    /* ���̐F */
	const static GLfloat lightpos[] = { 12.0, 16.0, 20.0, 1.0 }; /* �����̈ʒu */

	/* ���ʃN���A */
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	t = dt * tn;

	/* ���f���r���[�ϊ��s���̏����� */
	glLoadIdentity();

	if (batted) gluLookAt(px, py, pz, px, py - 2, pz - 15, 0, 0.8, 0.4);
	else gluLookAt(0, 0, 0, cam_x, cam_y, cam_z, 0, 1, 0);
	
	glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

	/* 回転 */
	glRotated(cam_x_angle, 1.0, 0.0, 0.0);
	glRotated(cam_y_angle, 0.0, 1.0, 0.0);

		

	/* �����̈ʒu���ݒ� */
	
	/* カメラの位置 */
	glTranslated(cam_x, cam_y, cam_z);

	zone(); // ストライクゾーンの描画	
	myGround(0.0); // 大地の描画

	base(); //ホームベースの描画
	line(); //塁線の描画
	scoreboard(0, -60, 15.0, 3.5, 1.25);
	//scoreboard(1, -60, 1.7, 1.5, 3.0);
	//scoreboard(2, -60, 1.1, 0.56, 3.75);

	//myBox(15, 13, 5, 0, 1, -80);
	//glPushMatrix();
	//glRotated(10, 1.0, 0.0, 0.0);
	//myPalse(0.0, 5.0, -10.0, 10.0, 8.0, 90);
	//glPopMatrix();

	tn++;

	/* ピッチャーの描画 */
	pitcher(QX, QY - 0.9, QZ);

	if (batted){ // 打球の軌道計算
		px = mx + vx * (t - 2.0);
		py = my + 0.5 * G * (t - 2.0) * (t - 2.0) + vy * (t - 2.0);
		pz = 16.0 + 6.5 + 0.5 * az * (t - 2.0) * (t - 2.0) + vz * (t - 2.0);

		/*px = px_achieve + vx * t;
		py = py_achieve + 0.5 * G * t * t + vy * t;
		pz = 18.0 + 0.5 * az * t * t + vz * t;*/
	} else { // 投球の軌道計算
		px = vx * (t - 2.0) + QX;
		py = 0.5 * G * (t - 2.0) * (t - 2.0) + vy * (t - 2.0) + QY;
		pz = 0.5 * az * (t - 2.0) * (t - 2.0) + vz * (t - 2.0) + QZ;

	}

	/* 着弾点の x, y座標を計算 */
	if (pz < 18.0){
		t_achieve = (-vz + sqrt(vz * vz + 2 * az * 18.0)) / az;
		px_achieve = vx * t_achieve + QX;
		py_achieve = 0.5 * G * t_achieve * t_achieve + vy * t_achieve + QY;
	}

	//printf("t = %f\n", t);
	//printf("(px, py, pz) = (%f, %f, %f)\n", px, py, pz);
	//printf("(vx, vy, vz) = (%f, %f, %f)\n", vx, vy, vz);
	/* 床との衝突 */
	if (py < R){
		py = R;
		vy *= -A;
	}
	/* スライダー */
	if (species == 1 && pz > 12 && pz < 18) {
		vx += 0.002 * pow(t, 4);
	}
	/* カーブ */
	if (species == 2 && pz > 12 && pz < 18) {
		vx += 0.001 * pow(t, 4);
		vy -= 0.002 * pow(t, 4);
	}
	/* スプリット */
	if (species == 3 && pz > 12 && pz < 18) {
		vy -= 0.002 * pow(t, 4);
	}
	/* シンカー */
	if (species == 4 && pz > 12 && pz < 18) {
		vx -= 0.001 * pow(t, 4);
		vy -= 0.002 * pow(t, 4);
	}
	/* シュート */
	if (species == 5 && pz > 12 && pz < 18) {
		vx -= 0.002 * pow(t, 4);
	}
	/* ライジングキャノン */
	if (species == 6 && pz > 12 && pz < 18){
		vy += 0.0015 * pow(t, 4);
	}
	/* Wボール */
	if (species == 7 && pz > 6 && pz < 9){
		vy -= 0.04 * pow(t, 4);
	}
	else if (species == 7 && pz > 9 && pz < 12){
		vy += 0.09 * pow(t, 4);
	}
	else if (species == 7 && pz > 12 && pz < 15){
		vy -= 0.07 * pow(t, 4);
	}
	else if (species == 7 && pz > 15 && pz < 18){
		vy += 0.04 * pow(t, 4);
	}

	char species_name[][15] = { "STRAIGHT", "SLIDER", "CURVE", "SFF", "SINKER", "SHOOT", "RISING_CANON", "W_BALL" };
	/* 球速の表示 */
	char str[100], vz_s[4] = { '\0' }, pz_s[4];
	if (t > t_achieve - 0.01 && t < t_achieve + 0.01){
		vz_achieve = vz;
	}
	if (t > t_achieve + 1.8){
		sprintf_s(vz_s, "%3d", (int)(vz_achieve * 2.7));
		strcpy_s(str, "Speed: ");
		strcat_s(str, vz_s);
		strcat_s(str, "km/h");
		//strcat_s(str, species[key]);
		if ((fabs(px_achieve) < 0.3 && py_achieve > 1.0 && py_achieve < 1.7) || (swinged == 1 && hitted == 0)) {
			strcpy_s(judge, " Judge: STRIKE! Count: S| ");
		}
		else if (vz < 0){
			strcpy_s(judge, " Judge: HIT! Count: S| ");
		}
		else if (!(fabs(px_achieve) < 0.3 && py_achieve > 1.0 && py_achieve < 1.7)) {
			strcpy_s(judge, " Judge: BALL. Count: S| ");
		}
		for (int i = 0; i < s_count; i++)strcat_s(judge, "*");
		strcat_s(judge, " B| ");
		for (int i = 0; i < b_count; i++)strcat_s(judge, "*");
		if (out == 1)strcat_s(judge, " BATTER OUT!");
		else if (four == 1)strcat_s(judge, " FOUR BALL!");
		//else if (az < 0) strcat_s(judge, " HIT!");
		strcat_s(str, judge);
		strcat_s(str, " Species: ");
		strcat_s(str, species_name[species]);
		if (batted == 1){
			fd = hypot(px, -pz + 18.0);
			sprintf_s(pz_s, "%3d", (int)(fd));
			strcat_s(str, " Frying Distance: ");
			strcat_s(str, pz_s);
			strcat_s(str, "m");
		}
		DrawString(str, 500, 200, 100, 10);
	}

	/* 着弾点を表示 */
	if (pitched){
		GLfloat white[] = { 1.f, 1.f, 1.f };
		if (t > 1.0 && t < 2.0){
			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
			PrintCircle(2.0 - 1.0 * t + R, 100, px_achieve, py_achieve, 18.0); //円を描画 (半径, 分割数, X座標, Y座標, Z座標)
		}
		else if (t > 2.0){
			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
			PrintCircle(R, 100, px_achieve, py_achieve, 18.0);
		}
		if (t < 2.0){
			arm_angle = 50 * t * t;
		}
		else if (t > 1.8 && t < 2.17){
			arm_angle += 2.0 * t * t;
		}
	}

	if (swinged){
		bat_angle += VS;
	}
	if (bat_angle > 300){
		bat_angle = 300;
	}
	/* 衝突時の処理 */
	if (hitted){
		bat_angle_hitted = bat_angle + 400 * (2 * t_achieve - 2 * swinged_time + 2.15); // ボールと衝突時のバットの角度を計算
		//th = 10 * PI / 180;
		th = (2 * (bat_angle_hitted - 180) - phi) * PI / 180; /* 打球のY-Z平面となす角度の計算 */
		//r = (200 * (py_achieve - my + 0.1) / 0.125) * PI / 180; /* 打球とX-Z平面となす角度の計算 */
		r = 195 * PI / 180;

		v = -0.3500 / (fabs(mx - px_achieve) + fabs(my - py_achieve)) * 0.5 * 4;

		px = px_achieve;
		py = py_achieve;
		pz = 18.0;
		az = -0.1;

		vx = v * sin(th) * cos(r);
		vy = v * sin(r);
		vz = v * cos(th) * cos(r);

		hitted = 0;
		printf("th = %f\n dt = %f\n",th,t_achieve - swinged_time + 2.0);
	}

	if (t > 2.0 && pitched){
		glPushMatrix();
		glTranslated(px, py, pz);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
		glutSolidSphere(R, 16, 8);
		glPopMatrix();
	}

	/* バッターの描画 */
	batter(mx - 1.2, my - 0.6, 18.0);

	/* バット */
	glPushMatrix();
	glTranslated(mx - 1.2, my, 18.0);
	glRotated(bat_angle, 0.0, 1.0, 0.0);
	glTranslated(-0.8, 0, 0);
	
	glEnable(GL_NORMALIZE);
	GLfloat bat_color[] = { 0.9, 0.7, 0.3, 1.0 };
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, bat_color);
	glScalef(1.f, 0.07f, 0.05f);
	displaySphere(0.5f, 0.8f, 0.8f, 0.8f, 0.2f, 0.2f, 0.2f, 10.f);
	glDisable(GL_NORMALIZE);
	glPopMatrix();

	/* ミートカーソルの表示 */

	GLfloat yellow[] = { 1.f, 1.f, 0.f, 1.f };
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, yellow);
	PrintEllipse(R + 0.1, 100, mx, my, mz);

	glutSwapBuffers();
}