示例#1
0
int main(void)
{
	WINDOW *mainw; /* An NCurses window to draw on. */
	Pile *deck; /* A deck of cards. */

	setlocale(LC_ALL, ""); /* Important for UTF-8 to print properly. */
	srandom(time(NULL)); /* Need to seed RNG for shuffling. */

	deck = standard_deck(1); /* Create a 52 card deck (1 copy). */
	shuffle_pile(&deck, &random); /* Shuffle it using standard random() */

	/* Init NCurses and setup a colour for printing our stuff. */
    if(!initscr() || start_color() == ERR)
		return 1;
	init_pair(1, COLOR_WHITE, COLOR_BLACK);
	mainw = newwin(24,80,0,0);
	clicards_init_ncurses(); /* This call to make colours work right. */
	refresh();
	flushinp();

	wattrset(mainw, COLOR_PAIR(1));
	wprintw(mainw, "%i cards:\n", num_cards(deck));
	wprint_pile(deck, mainw); /* Print the shuffled deck. */
	wrefresh(mainw);
	getch(); /* Allow user to see it before closing. */
	delwin(mainw);
	endwin(); /* Close NCurses session. */

	free_pile(deck); /* Free up memory used by deck. */
	return 0;
}
示例#2
0
int		launch_solve_by_length(t_case *root)
{
  t_link	*last;
  t_link	*root_pile;
  char		go_back;

  if (!(last = init_pile_root(root->next)))
    return (1);
  root_pile = last;
  go_back = 0;
  while (last)
    {
      last->cas->path = 1;
      if (last->cas->next == root)
	return (free_pile(root_pile), 0);
      if (add_to_pile(&go_back, &last))
	return (1);
      if (go_back)
	{
	  remove_from_pile(&last);
	  go_back = 0;
	}
    }
  return (2);
}
示例#3
0
int main(void)
{
	WINDOW *mainw;
	Pile *deck, *plr_hand, *cpu_hand, *tmp;
	int input, num;
	char change[5];

	setlocale(LC_ALL, "");
	srandom(time(NULL));

	deck = standard_deck(1);

    if(!initscr() || start_color() == ERR)
		return 1;
	noecho();
	init_pair(1, COLOR_WHITE, COLOR_BLACK);
	mainw = newwin(5,48,0,0);
	clicards_init_ncurses();
	refresh();
	flushinp();

	for(;;)
	{
		for(input = 0; input < 5; ++input)
			change[input] = 0;
		shuffle_pile(&deck, &random);
		plr_hand = draw_n_cards(&deck, 5);
		cpu_hand = draw_n_cards(&deck, 5);
		tmp = NULL;
		wattrset(mainw, COLOR_PAIR(1));
		wclear(mainw);
		waddstr(mainw, "Your hand: ");
		wprint_pile(plr_hand, mainw);
		waddstr(mainw, "\n           0  1  2  3  4\n"
			"Select cards to change, 'd' when done.");
		wrefresh(mainw);
		while(tolower(input = getch()) != 'd')
		{
			if(input >= '0' && input <= '4')
			{
				input -= '0';
				change[input] = !change[input];
				wmove(mainw, 1, 12+input*3);
				waddch(mainw, change[input] ? '*' : ' ');
				wrefresh(mainw);
			}
		}
		for(input = num = 0; input < 5; ++input)
		{
			if(change[input])
			{
				add_pile_to_pile(&tmp, nth_card(&plr_hand, input-num));
				++num;
			}
		}
		if(num)
			add_pile_to_pile(&plr_hand, draw_n_cards(&deck, num));
		sort_pile(&plr_hand, 0, 1);
		mvprint_pile(plr_hand, mainw, 11, 0);
		wmove(mainw, 1, 0);
		wclrtoeol(mainw);
		wmove(mainw, 2, 0);
		waddstr(mainw, "Computer's hand: ");
		sort_pile(&cpu_hand, 0, 1);
		wprint_pile(cpu_hand, mainw);
		wclrtoeol(mainw);
		waddstr(mainw, "\nHit 'q' to quit or any other key to deal again.");
		add_pile_to_pile(&deck, tmp);
		add_pile_to_pile(&deck, plr_hand);
		add_pile_to_pile(&deck, cpu_hand);
		wrefresh(mainw);
		if(getch() == 'q')
			break;
	}
	delwin(mainw);
	endwin();
	free_pile(deck);
	return 0;
}