Example #1
0
void FlipFlap::flip(int p){							//flip the top p pancakes
        ++current_flips;							//increment flips player has made
        for(Pancake* pancake : game_stack_p){					//detach old stack from window
                detach(*pancake);
        }
        auto it = std::next(game_stack_p.begin(), (p-1));			//flip order in the list
        reverse(it,game_stack_p.end());
        for(int i = (p-1); i < game_stack.size(); ++i){
                game_stack_p[i] = new Pancake(game_stack_p[i]->get_size(),i);
        }
        for(Pancake* pancake : game_stack_p){					//re-attach the changed pancakes
                attach(*pancake);
        }
        update_boxes();								//update on-screen counters
        redraw();								//redraw window
        if(check_score()){							//if stack is sorted
                for(Pancake* pancake : game_stack_p){				//detach pancake stack
                        detach(*pancake);
                }
                for(int i = 0; i < (current_level-1); ++i)			//detach flip buttons
                        detach(buttons[i]);
                show_scores(0);							//go to show scores (Win)
        }
       if(calc_score(current_flips) == 0){					//if score has hit 0
         for(Pancake* pancake : game_stack_p){					//detach pancakes
                        detach(*pancake);
                }
                for(int i = 0; i < (current_level-1); ++i)
                        detach(buttons[i]);					//detach flip buttons
                show_scores(1);							//go to show scores (Lose)
       }

}
Example #2
0
static void
end_of_game (char *title)
{
	int pos;

	pos = gnome_score_log(score, NULL, TRUE);
	show_scores(title, pos);
}
int main()
{
	const int ArSize = 10;
	int scores[ArSize] = {};

	std::cout << "Enter 10 scores (or less, enter a non-number to quit)\n";

	int sz = fill_scores(scores, ArSize);

	std::cout << "Thank You!\n";

	show_scores(scores, sz);

	return 0;
}
Example #4
0
/*
 * Menu command: see top twenty scores.
 */
