Browse Source

Gamesiterate

jl777
jl777 5 years ago
parent
commit
5330c23499
  1. 162
      src/cc/tetris.c

162
src/cc/tetris.c

@ -638,13 +638,13 @@ void init_colors(void)
*/
#include "dapps/dappstd.c"
int32_t issue_games_events(struct games_state *rs,bits256 gametxid,uint32_t eventid,char c)
int32_t issue_games_events(struct games_state *rs,char *gametxidstr,uint32_t eventid,char c)
{
static FILE *fp;
char params[512],*retstr,str[65]; cJSON *retjson,*resobj; int32_t retval = -1;
char params[512],*retstr; cJSON *retjson,*resobj; int32_t retval = -1;
if ( fp == 0 )
fp = fopen("events.log","wb");
sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,bits256_str(str,gametxid),eventid);
sprintf(params,"[\"events\",\"17\",\"[%%22%02x%%22,%%22%s%%22,%u]\"]",c,gametxidstr,eventid);
rs->buffered[rs->num++] = c;
if ( (retstr= komodo_issuemethod(USERPASS,(char *)"cclib",params,GAMES_PORT)) != 0 )
{
@ -685,70 +685,18 @@ char *clonestr(char *str)
struct games_state globalR;
int tetris(int argc, char **argv)
void gamesiterate(struct games_state *rs,tetris_game *tg)
{
tetris_game *tg;
tetris_move move = TM_NONE;
bool running = true;
uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE;
int32_t c,skipcount=0; uint32_t eventid = 0;
WINDOW *board, *next, *hold, *score;
struct games_state *rs = &globalR;
int32_t c,skipcount=0; bits256 gametxid; uint32_t eventid = 0;
memset(&gametxid,0,sizeof(gametxid));
memset(rs,0,sizeof(*rs));
rs->guiflag = 1;
rs->sleeptime = 1; // non-zero to allow refresh()
if ( argc == 3 && strlen(argv[2]) == 64 )
{
#ifdef _WIN32
#ifdef _MSC_VER
rs->seed = _strtoui64(argv[1], NULL, 10);
#else
rs->seed = atol(argv[1]); // windows, but not MSVC
#endif // _MSC_VER
#else
rs->seed = atol(argv[1]); // non-windows
#endif // _WIN32
strcpy(Gametxidstr,argv[2]);
fprintf(stderr,"setplayerdata\n");
if ( games_setplayerdata(rs,Gametxidstr) < 0 )
{
fprintf(stderr,"invalid gametxid, or already started\n");
return(-1);
}
} else rs->seed = 777;
/* Load file if given a filename.
if (argc >= 2) {
FILE *f = fopen(argv[1], "r");
if (f == NULL) {
perror("tetris");
exit(EXIT_FAILURE);
}
tg = tg_load(f);
fclose(f);
} else {
// Otherwise create new game.
tg = tg_create(rs,22, 10);
}*/
tg = tg_create(rs,22, 10);
// NCURSES initialization:
initscr(); // initialize curses
cbreak(); // pass key presses to program, but not signals
noecho(); // don't echo key presses to screen
keypad(stdscr, TRUE); // allow arrow keys
timeout(0); // no blocking on getch()
curs_set(0); // set the cursor to invisible
init_colors(); // setup tetris colors
// Create windows for each section of the interface.
board = newwin(tg->rows + 2, 2 * tg->cols + 2, 0, 0);
next = newwin(6, 10, 0, 2 * (tg->cols + 1) + 1);
hold = newwin(6, 10, 7, 2 * (tg->cols + 1) + 1);
score = newwin(6, 10, 14, 2 * (tg->cols + 1 ) + 1);
int32_t counter = 0;
// Game loop
while (running) {
while (running)
{
running = tg_tick(rs,tg, move);
display_board(board, tg);
display_piece(next, tg->next);
@ -776,9 +724,9 @@ int tetris(int argc, char **argv)
if ( c < 0 || skipcount == 0x7f )
{
if ( skipcount > 0 )
issue_games_events(rs,gametxid,eventid-skipcount,skipcount | 0x80);
issue_games_events(rs,Gametxidstr,eventid-skipcount,skipcount | 0x80);
if ( c != -1 )
issue_games_events(rs,gametxid,eventid,c);
issue_games_events(rs,Gametxidstr,eventid,c);
skipcount = 0;
} else skipcount++;
eventid++;
@ -800,21 +748,21 @@ int tetris(int argc, char **argv)
running = false;
move = TM_NONE;
break;
/*case 'p':
wclear(board);
box(board, 0, 0);
wmove(board, tg->rows/2, (tg->cols*COLS_PER_CELL-6)/2);
wprintw(board, "PAUSED");
wrefresh(board);
timeout(-1);
getch();
timeout(0);
move = TM_NONE;
break;
case 's':
save(tg, board);
move = TM_NONE;
break;*/
/*case 'p':
wclear(board);
box(board, 0, 0);
wmove(board, tg->rows/2, (tg->cols*COLS_PER_CELL-6)/2);
wprintw(board, "PAUSED");
wrefresh(board);
timeout(-1);
getch();
timeout(0);
move = TM_NONE;
break;
case 's':
save(tg, board);
move = TM_NONE;
break;*/
case ' ':
move = TM_HOLD;
break;
@ -822,7 +770,63 @@ int tetris(int argc, char **argv)
move = TM_NONE;
}
}
}
int tetris(int argc, char **argv)
{
tetris_game *tg;
struct games_state *rs = &globalR;
int32_t c,skipcount=0; uint32_t eventid = 0;
memset(rs,0,sizeof(*rs));
rs->guiflag = 1;
rs->sleeptime = 1; // non-zero to allow refresh()
if ( argc == 3 && strlen(argv[2]) == 64 )
{
#ifdef _WIN32
#ifdef _MSC_VER
rs->seed = _strtoui64(argv[1], NULL, 10);
#else
rs->seed = atol(argv[1]); // windows, but not MSVC
#endif // _MSC_VER
#else
rs->seed = atol(argv[1]); // non-windows
#endif // _WIN32
strcpy(Gametxidstr,argv[2]);
fprintf(stderr,"setplayerdata\n");
if ( games_setplayerdata(rs,Gametxidstr) < 0 )
{
fprintf(stderr,"invalid gametxid, or already started\n");
return(-1);
}
} else rs->seed = 777;
/* Load file if given a filename.
if (argc >= 2) {
FILE *f = fopen(argv[1], "r");
if (f == NULL) {
perror("tetris");
exit(EXIT_FAILURE);
}
tg = tg_load(f);
fclose(f);
} else {
// Otherwise create new game.
tg = tg_create(rs,22, 10);
}*/
tg = tg_create(rs,22, 10);
// NCURSES initialization:
initscr(); // initialize curses
cbreak(); // pass key presses to program, but not signals
noecho(); // don't echo key presses to screen
keypad(stdscr, TRUE); // allow arrow keys
timeout(0); // no blocking on getch()
curs_set(0); // set the cursor to invisible
init_colors(); // setup tetris colors
// Game loop
gamesiterate(rs,tg);
games_bailout(rs);
// Deinitialize NCurses
wclear(stdscr);
endwin();
@ -835,9 +839,5 @@ int tetris(int argc, char **argv)
return 0;
}
void gamesiterate(struct games_state *rs)
{
}
#endif

Loading…
Cancel
Save