task main()
{
	// Going forward at full speed
	go_forward(100);
	nxtDisplayCenteredTextLine (3, "Going Forward");
	wait1Msec (Drive_Time);
	// Going left at half speed
	go_left(50);
	nxtDisplayCenteredTextLine (3, "Turning Left");
	wait1Msec (Turn_Time);
	go_forward(100);
	nxtDisplayCenteredTextLine (3, "Going Forward");
	wait1Msec (Drive_Time);
	go_left(50);
	nxtDisplayCenteredTextLine (3, "Turning Left");
	wait1Msec (Turn_Time);
	go_forward(100);
	nxtDisplayCenteredTextLine (3, "Going Forward");
	wait1Msec (Drive_Time);
	go_left(50);
	nxtDisplayCenteredTextLine (3, "Turning Left");
	wait1Msec (Turn_Time);
	go_forward(100);
	nxtDisplayCenteredTextLine (3, "Going Forward");
	wait1Msec (Drive_Time);
	go_left(50);
	nxtDisplayCenteredTextLine (3, "Turning Left");
	wait1Msec (Turn_Time);
	StopAllTasks ();
}
void MainWindow::move()
{
    auto s_head = getHead();
    auto s_food = QPoint(food_pos.x(), food_pos.y());
    auto s_foot = getFoot();
    state_now = find_way(s_head, s_food);
    if(state_now == -1){
        state_now = find_way(s_head, s_foot);
    }
    if(state_now == to_left)
    {
        go_left();
    }else if(state_now == to_right){
        go_right();
    }else if(state_now == to_up){
        go_up();
    }else if(state_now == to_down){
        go_down();
    }else{
        state_now = getRandomStep(s_head);
        if(state_now == -1){
            QMessageBox::information(0, "", "end");
            gameover();
        }else if(state_now == to_left){
            go_left();
        }else if(state_now == to_right){
            go_right();
        }else if(state_now == to_up){
            go_up();
        }else if(state_now == to_down){
            go_down();
        }
    }
    update();
}
示例#3
0
文件: go.c 项目: Alban95/epikong
void		go_leftup(t_struct *st)
{
  if (up_once(st) == 0)
    {
      fct_ptr(st);
      SDL_Flip(st->ecran);
      go_left(st);
      fct_ptr(st);
      SDL_Flip(st->ecran);
      go_left(st);
    }
}
示例#4
0
void		Monster::right_left(float a, std::deque<AObject*> &map)
{
  if (a > 0) // RIGHT
    go_right(map, 1);
  else if (a < 0) // LEFT
    go_left(map, 1);
}
示例#5
0
文件: ai.cpp 项目: Coolcord/Trake
bool AI::try_go_left()
{
  if (is_left_safe_later())
    return go_left();
  else
    return false;
}
示例#6
0
文件: snake.c 项目: Seppho/snake
int main(int argc,char **argv){
	snake cobra;
	int i;
	struct winsize w;

	stat.i=0;
	if(argc>1)
		stat.velocity=atoi(argv[1]);

	else stat.velocity=1;
	ioctl(0, TIOCGWINSZ, &w);
	rows=w.ws_row-5;
	cols=w.ws_col-1;

	init_snake(&cobra);

	stat.i=0;
	while(1){
		print_matrix(cobra);
		sleep(stat.velocity);
		if(stat.i<2)
			go_left(cobra);
		else if(stat.i<4)
			go_right(cobra);
		else if(stat.i<10)
			go_up(cobra);
		else if(stat.i<18)
			go_right(cobra);
		else go_bottom(cobra);
		stat.i++;
	}

return 0;
}
示例#7
0
文件: event2.c 项目: cham-s/ft_select
void		key_handler(unsigned int key, t_entlist *l, int *running)
{
	if (key == K_ENT)
	{
		clean_screen(l);
		*running = 0;
	}
	else
	{
		if (key == K_ESC)
			quit(l);
		else if (key == K_DOWN)
			go_down(l);
		else if (key == K_UP)
			go_up(l);
		else if (key == K_RIGHT)
			go_right(l);
		else if (key == K_LEFT)
			go_left(l);
		else if (key == K_DEL || key == K_BKSPC)
			delete_key(l);
		else
			special_keys(key, l);
	}
}
示例#8
0
文件: press_key2.c 项目: cvrmj/bidon
void			movements_delete(int a)
{
	int h[2];

	tputs(tgetstr("cd", NULL), 0, tputs_putchar);
	h[0] = ft_putstr_i(g_shell.shell_line, g_cursor.position_line);
	h[1] = h[0];
	while (h[0] - 1 > 0)
	{
		move_cursor_right(g_cursor, g_shell);
		h[0]--;
	}
	if ((g_cursor.position_x_rel == g_shell.shell_win_size - 1) && \
			g_cursor.position_line != g_shell.length_line)
	{
		ft_putstr(" ");
		tputs(tgetstr("le", NULL), 0, tputs_putchar);
	}
	move_cursor_right(g_cursor, g_shell);
	while (h[1] - a > 0)
	{
		go_left(g_cursor, g_shell);
		move_cursor_left(g_cursor, g_shell);
		h[1]--;
	}
}
示例#9
0
文件: delete.c 项目: kokaz/42sh
char	*my_back_space(int buf, char *str, t_line *line)
{
  char	*cpy;

  if (!line->rk)
    return (str);
  if (!str[line->rk])
    {
      str[line->rk - 1] = 0;
      my_left(buf, str, line);
      write(line->fd, " ", 1);
      go_left();
      if (line->x == line->win_x - 1)
	go_right();
      return (str);
    }
  my_left(buf, str, line);
  if ((cpy = strdup(&str[line->rk + 1])) == NULL)
    return (NULL);
  write(line->fd, &str[line->rk + 1], strlen(&str[line->rk]));
  str[line->rk] = 0;
  if ((cpy = my_strcat(str, cpy)) == NULL)
    return (NULL);
  recup_position(cpy, line, str, 0);
  return (cpy);
}
示例#10
0
void		sh_pk_home(t_usent *us)
{
	while (us->curs_line != 0 || us->curs_col != us->prompt_size)
	{
		go_left(us);
		INDEX--;
	}
}
示例#11
0
文件: press_key3.c 项目: cvrmj/bidon
void			press_left_key(void)
{
	if (g_cursor.position_line > 0 && g_shell.backslash_index != 0)
	{
		go_left(g_cursor, g_shell);
		move_cursor_left(g_cursor, g_shell);
	}
	if (g_shell.backslash_index > 0)
		g_shell.backslash_index--;
}
示例#12
0
文件: delete.c 项目: kokaz/42sh
char	*my_delete(int buf, char *str, t_line *line)
{
  if (str == NULL || !str[line->rk])
    return (str);
  if (line->rk == 0 && !str[1])
    {
      line->x = 0;
      line->rk = 0;
      write(line->fd, " ", 1);
      go_left();
      xfree(1, &str);
      return (NULL);
    }
  if (!str[line->rk + 1])
    {
      str[line->rk] = 0;
      write(line->fd, " ", 1);
      go_left();
      return (str);
    }
  return (my_delete_and_recup(buf, str, line));
}
示例#13
0
文件: press_key3.c 项目: cvrmj/bidon
void			press_home_key(void)
{
	int			h;

	h = g_cursor.position_line;
	while (h > 0)
	{
		if (g_shell.backslash_index == 0)
			break ;
		go_left(g_cursor, g_shell);
		move_cursor_left(g_cursor, g_shell);
		if (g_shell.backslash_index > 0)
			g_shell.backslash_index--;
		h--;
	}
}
示例#14
0
文件: move.c 项目: jdhaisne/ft_select
int	move(char *key, t_data *data)
{
	if (key[0] == 27)
	{
		if (key[2] == 'D')
		{
			go_left(data->dlist);
			return (1);
		}
		else if(key[2] == 'A')
		{
			go_up(data->dlist, data->nb_word_line);
			return (1);
		}
		else if (key[2] == 'C')
		{
			go_right(data->dlist);
			return (1);
		}
		else if (key[2] == 'B')
		{
			go_down(data->dlist, data->nb_word_line);
			return (1);
		}
		else if (key[1] == 0)
			return(2);
	}
	else if(key[0] == 127)
	{
		data->dlist = del_word(data->dlist);
		tputs(tgetstr("up", NULL), 0, ft_putchar2);
		return(1);
	}
	else if (key[0] == ' ')
	{
		set_select(data->dlist);
		return (1);
	}
	else if (key[0] == '\n')
	{
		put_dlist(data->dlist, data->old_term);
		return (1);
	}
	return (0);
}
示例#15
0
文件: main.c 项目: TetraSomia/Wolf3D
void		move_me(t_win *win)
{
  const bool	*key_pressed;

  key_pressed = bunny_get_keyboard();
  if (key_pressed[BKS_W])
    move(win, FORWARD);
  if (key_pressed[BKS_S])
    move(win, BACKWARD);
  if (key_pressed[BKS_A])
    move(win, LEFT);
  if (key_pressed[BKS_D])
    move(win, RIGHT);
  if (key_pressed[BKS_LEFT])
    go_left(win);
  if (key_pressed[BKS_RIGHT])
    go_right(win);
}
示例#16
0
int			is_a_valid_key(int c)
{
	if (c == 27)
	{
		endwin();
		exit(0);
	}
	else if (c == KEY_DOWN)
		go_down();
	else if (c == KEY_UP)
		go_up();
	else if (c == KEY_RIGHT)
		go_right();
	else if (c == KEY_LEFT)
		go_left();
	else
		return (0);
	return (1);
}
示例#17
0
void		Monster::go_safe_place(std::deque<AObject*> &map)
{
  unsigned int	i = 0;
  bool		is_safe = false;
  int		left = 1, right = 1, up = 1, down = 1;

  while (is_safe == false && i < map.size())
    {
      if ((map[i]->getType() == DANGER || map[i]->getType() == BOMB) &&
	  map[i]->getPosition().x + 160 >= position_.x && map[i]->getPosition().x - 160 <= position_.x &&
	  map[i]->getPosition().z + 160 >= position_.z && map[i]->getPosition().z - 160 <= position_.z)
	{
	  if ((safe(position_.x + (300 * i), position_.z, map, &left) == true) || (safe(position_.x - (300 * i), position_.z, map, &right) == true))
	    {
	      if (left == 1)
		{
		  go_left(map, 0);
		  is_safe = true;
		}
	      else if (right == 1)
		{
		  go_right(map, 0);
		  is_safe = true;
		}
	    }
	  else
	    {
	      if (up == 1)
		{
		  go_up(map, 0);
		  is_safe = true;
		}
	      else if (down == 1)
		{
		  go_down(map, 0);
		  is_safe = true;
		}
	    }
	  i++;
	}
      i++;
    }
}
示例#18
0
文件: parcour.c 项目: NSSX/ffff
int go_right(char *chaine, char *piece, int chainei, int piecei, int count, int length)
{
  if(count < 4)
    {
  piecei = piecei + 1;
  chainei = chainei + 1;
  count++;  
  piece[piecei] = 'x'; 
  chaine[chainei] = 'x';
 if(piece[piecei + 1] == '#' && chaine[chainei + 1] == '.')
   count = go_right(chaine, piece, chainei, piecei, count, length);
 if(piece[piecei + 5] == '#' && chaine[chainei + length] == '.')
   count = go_down(chaine, piece, chainei, piecei, count, length);
 if(piece[piecei - 5] == '#' && chaine[chainei - length] == '.')
   count = go_up(chaine, piece, chainei, piecei, count, length);
 if(piece[piecei - 1] == '#' && chaine[chainei - 1] == '.')
   count = go_left(chaine, piece, chainei, piecei, count, length);
    }
  return (count);
}
示例#19
0
void		sh_pk_ctrl_l(t_usent *us)
{
	while (INDEX < us->c_size)
	{
		go_right(us);
		INDEX++;
	}
	while (us->curs_line != 0 || us->curs_col != us->prompt_size)
	{
		go_left(us);
		tputs(tgetstr("dc", NULL), 0, tputchar);
		INDEX--;
	}
	free(us->edit);
	if (!(us->edit = (char*)malloc(sizeof(char) * 255)))
		sh_error_quit("malloc us->edit fail");
	ft_memset(us->edit, '\0', 255);
	tputs(tgetstr("cl", NULL), 0, tputchar);
	printprompt(NULL);
}
示例#20
0
// moves the tank
void move_tank ( Tank *tank, int direction){

    //if this tank moved TANKSPEED earlier, just ignore. else, set move_state to 0
    if (tank->move_state < tank->move_speed ) return;

    tank->move_state = 0;

    switch(direction){
    case LEFT:
        go_left(tank);
        break;
    case RIGHT:
        go_right(tank);
        break;
    case UP:
        go_up(tank);
        break;
    case DOWN:
        go_down(tank);
        break;
    }
}
示例#21
0
int		main(int argc, char **argv)
{
	int key;
	t_map *g_map;
	t_game *snake;

	srand(time(NULL));
	if (argc < 3)
		return (-1);
	snake = malloc(sizeof(t_game));
	g_map = malloc(sizeof(t_map));

	g_map->x_max = ft_atoi(argv[2]);
	g_map->y_max = ft_atoi(argv[1]);
	if (g_map->x_max < 3 || g_map->y_max < 3)
		return (-1);
	g_map->x_map = rand_a_b(3, g_map->x_max + 1);
	g_map->y_map = rand_a_b(3, g_map->y_max + 1);
	// ft_putnbr(g_map->x_map);
	// ft_putchar('\n');
	// ft_putnbr(g_map->y_map);
	// ft_putchar('\n');
	snake->x_s = 1;
	snake->y_s = 1;
	// ft_putnbr(snake->x_s);
	// ft_putchar('\n');
	// ft_putnbr(snake->y_s);
	// ft_putchar('\n');
	snake->pv_s = 13;

	g_map->map = map_create(g_map->x_map, g_map->y_map);
	ft_putendl("placement du heros");
	g_map->map[snake->x_s][snake->y_s] = 's';
	ft_putendl("affichage");
	
	//free_all(snake, g_map);
	while (1)
	{
		key = 2;
		key = getarrowkey();
		aff_map(g_map);
		aff_pv(snake);
		ft_putstr("POSITION:");
		ft_putnbr(snake->x_s);
		ft_putchar(' ');
		ft_putnbr(snake->y_s);
		ft_putchar('\n');
		ft_putstr("MAP");
		ft_putnbr(g_map->x_map);
		ft_putchar(' ');
		ft_putnbr(g_map->x_map);
		if (key == 1)
		{
			if (go_left(snake, g_map))
			{
				add_room(g_map);
				g_map = g_map->next;
			}
		}
		else if (key == 2)
		{
			if (go_up(snake, g_map))
			{
				add_room(g_map);
				g_map = g_map->next;
			}
		}
		else if (key == 3)
		{
			if (go_down(snake, g_map))
			{
				add_room(g_map);
				g_map = g_map->next;
			}
		}	
		else if (key == 4)
		{
			if (go_right(snake, g_map))
			{
				add_room(g_map);
				g_map = g_map->next;
			}
		}
		else if (key == 5)
		{
			free_all(snake, g_map);
			return (0);
		}
		usleep(100000);
		system("CLEAR");
	}
	return (0);
}
示例#22
0
/******************************************************************
 * 			Main-function
 */