static void death_scores(const char *title, int row)
{
	screen_save();
	show_scores();
	screen_load();
}
Example #5
0
static void
game_top_ten_callback(GtkWidget *widget, gpointer data)
{
	show_scores(_("The Same Gnome"), 0);
}
Example #6
0
int welcome_main()
{
    int i,j;
    int mx,my;
    int welcome = true;
    int option_screen = false;
    int score_screen = false;
    int first_run = true;
    int credits_screen = false;
    SDL_Rect temp;
    TTF_Font *MyFont;
    SDL_Color GREEN = {0,255,0};
    SDL_Color WHITE = {255,255,255};
    SDL_Surface *message = NULL;
    
    int option = -1;
    
    init_buttons();
        
    init_images();
    
    draw_image(backk,screen,NULL,0,0);
    
    gameLog("Welcome screen initialized...");
    
    //draw_image(message,screen,NULL,0,0);
   //Mix_PlayMusic(background_music,-1);
    
    while(welcome)
    {
           while(SDL_PollEvent(&event))
           {
                switch(event.type)
                {
                    case SDL_MOUSEMOTION:
                        
                        for(i=0;i<TOTAL_NO_BUTTON;++i)
                        {
                            handle_mouseover(&button[i],event.motion.x,event.motion.y);
                            
                        }
                        break;
                        
                    case SDL_MOUSEBUTTONDOWN:
                
                         
                         
                         mx = event.button.x;
                         my = event.button.y;
                         for( i = 0; i < TOTAL_NO_BUTTON; ++i)
                         {
                               if(check_click(button[i],mx,my)==true)
                               {
                                    if(sound)Mix_PlayChannel(-1,click_sound,4);
                                    animate_button(button[i],i);
                                       
                                       
                                    first_run = true;
                                       switch(i)
                                       {
                                                case 0:
                                                       
                                                       option = 1;
                                                       welcome = false;
                                                       break;
                                                case 1:
                                                        option_screen = true;
                                                        break;
                                                case 2:
                                                        score_screen = true;
                                                        break;
                                                case 3:
                                                        credits_screen = true;
                                                        break;
                                                        
                                                case 4:
                                                       
                                                       option = -1;
                                                       welcome = false;
                                                       break;
                                       }
                                       
                               }
                         }
                         break;
                
                    case SDL_QUIT:
                        
                         welcome = false;
                         option = -1;
                         break;
                    
                    case SDL_KEYDOWN:
                         
                         switch(event.key.keysym.sym)
                         {
                                case SDLK_p:
                                    animate_button(button[0],0);
                                     welcome = false;
                                     option = 1;
                                     break;
                                
                                case SDLK_x:
                                    animate_button(button[4],4);
                                     welcome = false;
                                     option = -1;
                                     break;
                                
                                case SDLK_1:
                                    
                                    if(Mix_PlayingMusic() == 0)
                                    {
                                        Mix_PlayMusic(background_music,-1);
                                    }
                                    else
                                    {
                                        if(Mix_PausedMusic() == 1)
                                        {
                                            sound = true;
                                            Mix_ResumeMusic();
                                        }
                                        else
                                        {
                                            sound = false;
                                            Mix_PauseMusic();
                                        }
                                    }
                                    break;
                                
                                case SDLK_0:
                                    Mix_HaltMusic();
                                    break;
                         }
                    }
             }          
        //---=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        while(option_screen == true)
        {
            if(first_run)
            {
            draw_image(option_screen_image,screen,NULL,0,0);
            
            draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y);
            first_run = false;
            }
            draw_image(sound_icon[sound],screen,NULL,sound_button.dimension.x,sound_button.dimension.y);
            while(SDL_PollEvent(&event))
            {
                switch(event.type)
                {
                    case SDL_MOUSEBUTTONDOWN:
                        
                        if(sound)Mix_PlayChannel(-1,click_sound,0);
                        mx = event.button.x;
                        my = event.button.y;
                         
                        if(check_click(sound_button,mx,my) == true)
                        {
                            if(sound == 0) sound = 1;
                            else sound =0;
                        }
                        if(check_click(back_button,mx,my)== true)
                        {
                           
                            draw_image(backk,screen,NULL,0,0);
                            option_screen = false;
                        }
                }
            }
            SDL_Flip(screen);
            
        }
        //==========================================================================================
        while(score_screen == true)
        {
            if(first_run)
            {
                draw_image(score_screen_image,screen,NULL,0,0);
                draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y);
                show_scores();
                first_run = false;
            }                                           
            while(SDL_PollEvent(&event))
            {
                switch(event.type)
                {
                    case SDL_MOUSEBUTTONDOWN:
                        
                        if(sound)Mix_PlayChannel(-1,click_sound,0);
                        mx = event.button.x;
                        my = event.button.y;
                         
                        if(check_click(back_button,mx,my)== true)
                        {
                            draw_image(backk,screen,NULL,0,0);
                            score_screen = false;
                        }
                }
            }
            SDL_Flip(screen);
            
        }
        //==========================================================================================
        //==========================================================================================
        while(credits_screen == true)
        {
            if(first_run)
            {
                temp.x = 0;
                temp.y = 0;
                temp.w = 1100;
                temp.h = 600;
                clear_image(temp);
                
                
                MyFont  = TTF_OpenFont("fonts\\lfont.ttf",32);
                message  = TTF_RenderText_Blended(MyFont,"Developed By:",WHITE);
                draw_image(message,screen,NULL,100,100);
                SDL_FreeSurface(message);
                message = NULL;
                TTF_CloseFont(MyFont);
                
                MyFont = TTF_OpenFont("fonts\\sfont.ttf",20);
                message = TTF_RenderText_Blended(MyFont,"-> Bishruti Siku",GREEN);
                draw_image(message,screen,NULL,100,150);
                SDL_FreeSurface(message);
                message = NULL;
                
                message = TTF_RenderText_Blended(MyFont,"-> Nitish Dhaubhadel",GREEN);
                draw_image(message,screen,NULL,100,170);
                SDL_FreeSurface(message);
                message = NULL;
                
                message = TTF_RenderText_Blended(MyFont,"-> Iksha Gurung",GREEN);
                draw_image(message,screen,NULL,100,190);
                SDL_FreeSurface(message);
                message = NULL;
                
                message = TTF_RenderText_Blended(MyFont,"-> Pranaya Pradhananga",GREEN);
                draw_image(message,screen,NULL,100,210);
                SDL_FreeSurface(message);
                message = NULL;
                
                message = TTF_RenderText_Blended(MyFont,"-> Sandip Sahani",GREEN);
                draw_image(message,screen,NULL,100,230);
                SDL_FreeSurface(message);
                message = NULL;

                message = TTF_RenderText_Blended(MyFont,"Computer Engineering",WHITE);
                draw_image(message,screen,NULL,100,300);
                SDL_FreeSurface(message);
                message = NULL;
                
                message = TTF_RenderText_Blended(MyFont,"Kathmandu University",WHITE);
                draw_image(message,screen,NULL,100,320);
                SDL_FreeSurface(message);
                message = NULL;
                
                draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y);
                
                first_run = false;
                
            }                                           
            while(SDL_PollEvent(&event))
            {
                switch(event.type)
                {
                    case SDL_MOUSEBUTTONDOWN:
                        
                        if(sound)Mix_PlayChannel(-1,click_sound,0);
                        mx = event.button.x;
                        my = event.button.y;
                         
                        if(check_click(back_button,mx,my)== true)
                        {
                            draw_image(backk,screen,NULL,0,0);
                            credits_screen = false;
                        }
                }
            }
            SDL_Flip(screen);
            
        }
        //==========================================================================================

        for(i=0;i<TOTAL_NO_BUTTON;++i)
        {
             draw_image(button_image[i][button[i].state],screen,NULL,button[i].dimension.x,button[i].dimension.y);
    
        }
           
           SDL_Flip(screen);
    }
    SDL_FreeSurface(option_screen_image);
    SDL_FreeSurface(score_screen_image);
    SDL_FreeSurface(back_button_image);
    SDL_FreeSurface(sound_icon[0]);
    SDL_FreeSurface(sound_icon[1]);
    SDL_FreeSurface(message);
    message = NULL;
    
    
    SDL_FreeSurface(backk);
    for(i=0;i<TOTAL_NO_BUTTON;++i)
    {
        for(j=0;j<2;++j)
        {
            SDL_FreeSurface(button_image[i][j]);
        }
    }
    
    //TTF_CloseFont(font);
    gameLog("Welcome screen closed...");
    return option;
        
}
Example #7
0
/**
 * scores_cb
 * @action: Pointer to action
 * @data: Callback data
 *
 * Description:
 * Callback for scores menu entry
 *
 * Returns:
 **/
