Play through en entire game!!
This commit is contained in:
parent
98ba7fb670
commit
49af79f932
2
card.c
2
card.c
@ -96,7 +96,7 @@ void add_to_hand(Hand *h, Card *c) {
|
||||
}
|
||||
c->move.curve = CURVE_EASE_IN_OUT;
|
||||
c->move.current_time = 0.;
|
||||
c->move.end_time = 0.1;
|
||||
c->move.end_time = 0.5;
|
||||
|
||||
h->count++;
|
||||
}
|
||||
|
107
game.c
107
game.c
@ -71,10 +71,10 @@ void initialize_game(Game *g) {
|
||||
g->player_hand.position = (Vector2) { 300, 600 };
|
||||
g->player_hand.display_type = HAND_DISPLAY_ROW;
|
||||
g->right_hand.count = 0;
|
||||
g->right_hand.position = (Vector2) { 50, 125 };
|
||||
g->right_hand.position = (Vector2) { 750, 125 };
|
||||
g->right_hand.display_type = HAND_DISPLAY_ROW;
|
||||
g->left_hand.count = 0;
|
||||
g->left_hand.position = (Vector2) { 750, 125 };
|
||||
g->left_hand.position = (Vector2) { 50, 125 };
|
||||
g->left_hand.display_type = HAND_DISPLAY_ROW;
|
||||
g->field.count = 0;
|
||||
g->field.position = (Vector2) { 400, 300 };
|
||||
@ -83,10 +83,10 @@ void initialize_game(Game *g) {
|
||||
g->player_scored.position = (Vector2) { 300, 750 };
|
||||
g->player_scored.display_type = HAND_DISPLAY_ROW;
|
||||
g->right_scored.count = 0;
|
||||
g->right_scored.position = (Vector2) { 50, 25 };
|
||||
g->right_scored.position = (Vector2) { 750, 25 };
|
||||
g->right_scored.display_type = HAND_DISPLAY_ROW;
|
||||
g->left_scored.count = 0;
|
||||
g->left_scored.position = (Vector2) { 750, 25 };
|
||||
g->left_scored.position = (Vector2) { 50, 25 };
|
||||
g->left_scored.display_type = HAND_DISPLAY_ROW;
|
||||
|
||||
strcpy(teyaku_calculation, "");
|
||||
@ -166,6 +166,47 @@ void handle_input(Game *g) {
|
||||
}
|
||||
}
|
||||
|
||||
bool run_frame_from_deck(Game *g, Hand *to_hand) {
|
||||
Card *top_card = g->deck.cards[g->deck.count - 1];
|
||||
if (top_card->visible) {
|
||||
Card *target = valid_target(top_card, &g->field);
|
||||
if (target) {
|
||||
remove_from_hand(&g->field, target);
|
||||
add_to_hand(to_hand, target);
|
||||
remove_from_hand(&g->deck, top_card);
|
||||
add_to_hand(to_hand, top_card);
|
||||
} else {
|
||||
remove_from_hand(&g->deck, top_card);
|
||||
add_to_hand(&g->field, top_card);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
remove_from_hand(&g->deck, top_card);
|
||||
add_to_hand(&g->deck, top_card);
|
||||
top_card->visible = true;
|
||||
top_card->move.end_time = 0.3;
|
||||
top_card->move.destination.x = top_card->move.destination.x + 100;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void run_frame_ai_playing(Game *g, Hand *hand, Hand *scored) {
|
||||
Play play = ai_play(hand, &g->field);
|
||||
if (play.target) printf("Playing %d on %d\n", play.played->index, play.target->index);
|
||||
else printf("Playing %d on field\n", play.played->index);
|
||||
play.played->visible = true;
|
||||
|
||||
if (play.target) {
|
||||
remove_from_hand(hand, play.played);
|
||||
add_to_hand(scored, play.played);
|
||||
remove_from_hand(&g->field, play.target);
|
||||
add_to_hand(scored, play.target);
|
||||
} else {
|
||||
remove_from_hand(hand, play.played);
|
||||
add_to_hand(&g->field, play.played);
|
||||
}
|
||||
}
|
||||
|
||||
void run_frame_dealing(Game *g) {
|
||||
if (g->player_hand.count < 4) {
|
||||
deal(&g->deck, &g->player_hand, 4, true);
|
||||
@ -244,26 +285,32 @@ void run_frame_player_choosing_target(Game *g) {
|
||||
}
|
||||
|
||||
void run_frame_player_from_deck(Game *g) {
|
||||
Card *top_card = g->deck.cards[g->deck.count - 1];
|
||||
if (top_card->visible) {
|
||||
Card *target = valid_target(top_card, &g->field);
|
||||
if (target) {
|
||||
remove_from_hand(&g->field, target);
|
||||
add_to_hand(&g->player_scored, target);
|
||||
remove_from_hand(&g->deck, top_card);
|
||||
add_to_hand(&g->player_scored, top_card);
|
||||
} else {
|
||||
remove_from_hand(&g->deck, top_card);
|
||||
add_to_hand(&g->field, top_card);
|
||||
}
|
||||
g->state = GAME_STATE_INITIALIZING;
|
||||
} else {
|
||||
remove_from_hand(&g->deck, top_card);
|
||||
add_to_hand(&g->deck, top_card);
|
||||
top_card->visible = true;
|
||||
top_card->move.end_time = 0.3;
|
||||
top_card->move.destination.x = top_card->move.destination.x + 100;
|
||||
}
|
||||
if (run_frame_from_deck(g, &g->right_hand))
|
||||
g->state = GAME_STATE_RIGHT_PLAYING;
|
||||
}
|
||||
|
||||
void run_frame_right_playing(Game *g) {
|
||||
printf("right play\n");
|
||||
run_frame_ai_playing(g, &g->right_hand, &g->right_scored);
|
||||
g->state = GAME_STATE_RIGHT_FROM_DECK;
|
||||
}
|
||||
|
||||
void run_frame_right_from_deck(Game *g) {
|
||||
printf("right deck\n");
|
||||
if (run_frame_from_deck(g, &g->right_scored))
|
||||
g->state = GAME_STATE_LEFT_PLAYING;
|
||||
}
|
||||
|
||||
void run_frame_left_playing(Game *g) {
|
||||
printf("left play\n");
|
||||
run_frame_ai_playing(g, &g->left_hand, &g->left_scored);
|
||||
g->state = GAME_STATE_LEFT_FROM_DECK;
|
||||
}
|
||||
|
||||
void run_frame_left_from_deck(Game *g) {
|
||||
printf("left deck\n");
|
||||
if (run_frame_from_deck(g, &g->left_scored))
|
||||
g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND;
|
||||
}
|
||||
|
||||
void run_frame(Game *g) {
|
||||
@ -298,6 +345,18 @@ void run_frame(Game *g) {
|
||||
case GAME_STATE_PLAYER_FROM_DECK:
|
||||
run_frame_player_from_deck(g);
|
||||
break;
|
||||
case GAME_STATE_RIGHT_PLAYING:
|
||||
run_frame_right_playing(g);
|
||||
break;
|
||||
case GAME_STATE_RIGHT_FROM_DECK:
|
||||
run_frame_right_from_deck(g);
|
||||
break;
|
||||
case GAME_STATE_LEFT_PLAYING:
|
||||
run_frame_left_playing(g);
|
||||
break;
|
||||
case GAME_STATE_LEFT_FROM_DECK:
|
||||
run_frame_left_from_deck(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
4
game.h
4
game.h
@ -17,6 +17,10 @@ typedef enum GameState {
|
||||
GAME_STATE_PLAYER_CHOOSING_FROM_HAND,
|
||||
GAME_STATE_PLAYER_CHOOSING_TARGET,
|
||||
GAME_STATE_PLAYER_FROM_DECK,
|
||||
GAME_STATE_RIGHT_PLAYING,
|
||||
GAME_STATE_RIGHT_FROM_DECK,
|
||||
GAME_STATE_LEFT_PLAYING,
|
||||
GAME_STATE_LEFT_FROM_DECK,
|
||||
} GameState;
|
||||
|
||||
struct Game {
|
||||
|
10
play.c
10
play.c
@ -34,3 +34,13 @@ Card *valid_target(Card *active, Hand *field) {
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Play ai_play(Hand *hand, Hand *field) {
|
||||
// very naive play initially
|
||||
Card *played = hand->cards[0];
|
||||
for (int i = 0; i < field->count; i++) {
|
||||
Card *target = field->cards[i];
|
||||
if (valid_play(field, played, target)) return (Play) { played, target };
|
||||
}
|
||||
return (Play) { played, NULL };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user