What the heck
This commit is contained in:
		
							parent
							
								
									b13bc3a7bb
								
							
						
					
					
						commit
						08c5c08669
					
				
							
								
								
									
										76
									
								
								game.c
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								game.c
									
									
									
									
									
								
							@ -53,7 +53,7 @@ void initialize_game(Game *g) {
 | 
			
		||||
    case 41:
 | 
			
		||||
      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.position = &g->cards[i].position;
 | 
			
		||||
    g->cards[i].move.destination = (Vector2) { 800, 400 };
 | 
			
		||||
@ -86,37 +86,22 @@ void initialize_game(Game *g) {
 | 
			
		||||
 | 
			
		||||
bool stale_calculation = true;
 | 
			
		||||
void handle_input(Game *g) {
 | 
			
		||||
  if (IsMouseButtonPressed(0)) {
 | 
			
		||||
    mouse_pos = GetMousePosition();
 | 
			
		||||
    for (int i = 0; i < 48; i++) {
 | 
			
		||||
      if (point_within_card(&g->cards[i], mouse_pos)) {
 | 
			
		||||
	g->cards[i].selected = !g->cards[i].selected;
 | 
			
		||||
	stale_calculation = true;
 | 
			
		||||
	break;
 | 
			
		||||
  switch (g->state) {
 | 
			
		||||
  case GAME_STATE_PLAYER_CHOOSING_FROM_HAND:
 | 
			
		||||
    if (IsMouseButtonPressed(0)) {
 | 
			
		||||
      mouse_pos = GetMousePosition();
 | 
			
		||||
      for (int i = 0; i < g->player_hand.count; i++) {
 | 
			
		||||
	if (point_within_card(g->player_hand.cards[i], mouse_pos)) {
 | 
			
		||||
	  // g->selected_card = g->player_hand.cards[i];
 | 
			
		||||
	  break;
 | 
			
		||||
	}
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void run_calculation(Game *g) {
 | 
			
		||||
  int num_selected = 0;
 | 
			
		||||
  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;
 | 
			
		||||
    break;
 | 
			
		||||
  case GAME_STATE_PLAYER_CHOOSING_TARGET:
 | 
			
		||||
    break;
 | 
			
		||||
  default:
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -149,10 +134,18 @@ void run_frame_calculating_field_multiplier(Game *g) {
 | 
			
		||||
 | 
			
		||||
void run_frame_calculating_teyaku(Game *g) {
 | 
			
		||||
  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) {
 | 
			
		||||
  handle_input(g);
 | 
			
		||||
 | 
			
		||||
  float delta = GetFrameTime();
 | 
			
		||||
  bool done_moving = true;
 | 
			
		||||
  for (int i = 0; i < 48; i++) {
 | 
			
		||||
@ -161,8 +154,6 @@ void run_frame(Game *g) {
 | 
			
		||||
  }
 | 
			
		||||
  if (!done_moving) return;
 | 
			
		||||
 | 
			
		||||
  handle_input(g);
 | 
			
		||||
 | 
			
		||||
  switch (g->state) {
 | 
			
		||||
  case GAME_STATE_INITIALIZING:
 | 
			
		||||
    return;
 | 
			
		||||
@ -175,8 +166,13 @@ void run_frame(Game *g) {
 | 
			
		||||
  case GAME_STATE_CALCULATING_TEYAKU:
 | 
			
		||||
    run_frame_calculating_teyaku(g);
 | 
			
		||||
    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) {
 | 
			
		||||
@ -192,6 +188,18 @@ void draw_frame(Game *g) {
 | 
			
		||||
    teyaku_to_string(&g->player_teyaku, s);
 | 
			
		||||
    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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								game.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								game.h
									
									
									
									
									
								
							@ -14,6 +14,8 @@ typedef enum GameState {
 | 
			
		||||
  GAME_STATE_DEALING,
 | 
			
		||||
  GAME_STATE_CALCULATING_FIELD_MULTIPLIER,
 | 
			
		||||
  GAME_STATE_CALCULATING_TEYAKU,
 | 
			
		||||
  GAME_STATE_PLAYER_CHOOSING_FROM_HAND,
 | 
			
		||||
  GAME_STATE_PLAYER_CHOOSING_TARGET,
 | 
			
		||||
} GameState;
 | 
			
		||||
 | 
			
		||||
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