Пример #1
0
int main()												// Here is our main().
{
    // This is our buffer that will hold all the maze data we wish to display to the screen.
    CHAR_INFO screenBuffer[SCREEN_WIDTH * SCREEN_HEIGHT] = {0};
    COORD bufferSize = {SCREEN_WIDTH , SCREEN_HEIGHT};	// This is a COORD that holds the width and height of our window that we will display
    COORD playerPos = {START_X, START_Y};				// This will hold our players position

    srand( GetTickCount() );							// This seeds our random numbers with time so it isn't always the same maze

    // Below we create our maze with a bunch of random # signs.
    // This just fills in our screen buffer with the data, but DOESN'T draw it yet.
    // It is faster to draw it all at once, rather than using WriteConsoleOutputCharacter().

    for(int y = 0; y < bufferSize.Y; y++)				// This fills in the columns (y value) of our buffer
    {
        // You will notice that we start at x = 2.  This is so we have some room to freely walk around in front of the maze.

        for(int x = 2; x < bufferSize.X; x++)			// This fills in the rows (x value) of our buffer.
        {
            // Below, we fill in the current index with a wall and color.
            if(!(rand() % 3))							// If our random number is 2, then draw a wall in our maze.  This mixes up the maze.
            {
                screenBuffer[x + y * SCREEN_WIDTH].Char.AsciiChar = WALL;
                screenBuffer[x + y * SCREEN_WIDTH].Attributes = FOREGROUND_GREEN;
            }
        }
    }

    // This will draw the player in it's current position, along with the maze.
    // It takes our screen buffer, and the players position to be drawn at.
    // This will draw the initial maze to the screen.
    DrawMaze(screenBuffer, playerPos.X, playerPos.Y);

    // Below is our main loop that check to see if we move the player, and if so, redraw the screen.

    while(1)
    {
        // We pass in our player position because we will change it if we move.
        // If we do move, then we return TRUE from MovePlayer() and we need to redraw the screen.

        if(MovePlayer(screenBuffer, playerPos))
        {
            // Draw the new updated player position within the maze
            DrawMaze(screenBuffer, playerPos.X, playerPos.Y);
        }
    }

    return 0;											// Return with zero problems
}														// End of the program
Пример #2
0
StaffmodeWnd::StaffmodeWnd()
{
	int		i,j;
	ZeroMemory(this,sizeof(StaffmodeWnd));
	InitMaze();
	baseWnd.loadLGF(pack_gparts,"staffBase");
	logo.loadLGF(pack_gparts,"staffLogo");
	nameList.createColorBuf(800,22,32);

	dest.buf = (RGB24 *)g_DibInf.colorBuf.pBuf;
	dest.sx = 800; dest.sy = 600;
	selectNum = rndSelect(43);
	for(i=0;i<4;i++){
		j = selectNum +i;
		if(i==3) j = selectNum -1;
		if( j <  0) j += 44;
		if( j > 43) j -= 44;
		wsprintf(str,"stt%03d",j);
		panel[i].loadLGF(pack_eventcg,str);
		src[i].buf = (BYTE *)panel[i].pBuf;
		src[i].pal = (RGB32 *)panel[i].palColor;
		src[i].alp = NULL;
		src[i].sx = 400; src[i].sy = 300;
	}
	button.loadLGF(pack_gparts,"staffBtn");
	RECT	ptRect[3];
	rect.left = 20;	rect.right = rect.left +188;
	rect.top = 268;		rect.bottom = rect.top +172;
	for(i=0;i<3;i++){
		ptRect[i].left = 0;		ptRect[i].right = ptRect[i].left +188;
		ptRect[i].top = i*172;	ptRect[i].bottom = ptRect[i].top +172;
	}
	btn[0].Create(1,&button,&rect,ptRect,&g_DibInf.colorBuf);
	rect.left = 592;	rect.right = rect.left +188;
	rect.top = 268;		rect.bottom = rect.top +172;
	for(i=0;i<3;i++){
		ptRect[i].left = 188;	ptRect[i].right = ptRect[i].left +188;
		ptRect[i].top = i*172;	ptRect[i].bottom = ptRect[i].top +172;
	}
	btn[1].Create(1,&button,&rect,ptRect,&g_DibInf.colorBuf);
	rect.left = 400-216/2;	rect.right = rect.left +216;
	rect.top = 340;	rect.bottom = rect.top +156;
	for(i=0;i<3;i++){
		ptRect[i].left = 376;		ptRect[i].right = ptRect[i].left +216;
		ptRect[i].top = i*156;	ptRect[i].bottom = ptRect[i].top +156;
	}
	btn[2].Create(1,&button,&rect,ptRect,&g_DibInf.colorBuf);

	c_cls_all();
	msgWnd.MsgCLS();
	msgWnd.ForceHide();
	changeExecMode( staffmode_mode );
	bgInf.look_max = 900;
	bgInf.look_cnt = timeGetTime() +bgInf.look_max;
	panel[0].alpha = panel[1].alpha = button.alpha = baseWnd.alpha = logo.alpha = 0;


	DrawMaze(&baseWnd);
	writeName();
}
Пример #3
0
void StaffmodeWnd::Draw()
{
	int		i;

	g_DibInf.colorBuf.BltFast(0,0,&baseWnd,NULL,TRUE);
	if(state!=3 && state!=0 && state!=6){
		DrawMaze(&g_DibInf.colorBuf);
	}
	if(!(state==2&&bTurn==3) && state<3){
		g_DibInf.colorBuf.BltFast(0,46,&nameList,NULL,TRUE);
	}
	if(state<6){
		for(i=0;i<3;i++){
			btn[i].Draw();
		}
		g_DibInf.colorBuf.BltFast(510,490,&logo,NULL,TRUE);
	}
} // StaffmodeWnd::Draw()
Пример #4
0
int main(int argc, char *argv[]){
  int i,count, ** Maze, ascii;
  int width, height;
  if(argc<3){
    puts("Usage: width height ascii");
    exit(0);
  }
  width=atoi(argv[1]);
  height=atoi(argv[2]);
  ascii=atoi(argv[3]);
  Maze=(int**)malloc(height*sizeof(int*));
  for(i=0;i<width;i++){
    Maze[i]=(int*)malloc(height*sizeof(int));
  }
  srand (time(0));
  count=RandomMaze(10,10,Maze);
  DrawMaze(10,10,Maze, ascii);
  printf("\n%% Generated %d walls\n",count);
  return 0;
}
Пример #5
0
void displayFrame() {
	//Wyczyœæ bufor kolorów i bufor g³êbokoœci
	glClearColor(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//Wylicz macierz rzutowania
	matP = glm::perspective(cameraAngle, (float)windowWidth / (float)windowHeight, 0.5f, 100.0f);

	//Wylicz macierz widoku
	matV = glm::lookAt(m_eye, m_center, m_up);

	Animate();
	DrawFlashlight();
	DrawMaze();
	Sleep(1);

	//DrawFlashlight();

	//Tylny bufor na przedni
	glutSwapBuffers();
}
int snake_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile )
{
	struct timeval	tv;
	int		x;

	if ( FBInitialize( 720, 576, 8, fdfb ) < 0 )
		return -1;

	setup_colors();

	if ( RcInitialize( fdrc ) < 0 )
		return -1;

	Fx2ShowPig( 540, 449, 135, 96 );

	while ( doexit != 3 ) {
		DrawMaze( );	/* 0 = all */

		doexit=0;
		while ( !doexit ) {
			tv.tv_sec = 0;
			tv.tv_usec = 100000;
			x = select( 0, 0, 0, 0, &tv );		/* 10ms pause */

			RcGetActCode( );
			MoveSnake();
#if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
			FBFlushGrafic();
#endif
		}

		FreeSnake();

		if ( doexit != 3 ) {
			actcode=0xee;
			DrawFinalScore();
			DrawGameOver();
#if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
			FBFlushGrafic();
#endif

			doexit=0;
			while (( actcode != RC_OK ) && !doexit ) {
				tv.tv_sec = 0;
				tv.tv_usec = 200000;
				x = select( 0, 0, 0, 0, &tv );		/* 100ms pause */
				RcGetActCode( );
			}
		}
	}

	Fx2StopPig();

	/* fx2 */
	/* buffer leeren, damit neutrino nicht rumspinnt */
	realcode = RC_0;
	while ( realcode != 0xee ) {
		tv.tv_sec = 0;
		tv.tv_usec = 300000;
		x = select( 0, 0, 0, 0, &tv );		/* 300ms pause */
		RcGetActCode( );
	}

	RcClose();
	FBClose();

	return 0;
}
Пример #7
0
int pacman_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile )
{
	struct timeval	tv;
	int				x;
	int				jumplevel=-1;

	if ( FBInitialize( 720, 576, 8, fdfb ) < 0 )
		return -1;

	setup_colors();

	if ( RcInitialize( fdrc ) < 0 )
		return -1;

	InitLevel( 0 );

	while( doexit != 3 )
	{
		MazeInitialize();
		DrawMaze( );	/* 0 = all */
		DrawFill();
		DrawGhosts( );
		DrawPac( );
		MazePig();

		doexit=0;
		while( !doexit )
		{
			tv.tv_sec = 0;
#ifdef HAVE_DREAMBOX_HARDWARE
			tv.tv_usec = 8000;
#else
			tv.tv_usec = 1000;
#endif
			x = select( 0, 0, 0, 0, &tv );		/* 10ms pause */
	
			MovePac( );
			MoveGhosts( );
			DrawGhosts( );
			DrawPac( );
#if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
			FBFlushGrafic();
#endif
			RcGetActCode( );
			CheckGhosts( );
		}

		if ( doexit != 3 )
		{
			actcode=0xee;
			if ( score )
				DrawScore();
			if ( !gametime )
				DrawGameOver();
#if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
			FBFlushGrafic();
#endif
			doexit=0;
			jumplevel=-1;
			while(( actcode != RC_OK ) && !doexit )
			{
				tv.tv_sec = 0;
				tv.tv_usec = 100000;
				x = select( 0, 0, 0, 0, &tv );		/* 100ms pause */
				RcGetActCode( );
				if ( actcode == RC_HELP )
				{
					while( realcode != 0xee )
						RcGetActCode( );
					actcode=0xee;
					while(( actcode == 0xee ) && !doexit )
					{
						tv.tv_sec = 0;
						tv.tv_usec = 100000;
						x = select( 0, 0, 0, 0, &tv );		/* 100ms pause */
						RcGetActCode( );
					}
					if ( actcode <= RC_9 )
					{
						jumplevel=actcode;
						actcode=RC_OK;
					}
				}
			}
			if ( gametime )
				NextLevel();
			else
				InitLevel( jumplevel );
		}
	}

	Fx2StopPig();

/* fx2 */
/* buffer leeren, damit neutrino nicht rumspinnt */
	realcode = RC_0;
	while( realcode != 0xee )
	{
		tv.tv_sec = 0;
		tv.tv_usec = 300000;
		x = select( 0, 0, 0, 0, &tv );		/* 300ms pause */
		RcGetActCode( );
	}

	RcClose();
	FBClose();

	return 0;
}
Пример #8
0
/*
 * avatarMake
 *
 * Function: Initialize each avatar and send move messages during their respective turns
 *
 * Input: @id - current avatar's ID
 *
 */