static void
scores_cb (GtkAction * action, gpointer data)
{
  show_scores (0, FALSE);
}
Example #8
0
static void do_cmd_knowledge_scores(const char *name, int row)
{
	show_scores();
}
Example #9
0
/*
 * Simple "main" function for multiple platforms.
 *
 * Note the special "--" option which terminates the processing of
 * standard options.  All non-standard options (if any) are passed
 * directly to the "init_xxx()" function.
 */
int main(int argc, char *argv[])
{
	int i;

	bool done = FALSE;

	bool new_game = FALSE;

	int show_score = 0;

	const char * mstr = NULL;

	bool args = TRUE;


	/* Save the "program name" XXX XXX XXX */
	argv0 = argv[0];

#ifdef SET_UID

	/* Default permissions on files */
	(void)umask(022);

#endif


	/* Get the file paths */
	init_stuff();


#ifdef SET_UID

	/* Get the user id */
	player_uid = getuid();

	/* Save the effective GID for later recall */
	player_egid = getegid();

#  if 0	/* XXX XXX XXX */

	/* Redundant setting necessary in case root is running the game */
	/* If not root or game not setuid the following two calls do nothing */

	if (setgid(getegid()) != 0)
	{
		quit("setgid(): cannot set permissions correctly!");
	}

	if (setuid(geteuid()) != 0)
	{
		quit("setuid(): cannot set permissions correctly!");
	}

#  endif

#endif /* SET_UID */


#ifdef SET_UID

#ifdef PRIVATE_USER_PATH

	/* Create directories for the users files */
	create_user_dirs();

#endif /* PRIVATE_USER_PATH */

	/* Acquire the "user name" as a default player name */
	user_name(op_ptr->full_name, player_uid);

#endif /* SET_UID */


	/* Process the command line arguments */
	for (i = 1; args && (i < argc); i++)
	{
		/* Require proper options */
		if (argv[i][0] != '-') goto usage;

		/* Analyze option */
		switch (argv[i][1])
		{
			case 'N':
			case 'n':
			{
				new_game = TRUE;
				break;
			}

			case 'F':
			case 'f':
			{
				arg_fiddle = TRUE;
				break;
			}

			case 'W':
			case 'w':
			{
				arg_wizard = TRUE;
				break;
			}

			case 'V':
			case 'v':
			{
				arg_sound = TRUE;
				break;
			}

			case 'R':
			case 'r':
			{
				arg_force_roguelike = TRUE;
				break;
			}

			case 'O':
			case 'o':
			{
				arg_force_original = TRUE;
				break;
			}

			case 'S':
			case 's':
			{
				show_score = atoi(&argv[i][2]);
				if (show_score <= 0) show_score = 10;
				break;
			}

			case 'u':
			case 'U':
			{
				if (!argv[i][2]) goto usage;
				strncpy(op_ptr->base_name, &argv[i][2], 32);
				op_ptr->base_name[31] = '\0';
				break;
			}

			case 'm':
			{
				if (!argv[i][2]) goto usage;
				mstr = &argv[i][2];
				break;
			}

			case 'M':
			{
				arg_monochrome = TRUE;
				break;
			}

			case 'd':
			case 'D':
			{
				change_path(&argv[i][2]);
				break;
			}

			case '-':
			{
				argv[i] = argv[0];
				argc = argc - i;
				argv = argv + i;
				args = FALSE;
				break;
			}

			default:
			usage:
			{
				/* Dump usage information */
				puts("Usage: angband [options] [-- subopts]");
				puts("  -n        Start a new character");
				puts("  -f        Request fiddle mode");
				puts("  -w        Request wizard mode");
				puts("  -v        Request sound mode");
				puts("  -g        Request graphics mode");
				puts("  -o        Request original keyset");
				puts("  -r        Request rogue-like keyset");
				puts("  -M        Request monochrome mode");
				puts("  -s<num>   Show <num> high scores");
				puts("  -u<who>   Use your <who> savefile");
				puts("  -d<path>  Store pref files and screendumps in <path>");

#ifdef USE_X11
				puts("  -mx11     To use X11");
				puts("  --        Sub options");
				puts("  -- -d     Set display name");
				puts("  -- -s     Turn off smoothscaling graphics");
				puts("  -- -n#    Number of terms to use");
#endif /* USE_X11 */

#ifdef USE_GCU
				puts("  -mgcu     To use GCU (GNU Curses)");
				puts("  --        Sub options");
				puts("  -- -x     No extra sub-windows");
#endif /* USE_GCU */

#ifdef USE_SLA
				puts("  -msla     To use SLA (SLANG)");
#endif /* USE_SLA */

				/* Actually abort the process */
				quit(NULL);
			}
		}
	}

	/* Process the player name (but only if one is specified) */
	if (strlen(op_ptr->base_name)) process_player_name(FALSE);

	/* Hack -- Forget standard args */
	if (args)
	{
		argc = 1;
		argv[1] = NULL;
	}


	/* Install "quit" hook */
	quit_aux = quit_hook;


	/* Drop privs (so X11 will work correctly) */
 	safe_setuid_drop();

#ifdef USE_X11
	/* Attempt to use the "main-x11.c" support */
	if (!done && (!mstr || (streq(mstr, "x11"))))
	{
		extern errr init_x11(int, char**);
		if (0 == init_x11(argc, argv))
		{
			ANGBAND_SYS = "x11";
			done = TRUE;
		}
	}
#endif

#ifdef USE_GCU
	/* Attempt to use the "main-gcu.c" support */
	if (!done && (!mstr || (streq(mstr, "gcu"))))
	{
		extern errr init_gcu(int, char**);
		if (0 == init_gcu(argc, argv))
		{
			ANGBAND_SYS = "gcu";
			done = TRUE;
		}
	}
#endif

#ifdef USE_SLA
	/* Attempt to use the "main-sla.c" support */
	if (!done && (!mstr || (streq(mstr, "sla"))))
	{
		extern errr init_sla(void);
		if (0 == init_sla())
		{
			ANGBAND_SYS = "sla";
			done = TRUE;
		}
	}
#endif

	/* Grab privs (dropped above for X11) */
 	safe_setuid_grab();

	/* Make sure we have a display! */
	if (!done) quit("Unable to prepare any 'display module'!");

	/* Catch nasty signals */
	signals_init();

	/* Initialize */
	init_angband();

	/* Hack -- If requested, display scores and quit */
	if (show_score > 0)
	{
		show_scores();
		quit(NULL);
	}

	/* Wait for response */
	pause_line(23);

	/* Play the game */
	play_game(new_game);

	/* Quit */
	quit(NULL);

	/* Exit */
	return (0);
}