Exemplo n.º 1
0
void Exec::Execute(tstring const &folder, FileEvent *fileEvent, vector<HANDLE> &handles)
{
	using ch = tstring::value_type;
	tstring c = Format($("cmd /c %s"), ReplaceAllTokens(mCommand, fileEvent).c_str());
	ptr<ch> cmd(new ch[c.size() + 1]);
	memcpy(cmd.get(), c.c_str(), c.size() + 1);
	STARTUPINFO si = { 0 };
	PROCESS_INFORMATION pi = { 0 };
	si.cb = sizeof(si);
	ansi_printf($("%s..."), c.c_str());
	if (!CreateProcess(NULL, cmd.get(), NULL, NULL, TRUE, 0, NULL, folder.c_str(), &si, &pi))
	{
		error($("error: %s\n"), GetLastErrorText().c_str());
		return;
	}
	else
	{
		handles.push_back(pi.hProcess);
		if (!mAsync)
		{
			WaitForSingleObject(pi.hProcess, INFINITE);
			ansi_printf($("complete\n"), mCommand.c_str());
		}
		else
		{
			ansi_printf($("spawned\n"));
		}
	}
}
Exemplo n.º 2
0
void display_message (int message, int lives, int level, int score)
{
  char text [80];
  int height = MAX_SCR_MESSAGE_Y;
  int y1 = (MAX_SCR_ROWS - height) / 2 - MSG_BORDER_Y;

  if ((message == MSG_FLOOR) || (message == MSG_COLLISION) || (message == MSG_FIRE) || (message == MSG_WATER))
    {
      if (lives == 0)
	draw_message (MAX_SCR_GAMEOVER_X, gameover);
      else
	draw_message (MAX_SCR_CRASH_X, crash);
      sprintf (text, "Caused by %s", crash_messages [message]);
      ansi_SetAttr (ATTR_reverse);
      centre_text (text, y1 + MAX_SCR_MESSAGE_Y + 2 * MSG_BORDER_Y, MAX_SCR_COLS);
      centre_text ("Press <5> <Enter> or <Space>", y1 + MAX_SCR_MESSAGE_Y + 2 * MSG_BORDER_Y + 1, MAX_SCR_COLS);
      centre_text ("to continue....", y1 + MAX_SCR_MESSAGE_Y + 2 * MSG_BORDER_Y + 2, MAX_SCR_COLS); 
      ansi_Position (1, MAX_SCR_ROWS);
      ansi_printf (" Game Info  -  Score: [%6d]  Lives Remaining: [%2d]  Next Level: [%2d]    ", score, lives, level);
      ansi_SetAttr (ATTR_normal);
    }
  else if (message == MSG_WINLEVEL)
    draw_message (MAX_SCR_WINLEVEL_X, winlevel);
  wait_for_select ();
}
Exemplo n.º 3
0
void menu (void)
{
  int option;
  
  while (1)
    {
      option = menu_get_input ();
      
      switch (option)
	{
	case 0:
	  game ();
	  break;
	case 3:
   	  draw_frame ();
	  put_screen (credits);
	  wait_for_key ();
	  break;
	case 4:
	  draw_frame ();
	  put_screen (help_1);
	  wait_for_key ();
	  put_screen (help_2);
	  wait_for_key ();
	  break;
	case 5:
	  return;
	default:
	  ansi_Position (1, MAX_SCR_ROWS);
	  ansi_SetAttr (ATTR_reverse);
	  ansi_printf ("This option is currently not supported");
	  ansi_SetAttr (ATTR_normal);
	  break;
	}
    }
}
Exemplo n.º 4
0
void game_win (void)
{
  int x, y, prev_x, prev_y;
  int count;
  
  x = 53;
  y = 6;

/* Pilot appears out of aircraft */

  put_picture (x, y, MAX_SCR_PILOT_X, MAX_SCR_PILOT_Y, pilot, IMAGE_CLEAR);

  prev_y = y;
  
/* Pilot moves down ladder */
  
  for (y = 7; y <= 19; y++)
    {
      move_picture (x, prev_y, x, y, MAX_SCR_PILOT_X, MAX_SCR_PILOT_Y, pilot, MAX_SCR_COLS, MAX_SCR_ROWS, level_data [LAST_LEVEL].map);
      prev_y = y;
      terminal_sleep (0, WAIT_PILOT);
    }

/* Move the pilot a bit to the left now */

  prev_x = x;
  y--;

  for (x = 52; x >= 44; x--)
    {
      move_picture (prev_x, y, x, y, MAX_SCR_PILOT_X, MAX_SCR_PILOT_Y, pilot, MAX_SCR_COLS, MAX_SCR_ROWS, level_data [LAST_LEVEL].map);
      prev_x = x;
      terminal_sleep (0, WAIT_PILOT);
    }

  /* Pilot is in position - move in the helicopter from the right*/

  y = 13;
  prev_x = 79;

  for (x = 79; x >= 34; x--)
    {
      move_picture (prev_x, y, x, y, MAX_SCR_HELICOPTER_X, MAX_SCR_HELICOPTER_Y, helicopter, MAX_SCR_COLS, MAX_SCR_ROWS, level_data [LAST_LEVEL].map);
      prev_x = x;
      terminal_sleep (0, WAIT_HELICOPTER);
    }


  /* Pilot waves */

  for (count = 0; count <= 3; count++)
    {
      terminal_sleep (0, WAIT_PILOT);
           
      ansi_Position (44, 19);
      ansi_printf ("\\O/");
      ansi_Position (44, 20);
      ansi_printf (" | ");

      terminal_sleep (0, WAIT_PILOT);
      ansi_Position (44, 19);
      ansi_printf (" O ");
      ansi_Position (44, 20);
      ansi_printf ("/|\\");
    }

  /* Helicopter lowers rope */

  for (y = 16; y <= 19; y++)
    {
      terminal_sleep (0, WAIT_PILOT);
      ansi_Position (40, y);
      ansi_putchar ('|');
    }

/* Pilot now moves under the rope */

  y = 19;
  prev_x = 44;
  for (x = 43; x >= 39; x--)
    {
      move_picture (prev_x, y, x, y, MAX_SCR_PILOT_X, MAX_SCR_PILOT_Y, pilot, MAX_SCR_COLS, MAX_SCR_ROWS, level_data [LAST_LEVEL].map);
      prev_x = x;
      terminal_sleep (0, WAIT_PILOT);
    }

  prev_y = y;
  x = 39;

  for (y = 18; y >= 15; y--)
    {
      move_picture (x, prev_y, x, y, MAX_SCR_PILOT_X, MAX_SCR_PILOT_Y, pilot, MAX_SCR_COLS, MAX_SCR_ROWS, level_data [LAST_LEVEL].map);
      prev_y = y;
      terminal_sleep (0, WAIT_PILOT);
    }

/* Erase pilot */

  y = 15;
  for (count = y; count < y + 3; count++)
    ansi_PutString (39, count, "   ");
  y = 13;
  x = 34;
  put_picture (x, y, MAX_SCR_HELICOPTER_X, MAX_SCR_HELICOPTER_Y, helicopter, IMAGE_SOLID);

/* Move the helicopter off the screen */

  prev_x = x;

  for (x = 33; x >= -MAX_SCR_HELICOPTER_X; x--)
    {
      move_picture (prev_x, y, x, y, MAX_SCR_HELICOPTER_X, MAX_SCR_HELICOPTER_Y, helicopter, MAX_SCR_COLS, MAX_SCR_ROWS, level_data [LAST_LEVEL].map);
      prev_x = x;
      terminal_sleep (0, WAIT_HELICOPTER);
    }

  for (count = LAST_LEVEL - 1; count >= 0; count--)
    {
      put_screen (level_data [count].map);
      sleep (WAIT_FOR_UPDATE);
      
      prev_x = 80;
      for (x = 79; x >= -MAX_SCR_HELICOPTER_X; x--)
	{
	  move_picture (prev_x, y, x, y, MAX_SCR_HELICOPTER_X, MAX_SCR_HELICOPTER_Y, helicopter, MAX_SCR_COLS, MAX_SCR_ROWS, level_data [count].map);
	  prev_x = x;
	  terminal_sleep (0, WAIT_HELICOPTER);
	}
    }
}
Exemplo n.º 5
0
void signal_handler (int signum)
{
  ansi_printf ("Signal handler %d ... Exiting...", signum);
  exit (1);
}
Exemplo n.º 6
0
int play_level (int level, long int *score, int lives, int total_score)
{
  int aircraft_x = 2, prev_aircraft_x = aircraft_x;
  float aircraft_y_float = 8.0;
  int aircraft_y = aircraft_y_float, prev_aircraft_y = aircraft_y;
  int direction = DIR_FORWARD;
  int aircraft_stats;
  int x_offset = 0;
  float y_offset = 0.0;
  char KeyPressed = 0;
  struct timeval start_time, end_time;
  struct timezone start_timezone, end_timezone;
  long int bonus = 0;
  struct termios stored_terminal;

  struct get_arrow_keys num_keypad = { '8', '2', '4', '6' };
  struct get_arrow_keys alpha_keypad = { 0, 0, ',', '.' };

  get_term_settings (stored_terminal);
  set_term (0, 0);
  draw_frame ();
  put_screen (level_data [level].map);
  ansi_Position (2, MAX_SCR_ROWS);
  ansi_SetAttr (ATTR_reverse);
  ansi_printf (" Game Info  -  Score: [%6d]  Lives Remaining: [%2d]  Current Level: [%2d]", total_score, lives, level);
  ansi_SetAttr (ATTR_normal);
  park_cursor ();
  ansi_fflush ();
  sleep (WAIT_FOR_UPDATE); /* Really slow terminals need a few seconds to catch up */
  start_time ();
  
  put_plane (aircraft_x, aircraft_y, aircraft);

  do
    {
      aircraft_x += x_offset;
      aircraft_y_float += y_offset;
      aircraft_y = aircraft_y_float;
      
      move_picture (prev_aircraft_x, prev_aircraft_y, aircraft_x, aircraft_y, MAX_SCR_PLANE_X, MAX_SCR_PLANE_Y, aircraft, MAX_SCR_COLS, MAX_SCR_ROWS, level_data [level].map);

      prev_aircraft_x = aircraft_x;
      prev_aircraft_y = aircraft_y;
      
      if (delay_for_key (WAIT_TIME_Sec, WAIT_TIME_uSec))
	switch (get_arrow (TRUE, &num_keypad, &alpha_keypad))
	  {
	  case DIR_left: direction = DIR_BACKWARD; break;
	  case DIR_right: direction = DIR_FORWARD; break;
	  default: KeyPressed = terminal_getchar (); break;
	  }
      
      aircraft_stats = check_aircraft (aircraft_x, aircraft_y, level, aircraft);
      
/* Check to see if any 'events' have happened */
      
      if (aircraft_stats != OBJ_NOTHING)
	{
	  if ((aircraft_stats & OBJ_COLLISION) == OBJ_COLLISION)
	    {
	      set_term_settings (stored_terminal);
	      return (MSG_COLLISION);
	    }

	  if ((aircraft_stats & OBJ_FIRE) == OBJ_FIRE)
	    {
	      set_term_settings (stored_terminal);
	      return (MSG_FIRE);
	    }
	  
	  if ((aircraft_stats & OBJ_WATER) == OBJ_WATER)
	    {
	      set_term_settings (stored_terminal);
	      return (MSG_WATER);
	    }
	  
	  if ((aircraft_stats & OBJ_FLOOR) == OBJ_FLOOR)
	    {
	      set_term_settings (stored_terminal);	  
	      return (MSG_FLOOR);
	    }
	  
	  if ((aircraft_stats & OBJ_RIGHTWALL) == OBJ_RIGHTWALL)
	    {
	      end_time ();
	      *score = calculate_score (diff_time (), bonus, level);
	      set_term_settings (stored_terminal);
	      return (MSG_WINLEVEL);
	    }
	  
	  if ((aircraft_stats & OBJ_WINGAME) == OBJ_WINGAME)
	    {
	      end_time ();
	      *score = calculate_score (diff_time (), bonus, level);
	      set_term_settings (stored_terminal);
	      return (MSG_WINGAME);
	    }
	}
      
      if ((aircraft_stats & OBJ_BONUS) == OBJ_BONUS)
	bonus++;
      
      /* Ok, the Glider has not crashed and the level has not ended, we must now move it appropriately */
      
      x_offset = direction;
      y_offset = STEP_DOWN;
      
      if ((aircraft_stats & OBJ_VENT) == OBJ_VENT)
	y_offset = STEP_VENT;
      if ((aircraft_stats & OBJ_ROOF) == OBJ_ROOF)
	if ((aircraft_stats & OBJ_VENT) == OBJ_VENT)
	  y_offset = 0.0;
      if ((aircraft_stats & OBJ_LEFTWALL) == OBJ_LEFTWALL)
	if (direction == DIR_BACKWARD)
	  x_offset = 0;
    } while (toupper (KeyPressed) != 'Q');
  set_term_settings (stored_terminal); 
  return (MSG_QUIT);
}