Make "--colors" be "four-color-deck".
Also, some automatic file formatting with LSP via LLVM.
This commit is contained in:
		
							parent
							
								
									87619ed80a
								
							
						
					
					
						commit
						2fe7075946
					
				
							
								
								
									
										2
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								README
									
									
									
									
									
								
							| @ -84,7 +84,7 @@ | ||||
|      -v, --version              Show version | ||||
|      -h, --help                 Show this message | ||||
|      -p, --passes               Number of passes through the deck  (default: 3) | ||||
|      -c, --colors               Unique colors for each suit        (default: false) | ||||
|          --four-color-deck      Draw unique card suit colors       (default: false) | ||||
|          --no-background-color  Don't draw background color        (default: false) | ||||
|    #+end_src | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										66
									
								
								src/game.c
									
									
									
									
									
								
							
							
						
						
									
										66
									
								
								src/game.c
									
									
									
									
									
								
							| @ -1,24 +1,28 @@ | ||||
| #include <assert.h> | ||||
| #include <errno.h> | ||||
| #include <stdbool.h> | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <stdbool.h> | ||||
| #include <errno.h> | ||||
| #include <time.h> | ||||
| #include <assert.h> | ||||
| 
 | ||||
| #include "game.h" | ||||
| #include "card.h" | ||||
| #include "stack.h" | ||||
| #include "deck.h" | ||||
| #include "gui.h" | ||||
| #include "cursor.h" | ||||
| #include "common.h" | ||||
| #include "cursor.h" | ||||
| #include "deck.h" | ||||
| #include "game.h" | ||||
| #include "gui.h" | ||||
| #include "stack.h" | ||||
| 
 | ||||