int main(void) {

	/**************************************
	 * 	Set the clock to run at 80 MHz
	 */
	SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

	/**************************************
	 * 	Enable the floating-point-unit
	 */
	FPUEnable();
	// We also want Lazystacking, so enable that too
	FPULazyStackingEnable();
	// We also want to put numbers close to zero to zero
	FPUFlushToZeroModeSet(FPU_FLUSH_TO_ZERO_EN);

	/**************************************
	 * 	Init variables
	 */
	uint16_t mapData[MAP_DATA_SIZE];
	uint8_t stepDir = 0;

	/**************************************
	 * 	Init peripherals used
	 */
	bluetooth_init();
	init_stepper();							// Init the GPIOs used for the stepper and loading LED
	InitI2C1();								// Init the communication with the lidar-unit through I2C
	InitPWM();
	setupTimers();

	/**************************************
	 * 	State 2
	 */
	// Disable the timers that are used
	disableTimer(TIMER1_BASE);
	disableTimer(TIMER2_BASE);

	// Enable all interrupts
	IntMasterEnable();
	/**************************************
	 * 	State 3
	 */
	// Indicate we should start with a scan regardless of what other things we have already got
	// from UART-interrupt
	// This means setting the appropriate bit in the status vector
	stat_vec |= TAKE_MEAS;

	/**************************************
	 * 	State 4
	 */
	// Contains main-loop where decisions should be made
	for ( ; ; ) {
		/**********************************
		 * 	Decision tree
		 */
		// Highest priority case first


		// Check both interrupts at each iteration in the loop
		if ( int_vec & UART_INT ) {
			// Reset the indication
			int_vec &= ~UART_INT;

			// Remove drive-stop flag to enable movement
			stat_vec &= ~DRIVE_STOP;

			// Init data array
			uint8_t dataArr[MAX_UART_MSG_SIZE];

			// Collect the message
			if ( readUARTMessage(dataArr, MAX_UART_MSG_SIZE) < SUCCESS ) {
				// If we have recieved more data than fits in the vector we should simply
				// go in here again and grab data
				int_vec |= UART_INT;
			}
			// We have gathered a message
			// and now need to determine what the message is
			parseMsg(dataArr, MAX_UART_MSG_SIZE);
		}
		// Checking drive (movement) interrupt
		if ( int_vec & TIMER2_INT ) {
			int_vec &= ~TIMER2_INT;
			// Disable TIMER2
			disableTimer(TIMER2_BASE);
			// Set drive-stop in status vector
			stat_vec |= DRIVE_STOP;
		}
		// Checking measure interrupt
		if ( int_vec & TIMER1_INT ) {
			int_vec &= ~TIMER1_INT;
			// Disable TIMER1
			disableTimer(TIMER1_BASE);

			// Take reading from LIDAR
			mapData[stepCount++] = readLidar();
			SysCtlDelay(2000);

			// Take step
			// Note: We need to take double meas at randvillkor (100) !!!!!
			if ( stepCount > 0 && stepCount < 100 ) {
				stepDir = 1;
			}
			else if ( stepCount >= 100 && stepCount < 200) {
				stepDir = 0;
			}
			else {
				stepDir = 1;
				stepCount = 0;

				// Reset busy-flag
				stat_vec &= ~TAKE_MEAS;
			}
			step = takeStep(step, stepDir);

			// Request reading from LIDAR
			reqLidarMeas();

			if ( stat_vec & TAKE_MEAS ) {
				// Restart TIMER1
				enableTimer(TIMER1_BASE, (SYSCLOCK / MEASUREMENT_DELAY));
			}
			else {
				sendUARTDataVector(mapData, MAP_DATA_SIZE);
				stat_vec &= ~BUSY;
			}
		}

		// Check the drive_stop flag, which always should be set unless we should move
		if ( stat_vec & DRIVE_STOP ) {
			// Stop all movement
			SetPWMLevel(0,0);
			halt();

			// MAKE SURE all drive-flags are not set
			stat_vec &= ~(DRIVE_F | DRIVE_L | DRIVE_R | DRIVE_LL | BUSY);
		}
		// Should we drive?
		else if ( stat_vec & DRIVE ) {
			// Remove drive flag
			stat_vec &= ~DRIVE;
			// Increase PWM
			increase_PWM(0,MAX_FORWARD_SPEED,0,MAX_FORWARD_SPEED);
			if ( stat_vec & DRIVE_F ) {
				enableTimer(TIMER2_BASE, DRIVE_FORWARD_TIME);
			}
			else if ( stat_vec & DRIVE_LL ) {
				enableTimer(TIMER2_BASE, DRIVE_TURN_180_TIME);
			}
			else {
				enableTimer(TIMER2_BASE, DRIVE_TURN_TIME);
			}
		}
		if ( !(stat_vec & BUSY) ) {
			// Tasks
			switch ( stat_vec ) {
				case ((uint8_t)DRIVE_F) :
					// Call drive function
					go_forward();
					// Set the drive flag & BUSY
					stat_vec |= DRIVE | BUSY;
					break;
				case ((uint8_t)DRIVE_L) :
					// Call drive-left function
					go_left();
					// Set the drive flag
					stat_vec |= DRIVE | BUSY;
					break;
				case ((uint8_t)DRIVE_R) :
					// Call drive-right function
					go_right();
					// Set the drive flag
					stat_vec |= DRIVE | BUSY;
					break;
				case ((uint8_t)DRIVE_LL) :
					// Call turn 180-degrees function
					go_back();
					// Set the drive flag
					stat_vec |= DRIVE | BUSY;
					break;
				case ((uint8_t)TAKE_MEAS) :
					// Request reading from LIDAR
					reqLidarMeas();
					// Start TIMER1
					enableTimer(TIMER1_BASE, (SYSCLOCK / MEASUREMENT_DELAY)); // if sysclock = 1 s, 1/120 = 8.3 ms
					// We are busy
					stat_vec |= BUSY;
					break;

				default:
					break;
			}
		}
	}
}
示例#23
0
文件: tetris.c 项目: Zinurist/Tetris
void game_loop(int * input_key){
	//init game data
	init_game();
	
	//control data
	struct timeval *begin, *end, *tmp;
	unsigned long diff;//in us
	int key = 0; //for temporary storage of input_key, b/c of race conditions
	int reached_bottom = 0;
	
	begin=malloc(sizeof(struct timeval));
	end=malloc(sizeof(struct timeval));
	gettimeofday(begin, NULL);
	diff = 0;
	
	draw();
	while(1){
		//input
		key=*input_key;
		if(key != -1){
			*input_key = -1;//input read->reset
			switch(key){//TODO move block
				case KEY_DOWN:	
					reached_bottom = go_down(&current_tetromino, &world);
					break;
				case KEY_LEFT: 	
					if(!reached_bottom){
						go_left(&current_tetromino, &world);
					}
					break;
				case KEY_RIGHT: 
					if(!reached_bottom){
						go_right(&current_tetromino, &world);
					}
					break;
				case 'x':
					if(!reached_bottom){
						rotate(&current_tetromino, &world, 1);
					}
					break;
				case 'c':
					if(!reached_bottom){
						rotate(&current_tetromino, &world, 0);
					}
					break;
				case 27: /*ESC*/
					switch(menu(input_key)){
						case 0:break;//continue game
						case 1:init_game();break;//new game
						case -1://quit
							free(begin);
							free(end);
							return;
						default:break;
					} 
					gettimeofday(begin, NULL);
					break;
				case 32: /*Space*/
					while(!go_down(&current_tetromino, &world));
					reached_bottom=1;
					diff=tick_time;
					break;
				case -2: 		
					free(begin);
					free(end);
					return;
				default: break;
			}
		}
		
		//game tick & time
		gettimeofday(end, NULL);
		diff+=(end->tv_sec-begin->tv_sec)*1000000 + end->tv_usec-begin->tv_usec;
		tmp=begin;
		begin=end;
		end=tmp;
		
		if(diff >= tick_time){
			diff -= tick_time;
			tick(&reached_bottom);
		}
		
		//gui update
		draw();
		
		//sleep
		usleep(50*1000);
	}
}