Compare commits
	
		
			2 Commits
		
	
	
		
			9701cc9e61
			...
			08c5c08669
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 08c5c08669 | |||
| b13bc3a7bb | 
							
								
								
									
										86
									
								
								game.c
									
									
									
									
									
								
							
							
						
						
									
										86
									
								
								game.c
									
									
									
									
									
								
							| @ -53,10 +53,10 @@ void initialize_game(Game *g) { | |||||||
|     case 41: |     case 41: | ||||||
|       t = ANIMAL; break; |       t = ANIMAL; break; | ||||||
|     } |     } | ||||||
|     g->cards[i] = (Card) { i, t, rt, month, { 800, 100 }, false, false }; |     g->cards[i] = (Card) { i, t, rt, month, { 800, 100 }, false }; | ||||||
|     g->cards[i].move.end_time = 0.; |     g->cards[i].move.end_time = 0.; | ||||||
|     g->cards[i].move.position = &g->cards[i].position; |     g->cards[i].move.position = &g->cards[i].position; | ||||||
|     g->cards[i].move.destination = (Vector2) { 800, 300 }; |     g->cards[i].move.destination = (Vector2) { 800, 400 }; | ||||||
|     g->deck.cards[i] = &g->cards[i]; |     g->deck.cards[i] = &g->cards[i]; | ||||||
|     g->deck.count++; |     g->deck.count++; | ||||||
|   } |   } | ||||||
| @ -64,16 +64,16 @@ void initialize_game(Game *g) { | |||||||
|   shuffle_hand(&g->deck); |   shuffle_hand(&g->deck); | ||||||
| 
 | 
 | ||||||
|   g->player_hand.count = 0; |   g->player_hand.count = 0; | ||||||
|   g->player_hand.position = (Vector2) { 300, 550 }; |   g->player_hand.position = (Vector2) { 300, 600 }; | ||||||
|   g->player_hand.display_type = HAND_DISPLAY_ROW; |   g->player_hand.display_type = HAND_DISPLAY_ROW; | ||||||
|   g->right_hand.count = 0; |   g->right_hand.count = 0; | ||||||
|   g->right_hand.position = (Vector2) { 20, 100 }; |   g->right_hand.position = (Vector2) { 50, 125 }; | ||||||
|   g->right_hand.display_type = HAND_DISPLAY_ROW; |   g->right_hand.display_type = HAND_DISPLAY_ROW; | ||||||
|   g->left_hand.count = 0; |   g->left_hand.count = 0; | ||||||
|   g->left_hand.position = (Vector2) { 600, 100 }; |   g->left_hand.position = (Vector2) { 750, 125 }; | ||||||
|   g->left_hand.display_type = HAND_DISPLAY_ROW; |   g->left_hand.display_type = HAND_DISPLAY_ROW; | ||||||
|   g->field.count = 0; |   g->field.count = 0; | ||||||
|   g->field.position = (Vector2) { 400, 250 }; |   g->field.position = (Vector2) { 400, 300 }; | ||||||
|   g->field.display_type = HAND_DISPLAY_FIELD; |   g->field.display_type = HAND_DISPLAY_FIELD; | ||||||
| 
 | 
 | ||||||
|   strcpy(teyaku_calculation, ""); |   strcpy(teyaku_calculation, ""); | ||||||
| @ -86,37 +86,22 @@ void initialize_game(Game *g) { | |||||||
| 
 | 
 | ||||||
| bool stale_calculation = true; | bool stale_calculation = true; | ||||||
| void handle_input(Game *g) { | void handle_input(Game *g) { | ||||||
|   if (IsMouseButtonPressed(0)) { |   switch (g->state) { | ||||||
|     mouse_pos = GetMousePosition(); |   case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: | ||||||
|     for (int i = 0; i < 48; i++) { |     if (IsMouseButtonPressed(0)) { | ||||||
|       if (point_within_card(&g->cards[i], mouse_pos)) { |       mouse_pos = GetMousePosition(); | ||||||
| 	g->cards[i].selected = !g->cards[i].selected; |       for (int i = 0; i < g->player_hand.count; i++) { | ||||||
| 	stale_calculation = true; | 	if (point_within_card(g->player_hand.cards[i], mouse_pos)) { | ||||||
| 	break; | 	  // g->selected_card = g->player_hand.cards[i];
 | ||||||
|  | 	  break; | ||||||
|  | 	} | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |     break; | ||||||
| } |   case GAME_STATE_PLAYER_CHOOSING_TARGET: | ||||||
| 
 |     break; | ||||||
| void run_calculation(Game *g) { |   default: | ||||||
|   int num_selected = 0; |     break; | ||||||
|   if (stale_calculation) { |  | ||||||
|     Hand h; |  | ||||||
|     h.count = 0; |  | ||||||
|     for (int i = 0; i < 48; i++) { |  | ||||||
|       num_selected += g->cards[i].selected; |  | ||||||
|       if (g->cards[i].selected) h.cards[h.count++] = &g->cards[i]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     if (num_selected == 7) { |  | ||||||
|       Teyaku t; |  | ||||||
|       calculate_teyaku(h, &t); |  | ||||||
|       teyaku_to_string(&t, teyaku_calculation); |  | ||||||
|     } else { |  | ||||||
|       strcpy(teyaku_calculation, ""); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     stale_calculation = false; |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -149,10 +134,18 @@ void run_frame_calculating_field_multiplier(Game *g) { | |||||||
| 
 | 
 | ||||||
| void run_frame_calculating_teyaku(Game *g) { | void run_frame_calculating_teyaku(Game *g) { | ||||||
|   calculate_teyaku(g->player_hand, &g->player_teyaku); |   calculate_teyaku(g->player_hand, &g->player_teyaku); | ||||||
|   g->state = GAME_STATE_INITIALIZING; |   // g->selected_card = NULL;
 | ||||||
|  |   g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void run_frame_player_choosing_from_hand(Game *g) { | ||||||
|  | } | ||||||
|  | void run_frame_player_choosing_target(Game *g) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void run_frame(Game *g) { | void run_frame(Game *g) { | ||||||
|  |   handle_input(g); | ||||||
|  | 
 | ||||||
|   float delta = GetFrameTime(); |   float delta = GetFrameTime(); | ||||||
|   bool done_moving = true; |   bool done_moving = true; | ||||||
|   for (int i = 0; i < 48; i++) { |   for (int i = 0; i < 48; i++) { | ||||||
| @ -161,8 +154,6 @@ void run_frame(Game *g) { | |||||||
|   } |   } | ||||||
|   if (!done_moving) return; |   if (!done_moving) return; | ||||||
| 
 | 
 | ||||||
|   handle_input(g); |  | ||||||
| 
 |  | ||||||
|   switch (g->state) { |   switch (g->state) { | ||||||
|   case GAME_STATE_INITIALIZING: |   case GAME_STATE_INITIALIZING: | ||||||
|     return; |     return; | ||||||
| @ -175,8 +166,13 @@ void run_frame(Game *g) { | |||||||
|   case GAME_STATE_CALCULATING_TEYAKU: |   case GAME_STATE_CALCULATING_TEYAKU: | ||||||
|     run_frame_calculating_teyaku(g); |     run_frame_calculating_teyaku(g); | ||||||
|     break; |     break; | ||||||
|  |   case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: | ||||||
|  |     run_frame_player_choosing_from_hand(g); | ||||||
|  |     break; | ||||||
|  |   case GAME_STATE_PLAYER_CHOOSING_TARGET: | ||||||
|  |     run_frame_player_choosing_target(g); | ||||||
|  |     break; | ||||||
|   } |   } | ||||||
|   run_calculation(g); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void draw_frame(Game *g) { | void draw_frame(Game *g) { | ||||||
| @ -192,6 +188,18 @@ void draw_frame(Game *g) { | |||||||
|     teyaku_to_string(&g->player_teyaku, s); |     teyaku_to_string(&g->player_teyaku, s); | ||||||
|     DrawText(s, 5, 25, 30, BLACK); |     DrawText(s, 5, 25, 30, BLACK); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   switch (g->state) { | ||||||
|  |   case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: | ||||||
|  |     DrawText("Choose a card to play", 60, 485, 40, BLACK); | ||||||
|  |     break; | ||||||
|  |   case GAME_STATE_PLAYER_CHOOSING_TARGET: | ||||||
|  |     DrawText("Choose a target on the field", 60, 485, 40, BLACK); | ||||||
|  |     break; | ||||||
|  |   default: | ||||||
|  |     break; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   EndDrawing(); |   EndDrawing(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								game.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								game.h
									
									
									
									
									
								
							| @ -14,6 +14,8 @@ typedef enum GameState { | |||||||
|   GAME_STATE_DEALING, |   GAME_STATE_DEALING, | ||||||
|   GAME_STATE_CALCULATING_FIELD_MULTIPLIER, |   GAME_STATE_CALCULATING_FIELD_MULTIPLIER, | ||||||
|   GAME_STATE_CALCULATING_TEYAKU, |   GAME_STATE_CALCULATING_TEYAKU, | ||||||
|  |   GAME_STATE_PLAYER_CHOOSING_FROM_HAND, | ||||||
|  |   GAME_STATE_PLAYER_CHOOSING_TARGET, | ||||||
| } GameState; | } GameState; | ||||||
| 
 | 
 | ||||||
| struct Game { | struct Game { | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.c
									
									
									
									
									
								
							| @ -13,7 +13,7 @@ Texture2D cards_texture; | |||||||
| 
 | 
 | ||||||
| int main(int argc, char** argv) { | int main(int argc, char** argv) { | ||||||
|   srand(time(NULL)); |   srand(time(NULL)); | ||||||
|   InitWindow(1200, 700, "Hanafuda Hachi-Hachi"); |   InitWindow(1400, 900, "Hanafuda Hachi-Hachi"); | ||||||
|   SetTargetFPS(60); |   SetTargetFPS(60); | ||||||
| 
 | 
 | ||||||
|   Game g; |   Game g; | ||||||
|  | |||||||
							
								
								
									
										26
									
								
								play.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								play.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | |||||||
|  | #include <stddef.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  | #include "play.h" | ||||||
|  | 
 | ||||||
|  | bool valid_play(Hand *field, Card *played, Card *target) { | ||||||
|  |   if (target == NULL) { | ||||||
|  |     bool matching_month_in_field = false; | ||||||
|  |     for (int i = 0; i < field->count; i++) { | ||||||
|  |       if (field->cards[i]->month == target->month) { | ||||||
|  | 	matching_month_in_field = true; | ||||||
|  | 	break; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     return !matching_month_in_field; | ||||||
|  |   } else { | ||||||
|  |     bool target_in_field = false; | ||||||
|  |     for (int i = 0; i < field->count; i++) { | ||||||
|  |       if (field->cards[i]->index == target->index) { | ||||||
|  | 	target_in_field = true; | ||||||
|  | 	break; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     if (!target_in_field) return false; | ||||||
|  |     return played->month == target->month; | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user