index.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Kitchen Master</title>
  6. <!--http://www.html5rocks.com/en/mobile/mobifying/-->
  7. <meta name="viewport"
  8. content="width=device-width,user-scalable=no,initial-scale=1,minimum-scale=1,maximum-scale=1,minimal-ui=true" />
  9. <!--https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html-->
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  12. <meta name="format-detection" content="telephone=no">
  13. <!-- force webkit on 360 -->
  14. <meta name="renderer" content="webkit" />
  15. <meta name="force-rendering" content="webkit" />
  16. <!-- force edge on IE -->
  17. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  18. <meta name="msapplication-tap-highlight" content="no">
  19. <!-- force full screen on some browser -->
  20. <meta name="full-screen" content="yes" />
  21. <meta name="x5-fullscreen" content="true" />
  22. <meta name="360-fullscreen" content="true" />
  23. <!--fix fireball/issues/3568 -->
  24. <!--<meta name="browsermode" content="application">-->
  25. <meta name="x5-page-mode" content="app">
  26. <!--<link rel="apple-touch-icon" href=".png" />-->
  27. <!--<link rel="apple-touch-icon-precomposed" href=".png" />-->
  28. <link rel="stylesheet" type="text/css" href="style.css" />
  29. </head>
  30. <body>
  31. <div id="GameDiv" cc_exact_fit_screen="true">
  32. <div id="Cocos3dGameContainer">
  33. <canvas id="GameCanvas" oncontextmenu="event.preventDefault()" tabindex="99"></canvas>
  34. </div>
  35. </div>
  36. <!-- Polyfills bundle. -->
  37. <script src="src/polyfills.bundle.js" charset="utf-8"> </script>
  38. <!-- SystemJS support. -->
  39. <script src="src/system.bundle.js" charset="utf-8"> </script>
  40. <!-- Import map -->
  41. <script src="src/import-map.json" type="systemjs-importmap" charset="utf-8"> </script>
  42. <!-- <script>
  43. System.import('./index.js').catch(function (err) { console.error(err); })
  44. </script> -->
  45. <script>
  46. // adInstance = null
  47. // 动态加载外部脚本的方法
  48. loadScript = function (url) {
  49. return new Promise((resolve, reject) => {
  50. const script = document.createElement('script');
  51. script.src = url;
  52. script.async = true;
  53. script.onload = () => resolve();
  54. script.onerror = () => reject(new Error(`Failed to load script: ${url}`));
  55. document.head.appendChild(script);
  56. });
  57. }
  58. // 加载 PRESDK3.0.1.js,然后启动项目
  59. loadScript('https://www.cpsense.com/public/PRESDK3.0.1.js')
  60. .then(() => {
  61. console.log('PRESDK3.0.1.js loaded successfully');
  62. // 初始化广告 SDK
  63. var adSdkConfig = {
  64. el: document.querySelector("GameDiv"),
  65. client: 'cpsense-cd',
  66. is_test: false
  67. };
  68. var adInstance = new adSdk(adSdkConfig);
  69. window.adInstance = adInstance;
  70. window.CPSenseShowAd = {
  71. showAd: function (type) {
  72. return new Promise((resolve, reject) => {
  73. if (type === 'interstitial') {
  74. adInstance.interstitialAd({
  75. beforeAd: function () {
  76. console.log("The ad starts playing")
  77. },
  78. afterAd: function () {
  79. console.log("The ad ends playing")
  80. resolve({
  81. result: 'success',
  82. message: 'Interstitial ad closed'
  83. });
  84. },
  85. error: function (n) {
  86. console.log("error", n);
  87. reject(new Error('Interstitial ad error'));
  88. }
  89. });
  90. } else if (type === 'rewarded') {
  91. adInstance.rewardAd({
  92. beforeAd: function () {
  93. console.log("The ad starts playing, and the game should pause."),
  94. window.youxi.SoundManager.pauseAll(),
  95. window.youxi.GameManager.pauseAll();
  96. },
  97. adDismissed: function () {
  98. console.log("Player dismissed the ad before completion."),
  99. window.youxi.SoundManager.resumeAll(),
  100. window.youxi.GameManager.resumeAll();
  101. reject(new Error('Interstitial ad error'));
  102. },
  103. adViewed: function () {
  104. console.log("Ad was viewed and closed."),
  105. window.youxi.SoundManager.resumeAll(),
  106. window.youxi.GameManager.resumeAll();
  107. resolve({
  108. result: 'success',
  109. message: 'Interstitial ad closed'
  110. });
  111. },
  112. error: function (n) {
  113. console.log("error", n);
  114. window.youxi.SoundManager.resumeAll();
  115. window.youxi.GameManager.resumeAll();
  116. reject(new Error('Interstitial ad error'));
  117. }
  118. })
  119. } else {
  120. reject(new Error('Invalid ad type'));
  121. }
  122. });
  123. }
  124. };
  125. console.log('AD initialized successfully');
  126. })
  127. .then(() => {
  128. // 加载项目主入口
  129. return System.import('./index.js');
  130. })
  131. .catch(err => {
  132. console.error('Error during initialization:', err);
  133. });
  134. // 外部广告调用
  135. window.showAd = function (type) {
  136. type = type.toLowerCase();
  137. return new Promise((resolve, reject) => {
  138. window.CPSenseShowAd.showAd(type)
  139. .then((res) => {
  140. // 为游戏返回广告结果
  141. console.log(res);
  142. resolve(res);
  143. })
  144. .catch((err) => {
  145. console.log(err);
  146. reject(err);
  147. });
  148. });
  149. };
  150. // 回调测试
  151. function TopCallback() {
  152. //sound
  153. if (window.__woso.SoundManager.isSound) {
  154. window.youxi.SoundManager.resumeAll();
  155. } else {
  156. window.youxi.SoundManager.pauseAll();
  157. }
  158. }
  159. </script>
  160. </body>
  161. </html>