What the heck
This commit is contained in:
		
							parent
							
								
									b13bc3a7bb
								
							
						
					
					
						commit
						08c5c08669
					
				
							
								
								
									
										68
									
								
								game.c
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								game.c
									
									
									
									
									
								
							@ -53,7 +53,7 @@ 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, 400 };
 | 
					    g->cards[i].move.destination = (Vector2) { 800, 400 };
 | 
				
			||||||
@ -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) {
 | 
				
			||||||
 | 
					  switch (g->state) {
 | 
				
			||||||
 | 
					  case GAME_STATE_PLAYER_CHOOSING_FROM_HAND:
 | 
				
			||||||
    if (IsMouseButtonPressed(0)) {
 | 
					    if (IsMouseButtonPressed(0)) {
 | 
				
			||||||
      mouse_pos = GetMousePosition();
 | 
					      mouse_pos = GetMousePosition();
 | 
				
			||||||
    for (int i = 0; i < 48; i++) {
 | 
					      for (int i = 0; i < g->player_hand.count; i++) {
 | 
				
			||||||
      if (point_within_card(&g->cards[i], mouse_pos)) {
 | 
						if (point_within_card(g->player_hand.cards[i], mouse_pos)) {
 | 
				
			||||||
	g->cards[i].selected = !g->cards[i].selected;
 | 
						  // g->selected_card = g->player_hand.cards[i];
 | 
				
			||||||
	stale_calculation = true;
 | 
					 | 
				
			||||||
	  break;
 | 
						  break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					    break;
 | 
				
			||||||
 | 
					  case GAME_STATE_PLAYER_CHOOSING_TARGET:
 | 
				
			||||||
void run_calculation(Game *g) {
 | 
					    break;
 | 
				
			||||||
  int num_selected = 0;
 | 
					  default:
 | 
				
			||||||
  if (stale_calculation) {
 | 
					    break;
 | 
				
			||||||
    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 {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										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