| static int foundation_begin_x(int x) { | ||||
|   switch (x) { | ||||
|   case 0: return(FOUNDATION_0_BEGIN_X); | ||||
|   case 1: return(FOUNDATION_1_BEGIN_X); | ||||
|   case 2: return(FOUNDATION_2_BEGIN_X); | ||||
|   case 3: return(FOUNDATION_3_BEGIN_X); | ||||
|   case 0: | ||||
|     return (FOUNDATION_0_BEGIN_X); | ||||
|   case 1: | ||||
|     return (FOUNDATION_1_BEGIN_X); | ||||
|   case 2: | ||||
|     return (FOUNDATION_2_BEGIN_X); | ||||
|   case 3: | ||||
|     return (FOUNDATION_3_BEGIN_X); | ||||
|   default: | ||||
|     endwin(); | ||||
|     game_end(); | ||||
| @ -28,13 +32,20 @@ static int foundation_begin_x(int x) { | ||||
| 
 | ||||
| static int maneuvre_begin_x(int x) { | ||||
|   switch (x) { | ||||
|   case 0: return(MANEUVRE_0_BEGIN_X); | ||||
|   case 1: return(MANEUVRE_1_BEGIN_X); | ||||
|   case 2: return(MANEUVRE_2_BEGIN_X); | ||||
|   case 3: return(MANEUVRE_3_BEGIN_X); | ||||
|   case 4: return(MANEUVRE_4_BEGIN_X); | ||||
|   case 5: return(MANEUVRE_5_BEGIN_X); | ||||
|   case 6: return(MANEUVRE_6_BEGIN_X); | ||||
|   case 0: | ||||
|     return (MANEUVRE_0_BEGIN_X); | ||||
|   case 1: | ||||
|     return (MANEUVRE_1_BEGIN_X); | ||||
|   case 2: | ||||
|     return (MANEUVRE_2_BEGIN_X); | ||||
|   case 3: | ||||
|     return (MANEUVRE_3_BEGIN_X); | ||||
|   case 4: | ||||
|     return (MANEUVRE_4_BEGIN_X); | ||||
|   case 5: | ||||
|     return (MANEUVRE_5_BEGIN_X); | ||||
|   case 6: | ||||
|     return (MANEUVRE_6_BEGIN_X); | ||||
|   default: | ||||
|     endwin(); | ||||
|     game_end(); | ||||
| @ -113,7 +124,8 @@ void move_card(struct stack **origin, struct stack **destination) { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void move_block(struct stack **origin, struct stack **destination, int block_size) { | ||||
| void move_block(struct stack **origin, struct stack **destination, | ||||
|                 int block_size) { | ||||
|   struct stack *tmp; | ||||
|   stack_malloc(&tmp); | ||||
|   stack_init(tmp); | ||||
| @ -175,7 +187,8 @@ static void deal_cards(struct deck *deck) { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void game_init(struct game *game, int passes_through_deck, int color_mode) { | ||||
| void game_init(struct game *game, int passes_through_deck, | ||||
|                int four_color_deck) { | ||||
|   cursor_malloc(&cursor); | ||||
|   cursor_init(cursor); | ||||
|   deck_malloc(&deck); | ||||
| @ -183,15 +196,18 @@ void game_init(struct game *game, int passes_through_deck, int color_mode) { | ||||
| 
 | ||||
|   /* Setting initial stacks' coordinates. */ | ||||
|   frame_set(deck->stock->card->frame, STOCK_BEGIN_Y, STOCK_BEGIN_X); | ||||
|   frame_set(deck->waste_pile->card->frame, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X); | ||||
|   frame_set(deck->waste_pile->card->frame, WASTE_PILE_BEGIN_Y, | ||||
|             WASTE_PILE_BEGIN_X); | ||||
|   for (int i = 0; i < FOUNDATION_STACKS_NUMBER; i++) { | ||||
|     frame_set(deck->foundation[i]->card->frame, FOUNDATION_BEGIN_Y, foundation_begin_x(i)); | ||||
|     frame_set(deck->foundation[i]->card->frame, FOUNDATION_BEGIN_Y, | ||||
|               foundation_begin_x(i)); | ||||
|   } | ||||
|   for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) { | ||||
|     frame_set(deck->maneuvre[i]->card->frame, MANEUVRE_BEGIN_Y, maneuvre_begin_x(i)); | ||||
|     frame_set(deck->maneuvre[i]->card->frame, MANEUVRE_BEGIN_Y, | ||||
|               maneuvre_begin_x(i)); | ||||
|   } | ||||
| 
 | ||||
|   game->color_mode = color_mode; | ||||
|   game->four_color_deck = four_color_deck; | ||||
| 
 | ||||
|   fill_deck(deck); | ||||
|   shuffle_deck(deck); | ||||
|  | ||||
| @ -32,7 +32,7 @@ | ||||
| 
 | ||||
| struct game { | ||||
|   int passes_through_deck_left; | ||||
|   int color_mode; | ||||
|   int four_color_deck; | ||||
| }; | ||||
| 
 | ||||
| struct deck *deck; | ||||
|  | ||||
							
								
								
									
										25
									
								
								src/gui.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/gui.c
									
									
									
									
									
								
							| @ -1,28 +1,25 @@ | ||||
| #include <ncurses.h> | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <ncurses.h> | ||||
| 
 | ||||
| #include "gui.h" | ||||
| #include "card.h" | ||||
| #include "deck.h" | ||||
| #include "game.h" | ||||
| #include "card.h" | ||||
| #include "gui.h" | ||||
| 
 | ||||
| static const char *card_suits[4] = {"\u2666", "\u2660", "\u2665", "\u2663"}; | ||||
| static const char *card_values[13] = { | ||||
|   "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" | ||||
| }; | ||||
| static const char *card_values[13] = {"A", "2", "3",  "4", "5", "6", "7", | ||||
|                                       "8", "9", "10", "J", "Q", "K"}; | ||||
| 
 | ||||
| static void draw_value(struct card *card) { | ||||
|   mvwprintw(card->frame->window, 0, 0, card_values[card->value]); | ||||
|   mvwprintw(card->frame->window, | ||||
|             4, | ||||
|             7 - strlen(card_values[card->value]), | ||||
|   mvwprintw(card->frame->window, 4, 7 - strlen(card_values[card->value]), | ||||
|             card_values[card->value]); | ||||
| } | ||||
| 
 | ||||
| static void draw_suit(struct card *card) { | ||||
|   if (game.color_mode == 0) { | ||||
|   if (game.four_color_deck == 0) { | ||||
|     if (card->suit % 2 == 0) { | ||||
|       wattron(card->frame->window, COLOR_PAIR(RED_ON_WHITE)); | ||||
|     } else { | ||||
| @ -45,13 +42,9 @@ static void draw_suit(struct card *card) { | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
|   mvwprintw(card->frame->window, | ||||
|             0, | ||||
|             strlen(card_values[card->value]), | ||||
|   mvwprintw(card->frame->window, 0, strlen(card_values[card->value]), | ||||
|             card_suits[card->suit]); | ||||
|   mvwprintw(card->frame->window, | ||||
|             4, | ||||
|             6 - strlen(card_values[card->value]), | ||||
|   mvwprintw(card->frame->window, 4, 6 - strlen(card_values[card->value]), | ||||
|             card_suits[card->suit]); | ||||
|   if (card->suit % 2 == 0) { | ||||
|     wattroff(card->frame->window, COLOR_PAIR(RED_ON_WHITE)); | ||||
|  | ||||
| @ -23,13 +23,13 @@ int main(int argc, char *argv[]) { | ||||
|   int option; | ||||
|   int option_index; | ||||
|   int passes_through_deck = 3; | ||||
|   int color_mode = 0; | ||||
|   static int four_color_deck; | ||||
|   static int no_background_color; | ||||
|   static const struct option options[] = { | ||||
|       {"help", no_argument, NULL, 'h'}, | ||||
|       {"version", no_argument, NULL, 'v'}, | ||||
|       {"passes", required_argument, NULL, 'p'}, | ||||
|       {"colors", no_argument, NULL, 'c'}, | ||||
|       {"four-color-deck", no_argument, &four_color_deck, 1}, | ||||
|       {"no-background-color", no_argument, &no_background_color, 1}, | ||||
|       {0, 0, 0, 0}}; | ||||
| 
 | ||||
| @ -44,12 +44,13 @@ int main(int argc, char *argv[]) { | ||||
|     case 'p': | ||||
|       passes_through_deck = atoi(optarg); | ||||
|       break; | ||||
|     case 'c': | ||||
|       color_mode = 1; | ||||
|       break; | ||||
|     case 'h': | ||||
|     case '?': | ||||
|       usage(program_name); | ||||
|       exit(0); | ||||
|     case 0: | ||||
|       /* If this option set a "no_argument" flag, do nothing else now. */ | ||||
|       printf("options[option_index].name: %s\n", options[option_index].name); | ||||
|       if (options[option_index].flag != 0) | ||||
|         break; | ||||
|     default: | ||||
| @ -106,7 +107,7 @@ int main(int argc, char *argv[]) { | ||||
|       if (key == KEY_SPACEBAR) { | ||||
|         clear(); | ||||
|         refresh(); | ||||
|         game_init(&game, passes_through_deck, color_mode); | ||||
|         game_init(&game, passes_through_deck, four_color_deck); | ||||
|         break; | ||||
|       } | ||||
|     } else if (key == KEY_RESIZE) { | ||||
| @ -142,7 +143,8 @@ void usage(const char *program_name) { | ||||
|   printf("  -h, --help                 Show this message\n"); | ||||
|   printf("  -p, --passes               Number of passes through the deck  " | ||||
|          "(default: 3)\n"); | ||||
|   printf("  -c, --colors               Unique colors for each suit\n"); | ||||
|   printf("      --four-color-deck      Draw unique card suit colors       " | ||||
|          "(default: false)\n"); | ||||
|   printf("      --no-background-color  Don't draw background color        " | ||||
|          "(default: false)\n"); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user