Example #1
0
void ram(void) {
  board_t b;

  board_init(&b, 4, 4, 0);

  const int anim_N = 10;

  do {
    if (b.menu_active) {
      lcdFill(0x00);
      board_menu_draw(&b);
      lcdDisplay();
    }
    else {
      for (int anim_i = 1; anim_i <= anim_N; anim_i ++) {
        lcdFill(0x00);
        board_draw(&b, anim_i, anim_N);
        lcdDisplay();
      }

      board_drop_new_value(&b);

      lcdFill(0x00);
      board_draw(&b, anim_N, anim_N);
      lcdDisplay();
    }

  } while(board_handle_input(&b));

  setTextColor(0xFF,0x00);
  return;
}
Example #2
0
void board_update()
{
  cgGLEnableProfile(cg__fragmentProfile);
  cgGLBindProgram(cg__fragmentProgram);

  // transfer data to texture
    texture_load_array(board__computeTexture, GL_TEXTURE_RECTANGLE_ARB, board__width, board__width, board__data);

  // perform computation
    CGparameter textureCg = cgGetNamedParameter(cg__fragmentProgram, "aBoard");
    cgGLSetTextureParameter(textureCg, board__computeTexture);
    cgGLEnableTextureParameter(textureCg);

    CGparameter widthCg = cgGetNamedParameter(cg__fragmentProgram, "aWidth");
    cgSetParameter1f(widthCg, board__width);

    board_draw(); // GPGPU CONCEPT 4: Viewport-Sized Quad = Data Stream Generator.

    cgGLDisableTextureParameter(textureCg);
    cgGLDisableProfile(cg__fragmentProfile);

  // Read back the results
    glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
    // The glReadBuffer function selects a color buffer source for pixels.
    // void glReadBuffer(GLenum mode); mode is a color buffer

    // The glReadPixels function reads a block of pixels from the framebuffer.
    glReadPixels(
      0, 0,           // GLint x, y The window coordinates of the first pixel that is read from the framebuffer. This location is the lower-left corner of a rectangular block of pixels
      board__width,   // GLsizei width
      board__width,   // GLsizei height
      GL_RGBA,        // GLenum format
      GL_FLOAT,       // GLenum type
      board__data);   // GLvoid *pixels
}
Example #3
0
static XP_Bool
scrollTimerProc( void* closure, XWTimerReason XP_UNUSED_DBG(why) )
{
    XP_Bool draw = XP_FALSE;
    BoardCtxt* board = (BoardCtxt*)closure;
    DragState* ds = &board->dragState;
    XP_ASSERT( why == TIMER_PENDOWN );

    if ( ds->scrollTimerSet ) {
        XP_S16 changeX = 0;
        XP_S16 changeY = 0;
        ds->scrollTimerSet = XP_FALSE;
        XP_Bool canScroll = onBorderCanScroll( board, SCROLL_H, 
                                               ds->cur.u.board.col, &changeX );
        canScroll = onBorderCanScroll( board, SCROLL_V, ds->cur.u.board.row, 
                                       &changeY ) || canScroll;
        if ( canScroll ) {
            invalDragObj( board, &ds->cur );
            if ( 0 != changeX ) {
                ds->cur.u.board.col += (changeX >0 ? 1 : -1);
            }
            if ( 0 != changeY ) {
                ds->cur.u.board.row += (changeY >0 ? 1 : -1);
            }

            if ( scrollIntoView( board, ds->cur.u.board.col, 
                                 ds->cur.u.board.row ) ) {
                board_draw( board ); /* may fail, e.g. on wince */
                startScrollTimerIf( board, XP_TRUE );
                draw = XP_TRUE;
            }
        }
    }
    return draw;
} /* scrollTimerProc */
Example #4
0
void board_render() {
  fbo_disable(); // render to screen, not the FBO

  // draw board contents
    texture_load_array(board__displayTexture, GL_TEXTURE_2D, board__width, board__width, board__data);
    glEnable(GL_TEXTURE_2D);
      board_draw();
    glDisable(GL_TEXTURE_2D);

  // draw board outline (grid)
    glCallList(board__gridDisplayList);

  fbo_enable();
}
int main(int argc, char* argv[])
{
   bool now = false;

   clock_t begin, end; // °ÔÀÓÀ» ÁøÇà ÇÒ ‹š ½Ã°£À» Àç´Â º¯¼ö ¼±¾ð
   begin = clock();    // °ÔÀÓ ½ÃÀÛ
   double all_clock;   // °ÔÀÓ ÁøÇà ÈÄ ÃÑ ½Ã°£ Ãâ·Â º¯¼ö ¼±¾ð
 
   rotate_tetris();
   srand(clock());
   Cursor(0);
 
   board_draw(true);
 
   now_tetris = rand() % 7;
   next_tetris = rand() % 7; // ÇöÀç Å×Æ®¸®½º, ´ÙÀ½ Å×Æ®¸®½º ·£´ý
 
   next_draw();
 
   char keyvalue;
 
   clock_t s_time = clock();
   clock_t e_time;  //  ½Ã°£¿¡ °üÇÑ ÇÔ¼ö
 
    cx = 4; cy = -1;
    cr = 0;
 
   while(1)
   {
 
   if(_kbhit())  //Å°º¸µå À̺¥Æ® ó¸®
   {
      keyvalue = _getch();
 
   switch(keyvalue)
   {
   case SPACE: // spsce bar ¸¦ ´©¸¦ ½Ã ¸ð¾çÀÌ ³»·Á°£´Ù.
      cy = point_get()-1;
      preview_cp();
      now_cp();
      cy++;
      now = true;
      break;
      
   case LEFT: //¹æÇâÅ° ¿ÞÂÊÀ» ´©¸¦ ½Ã µµÇü ¿ÞÂÊ À̵¿
      cx--;
      if(move_ck(LEFT))
      cx++;
      else 
      now = true;
      break;
      
   case RIGHT:// ¹æÇâÅ° ¿À¸¥ÂÊ À» ´©¸¦ ½Ã µµÇü ¿À¸¥ÂÊ À̵¿
      cx++;
      if(move_ck(RIGHT))cx--;
      else now = true;
      break;
 
   case UP: // ¹æÇâÅ° À§·Î¸¦ ´©¸¦ ½Ã µµÇüÀÌ È¸Àü
      //ȸÀü °¡´ÉÇÑÁö Á¶»çÇÏ°í
      //°¡´ÉÇϸé ȸÀüÇÑ´Ù.
      cr = (cr+1) % 4;
      if(move_ck(UP))
      cr = (cr-1) % 4;
      else 
      now = true;
      break;
      case ',': // ¾Æ·¡·Î ÇÑÄ­ À̵¿
      cy++;
      now = true;
      break;
      }
   }
   e_time = clock();
   if((float)(e_time - s_time) / (float)CLOCKS_PER_SEC >=0.5
   ^ now == true)
   {
      // Á¤ÇØÁø ½Ã°£°ú now Áß Çϳª¸¸ trueÀÏ ¶§ ÁøÀÔ
 
   s_time=clock();
 
   if(!now)
    cy++;
   // Ãæµ¹ °Ë»ç
   now = false;
   if(!move_ck(DOWN))
    now_cp();
   else 
   {
		now_tetris = next_tetris;
		next_tetris = rand() % 7;
		next_draw();
		cx = 4; cy = -1;
		cr=0;
		join_down();
		clear_line();
		if(check())
		{
			gotoxy(20, 10);
			setColor(0,15);
    
			printf("========== Game Over ==========");
			setColor(7,0);

			end = clock(); // °ÔÀÓ Á¾·á ½Ã°£
			all_clock = (double)(end-begin)/(double)CLOCKS_PER_SEC; // ÃÑ °ÔÀӽð£ Ãâ·Â
			gotoxy(0,0);
			printf(" ÃÑ Ç÷¹ÀÌ ½Ã°£Àº %lf ÃÊ ÀÔ´Ï´Ù. ", all_clock);

			gotoxy(40, 23);
			// printf("\n");
			 exit(0);
		}
		store = true;
		now_cp();
	}
	board_draw(false);
	shadow_draw(point_get());
  }
 }
 
 return 0;
}
Example #6
0
void game_draw(void) {
    board_draw();
}
Example #7
0
int main(int argc, char **argv) {
	struct timeval tv;
	gettimeofday(&tv, NULL);
	srand(tv.tv_sec*1000000ULL + tv.tv_usec);

	if (argc >= 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
		fprintf(stderr, "Usage: %s [width] [height] [nbombs]\n", argv[0]);
		return 1;
	}

	int width = DEF_WIDTH;
	int height = DEF_HEIGHT;
	int nbombs = -1;
	for (int i = 1; i < argc; i++) {
		int val = atoi(argv[i]);
		switch (i) {
		case 1: width = val; break;
		case 2: height = val; break;
		case 3: nbombs = val; break;
		}
	}
	if (nbombs == -1) {
		nbombs = .123 * width * height;
	}

	if (nbombs >= width*height) {
		fprintf(stderr, "nbombs (=%d) more than or equal to width * height (=%d)\n", nbombs, width*height);
		return 1;
	}

	initscreen();
	atexit(endscreen);
	signal(SIGINT, signalend);

	Board *bd=board_make(width, height, nbombs);
	Key key;
	bool quit = false;
	int repeat = 1;
	bool have_repeat_num = false;
	while (!quit) {
		board_draw(bd);
		if (board_win(bd)) {
			char *timestamp;
			formatTime(&timestamp, time(NULL) - bd->startTime);

			if (!prompt_playagain("You win!", timestamp, height + 2)) {
				break;
			}

			board_destroy(bd);
			bd = board_make(width, height, nbombs);
			continue;
		}
		getkey(&key);
		switch (key.type) {
		case KNUM:
			if (have_repeat_num) {
				if (repeat >= (INT_MAX - key.num) / 10) {  // would overflow
					bel();
					repeat = 1;
					have_repeat_num = false;
				} else {
					repeat = 10 * repeat + key.num;
				}
			} else if (key.num >= 1) {
				repeat = key.num;
				have_repeat_num = true;
			}
			break;
		case KARROW:
			board_shiftcursor(bd, key.dir, repeat);
			repeat = 1;
			have_repeat_num = false;
			break;
		case KCHAR:
			switch (key.ch) {
			case 'q':
				prompt_quit(height + 2);
				break;
			case 'f':
				board_flag(bd);
				break;
			case 'r':
				board_destroy(bd);
				bd=board_make(width, height, nbombs);
				break;
			case ' ':
				if (!board_open(bd)) break;
				board_revealbombs(bd);
				char *timestamp;
				formatTime(&timestamp, time(NULL) - bd->startTime);
				if (!prompt_playagain("BOOM!", timestamp, height + 2)) {
					quit = true;
					break;
				}
				board_destroy(bd);
				bd = board_make(width, height, nbombs);
				break;
			}
			if (have_repeat_num) bel();
			repeat = 1;
			have_repeat_num = false;
			break;
		default:
			bel();
			if (have_repeat_num) bel();
			repeat = 1;
			have_repeat_num = false;
			break;
		}
	}

	board_destroy(bd);
}
Example #8
0
File: game.c Project: ralight/ggz
/* Events:
 * CHESS_EVENT_INIT -> NULL
 * CHESS_EVENT_SEAT -> arg[0] = (char)SEAT
 *                     arg[1] = (char)VERSION
 * CHESS_EVENT_PLAYERS arg[0] = (char)ASSIGN1
 *                     arg[1-17] = (string)NAME1
 *                     arg[20] = (char)ASSIGN2
 *                     arg[21-37] = (string)NAME2
 * CHESS_EVENT_TIME_REQUEST -> NULL
 * CHESS_EVENT_TIME_OPTION -> time option
 * CHESS_EVENT_START -> NULL
 * CHESS_EVENT_MOVE_END -> arg = (str)MOVE
 * CHESS_EVENT_MOVE -> arg = (str)MOVE
 * CHESS_EVENT_GAMEOVER -> arg[0] = (char)OVER_CODE
 * CHESS_EVENT_UPDATE_TIME -> arg[0] = (int)TIME_1
 *                            arg[1] = (int)TIME_2
 *
 */
