コード例 #1
0
int main() {
	int choice, last_game;

	srand(time(0)); // Seed the randomizer with the current time.

	if(get_player_data() == -1)  // Try to read player data from file.
	      register_new_player();    // If there is no data, register a new player.

	while(choice != 7) {
		printf("-=[ Game of Chance Menu ]=-\n");
		printf("1 - Play the Pick a Number game\n");
		printf("2 - Play the No Match Dealer game\n");
		printf("3 - Play the Find the Ace game\n");
		printf("4 - View current high score\n");
		printf("5 - Change your user name\n");
		printf("6 - Reset your account at 100 credits\n");
		printf("7 - Quit\n");
		printf("[Name: %s]\n", player.name);
		printf("[You have %u credits] ->  ", player.credits);
		scanf("%d", &choice);

		if((choice < 1) || (choice > 7))
		      printf("\n[!!] The number %d is an invalid selection.\n\n", choice);
		else if (choice < 4) {          // Otherwise, choice was a game of some sort.
			if(choice != last_game) { // If the function ptr isn't set
				if(choice == 1)        // then point it at the selected game
				      player.current_game = pick_a_number;
				else if(choice == 2)
				      player.current_game = dealer_no_match;
				else
				      player.current_game = find_the_ace;
				last_game = choice;    // and set last_game.
			}
			play_the_game();          // Play the game.
		}
		else if (choice == 4)
		      show_highscore();
		else if (choice == 5) {
			printf("\nChange user name\n");
			printf("Enter your new name: ");
			input_name();
			printf("Your name has been changed.\n\n");
		}
		else if (choice == 6) {
			printf("\nYour account has been reset with 100 credits.\n\n");
			player.credits = 100;
		}
	}
	update_player_data();
	printf("\nThanks for playing! Bye.\n");
}
コード例 #2
0
ファイル: Snake.c プロジェクト: ShipuW/snake-C-MySql
void db_in(int score)
{
	int res;
	char* name;
    MYSQL mysql;
  
    mysql_init(&mysql);	// 初始化mysql结构  
						//mysql_real_connect()函数的功能是连接一个MYSql数据库服务器,
						//MYSQL结构地址是&mysql,host主机名或地址是localhost,
						//用户名是root,密码是root,数据库是mydb,端口是3306
    if (!mysql_real_connect(&mysql, "localhost", "root", "", "snake", 3306, NULL, 0))
    {
        printf("\n数据库连接发生错误!");
    }
    else
    {
        printf("\n数据库连接成功!\n"); 			
		//插入一条数据到数据库
	switch(ms)
	{
	case 200:mul=1;break;
	case 100:mul=2;break;
	case 50 :mul=4;break;
	default:break;
	}

			///////////取时间
			time ( &rawtime );
			timeinfo = localtime ( &rawtime );
			name=input_name();

		sprintf(sql_insert, "INSERT INTO score(name,score,time) values('%s','%d','%s')",name,mul*score,asctime (timeinfo));
		res = mysql_query(&mysql, sql_insert);
        if(res)
        {		
			 printf("插入数据失败!\n");
        }else 
		{
			printf("成绩输入成功\n");
		}
    }  
    mysql_close(&mysql); // 释放数据库连接 
	printf("任意键重试!");
	fgetchar();
	replay();

}
コード例 #3
0
ファイル: bga_util.c プロジェクト: B-Rich/tcoffee
void input_parameter ( char *name1, char *name_type, int interactive, Parameter *PARAM)
	{
	char *string3;
	
	if ( interactive==0)
		return;
	else
		{
		printf ( "\nPRESENT NAME OF %s:\n##%s##", name_type, name1);
		printf ( "\nENTER A NEW NAME (RETURN TO KEEP THE PREVIOUS): ");
		if ( (string3=input_name())!=NULL)
    			{
    			sprintf ( name1, "%s", string3);
    			free ( string3);
    			}	
		}
	}		     
コード例 #4
0
// This is the new user registration function.
// It will create a new player account and append it to the file.
void register_new_player()  { 
	int fd;

	printf("-=-={ New Player Registration }=-=-\n");
	printf("Enter your name: ");
	input_name();

	player.uid = getuid();
	player.highscore = player.credits = 100;

	fd = open(DATAFILE, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
	if(fd == -1)
	      fatal("in register_new_player() while opening file");
	write(fd, &player, sizeof(struct user));
	close(fd);

	printf("\nWelcome to the Game of Chance %s.\n", player.name);
	printf("You have been given %u credits.\n", player.credits);
}
コード例 #5
0
ファイル: color.cpp プロジェクト: jedirandy/NaoTrack
int main(int argc, char* argv[]) {
    ImageRGB input_image;
    ImageRGB output_image;

    std::string input_name("input.jpg");
    std::string output_name("output.jpg");

    try {
        mirage::img::JPEG::read(input_image, input_name);

        output_image.resize(input_image._dimension);

        ImageRGB::pixel_type p1,p2,p_end;
        ImageRGB::value_type black(0,0,0);
        ImageRGB::value_type green(0,255,0);
        int threshold = 50;
        for(p1=input_image.begin(),p2=output_image.begin(),p_end=input_image.end();
            p1 != p_end;
            ++p1,++p2) {
            ImageRGB::value_type& v1 = *p1;
            
            if (v1._green > v1._blue && v1._green > v1._red) {
                int temp = v1._blue < v1._red ? v1._blue : v1._red;
                if (v1._green - temp > threshold)
                    *p2 = green;
                else
                    *p2 = black;
            }
            else
                *p2 = black;
        }

        mirage::img::JPEG::write(output_image, output_name, 70);
    }
    catch(mirage::Exception::Any& e) {
        std::cerr << "Error : " <<  e.what() << std::endl;
    }
    catch(...) {
        std::cerr << "Unknown error" << std::endl;
    }
    return 0;
}
コード例 #6
0
ファイル: heap.c プロジェクト: lmy375/Practices
int main()
{
	int option;
	setbuf(stdin, 0);
	setbuf(stdout,0);
	setbuf(stderr,0);
	while(1){
		puts("1 - new\n2 - edit\n3 - print\n4 - free\n5 - name\n6 - exit\ninput:");
		scanf("%d", &option);
		switch(option){
			case 1: new_heap(); break;
			case 2: edit_heap(); break;
			case 3: print_heap(); break;
			case 4: free_heap(); break;
			case 5: input_name(); break;
			case 6: exit(0); break;
			default: puts("error!\n");
		}
	}
}