diff options
author | Nathan Vance <nathav63@gmail.com> | 2015-02-24 17:59:11 -0500 |
---|---|---|
committer | Nathan Vance <nathav63@gmail.com> | 2015-02-24 17:59:11 -0500 |
commit | 5f3bf1119c9f694e0f8f4b1c169ef1513cd5cacb (patch) | |
tree | 2bdcedaf8477563d137e880aef24ea430cc773cb | |
parent | Added messages, fixed indefinites (diff) | |
download | 7w-5f3bf1119c9f694e0f8f4b1c169ef1513cd5cacb.tar.gz 7w-5f3bf1119c9f694e0f8f4b1c169ef1513cd5cacb.tar.bz2 7w-5f3bf1119c9f694e0f8f4b1c169ef1513cd5cacb.zip |
Can select build type
-rw-r--r-- | data.c | 28 | ||||
-rw-r--r-- | messenger.c | 32 | ||||
-rw-r--r-- | player_turn.c | 33 | ||||
-rw-r--r-- | trade.c | 6 |
4 files changed, 75 insertions, 24 deletions
@@ -136,33 +136,39 @@ int data_getgold(int p) return player[p][3][3]; } +void data_addgold(int amnt, int p) +{ + buffer[p][1] += amnt; +} + int data_numplayers() { return numplayers; } -void data_build(int p, int card) +void data_discard(int p, int card) { int i; int *hand = data_gethand(p); for(i = 0; hand[i] != card; i++); for(; i < 6; i++) hand[i] = hand[i+1]; hand[6] = -1; +} + +void data_build(int p, int card) +{ + data_discard(p, card); buffer[p][0] = card; //will be added to player array at end of turn - buffer[p][1] -= cards_getcost(era, card)[GOLD]; - buffer[p][1] += cards_getproduction(era, card)[GOLD]; + data_addgold(cards_getcost(era, card)[GOLD] * -1, p); + data_addgold(cards_getproduction(era, card)[GOLD], p); } void data_buildwonder(int p, int card) { - int i; - int *hand = data_gethand(p); - for(i = 0; hand[i] != card; i++); - for(; i < 6; i++) hand[i] = hand[i+1]; - hand[6] = -1; + data_discard(p, card); buffer[p][0] = -2; - buffer[p][1] -= cards_getcost(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD]; - buffer[p][1] += cards_getproduction(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD]; + data_addgold(cards_getcost(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD] * -1, p); + data_addgold(cards_getproduction(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD], p); } //0 is non producing, 1 produces one kind of resource, 2 produces multiple resources @@ -260,7 +266,7 @@ static int recurse(int *cost, int **indef, int c) int data_canafford(int p, int *cost) { - if(cost[GOLD] > player[p][MISC][DATAGOLD]) return 0; + if(cost[GOLD] > data_getgold(p)) return 0; int i, j, k; data_removedefinites(p, cost); if(data_iszerocost(cost)) return 1; diff --git a/messenger.c b/messenger.c index 5c3c947..45e872e 100644 --- a/messenger.c +++ b/messenger.c @@ -1,5 +1,6 @@ #include "7w.h" +int io_getkey(); int io_printtext(int xorigin, int y, int width, char* text); void io_printborder(int x, int y, int width); @@ -29,3 +30,34 @@ void posthelp() { postmessage(" 7 Wonders Help:\nKeys:\n Arrow keys move cursor\n Return - buys resource\n h - prints this message"); } + +int postoptions(int x, int y) +{ + int width = 19; + int yorig = y; + int cursor = 0; + char* a = "Buy Sell Wonder"; + char* b = " *"; + char* c = " *"; + char* d = " *"; + while(1) { + y = yorig; + io_printborder(x, y++, width); + y = io_printtext(x, y, width, a); + if(cursor == 0) y = io_printtext(x, y, width, b); + if(cursor == 1) y = io_printtext(x, y, width, c); + if(cursor == 2) y = io_printtext(x, y, width, d); + io_printborder(x, y++, width); + switch(io_getkey()) { + case LEFT: cursor--; + break; + case RIGHT: cursor++; + break; + case ENTER: return cursor; + break; + default: break; + } + if(cursor < 0) cursor = 2; + cursor = cursor%3; + } +} diff --git a/player_turn.c b/player_turn.c index 5d1b122..d3dff67 100644 --- a/player_turn.c +++ b/player_turn.c @@ -2,14 +2,13 @@ int* data_gethand(int p); int data_getera(); -void io_printhand(int x, int y, int player, int cursor); -void io_printcard(int x, int y, int era, int card); int io_getkey(); void data_endturn(); -void data_nextera(); int data_numplayers(); void data_build(int p, int card); +void data_discard(int p, int card); void data_buildwonder(int p, int card); +void data_addgold(int amnt, int p); void view_refresh(int focus, int cursor, int player); int wonder_numstages(int player); int* cards_getcost(int era, int card); @@ -17,21 +16,29 @@ int data_numbuilt(int p); void postmessage(char* message); void posthelp(); void clearmessage(); +int postoptions(int x, int y); int player_build(int focus, int cursor, int player) { + int *hand = data_gethand(player); if(focus == data_numplayers()) { - int *hand = data_gethand(player); - if(data_canafford(player, cards_getcost(data_getera(), hand[cursor]))) { - data_build(player, hand[cursor]); - return 1; - } - else postmessage("Can't afford this!"); - } - if(focus == 0) { - if(data_canafford(player, cards_getcost(data_getwonder(player), data_getwonderside(player)*3+1+cursor))) { - data_buildwonder(player, 0); //change to choose card used + if(hand[cursor] == -1) return 0; + int choice = postoptions(65, 20); + if(choice == 0) { + if(data_canafford(player, cards_getcost(data_getera(), hand[cursor]))) { + data_build(player, hand[cursor]); + return 1; + } + else postmessage("Can't afford this!"); + } else if(choice == 1) { + data_discard(player, hand[cursor]); + data_addgold(3, player); return 1; + } else if(choice == 2) { + if(data_canafford(player, cards_getcost(data_getwonder(player), data_getwonderside(player)*3+1+cursor))) { + data_buildwonder(player, hand[cursor]); + return 1; + } } } return 0; @@ -0,0 +1,6 @@ +#include "7w.h" + +//0 is east, 1 is west +int get_trade(int direction) { + +} |