void game_update(int event, void *arg)
{
	char move[6];
	/*int diff[2]; */
	int retval = 0;
	switch (event) {
	case CHESS_EVENT_INIT:
		if (game_info.state != CHESS_STATE_INIT)
			break;
		game_init();
		game_info.state = CHESS_STATE_WAIT;
		break;
	case CHESS_EVENT_SEAT:
		if (game_info.state != CHESS_STATE_WAIT)
			break;
		/* Update the game info structure */
		game_info.seat = ((char *)arg)[0];
		game_info.version = ((char *)arg)[1];
		if (game_info.version != PROTOCOL_VERSION)
			game_popup
			    ("Incompatible version. The game may not run as expected");
		break;
	case CHESS_EVENT_PLAYERS:
		if (game_info.state != CHESS_STATE_WAIT)
			break;
		/* Update the game info structure */
		game_info.assign[0] = *(char *)arg;
		game_info.assign[1] = *(((char *)arg) + 20);
		if (game_info.assign[0] != GGZ_SEAT_OPEN)
			strcpy(game_info.name[0], (char *)arg + 1);
		if (game_info.assign[1] != GGZ_SEAT_OPEN)
			strcpy(game_info.name[1], (char *)arg + 21);
		board_info_update();
		free(arg);
		break;
	case CHESS_EVENT_TIME_REQUEST:
		if (game_info.state != CHESS_STATE_WAIT)
			break;
		/* FIXME: Should ask the user for the time */
		gtk_widget_show(create_clock_dialog());
		break;
	case CHESS_EVENT_TIME_OPTION:
		if (game_info.state != CHESS_STATE_WAIT)
			break;
		game_info.clock_type = (*((int *)arg)) >> 24;
		game_info.seconds[0] = (*((int *)arg)) & 0xFFFFFF;
		game_info.seconds[1] = (*((int *)arg)) & 0xFFFFFF;
		game_info.t_seconds[0] = (*((int *)arg)) & 0xFFFFFF;
		game_info.t_seconds[1] = (*((int *)arg)) & 0xFFFFFF;
		switch (game_info.clock_type) {
		case CHESS_CLOCK_NOCLOCK:
			game_popup("This game won't have a time limit.");
			break;
		case CHESS_CLOCK_CLIENT:
			game_popup
			    ("This game will use a client clock.\nThis option should only be used when playing against people you trust, as it relies much in the client program, that can be cheated.\nSo, if the time behaves very strangely (like your oponnent time never wearing out), he may be running a cheated client.\n\nEach player will have %d min : %d sec to win the game.",
			     game_info.seconds[0] / 60,
			     game_info.seconds[0] % 60);
			break;
		case CHESS_CLOCK_SERVER:
			game_popup
			    ("This game will use a server clock.\nIt is very difficult to cheat when using this type of clock, and you should use it if you suspect your oponnent may have a cheated client or if you don't trust him.\nHowever, if either your connection or your opponent's is deeply lagged, it will have a deep effect on the time count as well.\n\nEach player will have %d min : %d sec to win the game.",
			     game_info.seconds[0] / 60,
			     game_info.seconds[0] % 60);
			break;
		case CHESS_CLOCK_SERVERLAG:
			game_popup
			    ("This game will use a server clock with lag support.\nIn this option, we will use a server clock, but using a lag meter to compensate for any lag due to Internet connection. Although it's possible to cheat with this option, it is much more difficult then cheating with the client clock.\nBesides, the lag of either connect won't have a so deep effect on the time of the players.\n\nEach player will have %d min : %d sec to win the game.",
			     game_info.seconds[0] / 60,
			     game_info.seconds[0] % 60);
			break;
		default:
			game_popup("Clock type is %d and time is %d",
				   game_info.clock_type,
				   game_info.seconds[0]);
			break;
		}
		board_info_update();
		break;
	case CHESS_EVENT_START:
		if (game_info.state != CHESS_STATE_WAIT)
			break;
		game_info.state = CHESS_STATE_PLAYING;
		if (game_info.clock_type != CHESS_CLOCK_NOCLOCK)
			g_timeout_add(1000, game_timer, NULL);
		game_message("The game has started!");
		break;
	case CHESS_EVENT_MOVE_END:
		if (game_info.state != CHESS_STATE_PLAYING)
			break;
		ggz_debug("main", "Sending move... %s", (char *)arg);
		if (game_info.clock_type != CHESS_CLOCK_CLIENT
		    || game_info.turn == 0)
			/* Client clock is only tracked if we're using that
			 * clock system, and the first turn is never timed. */
			net_send_move(arg, -1);
		else {
			g_source_remove(timeout_id);
			if (game_info.turn == 0 || game_info.turn == 1)
				net_send_move(arg, 0);
			else
				net_send_move(arg,
					      g_timer_elapsed(game_info.
							      timer,
							      NULL));
			g_timer_stop(game_info.timer);
			g_timer_reset(game_info.timer);
		}
		game_message("Sending move to server...");
		break;
	case CHESS_EVENT_MOVE:
		if (game_info.state != CHESS_STATE_PLAYING)
			break;
		if (!arg) {
			game_message("Invalid move!");
			break;
		}
		strncpy(move, arg, 6);
		game_message("Making move %s", move);
		game_info.check = FALSE;
		retval = cgc_make_move(game, move);
		if (retval == CHECK || retval == MATE) {
			if ((game_info.turn % 2 != game_info.seat)) {
				game_info.check = TRUE;
				game_message("You are in check!");
			} else {
				game_message("Your opponent is in check!");
			}
		}
		/* Now update the time, if that's the case */
		if (game_info.clock_type != CHESS_CLOCK_NOCLOCK) {
			game_info.seconds[game_info.turn % 2] -=
			    *((gint32 *) arg + 2);
			/* Ok, adjust the timer clocks */
			game_info.t_seconds[0] = game_info.seconds[0];
			game_info.t_seconds[1] = game_info.seconds[1];
		}
		game_info.turn++;
		/* Check if it's my turn now and we have CLIENT_CLOCK */
		if (game_info.clock_type == CHESS_CLOCK_CLIENT
		    && game_info.turn % 2 == game_info.seat) {
			/* Starts the timer ! */
			g_timer_start(game_info.timer);
			/* Starts the timeout for MSG_UPDATE */
			timeout_id =
			    g_timeout_add(15000, game_update_server, NULL);
		}
		board_info_update();
		board_info_add_move(move);
		board_draw();
		break;
	case CHESS_EVENT_UPDATE_TIME:
		game_info.seconds[0] = *((int *)arg);
		game_info.seconds[1] = *((int *)arg + 1);
		game_info.t_seconds[0] = game_info.seconds[0];
		game_info.t_seconds[1] = game_info.seconds[1];
		board_info_update();
		break;
	case CHESS_EVENT_GAMEOVER:
		switch (*(char *)arg) {
		case CHESS_GAMEOVER_DRAW_AGREEMENT:
			game_message
			    ("Game is over! Both players agred on a draw");
			break;
		case CHESS_GAMEOVER_DRAW_STALEMATE:
			game_message("Game is over! We have a stalemate");
			break;
		case CHESS_GAMEOVER_DRAW_POSREP:
			game_message
			    ("Game is over! Too much repetition of positions");
			break;
		case CHESS_GAMEOVER_DRAW_MATERIAL:
			game_message
			    ("Game is over! Neither of the players has material for a mate");
			break;
		case CHESS_GAMEOVER_DRAW_MOVECOUNT:
			game_message
			    ("Game is over! The maximum movecount was reached");
			break;
		case CHESS_GAMEOVER_DRAW_TIMEMATERIAL:
			game_message
			    ("Gams is over! Time is out and the remaining player doesn't have enough material for a mate");
			break;
		case CHESS_GAMEOVER_WIN_1_MATE:
			game_message("Game is over! %s wins by a mate",
				     game_info.name[0]);
			break;
		case CHESS_GAMEOVER_WIN_1_RESIGN:
			game_message
			    ("Game is over! %s wins, %s has resigned",
			     game_info.name[0], game_info.name[1]);
			break;
		case CHESS_GAMEOVER_WIN_1_FLAG:
			game_message
			    ("Game is over! %s wins, %s has run out of time",
			     game_info.name[0], game_info.name[1]);
			break;
		case CHESS_GAMEOVER_WIN_2_MATE:
			game_message("Game is over! %s wins by a mate",
				     game_info.name[1]);
			break;
		case CHESS_GAMEOVER_WIN_2_RESIGN:
			game_message
			    ("Game is over! %s wins, %s has resigned",
			     game_info.name[1], game_info.name[0]);
			break;
		case CHESS_GAMEOVER_WIN_2_FLAG:
			game_message
			    ("Game is over! %s wins, %s has run out of time",
			     game_info.name[1], game_info.name[0]);
			break;
		default:
			game_message
			    ("The game should be over, but I don't know why");
		}
		game_info.state = CHESS_STATE_DONE;
		break;
	case CHESS_EVENT_DRAW:
		gtk_widget_show(create_draw_dialog());
		break;
	default:
		game_message("Unknown event! %d", event);
		break;
	}
}