pfly.c
Upload User: shyhai1508
Upload Date: 2007-06-11
Package Size: 48k
Code Size: 3k
Category:

BREW

Development Platform:

Visual C++

  1. #include "pfly.h"
  2. #include "AEEStdLib.h"
  3. #include "pfly.bid"
  4. #include "commondef.h"
  5. static boolean Pfly_HandleEvent(PflyApp * pme, AEEEvent eCode,uint16 wParam, uint32 dwParam);
  6. static boolean Pfly_Init(PflyApp *pMe);
  7. static void Pfly_Free(PflyApp *pMe);
  8. boolean Pfly_SetActiveWnd(PflyApp *pMe, int wnd)
  9. {
  10. switch(pMe->activeView) {
  11. case IDW_GAME:
  12. GameWnd_Close(&pMe->game);
  13. break;
  14. case IDW_GAMEEND:
  15. GameEndWnd_Close(&pMe->end);
  16. break;
  17. case IDW_MAINMENU:
  18. MainMenuWnd_Close(&pMe->mainMenu);
  19. break;
  20. case IDW_SCORELIST:
  21. ScoreListWnd_Close(&pMe->score);
  22. break;
  23. default:
  24. break;
  25. }
  26. pMe->activeView = wnd;
  27. switch(pMe->activeView) {
  28. case IDW_GAME:
  29. return GameWnd_Open(&pMe->game);
  30. case IDW_GAMEEND:
  31. return GameEndWnd_Open(&pMe->end);
  32. case IDW_MAINMENU:
  33. return MainMenuWnd_Open(&pMe->mainMenu);
  34. case IDW_SCORELIST:
  35. return ScoreListWnd_Open(&pMe->score);
  36. default:
  37. return FALSE;
  38. }
  39. }
  40. int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * pMod,void ** ppObj)
  41. {
  42. *ppObj = NULL;
  43. if (!AEEApplet_New(sizeof(PflyApp),     // Size of our private class
  44. ClsId,                              // Our class ID
  45. pIShell,                            // Shell interface
  46. pMod,                               // Module instance
  47. (IApplet**)ppObj,                   // Return object
  48. (AEEHANDLER)Pfly_HandleEvent, // Our event handler
  49. (PFNFREEAPPDATA)Pfly_Free))
  50. return EFAILED;
  51. return SUCCESS;
  52. }
  53. static boolean Pfly_HandleEvent(PflyApp * pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
  54. {
  55. switch (eCode) {
  56. case EVT_APP_START:
  57. if (Pfly_Init(pMe) != TRUE) {
  58. return FALSE;
  59. }
  60. return Pfly_SetActiveWnd(pMe, IDW_MAINMENU);
  61. case EVT_APP_STOP:
  62. return TRUE;
  63. default:
  64. switch(pMe->activeView) {
  65. case IDW_GAME:
  66. return GameWnd_HandleEvent(&pMe->game, eCode, wParam, dwParam);
  67. case IDW_MAINMENU:
  68. return MainMenuWnd_HandleEvent(&pMe->mainMenu, eCode, wParam, dwParam);
  69. case IDW_GAMEEND:
  70. return GameEndWnd_HandleEvent(&pMe->end, eCode, wParam, dwParam);
  71. case IDW_SCORELIST:
  72. return ScoreListWnd_HandleEvent(&pMe->score, eCode, wParam, dwParam);
  73. default:
  74. break;
  75. }
  76. }
  77. return FALSE;
  78. }
  79. static boolean Pfly_Init(PflyApp *pMe)
  80. {
  81. pMe->activeView = IDW_NOWND;
  82. if (GameWnd_New(&pMe->game, pMe) != TRUE) {
  83. return FALSE;
  84. }
  85. if (MainMenuWnd_New(&pMe->mainMenu, pMe) != TRUE) {
  86. return FALSE;
  87. }
  88. if (GameEndWnd_New(&pMe->end, pMe) != TRUE) {
  89. return FALSE;
  90. }
  91. if (ScoreListWnd_New(&pMe->score, pMe) != TRUE) {
  92. return FALSE;
  93. }
  94. return TRUE;
  95. }
  96. static void Pfly_Free(PflyApp *pMe)
  97. {
  98. GameWnd_Free(&pMe->game);
  99. MainMenuWnd_Free(&pMe->mainMenu);
  100. GameEndWnd_Free(&pMe->end);
  101. ScoreListWnd_Free(&pMe->score);
  102. }