Example #1
0
//-------------------------------- WinMain -------------------------------
//
//	The entry point of the windows program
//------------------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     szCmdLine, 
                    int       iCmdShow)
{

  //handle to our window
  HWND						hWnd;
    
  //our window class structure
  WNDCLASSEX     winclass;
		 
  // first fill in the window class stucture
  winclass.cbSize        = sizeof(WNDCLASSEX);
  winclass.style         = CS_HREDRAW | CS_VREDRAW;
  winclass.lpfnWndProc   = WindowProc;
  winclass.cbClsExtra    = 0;
  winclass.cbWndExtra    = 0;
  winclass.hInstance     = hInstance;
  winclass.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
  winclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  winclass.hbrBackground = NULL;
  winclass.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
  winclass.lpszClassName = g_szWindowClassName;
  winclass.hIconSm       = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));

  //register the window class
  if (!RegisterClassEx(&winclass))
  {
    MessageBox(NULL, "Registration Failed!", "Error", 0);

    //exit the application
    return 0;
  }

  //create the window and assign its ID to hwnd    
  hWnd = CreateWindowEx (NULL,                 // extended style
                         g_szWindowClassName,  // window class name
                         g_szApplicationName,  // window caption
                         WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
                         GetSystemMetrics(SM_CXSCREEN)/2 - WindowWidth/2,
                         GetSystemMetrics(SM_CYSCREEN)/2 - WindowHeight/2,                    
                         WindowWidth,     // initial x size
                         WindowHeight,    // initial y size
                         NULL,                 // parent window handle
                         NULL,                 // window menu handle
                         hInstance,            // program instance handle
                         NULL);                // creation parameters

  //make sure the window creation has gone OK
  if(!hWnd)
  {
    MessageBox(NULL, "CreateWindowEx Failed!", "Error!", 0);
  }
  
  //start the timer
  timer.Start();

  MSG msg;

  //enter the message loop
  bool bDone = false;

  while(!bDone)
  {
					
    while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
    {
      if( msg.message == WM_QUIT ) 
      {
        // Stop loop if it's a quit message
	      bDone = true;
      } 

      else 
      {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
      }
    }

    if (timer.ReadyForNextFrame() && msg.message != WM_QUIT)
    {
      //update game states
      g_SoccerPitch->Update(); 
      
      //render 
      RedrawWindow(hWnd, true);

      Sleep(2);
    }
   	if (g_SoccerPitch->IsTimeUp(Prm.GameTime)) 
		bDone = true;
  }//end while

  char* buff;
  buff = new char[150];
  int blueScore = g_SoccerPitch->m_pRedGoal->NumGoalsScored();
  int redScore = g_SoccerPitch->m_pBlueGoal->NumGoalsScored();
  LONGLONG redTime = g_SoccerPitch->m_redTotalTime.QuadPart;
  LONGLONG blueTime = g_SoccerPitch->m_blueTotalTime.QuadPart;
  LARGE_INTEGER freq;
  freq.QuadPart = 0I64;
  QueryPerformanceFrequency (&freq);
  double redAdjScore = redScore;
  double blueAdjScore = blueScore;
  if (redTime > blueTime)
  {
	if (redScore >= blueScore)
	{
		blueAdjScore = adjustedScore (redTime, blueTime, blueScore);
	}
  } else if (blueTime > redTime)
  {
	if (blueScore >= redScore)
	{
		redAdjScore = adjustedScore (blueTime, redTime, redScore);
	}
  }
  double fRedTime = (redTime * 1.0) / freq.QuadPart;
  double fBlueTime = (blueTime * 1.0) / freq.QuadPart;

  sprintf(buff, "Game Over\nRed: %i (%2.3f) = %2.2f \nBlue: %i (%2.3f) = %2.2f", 
			redScore, fRedTime, redAdjScore, blueScore, fBlueTime, blueAdjScore);
  //sprintf(buff, "Game Over\nRed: %i = %2.2f \nBlue: %i = %2.2f", 
	//		redScore, redAdjScore, blueScore, blueAdjScore);  
  debug_con << buff << "\n";
  MessageBox(NULL, buff, "Final Result", 0);
  delete g_SoccerPitch;

  UnregisterClass( g_szWindowClassName, winclass.hInstance );

  return msg.wParam;
}