End of round screen
This commit is contained in:
		
							parent
							
								
									d31defec74
								
							
						
					
					
						commit
						e585551df0
					
				
							
								
								
									
										43
									
								
								dialog.c
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								dialog.c
									
									
									
									
									
								
							| @ -1,4 +1,5 @@ | |||||||
| #include <stddef.h> | #include <stddef.h> | ||||||
|  | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| 
 | 
 | ||||||
| @ -6,7 +7,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "dialog.h" | #include "dialog.h" | ||||||
| 
 | 
 | ||||||
| Dialog dialogs[2]; | Dialog dialogs[6]; | ||||||
| 
 | 
 | ||||||
| void handle_click_cancel_yes(Game *g) { | void handle_click_cancel_yes(Game *g) { | ||||||
|   g->player.dekiyaku_action = DEKIYAKU_ACTION_CANCEL; |   g->player.dekiyaku_action = DEKIYAKU_ACTION_CANCEL; | ||||||
| @ -28,10 +29,15 @@ void handle_click_sage(Game *g) { | |||||||
|   g->state = GAME_STATE_CHOOSING_FROM_HAND; |   g->state = GAME_STATE_CHOOSING_FROM_HAND; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void handle_click_ok_end_of_game(Game *g) { | ||||||
|  |   g->state = GAME_STATE_INITIALIZING; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void init_dialogs(Game *g) { | void init_dialogs(Game *g) { | ||||||
|   Dialog *cancel_dialog = &dialogs[0]; |   Dialog *cancel_dialog = &dialogs[0]; | ||||||
|   cancel_dialog->text = malloc(200); |   cancel_dialog->text_count = 1; | ||||||
|   strcpy(cancel_dialog->text, "Would you like to cancel?"); |   cancel_dialog->text[0] = malloc(200); | ||||||
|  |   strcpy(cancel_dialog->text[0], "Would you like to cancel?"); | ||||||
|   cancel_dialog->text_color = BLACK; |   cancel_dialog->text_color = BLACK; | ||||||
|   cancel_dialog->options_count = 2; |   cancel_dialog->options_count = 2; | ||||||
|   cancel_dialog->game = g; |   cancel_dialog->game = g; | ||||||
| @ -46,10 +52,10 @@ void init_dialogs(Game *g) { | |||||||
|   cancel_dialog->options[1].color = RED; |   cancel_dialog->options[1].color = RED; | ||||||
|   cancel_dialog->options[1].handle = &handle_click_cancel_no; |   cancel_dialog->options[1].handle = &handle_click_cancel_no; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|   Dialog *shoubu_dialog = &dialogs[1]; |   Dialog *shoubu_dialog = &dialogs[1]; | ||||||
|   shoubu_dialog->text = malloc(200); |   shoubu_dialog->text_count = 1; | ||||||
|   strcpy(shoubu_dialog->text, "You have dekiyaku! Sage or shoubu?"); |   shoubu_dialog->text[0] = malloc(200); | ||||||
|  |   strcpy(shoubu_dialog->text[0], "You have dekiyaku! Sage or shoubu?"); | ||||||
|   shoubu_dialog->text_color = BLACK; |   shoubu_dialog->text_color = BLACK; | ||||||
|   shoubu_dialog->options_count = 2; |   shoubu_dialog->options_count = 2; | ||||||
|   shoubu_dialog->game = g; |   shoubu_dialog->game = g; | ||||||
| @ -63,10 +69,28 @@ void init_dialogs(Game *g) { | |||||||
|   strcpy(shoubu_dialog->options[1].text, "Shoubu"); |   strcpy(shoubu_dialog->options[1].text, "Shoubu"); | ||||||
|   shoubu_dialog->options[1].color = RED; |   shoubu_dialog->options[1].color = RED; | ||||||
|   shoubu_dialog->options[1].handle = &handle_click_shoubu; |   shoubu_dialog->options[1].handle = &handle_click_shoubu; | ||||||
|  | 
 | ||||||
|  |   Dialog *no_dekiyaku_end_of_round_dialog = &dialogs[2]; | ||||||
|  |   no_dekiyaku_end_of_round_dialog->text_count = 3; | ||||||
|  |   no_dekiyaku_end_of_round_dialog->text[0] = malloc(200); | ||||||
|  |   no_dekiyaku_end_of_round_dialog->text[1] = malloc(200); | ||||||
|  |   no_dekiyaku_end_of_round_dialog->text[2] = malloc(200); | ||||||
|  |   strcpy(no_dekiyaku_end_of_round_dialog->text[0], "Player score"); | ||||||
|  |   strcpy(no_dekiyaku_end_of_round_dialog->text[1], "Right score"); | ||||||
|  |   strcpy(no_dekiyaku_end_of_round_dialog->text[2], "Left score"); | ||||||
|  |   no_dekiyaku_end_of_round_dialog->text_color = BLACK; | ||||||
|  |   no_dekiyaku_end_of_round_dialog->options_count = 1; | ||||||
|  |   no_dekiyaku_end_of_round_dialog->game = g; | ||||||
|  | 
 | ||||||
|  |   no_dekiyaku_end_of_round_dialog->options[0].text = malloc(50); | ||||||
|  |   strcpy(no_dekiyaku_end_of_round_dialog->options[0].text, "Okay"); | ||||||
|  |   no_dekiyaku_end_of_round_dialog->options[0].color = GREEN; | ||||||
|  |   no_dekiyaku_end_of_round_dialog->options[0].handle = &handle_click_ok_end_of_game; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void cancel_dialog(Game *g) { g->dialog = &dialogs[0]; } | void cancel_dialog(Game *g) { g->dialog = &dialogs[0]; } | ||||||
| void shoubu_dialog(Game *g) { g->dialog = &dialogs[1]; } | void shoubu_dialog(Game *g) { g->dialog = &dialogs[1]; } | ||||||
|  | void no_dekiyaku_end_of_round_dialog(Game *g) { g->dialog = &dialogs[2]; } | ||||||
| 
 | 
 | ||||||
| Rectangle dialog_option_outer_rectangle(Dialog *d, int i) { | Rectangle dialog_option_outer_rectangle(Dialog *d, int i) { | ||||||
|   return (Rectangle) { |   return (Rectangle) { | ||||||
| @ -91,8 +115,11 @@ void dialog_draw(Dialog *d) { | |||||||
|   int text_width; |   int text_width; | ||||||
|   DrawRectangleRec(DIALOG_OUTER_RECTANGLE, BLACK); |   DrawRectangleRec(DIALOG_OUTER_RECTANGLE, BLACK); | ||||||
|   DrawRectangleRec(DIALOG_INNER_RECTANGLE, WHITE); |   DrawRectangleRec(DIALOG_INNER_RECTANGLE, WHITE); | ||||||
|   text_width = MeasureText(d->text, DIALOG_TEXT_FONT_SIZE); | 
 | ||||||
|   DrawText(d->text, 700 - (text_width / 2), 400, DIALOG_TEXT_FONT_SIZE, d->text_color); |   for (int i = 0; i < d->text_count; i++) { | ||||||
|  |     text_width = MeasureText(d->text[i], DIALOG_TEXT_FONT_SIZE); | ||||||
|  |     DrawText(d->text[i], 700 - (text_width / 2), 300 + (70 * (i - 1)), DIALOG_TEXT_FONT_SIZE, d->text_color); | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   for (int i = 0; i < d->options_count; i++) { |   for (int i = 0; i < d->options_count; i++) { | ||||||
|     DialogOption *o = &d->options[i]; |     DialogOption *o = &d->options[i]; | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								dialog.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								dialog.h
									
									
									
									
									
								
							| @ -18,7 +18,8 @@ struct DialogOption { | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| struct Dialog { | struct Dialog { | ||||||
|   char *text; |   char *text[3]; | ||||||
|  |   int text_count; | ||||||
|   Color text_color; |   Color text_color; | ||||||
|   DialogOption options[3]; |   DialogOption options[3]; | ||||||
|   int options_count; |   int options_count; | ||||||
| @ -28,6 +29,7 @@ struct Dialog { | |||||||
| void init_dialogs(Game *g); | void init_dialogs(Game *g); | ||||||
| void cancel_dialog(Game *g); | void cancel_dialog(Game *g); | ||||||
| void shoubu_dialog(Game *g); | void shoubu_dialog(Game *g); | ||||||
|  | void no_dekiyaku_end_of_round_dialog(Game *g); | ||||||
| void dialog_draw(Dialog *d); | void dialog_draw(Dialog *d); | ||||||
| void dialog_handle_input(Dialog *d); | void dialog_handle_input(Dialog *d); | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										27
									
								
								game.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								game.c
									
									
									
									
									
								
							| @ -72,9 +72,9 @@ void initialize_game(Game *g) { | |||||||
|     g->cards[i].selected = false; |     g->cards[i].selected = false; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   g->player.points = 10 * g->kan_value; |   g->player.points = 100 * g->kan_value; | ||||||
|   g->right.points = 10 * g->kan_value; |   g->right.points = 100 * g->kan_value; | ||||||
|   g->left.points = 10 * g->kan_value; |   g->left.points = 100 * g->kan_value; | ||||||
|   g->player.points_string[0] = '\0'; |   g->player.points_string[0] = '\0'; | ||||||
|   g->right.points_string[0] = '\0'; |   g->right.points_string[0] = '\0'; | ||||||
|   g->left.points_string[0] = '\0'; |   g->left.points_string[0] = '\0'; | ||||||
| @ -153,11 +153,13 @@ void handle_input(Game *g) { | |||||||
|     g->state = GAME_STATE_INITIALIZING; |     g->state = GAME_STATE_INITIALIZING; | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   if (!is_player_turn(g)) return; | 
 | ||||||
|   if (g->dialog) { |   if (g->dialog) { | ||||||
|     return dialog_handle_input(g->dialog); |     return dialog_handle_input(g->dialog); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   if (!is_player_turn(g)) return; | ||||||
|  | 
 | ||||||
|   switch (g->state) { |   switch (g->state) { | ||||||
|   case GAME_STATE_CHOOSING_FROM_HAND: |   case GAME_STATE_CHOOSING_FROM_HAND: | ||||||
|     if (IsMouseButtonPressed(0)) { |     if (IsMouseButtonPressed(0)) { | ||||||
| @ -310,8 +312,8 @@ void run_frame_initializing(Game *g) { | |||||||
|     add_to_hand(&g->deck, c); |     add_to_hand(&g->deck, c); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // shuffle_hand(&g->deck);
 |   shuffle_hand(&g->deck); | ||||||
|   order_deck(&g->deck); |   // order_deck(&g->deck);
 | ||||||
| 
 | 
 | ||||||
|   kan_points_string(g, g->player.points, g->player.points_string); |   kan_points_string(g, g->player.points, g->player.points_string); | ||||||
|   kan_points_string(g, g->right.points, g->right.points_string); |   kan_points_string(g, g->right.points, g->right.points_string); | ||||||
| @ -534,23 +536,26 @@ void run_frame_selecting_dekiyaku_action(Game *g) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void run_frame_calculating_scores(Game *g) { | void run_frame_calculating_scores(Game *g) { | ||||||
|  |   no_dekiyaku_end_of_round_dialog(g); | ||||||
|  | 
 | ||||||
|   int hp[3]; |   int hp[3]; | ||||||
|   hp[0] = hand_points(&g->player.scored); |   hp[0] = hand_points(&g->player.scored); | ||||||
|   hp[1] = hand_points(&g->right.scored); |   hp[1] = hand_points(&g->right.scored); | ||||||
|   hp[2] = hand_points(&g->left.scored); |   hp[2] = hand_points(&g->left.scored); | ||||||
|   printf("Hand scores: %d %d %d\n", hp[0], hp[1], hp[2]); |  | ||||||
| 
 | 
 | ||||||
|   SpecialCase special_case = calculate_special_case(g); |   SpecialCase special_case = calculate_special_case(g); | ||||||
|   switch(special_case.type) { |   switch(special_case.type) { | ||||||
|   case SPECIAL_CASE_ALL_EIGHTS: |   case SPECIAL_CASE_ALL_EIGHTS: | ||||||
|     printf("All eights! Dealer gets %d kan\n", special_case.score); |     sprintf(g->dialog->text[0], "All eights!"); | ||||||
|  |     sprintf(g->dialog->text[0], "Dealer gets %d kan", special_case.score); | ||||||
|     transfer_kan(g, &g->dealer->points, &g->player.points, special_case.score); |     transfer_kan(g, &g->dealer->points, &g->player.points, special_case.score); | ||||||
|     transfer_kan(g, &g->dealer->points, &g->right.points, special_case.score); |     transfer_kan(g, &g->dealer->points, &g->right.points, special_case.score); | ||||||
|     transfer_kan(g, &g->dealer->points, &g->left.points, special_case.score); |     transfer_kan(g, &g->dealer->points, &g->left.points, special_case.score); | ||||||
|     break; |     break; | ||||||
|   case SPECIAL_CASE_DOUBLE_EIGHTS: |   case SPECIAL_CASE_DOUBLE_EIGHTS: | ||||||
|   case SPECIAL_CASE_SIXTEEN_CHAFF: |   case SPECIAL_CASE_SIXTEEN_CHAFF: | ||||||
|     printf("Double eights or 16 chaff! Player %d gets %d kan\n", special_case.target, special_case.score); |     sprintf(g->dialog->text[0], "Double eights or 16 chaff!"); | ||||||
|  |     sprintf(g->dialog->text[1], "Player %d gets %d kan\n", special_case.target, special_case.score); | ||||||
|     switch (special_case.target) { |     switch (special_case.target) { | ||||||
|     case SPECIAL_CASE_TARGET_PLAYER: |     case SPECIAL_CASE_TARGET_PLAYER: | ||||||
|       transfer_kan(g, &g->player.points, &g->right.points, special_case.score); |       transfer_kan(g, &g->player.points, &g->right.points, special_case.score); | ||||||
| @ -570,6 +575,9 @@ void run_frame_calculating_scores(Game *g) { | |||||||
|     } |     } | ||||||
|     break; |     break; | ||||||
|   default: |   default: | ||||||
|  |     sprintf(g->dialog->text[0], "Player score: %d", hp[0]); | ||||||
|  |     sprintf(g->dialog->text[1], "Right score: %d", hp[1]); | ||||||
|  |     sprintf(g->dialog->text[2], "Left score: %d", hp[2]); | ||||||
|     transfer_points(g, &g->player.points, &g->temp_points, hp[0]); |     transfer_points(g, &g->player.points, &g->temp_points, hp[0]); | ||||||
|     transfer_points(g, &g->right.points, &g->temp_points, hp[1]); |     transfer_points(g, &g->right.points, &g->temp_points, hp[1]); | ||||||
|     transfer_points(g, &g->left.points, &g->temp_points, hp[2]); |     transfer_points(g, &g->left.points, &g->temp_points, hp[2]); | ||||||
| @ -584,7 +592,6 @@ void run_frame_calculating_scores(Game *g) { | |||||||
|     } |     } | ||||||
|     break; |     break; | ||||||
|   } |   } | ||||||
|   g->state = GAME_STATE_INITIALIZING; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void run_frame_calculating_dekiyaku_score(Game *g) { | void run_frame_calculating_dekiyaku_score(Game *g) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user