Shuffle cards
This commit is contained in:
parent
f17bd76b83
commit
f852af7cd7
14
card.c
14
card.c
@ -1,3 +1,6 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
#include "card.h"
|
#include "card.h"
|
||||||
|
|
||||||
static Vector2 card_size = (Vector2) { CARD_WIDTH, CARD_HEIGHT };
|
static Vector2 card_size = (Vector2) { CARD_WIDTH, CARD_HEIGHT };
|
||||||
@ -26,3 +29,14 @@ bool point_within_card(Card *c, Vector2 point) {
|
|||||||
return point.x > c->position.x && point.x < c->position.x + card_size.x &&
|
return point.x > c->position.x && point.x < c->position.x + card_size.x &&
|
||||||
point.y > c->position.y && point.y < c->position.y + card_size.y;
|
point.y > c->position.y && point.y < c->position.y + card_size.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void shuffle_hand(Hand *h) {
|
||||||
|
srand(time(NULL));
|
||||||
|
Card *swap;
|
||||||
|
for (int i = h->count - 1; i >= 0; i--) {
|
||||||
|
int index = rand() % (i + 1);
|
||||||
|
swap = h->cards[i];
|
||||||
|
h->cards[i] = h->cards[index];
|
||||||
|
h->cards[index] = swap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
card.h
1
card.h
@ -55,5 +55,6 @@ struct Hand {
|
|||||||
|
|
||||||
void draw_card(Card *c, Texture2D *cards_texture);
|
void draw_card(Card *c, Texture2D *cards_texture);
|
||||||
bool point_within_card(Card *c, Vector2 v);
|
bool point_within_card(Card *c, Vector2 v);
|
||||||
|
void shuffle_hand(Hand *h);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
5
game.c
5
game.c
@ -1,4 +1,5 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "card.h"
|
#include "card.h"
|
||||||
@ -47,8 +48,12 @@ void initialize_game(Game *g) {
|
|||||||
t = ANIMAL; break;
|
t = ANIMAL; break;
|
||||||
}
|
}
|
||||||
g->cards[i] = (Card) { i, t, rt, month, (Vector2) { month * 75, (i % 4) * 123 }, false };
|
g->cards[i] = (Card) { i, t, rt, month, (Vector2) { month * 75, (i % 4) * 123 }, false };
|
||||||
|
g->deck.cards[i] = &g->cards[i];
|
||||||
|
g->deck.count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shuffle_hand(&g->deck);
|
||||||
|
|
||||||
strcpy(teyaku_calculation, "");
|
strcpy(teyaku_calculation, "");
|
||||||
strcpy(dekiyaku_calculation, "");
|
strcpy(dekiyaku_calculation, "");
|
||||||
|
|
||||||
|
2
game.h
2
game.h
@ -11,7 +11,7 @@ struct Game {
|
|||||||
bool should_close;
|
bool should_close;
|
||||||
Card cards[48];
|
Card cards[48];
|
||||||
Texture2D cards_texture;
|
Texture2D cards_texture;
|
||||||
Hand player_hand, left_hand, right_hand;
|
Hand player_hand, left_hand, right_hand, deck;
|
||||||
};
|
};
|
||||||
|
|
||||||
void initialize_game(Game *g);
|
void initialize_game(Game *g);
|
||||||
|
Loading…
Reference in New Issue
Block a user