예제 #1
0
BOOL CMFCApplication1Dlg::PreTranslateMessage(MSG* pMsg) {
	CWnd* temp_time = GetDlgItem(IDC_TIMER);
	CString t_time;

	switch (pMsg->message)
	{
		

		case WM_TIMER: //ako traje igra, svakih 0.1 sekundi provjerava da li je "duration" manji od 0, ako je poziva se "game over", ako nije da se "duration" smanji za 0.1
			if (game == true) {
				duration -= 0.1;
				if (duration < 0)
					game_over();
				t_time.Format(_T("%.1f"), duration);
				temp_time->SetWindowText(LPCTSTR(t_time));
				return false;
			}

		case WM_KEYUP: //prepoznavanje stisnute tipke
			if (pMsg->wParam == VK_RETURN) { // poèetak ili reset igre
				new_game();
				CWnd *_help = GetDlgItem(IDC_INST);
				_help->SetWindowText(_T(""));
			}
			else if (pMsg->wParam == VK_ESCAPE) { // izlazak iz igre
				EndDialog(IDCANCEL);

			}
			else if (GetAsyncKeyState(current_word[0]) && game == true) { //provjera da li je pritisnuta tipka jednaka traženom slovu

				if (current_word.Mid(1).IsEmpty()) { //ako nema više slova poveæava se "score"  i postavlja se nova rijeè

					set_score();
					new_word();
				}

				else { //za svako pogoðeno slovo, to slovo se mièe iz prikaza rijeèi i svira zvuk za pogoðeno slovo

					sound_path.LoadString(IDS_S_WRITE);
					PlaySound(sound_path, GetModuleHandle(NULL), SND_ASYNC); //zvuk za dobro upisano slovo
					current_word = current_word.Mid(1); //mièe se prvi znak(slovo) iz rijeèi
					change_text(); //postavlja se tekst bez prvog znaka
				}
			}
			else if (GetAsyncKeyState('H') && game == false) //kada igra ne traje ako je "H" pritisnut prikazuju se instrukcije za igranje igre
			{
				CString res;
				CString res2;
				res.LoadString(IDS_M_HELP);
				res2.LoadString(IDS_M_HELP_T);
				MessageBox(res, res2);
			}
			else if (game == true) //ako igra traje i nije pogoðeno slovo, poziva se "game over"
				game_over();

			return true;

	}
		return false;
}
예제 #2
0
파일: game.c 프로젝트: Picatout/lpc810-pong
// le joueur a manquer la balle
// mettre à jour le pointage
// faire entendre le son associé
// player est le joueur qui a manqué la balle.
void ball_missed(int player){
	plot(ball.x,ball.y,INVERT);
	sound_miss();
	plot(ball.x,ball.y,INVERT);
	ball.dx=0;
	ball.dy=0;
	if (player==LEFT_PLAYER){
		score[RIGHT_PLAYER]++;
		write_score(RIGHT_PLAYER,score[RIGHT_PLAYER]);
		if (score[RIGHT_PLAYER]==WIN_SCORE){
			game_over();
			return;
		}
		ball.x=RIGHT_BORDER-1;
		ball.y=paddle[RIGHT_PLAYER]+1;
		server=RIGHT_PLAYER;
	}else{
		score[LEFT_PLAYER]++;
		write_score(LEFT_PLAYER,score[LEFT_PLAYER]);
		if (score[LEFT_PLAYER]==WIN_SCORE){
			game_over();
			return;
		}
		ball.x=LEFT_BORDER+1;
		ball.y=paddle[LEFT_PLAYER]+1;
		server=LEFT_PLAYER;
	}
	plot(ball.x,ball.y,WHITE);
	wait_service();
}//f()
예제 #3
0
void doisjogadores(char **board) {
    system("clear");
    print_usage2();
    print_board(board);
    while ((!game_over(board) && (!someone_wins(board, 'O')))) {
        while(1) {
            printf("\n\t\t\tVez de jogador 1:\n");
            if (jogada(board,'X')) {
                break;
                //print_board(board)
            }
        }
        if(game_over(board) || someone_wins(board, 'X'))
            break;
        system("clear");
        print_board(board);

        while (1) {
            printf("\n\t\t\tVez de jogador 2:\n");
            if(jogada(board,0)) {
                break;
            }
        }
        system("clear");
        print_board(board);
    }
    system("clear");
    print_board(board);
    if (someone_wins(board, 'X')) {
        printf("\t\t\t\t\t\t\t\tJogador 1 ganhou!\n");

        enter();

        getchar();
        ultimos(board, 1);
    } else if (someone_wins(board, 'O'))  {
        printf("\t\t\t\t\t\t\t\tJogador 2 ganhou!\n");

        enter();


        getchar();
        ultimos(board, 2);
    } else {
        printf("\t\t\t\t\t\t\t\tFoi um empate!\n");

        enter();
        getchar();
        getchar();
    }


}
예제 #4
0
int main(int argc, char* argv[]) {
  signal(SIGINT, sigint);
  
  if(argc > 1)
    args_handle(argc, argv);

  if(client_host_addr != NULL) {
    int highscore_sd = connect_to_server();
    if(highscore_sd == -1) {
      perror("Error connecting to the highscoreserver.\n");
      return -1;
    }else{
      set_client_socket_descriptor(highscore_sd);
    }
  }

  
  while(1) {
    init_server();  

    listen_for_connections();
    
    game_over();
  }
  return 0;
}
예제 #5
0
void umjogador(char **board) {
    system("clear");
    print_usage1();
    int hor, vert, alpha;
    move best_move = (move) malloc (sizeof(struct legal_move));
    print_board(board);

    while (!game_over(board) && (!someone_wins(board, 'X'))) {
        if (jogada(board,0)) {
            system("clear");
            printf("A posição depois de sua última jogada:\n");
            print_board(board);
            alpha = minimax(board, 1, best_move);
            update_board(board, best_move -> hor, best_move -> vert, 1);
            printf("A posição depois da última jogada do computador:\n");
            print_board(board);
        }
    }


    if (someone_wins(board, 'X')) {
        ai_wins();
    } else {
        cats_game();
    }
}
void* solder () {

	if (pthread_mutex_lock(&mutex_solders) != 0) {
		perror("Failed to lock mutex: solders!");
		game_over();
		return;
	}
	if (pthread_mutex_unlock(&mutex_solders) != 0) {
		perror("Failed to unlock mutex: solders!");
		game_over();
		return;
	}	
	printf("You wanna piece of me, boy?\n");
	
	return;
}
예제 #7
0
static RET_CODE on_othello_board_select(control_t *p_ctrl, u16 msg,
  u32 para1, u32 para2)
{
  BOOL ret;
  
  if (do_move_chess(&chess_board,
                    (u16)((cur_row + 1) * 10 + (cur_col + 1)),
                    (u8)(~computer_side & 3), callback))
  {
    othello_game = OTHELLO_HAPPY;
    get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
    othello_update_status();
    othello_draw_background(FALSE);
    /* computer round */
    ret = computer_play(&chess_board, callback);
    get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
    othello_update_status();
    othello_draw_background(FALSE);
    
    if(!ret)
    {
      game_over(&chess_board, callback);
    }
  }  

  return SUCCESS;
}
예제 #8
0
void game_mode_handler::tick(game_state* state)
{
    current_session_state.time_elapsed += clk.getElapsedTime().asMicroseconds() / 1000.f;
    clk.restart();

    if(game_over())
    {
        ///just changed
        if(!in_game_over_state)
        {
            game_over_timer.restart();

            printf("Round end\n");
        }

        in_game_over_state = true;
    }

    ///we'd need to update all the client positions here
    if(in_game_over_state && game_over_timer.getElapsedTime().asSeconds() > game_data::game_over_time)
    {
        ///reset the session state
        current_session_state = session_state();

        in_game_over_state = false;

        state->respawn_requests.clear();

        printf("Round begin\n");
    }
}
예제 #9
0
t_proc	*destroy_process(t_cwar *cwar, t_proc *proc, t_proc *prev)
{
	int		i;
	int		kill;

	i = 0;
	kill = 0;
	while (i <= REG_NUMBER)
		free(proc->reg[i++]);
	free(proc->reg);
	if (cwar->proc == proc)
	{
		cwar->proc = proc->next;
		free(proc);
		kill++;
	}
	else
		kill = find_process(cwar, proc, prev);
	if (!kill)
		cw_error("The process to kill wasn't found\n", cwar);
	cwar->proc_number--;
	if (!cwar->proc_number)
		game_over(cwar);
	return (cwar->proc);
}
예제 #10
0
void* solder () {
	sleep(1);
	if (pthread_mutex_lock(&mutex_solders) != 0) {
		printf("Failed to lock mutex: solders!\n");
		game_over();
		return;
	}
	m++;
	if (pthread_mutex_unlock(&mutex_solders) != 0) {
		printf("Failed to unlock mutex: solders!\n");
		game_over();
		return;
	}	
	printf("You wanna piece of me, boy?\n");
	return;
}
예제 #11
0
void move_block_max_down()
{
	int i;
	while(!collision())
	{
		for ( i = 0; i < 4 ; ++i)
		{
			if(z[i]==0) goto a;
		}
		move_down();
		tetris_board->score+=5;
	}
	a : for ( i = 0; i < 4; ++i)
	{
		if(z[i]==8)
		{
			game_over();
		}
	}
	increment_board_status(global_type);
	update_created_status(0);
	printf("\nScore==%d\n",tetris_board->score );
	check_game_over();
	flag=1;
}
예제 #12
0
int main()
{
	//Vetor de opções do menu principal. Pode ser expandido, contanto que seja adaptada a variavel NUM_OPT
	char* options[] = {
			"Jogar",
			"Sair"
			};

	//String que monta a tela de apresentação do menu inicial.
	char title[] = 
"	===========================================================\n\
			PSYCHO TETRIS MEGA BETA\n\
	===========================================================";


	//String que monta a tela de game over.
	char gameover[] = 
"	===========================================================\n\
				GAMEOVER\n\
	===========================================================";

	int opt;
	inicializa_ncurses();
	if((opt = menu(options, NUM_OPT, title)) != 1)
	{
		start_game(opt);
		game_over(gameover);
	}

	finaliza_ncurses();
	return 0;
}
예제 #13
0
파일: main.c 프로젝트: banisadr/robockey
/* Update Game State Based on Comm Protocol */
void update_game_state(void)
{
	switch(game_state){
		case 0xA0: // Comm Test
			comm_test();
			break;
		case 0xA1: // Play
			play();
			break;
		case 0xA2: // Goal R
			SR = buffer[1]
			SB = buffer[2]
			pause();
			break;
		case 0xA3: // Goal B
			SR = buffer[1]
			SB = buffer[2]
			pause();
			break;
		case 0xA4: // Pause
			pause();
			break;
		case 0xA6: // Halftime
			halftime();
			break;
		case 0xA7: // Game Over
			game_over();
			break;
		case 0xA8: // Enemy Positions
			break;
		default: // Invalid Comm
			break;
	}
}
예제 #14
0
void update_game(Game *g) {
    --(g->swait);
    update_object(&(g->player));
    if(g->player.speed > 0.0)
        g->player.speed -= 0.01;
    for(Object *o = g->asteroids; o; o = o->next) {
        rotate(o, 0.05);
        update_object(o);
        if(check_collision(&g->player, o) || check_collision(o, &g->player))
            game_over(g);
    }
    for(Object **o = &(g->shot); *o; o = &(*o)->next) {
        update_object(*o);
        if((*o)->lifetime == 0) {
            Object *t = *o;
            *o = (*o)->next;
            free(t);
            if(!*o)
                return;
        }
        for(Object **p = &(g->asteroids); *p; p = &(*p)->next) {
            if(check_collision(*p, *o)) {
                Object *t = *o;
                *o = (*o)->next;
                free(t);
                
                (*p)->size *= 0.75;
                if((*p)->size < 0.5) {
                    t = *p;
                    *p = (*p)->next;
                    free(t);
                } else {
                    t = (*p)->next;
                    (*p)->next = memcpy(malloc(sizeof(Object)), *p, sizeof(Object));
                    (*p)->next->next = t;
                    (*p)->dir += ((float)(rand()%628))/100.0;
                    accelerate(g, *p, 0.5);
                    (*p)->next->dir += ((float)(rand()%628))/100.0;
                    accelerate(g, (*p)->next, 1.0);
                }

                if(!*o)
                    return;
                if(!*p)
                    break;
            }
        }
    }
    for(Object **o = &(g->particles); *o;) {
        update_object(*o);
        if((*o)->lifetime == 0) {
            Object *t = *o;
            *o = (*o)->next;
            free(t);
        } else {
            o = &(*o)->next;
        }
    }
}
예제 #15
0
void processa_buffer(Buffer* buffer){
	processa_wave(buffer->invasores);
	processa_tanque(buffer->tanque);
	processa_colisao(buffer);

	if(get_bottom_wave(buffer->invasores) <= get_top_tanque(buffer->tanque))
		game_over();
}
예제 #16
0
파일: ctype_game.c 프로젝트: hangyan/Code
void *
animation (void *arg)
{
    srand ((unsigned) time (NULL));

    int ch;
    int i;
    char charToPrint;
    int column;
    int M = (ROWS - 1) * (COLUMNS + 1);
    while (1) {
        ch = rand () % 36;	//0-35
        column = rand () % (COLUMNS + 1);
        move (0, column);
        if (ch >= 0 && ch <= 9) {
            charToPrint = (char) (ch + 48);
        }
        if (ch >= 10 && ch <= 35) {
            charToPrint = (char) (ch + 87);
        }
        addch (charToPrint);

        ScreenTable[column] = charToPrint;
        CharTable[ch]++;
        refresh ();
        usleep ((55 - LEVEL) * 500 * 1000);
        insertln ();
        refresh ();


        for (i = 0; i < N; ++i) {
            if (ScreenTable[i] != 0 && Move[i] == 0) {
                if (i >= M) {
                    game_over ();	//clean up the windows
                    save_exit (GAME_OVER);	//keep this call in 'main'
                }
                ScreenTable[i + COLUMNS + 1] = ScreenTable[i];
                ScreenTable[i] = 0;
                Move[i + COLUMNS + 1] = 1;
            }
            if ((ScreenTable[i] == TYPINGCHAR) && (isOld == 0)) {
                move (i / (COLUMNS + 1), i % (COLUMNS + 1));
                addch (' ');
                flash ();
                refresh ();
                if (TYPINGCHAR >= 48 && (TYPINGCHAR <= 57)) {
                    if (--CharTable[TYPINGCHAR - 48] == 0)
                        isOld = 1;
                }

                ScreenTable[i] = 0;
                SCORE++;
            }
        }
        memset (Move, 0, N);
    }

}
예제 #17
0
파일: game.c 프로젝트: zhiyb/Il-Matto
void game_conn3(void)
{
	uint8_t cheat = 0;

get:
	switch (ROE_get()) {
	case ROE_CW1:
	case ROE_CW2:
		if (!cheat)
			bar_movey(1, 1);
		break;
	case ROE_CCW1:
	case ROE_CCW2:
		if (!cheat)
			bar_movey(1, 0);
		break;
	case ROE_SW1:
	case ROE_SW2:
		while (ROE_get() != ROE_N);
		if (!box.e)
			return;
#ifdef ENABLE_CHEAT
		cheat = !cheat;
#endif
		break;
	default:
		if (timer0()) {
			if (cheat && box.e)
				bar_follow(1);
			if (!box_move())
				return;
		}
	}
	switch (connect_read()) {
	case CONN_REPORT:
		connect_put(CONN_READY);
		box.x = connect_get();
		box.y = connect_get16();
		box.dx = connect_get();
		connect_put(CONN_READY);
		if (box.y + BOX_SIZE > tft.h)
			box.y = tft.h - BOX_SIZE;
		box.dy = (box.dx >> 1) & 0x01;
		box.dx &= 0x01;
		box.n = 1;
		box.e = 1;
		break;
	case CONN_GAMEOVER:
		cheat = connect_get();
		connect_put(CONN_READY);
		game.mode = 1;		// Disable game_over() send function
		game_over(cheat);
		return;
	case CONN_SOUND:
		sound_freq(connect_get16());
	}
	goto get;
}
예제 #18
0
파일: snake.c 프로젝트: gatsbydhn/myToy
int main()
{
	init();
	while (1)
	{
		key_control();
	}
	game_over();
}
예제 #19
0
파일: main.c 프로젝트: gitustc/d2imdev
int main(){

	game g;
	game_init( &g );
	game_run ( &g );
	game_over( &g );

	return 0;
}
예제 #20
0
//The main code is implemented here
void update_game()
{
	int type,i;
	check_game_over();
	global_type_block=squareshape;
	if(flag==1)
	{ 
		allow_movement=true;
		printf("\n\n");
		flag=0;
		// count=height/0.1;
		type= next_block_type;
		next_block_type= rand()%4 +1;
		// next_block_type=1;
		// type=2;
		global_type=type;
		color_block=rand()%3;
		printf("Creating the blocks\n");
		create_new_shape(type,color_block);
		update_created_status(1);
	}
	if(collision())
	{
		allow_movement=false;
		for ( i = 0; i < 4; ++i)
		{
			if(z[i]==8)
			{
				game_over();
			}
		}
		printf("type==%d\n",global_type );
		// fix_block_at_z();
		if(!collision())
		{
			allow_movement=true;
			move_down();
			return;
		}
		increment_board_status(global_type); 
		update_created_status(0);
		tetris_board->score+=5;
		printf("\nScore==%d\n",tetris_board->score );
		check_game_over();
		// for(i=0;i<4;++i)
		// {
		// 	printf("z==%f\n",tetris_board->board[CELL(x[i], y[i],0)]->pos[1] );
		// }
		flag=1;
	}
	else
	{
		move_down();
	}
}
예제 #21
0
// 用 wsad 来表示上下左右方向
void play() {

  int old_empty;
  char ch;

  while (1) {
    moved = 0;
    old_empty = empty;

    ch = getch();
    switch (ch) {
    case 'A':
    case 'a':
      left();
      break;
    case 'D':
    case 'd':
      right();
      break;
    case 'W':
    case 'w':
      up();
      break;
    case 'S':
    case 's':
      down();
      break;
    case 'Q':
    case 'q':
      endflag = quit;
      break;
    default:
      continue;
    }

    draw(); // refresh

    // 游戏失败
    if (empty <= 0 && test_lose()) {
      endflag = lose;
    }

    // 判断游戏结束条件
    if (endflag != playing) {
      game_over();
    }

    //生成新方块
    if ((empty != old_empty) ||
        (moved == 1)) { //修复了不移动或不消除方块也生成新方块的bug
      add_number();
      draw();
    }
  }
}
예제 #22
0
파일: ai.c 프로젝트: jneufeld/Rooked
/* Alpha-beta pruning search.  */
int abp_search (int player, int depth, int alpha, int beta)
{
    int legal_moves[BOARD_SIZE];
    int curr_util = NEG_INF, i;
    int mod = -1 * ((player == BPLAYER) ? -1 : 1);

    /* For each piece on the board, generate its legal moves and evaluate
     * its utility. Track the move with the greatest utility.  */
    for (i = 0; i < BOARD_SIZE; i++) {
        if (board[i] > chp_null * mod) {
            init_moves_board (legal_moves);
            gen_plegal_moves (player, i, legal_moves);

            int j;
            for (j = 0; j < BOARD_SIZE; j++) {
                if (legal_moves[j] == TRUE) {
                    int attacked_piece = move_piece (i, j);
                    int move_util = 0;

                    /* If move wins the game, automatically make that move.  */
                    if (game_over () == TRUE) {
                        unmove_piece (i, j, attacked_piece);
                        return (-1 * mod) * POS_INF;
                    }

                    /* If maximum depth reached evaluate the board. Else,
                     * continue search.  */
                    if (depth == 1) {
                        move_util = mod * board_utility ();
                    } else {
                        move_util = mod * abp_search (opponent_player (player),
                            depth - 1, -1 * beta, -1 * alpha);
                    }
                    
                    /* If this move's utility is a new maximum, save it. Alter
                     * alpha value and check against beta to potentially short
                     * circuit the search.  */
                    if (move_util > curr_util) {
                        curr_util = move_util;
                    }
                    if (curr_util > alpha) {
                        alpha = curr_util;
                    }
                    if (alpha >= beta) {
                        unmove_piece (i, j, attacked_piece);
                        return alpha;
                    }
                    
                    unmove_piece (i, j, attacked_piece);
                }
            }
        }
    }
    return curr_util;
}
예제 #23
0
void his_step() {
	chip damka;
	if (HisColor == White) damka = WDamka;
	else damka = BDamka;

	click_x = hishod[3 + 2*hishod_part] - 65;
	click_y = hishod[4 + 2*hishod_part] - 49;
	hishod_part++;

	if (board[click_y][click_x] == None) {
		byte step_status = do_step(click_x, click_y, HisColor);
		if (step_status > 0) {
			apply_select(selected_x, selected_y, 0);
			chip old_chip = board[selected_y][selected_x];
			board[selected_y][selected_x] = None;
			apply_color(selected_x, selected_y);
			board[click_y][click_x] = old_chip;
			if (step_status == 2 && can_eat(click_x, click_y, HisColor)) { // 2 - возможен повторный ход, т.к. предыдущий был рубкой.
				apply_color(click_x, click_y);
				apply_select(click_x, click_y, 1);
				if ((HisColor == White && click_y == 7) || (HisColor == Black && click_y == 0)) futureDamka = 1;
				if (hishod_part < hishod_len) {
					his_step();
				} else {
					debug_print("his_step error4", 15, 6);
					error();
				}
			} else {
				if (futureDamka || (HisColor == White && click_y == 7) || (HisColor == Black && click_y == 0))
					board[click_y][click_x] = damka;
				apply_color(click_x, click_y);
				forbidden_direction = DNone;
				if (hishod_part == hishod_len) {
					if (game_over()) {
						ggs = GGNEW;
					} else {
						if (HisColor == White) ggs = GGStartStepBlack;
						else ggs = GGStartStepWhite;
					}
					Mouse_Clc_Restart();
				} else {
					debug_print("his_step error3", 15, 6);
					error();
				}
			}
		} else {
			debug_print("his_step error2", 15, 6);
			error();
		}
	} else {
		debug_print("his_step error1", 15, 6);
		error();
	}
}
예제 #24
0
void move_head(uint8_t new_dir)
{
  if (new_dir)
  {
    //Copy head to new position
    head = get_next_node(head); //increment head
    corners[head].x = corners[get_previous_node(head)].x;
    corners[head].y = corners[get_previous_node(head)].y;
    change_direction();  //change direction
  }
  
  //Have we left the game board?
  if ((corners[head].x == 0) && (dirX == -1)) { game_over(); return; }
  if ((corners[head].y == 0) && (dirY == -1)) { game_over(); return; }
  if ((corners[head].x == GAMEBOARD_X-1) && (dirX == 1)) { game_over(); return; }
  if ((corners[head].y == GAMEBOARD_Y-1) && (dirY == 1)) { game_over(); return; }
  corners[head].x += dirX;
  corners[head].y += dirY;
  ++snake_length_current;
}
예제 #25
0
void check_if_dead(int y, int x) {
    if (hud.power < 1) { 
        hud.lives--;
        hud.power = 9; 
    
        if (hud.lives < 1) {
            game_over(y, x);
        }
    }
    show_stars();
}
예제 #26
0
void* command_center () {
	if (pthread_mutex_init(&mutex_command_centers_minerals[k], NULL) != 0) {
		printf("Failed to initialize mutex: mutex_command_centers_minerals %d\n", (k + 2));
		game_over();
		return;
	} else {
		if (pthread_mutex_lock(&mutex_command_centers) != 0) {
		printf("Failed to lock mutex: mutex_command_centers_minerals %d\n", (k + 2));
		game_over();
		return;
		}
		k++;
		if (pthread_mutex_unlock(&mutex_command_centers) != 0) {
			printf("Failed to unlock mutex: mutex_command_centers_minerals %d\n", (k + 1));
			game_over();
			return;
		}
		printf("Command center %d created.\n", (k + 1));
	}
	return;
}
예제 #27
0
void BlockArea::slot_turn_over(bool is_mine)
{
    if(is_mine){
        game_over_flag = true;
        emit game_over(false);      //以失败结束游戏
    }else{
        ++turn_over_blocks;
        if(turn_over_blocks == total_blocks-total_mines){
            game_over_flag = true;
            emit game_over(true);       //成功结束游戏
        }else{
            for(int i = 0; i < row; i++)
                for(int j = 0; j < column; j++)
                {
                    Block * current = static_cast<Block*>(grid_layout->itemAtPosition(i,j)->widget());
                    if(sender()== current && calc_number(i, j)==0)
                        try_to_turn_more_blocks(i,j);
                }
        }
    }
}
예제 #28
0
파일: snake.c 프로젝트: gatsbydhn/myToy
void snake_move()
{
    snake_tp p, tmp;
    for (p = tail; p != head; p = p->prev) {
        p->x = p->prev->x;
        p->y = p->prev->y;
    }
    p->x += dir_x;
    p->y += dir_y;

   if (head->x > WINDOW_RIGHT)
		head->x = 0;
   if (head->x < 0)
		 head->x = WINDOW_RIGHT;
   if (head->y > WINDOW_BOTTOM)
		head->y = 0;  
   if (head->y < 0)
       head->y = WINDOW_BOTTOM;

    move(head->y, head->x);
	if ((char)inch() == CHAR_SNAKE) { //eat self
        game_over();
    }
    if ((char)inch() == CHAR_FOOD) { //eat food
        move(head->y, head->x);
        addch(CHAR_SNAKE);
        refresh();

        tmp = (snake_tp)malloc(sizeof(snake_t));
        tmp->x = head->x + dir_x;
        tmp->y = head->y + dir_y;
        tmp->next = head;
        head->prev = tmp;
        head = tmp;

        do {
            food.x = rand() % WINDOW_RIGHT;
            food.y = rand() % WINDOW_BOTTOM;
            move(food.y, food.x);
        } while (((char)inch()) == CHAR_SNAKE);
        move(food.y, food.x);
        addch(CHAR_FOOD);
        refresh();
    }

    move(head->y, head->x);
    addch(CHAR_SNAKE);
    refresh();
    move(tail->y, tail->x);
    addch(CHAR_BLANK);
    refresh();
}
예제 #29
0
int main()
{
  grid testG = new_grid();
  printf("grid created\n");

  add_tile(testG);
  
  bool isGameOver = game_over(testG);
  
  if(isGameOver) // check if an empty grid is a gameover
    {
      return EXIT_FAILURE;
    }
  else
    printf("game not over with an empty grid\n");

  // FILLING THE GRID WITH UNIQUE VALUES
  int k = 1;
  for(int i = 0; i < GRID_SIDE; i++)
    {
      for(int j = 0; j < GRID_SIDE; j++)
	{
	  set_tile(testG, i, j, (tile)k);
	  printf("[%d][%d]:%d\n", i, j, get_tile(testG, i, j));
	  k++;
	}
    }

  isGameOver = game_over(testG);
  if(!isGameOver)
    return EXIT_FAILURE; // check if it's game over with a grid filled with unique values
  else
    printf("gameover with a grid filled with unique values\n");
  
  delete_grid(testG);
  printf("grid deleted\n");

  return EXIT_SUCCESS;
}
예제 #30
0
void check_interrupt()
{
    dlog("[D] In interrupt. Flag: %d\n",config.intr_flag);
    if (ISSET_INTERRUPT_END(config)) {
        game_over();
    } else if (ISSET_INTERRUPT_SESSION(config)) {
        set_end_sessions();
    } else if (ISSET_INTERRUPT_DNS(config)) {
        set_end_dns_records();
    } else {
        config.intr_flag = 0;
    }
}