void *avatarMake (void *id){
  int avatarID = (intptr_t)id;

  // Creating ready message
  AM_Message am_ready;
  memset(&am_ready, 0, sizeof(AM_Message));
  am_ready.type = htonl(AM_AVATAR_READY);
  am_ready.avatar_ready.AvatarId = htonl(avatarID);

  // Creting socket for the avatar
  int sockId;
  if ((sockId = socket(AF_INET, SOCK_STREAM, 0)) < 0){
    fprintf(stderr, "ERROR IN SOCKET 2");
    fprintf(logFile, "ERROR IN SOCKET");
    exit(1);
  }

  // Connect the client to socket                                                             
  if (connect(sockId, (struct sockaddr *) &maze_address, sizeof(maze_address)) < 0) {
    fprintf(stderr, "There was a problem connecting client to the socket 2\n");
    fprintf(logFile, "There was a problem connecting client to the socket\n");    
    exit(1);
  }

  // Sending message to our server
  send(sockId,&am_ready,sizeof(am_ready),0);
  
  // Receiving and checking reply from server
  AM_Message receiveMessage;
  if (recv(sockId,&receiveMessage,sizeof(receiveMessage),0) == 0){
    fprintf(stderr,"The server connection was closed 2\n");
    fprintf(logFile,"The server connection was closed\n");    
    exit(1);
  }
  
  if (ntohl(receiveMessage.type) != AM_AVATAR_TURN){
    fprintf(stderr,"Initialization failed 2");
    fprintf(logFile,"Initialization failed");
    exit(1);
  }
 
  // initialize avatar position
  pthread_mutex_lock(&init_mutex);
  avatarGroup[avatarID]->currpos->x = ntohl(receiveMessage.avatar_turn.Pos[avatarID].x);
  avatarGroup[avatarID]->currpos->y = ntohl(receiveMessage.avatar_turn.Pos[avatarID].y);
  avatarGroup[avatarID]->prevpos->x = avatarGroup[avatarID]->currpos->x;
  avatarGroup[avatarID]->prevpos->y = avatarGroup[avatarID]->currpos->y;
  pthread_mutex_unlock(&init_mutex);

  avFlag++;

  while(avFlag != avatarNum){
    sleep(1);
  }

  int move;
  while(1){
    // enters only on the avatar's specified turn
    if(ntohl(receiveMessage.avatar_turn.TurnId) == avatarID){

      pthread_mutex_lock(&turn_mutex);
      totalMoves++;
      fprintf(logFile,"\nMOVE #%d\n",totalMoves);
      fprintf(logFile,"avatar %d is at position (%d,%d)\n",avatarID,avatarGroup[avatarID]->currpos->x,avatarGroup[avatarID]->currpos->y);
      
      turnID = avatarID;

      setTarget();
      
      // figure out what move to make (FIX NESW)
      move = nextMove(avatarID, avatarGroup[avatarID]->currpos,avatarGroup[avatarID]->prevpos);
      
      if (move == -1){
        fprintf(stderr, "Maze node null\n");
        fprintf(logFile,"Maze node null\n");
        exit(1);
      }
      
      
      // print to file saying what move the avatar is trying to make
      fprintf(logFile,"Avatar %d is trying to move %s \n",avatarID,translateDirection(move));
      // Create move message
      AM_Message moveMessage;
      memset(&moveMessage,0,sizeof(AM_Message));
      moveMessage.type = htonl(AM_AVATAR_MOVE);
      moveMessage.avatar_move.Direction = htonl(move);
      moveMessage.avatar_move.AvatarId = htonl(avatarID);
      
      // Sending move message
      send(sockId,&moveMessage,sizeof(moveMessage),0);

      //receive and check message
      while (ntohl(receiveMessage.avatar_turn.TurnId) == avatarID){
        if (recv(sockId,&receiveMessage,sizeof(receiveMessage),0) == 0){
        fprintf(stderr,"The server connection was closed 3\n");
        fprintf(logFile,"The server connection was closed\n");
        exit(1);
        }

        if( totalMoves == (AM_MAX_MOVES*(difficulty+1)*avatarNum)){
          if(terminate == 0){
            fprintf(stderr,"Exceeded the max number of moves\n");
            fprintf(logFile,"\nEXCEEDED THE MAX NUMBER OF MOVES");
            terminate = 1;
          }
          exit (1);
        }
  
        if(ntohl(receiveMessage.type) == AM_MAZE_SOLVED){
          DrawMaze(height, width, avatarGroup, maze, avatarID, avatarNum, filename);
          if (terminate == 0 ){
            printf("solved");
            fprintf(logFile,"\nMAZE SOLVED!");
            terminate = 1;
          }
          return 0;
        }
        
        if(IS_AM_ERROR(ntohl(receiveMessage.type))){
          fprintf(stderr,"Error from the server 3");
          fprintf(logFile,"Error from the server");
          exit(1);
        }
      }

      if (move != M_NULL_MOVE){
        XYPos *tmp = (XYPos *)malloc(sizeof(XYPos));
        tmp->x = ntohl(receiveMessage.avatar_turn.Pos[avatarID].x);
        tmp->y = ntohl(receiveMessage.avatar_turn.Pos[avatarID].y);
        if (avatarMoved(avatarID, avatarGroup[avatarID]->currpos, tmp, move) == 1){
          // if the avatar moved, update its previous and current positions
          avatarGroup[avatarID]->prevpos->x = avatarGroup[avatarID]->currpos->x;
          avatarGroup[avatarID]->prevpos->y = avatarGroup[avatarID]->currpos->y;
          avatarGroup[avatarID]->currpos->x = tmp->x;
          avatarGroup[avatarID]->currpos->y = tmp->y;
        }
        free(tmp);
      }
     
      // update the maze graphic
      DrawMaze(height, width, avatarGroup, maze, avatarID, avatarNum, filename);
      pthread_mutex_unlock(&turn_mutex);
    }
    // when it's not an avatar's turn, it continues to check server messages
    else{
        //receive and check message
      if (recv(sockId,&receiveMessage,sizeof(receiveMessage),0) == 0){
        if(terminate == 0 ){
          fprintf(stderr,"The server connection was closed 3\n");
          fprintf(logFile,"The server connection was closed\n");
          terminate = 1;
        }
        exit(1);
      }

      if( totalMoves == (AM_MAX_MOVES*(difficulty+1)*avatarNum) ){
              if(terminate == 0){
          fprintf(stderr,"Exceeded the max number of moves\n");
          fprintf(logFile,"\nEXCEEDED MAX NUMBER OF MOVES");
          terminate = 1;
        }
        exit (1);
      }

      if(ntohl(receiveMessage.type) == AM_MAZE_SOLVED){
        DrawMaze(height, width, avatarGroup, maze, avatarID, avatarNum, filename);
        if(terminate == 0){
          printf("solved");
          fprintf(logFile,"\nMAZE SOLVED!");
          terminate = 1;
        }
        return 0;
      }
      
      if(IS_AM_ERROR(ntohl(receiveMessage.type))){
        if(terminate == 0){
          fprintf(stderr,"Error from the server 3");
          fprintf(logFile,"Error from the server");
          terminate = 1;
        }
        exit(1);
      }

    }
  }
  
  return 0;
}