aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-02-20 17:18:43 -0500
committerNathan Vance <nathav63@gmail.com>2015-02-20 17:18:43 -0500
commitb29c03dd3b933d05e2f569acafeb7405971eb9e2 (patch)
treeea9090a2a45be4f675fde6023af1e49a886271b1
parentStarted backend for game view (diff)
download7w-b29c03dd3b933d05e2f569acafeb7405971eb9e2.tar.gz
7w-b29c03dd3b933d05e2f569acafeb7405971eb9e2.tar.bz2
7w-b29c03dd3b933d05e2f569acafeb7405971eb9e2.zip
Added view for all wonders
-rw-r--r--data.c5
-rw-r--r--main.c38
-rw-r--r--view.c26
-rw-r--r--wonder.c19
4 files changed, 64 insertions, 24 deletions
diff --git a/data.c b/data.c
index 8be97a9..eb499cc 100644
--- a/data.c
+++ b/data.c
@@ -212,15 +212,16 @@ int data_canafford(int p, int *cost)
int* data_getbuilt(int p)
{
- int *ret = get_intarray(42);
+ int *ret = get_intarray(43);
int type, e, c;
int i = 0;
for(type = 0; type <= 7; type++)
for(e = 0; e < 3; e++)
for(c = 0; c < 7; c++)
- if(cards_gettype(e, player[p][e][c]) == type) {
+ if(player[p][e][c] != -1 && cards_gettype(e, player[p][e][c]) == type) {
ret[i++] = e;
ret[i++] = player[p][e][c];
}
+ ret[i] = -1; //Cap it here
return ret;
}
diff --git a/main.c b/main.c
index 5ab0da7..0e38776 100644
--- a/main.c
+++ b/main.c
@@ -1,15 +1,17 @@
#include "7w.h"
#include <stdlib.h>
+void tester();
void io_init();
void cards_init();
void io_printcard(int x, int y, int era, int card);
-void cardtour();
void io_clearscreen();
int* getdeck(int era, int numplayers);
void data_init(int num_players);
void player_turn(int player);
void wonder_selected(int player);
+void view_refresh(int focus, int cursor, int player);
+int data_numplayers();
void halt()
{
@@ -21,34 +23,30 @@ main()
{
io_init();
cards_init();
- data_init(4);
-// cardtour();
- wonder_selected(0);
- player_turn(1);
+ data_init(7);
+ tester();
+// wonder_selected(0);
+// player_turn(1);
halt();
}
-void cardtour()
+void tester()
{
- int era, card;
- era = card = 0;
- int deckpos = 0;
- int numplayers = 4;
- int *decks[3];
- decks[0] = getdeck(0, numplayers);
- decks[1] = getdeck(1, numplayers);
- decks[2] = getdeck(2, numplayers);
+ int focus, cursor, player;
+ focus = cursor = player = 0;
+ int numplayers = data_numplayers();
while(1) {
- io_clearscreen();
- io_printcard(0, 0, era, decks[era][card]);
+ view_refresh(focus, cursor, player);
switch(io_getkey()) {
- case DOWN: if(card < numplayers*7) card++;
+ case DOWN: cursor++;
break;
- case UP: if(card > 0) card--;
+ case UP: if(cursor > 0) cursor--;
break;
- case LEFT: if(era > 0) era--;
+ case LEFT: if(focus > 0) focus--;
break;
- case RIGHT: if(era < 2) era++;
+ case RIGHT: if(focus < numplayers) focus++;
+ break;
+ case ENTER: player = (player+1)%numplayers;
break;
case 'q': halt();
break;
diff --git a/view.c b/view.c
index beb62aa..7d1c99a 100644
--- a/view.c
+++ b/view.c
@@ -1,12 +1,34 @@
#include "7w.h"
void print_wonder(int x, int y, int player, int cursor);
+void print_wondersmall(int x, int y, int player);
void io_printcard(int x, int y, int era, int card);
void io_printhand(int x, int y, int player, int cursor);
void io_clearscreen();
int data_numplayers();
-void view_refresh(int focus, int cursor)
+void view_refresh(int focus, int cursor, int player)
{
-
+ io_clearscreen();
+ int num = data_numplayers();
+ int x, y, i;
+ int offset = 0;
+ if(num == 3) x = 0;
+ if(num == 4 || num == 5) x = 1;
+ if(num == 6 || num == 7) x = 2, offset = -1;
+ y = 4;
+ int change = -1;
+ for(i = 0; i < num; i++) {
+ int p = (player+i+offset)%num;
+ if(p < 0) p += num;
+ if(focus == p)
+ print_wonder(x*27, y, p, cursor);
+ else print_wondersmall(x*27, y, p);
+ if(x == 0) {
+ if(change == -1) change = 0;
+ else change = 1;
+ y = 0;
+ }
+ x += change;
+ }
}
diff --git a/wonder.c b/wonder.c
index 5fa2cc2..54ecba6 100644
--- a/wonder.c
+++ b/wonder.c
@@ -11,11 +11,13 @@ int data_getwonderside(int p);
void io_printborder(int x, int y);
int io_printtext(int xorigin, int y, int width, char* text);
void io_printcard(int x, int y, int wonder, int stage);
+void io_printname(int x, int y, int era, int card);
int data_getwonderstages(int p);
char* cat(char a[], char b[]);
char* itoa(int i);
int io_getkey();
void io_clearscreen();
+int* data_getbuilt(int p);
int wonder_hasstage(int wonder, int side, int stage)
{
@@ -46,10 +48,27 @@ void print_wonder(int x, int y, int player, int cursor)
text = cat(text, " ");
y = io_printtext(x, y, 29, text);
}
+ io_printborder(x, y++);
+
+ //Print what has been built
+ int *built = data_getbuilt(player);
+ for(i = 0; built[i] != -1; i+=2) {
+ io_printname(x, y++, built[i], built[i+1]);
+ }
+ if(i == 0) y--;
+
+ //Info about component
if(wonder_hasstage(data_getwonder(player), data_getwonderside(player), cursor))
io_printcard(x, y, data_getwonder(player), cursor+1+3*data_getwonderside(player));
}
+void print_wondersmall(int x, int y, int player)
+{
+ io_printborder(x, y++);
+ y = io_printtext(x, y, 29, cards_getname(data_getwonder(player), 0));
+ io_printborder(x, y);
+}
+
void wonder_selected(int player)
{
int cursor = 0;
bgstack15