Name-spaced functions for frame.
This commit is contained in:
		
							parent
							
								
									bc6b04eb36
								
							
						
					
					
						commit
						955f2fbc90
					
				
							
								
								
									
										12
									
								
								src/card.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/card.c
									
									
									
									
									
								
							| @ -11,18 +11,18 @@ void card_malloc(struct card **card) { | |||||||
|     fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__)); |     fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__)); | ||||||
|     exit(errno); |     exit(errno); | ||||||
|   } |   } | ||||||
|   allocate_frame(&((*card)->frame)); |   frame_malloc(&((*card)->frame)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void card_init(struct card *card) { | void card_init(struct card *card) { | ||||||
|   initialize_frame(card->frame); |   frame_init(card->frame); | ||||||
|   card->value = NO_VALUE; |   card->value = NO_VALUE; | ||||||
|   card->suit = NO_SUIT; |   card->suit = NO_SUIT; | ||||||
|   card->face = NO_FACE; |   card->face = NO_FACE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void card_free(struct card *card) { | void card_free(struct card *card) { | ||||||
|   free_frame(card->frame); |   frame_free(card->frame); | ||||||
|   free(card); |   free(card); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -32,7 +32,7 @@ void card_set(struct card *card, | |||||||
|               enum face face, |               enum face face, | ||||||
|               int begin_y, |               int begin_y, | ||||||
|               int begin_x) { |               int begin_x) { | ||||||
|   set_frame(card->frame, begin_y, begin_x); |   frame_set(card->frame, begin_y, begin_x); | ||||||
|   card->value = value; |   card->value = value; | ||||||
|   card->suit = suit; |   card->suit = suit; | ||||||
|   card->face = face; |   card->face = face; | ||||||
| @ -47,11 +47,11 @@ void card_cover(struct card *card) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void card_mark(struct card *card) { | void card_mark(struct card *card) { | ||||||
|   set_frame(card->frame, card->frame->begin_y + 1, card->frame->begin_x); |   frame_set(card->frame, card->frame->begin_y + 1, card->frame->begin_x); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void card_unmark(struct card *card) { | void card_unmark(struct card *card) { | ||||||
|   set_frame(card->frame, card->frame->begin_y - 1, card->frame->begin_x); |   frame_set(card->frame, card->frame->begin_y - 1, card->frame->begin_x); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct card *card_dup(struct card *card) { | struct card *card_dup(struct card *card) { | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								src/frame.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/frame.c
									
									
									
									
									
								
							| @ -6,7 +6,7 @@ | |||||||
| #include "frame.h" | #include "frame.h" | ||||||
| #include "common.h" | #include "common.h" | ||||||
| 
 | 
 | ||||||
| void allocate_frame(struct frame **frame) { | void frame_malloc(struct frame **frame) { | ||||||
|   if (!(*frame = malloc(sizeof(**frame)))) { |   if (!(*frame = malloc(sizeof(**frame)))) { | ||||||
|     fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__)); |     fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__)); | ||||||
|     exit(errno); |     exit(errno); | ||||||
| @ -14,27 +14,27 @@ void allocate_frame(struct frame **frame) { | |||||||
|   (*frame)->window = newwin(FRAME_HEIGHT, FRAME_WIDTH, 0, 0); |   (*frame)->window = newwin(FRAME_HEIGHT, FRAME_WIDTH, 0, 0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void initialize_frame(struct frame *frame) { | void frame_init(struct frame *frame) { | ||||||
|   frame->begin_y = 0; |   frame->begin_y = 0; | ||||||
|   frame->begin_x = 0; |   frame->begin_x = 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void free_frame(struct frame *frame) { | void frame_free(struct frame *frame) { | ||||||
|   delwin(frame->window); |   delwin(frame->window); | ||||||
|   free(frame); |   free(frame); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void set_frame(struct frame *frame, int begin_y, int begin_x) { | void frame_set(struct frame *frame, int begin_y, int begin_x) { | ||||||
|   frame->begin_y = begin_y; |   frame->begin_y = begin_y; | ||||||
|   frame->begin_x = begin_x; |   frame->begin_x = begin_x; | ||||||
|   mvwin(frame->window, begin_y, begin_x); |   mvwin(frame->window, begin_y, begin_x); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct frame *duplicate_frame(struct frame *frame) { | struct frame *frame_dup(struct frame *frame) { | ||||||
|   struct frame *new_frame; |   struct frame *new_frame; | ||||||
| 
 | 
 | ||||||
|   allocate_frame(&new_frame); |   frame_malloc(&new_frame); | ||||||
|   set_frame(new_frame, frame->begin_y, frame->begin_x); |   frame_set(new_frame, frame->begin_y, frame->begin_x); | ||||||
| 
 | 
 | ||||||
|   return(new_frame); |   return(new_frame); | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								src/frame.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/frame.h
									
									
									
									
									
								
							| @ -12,10 +12,10 @@ struct frame { | |||||||
|   int    begin_x; |   int    begin_x; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| void allocate_frame(struct frame **); | void frame_malloc(struct frame **); | ||||||
| void initialize_frame(struct frame *); | void frame_init(struct frame *); | ||||||
| void free_frame(struct frame *); | void frame_free(struct frame *); | ||||||
| void set_frame(struct frame *, int, int); | void frame_set(struct frame *, int, int); | ||||||
| struct frame *duplicate_frame(struct frame *); | struct frame *frame_dup(struct frame *); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								src/game.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/game.c
									
									
									
									
									
								
							| @ -110,7 +110,7 @@ void move_card(struct stack **origin, struct stack **destination) { | |||||||
|       destination_y++; |       destination_y++; | ||||||
|     } |     } | ||||||
|     stack_push(destination, tmp); |     stack_push(destination, tmp); | ||||||
|     set_frame((*destination)->card->frame, destination_y, destination_x); |     frame_set((*destination)->card->frame, destination_y, destination_x); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -184,13 +184,13 @@ void game_init() { | |||||||
|   deck_init(deck); |   deck_init(deck); | ||||||
| 
 | 
 | ||||||
|   /* Setting initial stacks' coordinates. */ |   /* Setting initial stacks' coordinates. */ | ||||||
|   set_frame(deck->stock->card->frame, STOCK_BEGIN_Y, STOCK_BEGIN_X); |   frame_set(deck->stock->card->frame, STOCK_BEGIN_Y, STOCK_BEGIN_X); | ||||||
|   set_frame(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++) { |   for (int i = 0; i < FOUNDATION_STACKS_NUMBER; i++) { | ||||||
|     set_frame(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++) { |   for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) { | ||||||
|     set_frame(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)); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   fill_deck(deck); |   fill_deck(deck); | ||||||
|  | |||||||
| @ -2,48 +2,48 @@ | |||||||
| #include "test_helper.h" | #include "test_helper.h" | ||||||
| #include "../src/frame.h" | #include "../src/frame.h" | ||||||
| 
 | 
 | ||||||
| void test_initialize_frame() { | void test_frame_init() { | ||||||
|   struct frame *frame; |   struct frame *frame; | ||||||
| 
 | 
 | ||||||
|   allocate_frame(&frame); |   frame_malloc(&frame); | ||||||
|   initialize_frame(frame); |   frame_init(frame); | ||||||
| 
 | 
 | ||||||
|   assert(frame->window == NULL); |   assert(frame->window == NULL); | ||||||
|   assert(frame->begin_y == 0); |   assert(frame->begin_y == 0); | ||||||
|   assert(frame->begin_x == 0); |   assert(frame->begin_x == 0); | ||||||
| 
 | 
 | ||||||
|   free_frame(frame); |   frame_free(frame); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void test_duplicate_frame() { | void test_frame_dup() { | ||||||
|   struct frame *frame_0, *frame_1; |   struct frame *frame_0, *frame_1; | ||||||
|   const int begin_y = 5, begin_x = 10; |   const int begin_y = 5, begin_x = 10; | ||||||
| 
 | 
 | ||||||
|   allocate_frame(&frame_0); |   frame_malloc(&frame_0); | ||||||
|   set_frame(frame_0, begin_y, begin_x); |   frame_set(frame_0, begin_y, begin_x); | ||||||
|   frame_1 = duplicate_frame(frame_0); |   frame_1 = frame_dup(frame_0); | ||||||
| 
 | 
 | ||||||
|   assert(frame_0 != frame_1); |   assert(frame_0 != frame_1); | ||||||
|   assert(frames_equal(frame_0, frame_1)); |   assert(frames_equal(frame_0, frame_1)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void test_set_frame() { | void test_frame_set() { | ||||||
|   struct frame *frame; |   struct frame *frame; | ||||||
|   int begin_y = 5; |   int begin_y = 5; | ||||||
|   int begin_x = 10; |   int begin_x = 10; | ||||||
| 
 | 
 | ||||||
|   allocate_frame(&frame); |   frame_malloc(&frame); | ||||||
|   initialize_frame(frame); |   frame_init(frame); | ||||||
|   set_frame(frame, begin_y, begin_x); |   frame_set(frame, begin_y, begin_x); | ||||||
| 
 | 
 | ||||||
|   assert(frame->begin_y == begin_y); |   assert(frame->begin_y == begin_y); | ||||||
|   assert(frame->begin_x == begin_x); |   assert(frame->begin_x == begin_x); | ||||||
| 
 | 
 | ||||||
|   free_frame(frame); |   frame_free(frame); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void test_frame() { | void test_frame() { | ||||||
|   test_initialize_frame(); |   test_frame_init(); | ||||||
|   test_duplicate_frame(); |   test_frame_dup(); | ||||||
|   test_set_frame(); |   test_frame_set(); | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ void test_frames_equal_with_two_nulls() { | |||||||
| void test_frames_equal_with_one_null() { | void test_frames_equal_with_one_null() { | ||||||
|   struct frame *frame; |   struct frame *frame; | ||||||
| 
 | 
 | ||||||
|   allocate_frame(&frame); |   frame_malloc(&frame); | ||||||
|   assert(!frames_equal(frame, NULL)); |   assert(!frames_equal(frame, NULL)); | ||||||
|   assert(!frames_equal(NULL, frame)); |   assert(!frames_equal(NULL, frame)); | ||||||
| } | } | ||||||
| @ -17,10 +17,10 @@ void test_frames_equal_with_two_equivalent_frames() { | |||||||
|   struct frame *frame_0, *frame_1; |   struct frame *frame_0, *frame_1; | ||||||
|   const int begin_y = 5, begin_x = 10; |   const int begin_y = 5, begin_x = 10; | ||||||
| 
 | 
 | ||||||
|   allocate_frame(&frame_0); |   frame_malloc(&frame_0); | ||||||
|   allocate_frame(&frame_1); |   frame_malloc(&frame_1); | ||||||
|   set_frame(frame_0, begin_y, begin_x); |   frame_set(frame_0, begin_y, begin_x); | ||||||
|   set_frame(frame_1, begin_y, begin_x); |   frame_set(frame_1, begin_y, begin_x); | ||||||
| 
 | 
 | ||||||
|   assert(frames_equal(frame_0, frame_1)); |   assert(frames_equal(frame_0, frame_1)); | ||||||
| } | } | ||||||
| @ -28,7 +28,7 @@ void test_frames_equal_with_two_equivalent_frames() { | |||||||
| void test_frames_equal_with_two_frame_pointers_to_the_same_address() { | void test_frames_equal_with_two_frame_pointers_to_the_same_address() { | ||||||
|   struct frame *frame; |   struct frame *frame; | ||||||
| 
 | 
 | ||||||
|   allocate_frame(&frame); |   frame_malloc(&frame); | ||||||
| 
 | 
 | ||||||
|   assert(frames_equal(frame, frame)); |   assert(frames_equal(frame, frame)); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user