PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/simulator.php

https://github.com/KJSoo/SW_BasketBall
PHP | 415 lines | 339 code | 67 blank | 9 comment | 190 complexity | 59e8ca2431b0f84adc42d50978a02204 MD5 | raw file
  1. <?
  2. // session start //
  3. session_cache_expire(30);
  4. session_start();
  5. //session_destroy();session_start();
  6. // //
  7. require_once("DBAccess.php");
  8. require_once("config.php");
  9. $uid = $_GET["uid"];
  10. if($uid == "") $uid = "0B4EE7E5-C73F-4F14-A38E-357D305EBC26";
  11. $strSQL = "select * from member";
  12. $rs = DBSelect($strSQL);
  13. $row = mysql_fetch_array($rs);
  14. $name = $row['name'];
  15. $gender = $row['gender'];
  16. $position = $row['position'];
  17. $level = $row['level'];
  18. $gold = $row['gold'];
  19. $cash = $row['cash'];
  20. $exp = $row['exp'];
  21. $energy = $row['energy'];
  22. $last = $row['last'];
  23. $league = $row['league'];
  24. $team = $row['team'];
  25. $speed = $row['speed'];
  26. $jump = $row['jump'];
  27. $power = $row['power'];
  28. $technique = $row['technique'];
  29. $pace = $row['pace'];
  30. $playcount = $row['playcount'];
  31. $goalcount = $row['goalcount'];
  32. $dunkcount = $row['dunkcount'];
  33. $pacecount = $row['pacecount'];
  34. $blockcount = $row['blockcount'];
  35. $interceptcount = $row['interceptcount'];
  36. $shoottotal = $row['shoottotal'];
  37. $pacetotal = $row['pacetotal'];
  38. $blocktotal = $row['blocktotal'];
  39. $intercepttotal = $row['intercepttotal'];
  40. $grade = $row['grade'];
  41. $week = $row['week'];
  42. $strSQL = "SELECT * from team where grade = '{$grade}'";
  43. $rs = DBSelect($strSQL);
  44. $teamcount = mysql_num_rows($rs);
  45. for($Loop1 = 1; $Loop1 <= $teamcount; $Loop1++)
  46. {
  47. $row = mysql_fetch_array($rs);
  48. $teamname[$Loop1] = $row['name'];
  49. $teamnum[$Loop1] = $Loop1;
  50. $teamrebound[$Loop1] = $row['rebound'];
  51. $teamshoot[$Loop1] = $row['shoot'];
  52. $teamintercept[$Loop1] = $row['intercept'];
  53. $teamblocking[$Loop1] = $row['blocking'];
  54. $teampace[$Loop1] = $row['pace'];
  55. if(strcmp($team,$teamname[$Loop1]) == 0)
  56. {
  57. $home = $Loop1;
  58. }
  59. }
  60. function swap($a, $b) {
  61. $temp = $a;
  62. $a = $b;
  63. $b = $temp;
  64. }
  65. function matchtable($teamcount, $week,$home){
  66. if($teamcount % 2 == 1){
  67. $teamcount++;
  68. }
  69. for($Loop1 = 1; $Loop1 <= $teamcount/2; $Loop1++)
  70. {
  71. $match[$Loop1][1] = $Loop1;
  72. $match[$Loop1][2]= $teamcount+1-$Loop1;
  73. //echo("<br>".$match[$Loop1][1].":".$match[$Loop1][2]."<br>");
  74. }
  75. for($Loop1 = 1; $Loop1 <= $week; $Loop1++)
  76. {
  77. for($Loop2 = 1; $Loop2 <= $teamcount/2; $Loop2++)
  78. {
  79. $match[$Loop2][1]--;
  80. if($match[$Loop2][1]==0) $match[$Loop2][1] = $teamcount-1;
  81. if($Loop2 > 1){
  82. $match[$Loop2][2]--;
  83. if($match[$Loop2][2] == 0) $match[$Loop2][2] = $teamcount-1;
  84. }
  85. }
  86. }
  87. for($Loop1 = 1; $Loop1 <= $teamcount/2; $Loop1++)
  88. {
  89. $result[$match[$Loop1][1]] = $match[$Loop1][2];
  90. $result[$match[$Loop1][2]] = $match[$Loop1][1];
  91. }
  92. return $result[$home];
  93. }
  94. $away = matchtable($teamcount, $week, $home);
  95. $awayname = $teamname[$away];
  96. // Simulator
  97. $output = "";
  98. $count = "";
  99. $homescore = 0;
  100. $awayscore = 0;
  101. $try = 0;
  102. function outputaddhome($str){
  103. global $output;
  104. $output.="<li style='display:none;' class='home'>".$str."</li>";
  105. }
  106. function outputaddhomegoal($str){
  107. global $output;
  108. $output.="<li style='display:none;' class='homegoal'>".$str."</li>";
  109. }
  110. function outputaddaway($str){
  111. global $output;
  112. $output.="<li style='display:none;' class='away'>".$str."</li>";
  113. }
  114. function outputaddawaygoal($str){
  115. global $output;
  116. $output.="<li style='display:none;' class='awaygoal'>".$str."</li>";
  117. }
  118. $ball = mt_rand(1,2);
  119. $countplus = mt_rand(1, 5);
  120. $counttemp = 0;
  121. if(isset($_SESSION['count']) == 0) {
  122. // 경기시작부
  123. if($ball == 1) outputaddhome("경기시작! ".$teamname[$home]."의 선제공격이 시작되었어!");
  124. else if($ball == 2) outputaddaway("경기시작! ".$teamname[$away]."의 선제공격이 시작되었어!");
  125. $_SESSION['count'] = 0;
  126. $counttemp++;
  127. } else {
  128. global $output;
  129. // 경기지속부
  130. $output = str_replace(" style='display:none;'", "", $_SESSION['data']);
  131. $count = $_SESSION['count'];
  132. $homescore = $_SESSION['homescore'];
  133. $awayscore = $_SESSION['awayscore'];
  134. $try = $_SESSION['try'];
  135. // 이전 내용들은 그냥 표시
  136. }
  137. for($Loop1 = 1; $Loop1 <= $countplus; $Loop1++)
  138. {
  139. if($ball == 1){ // home팀 볼소유
  140. $next = mt_rand(1,4);
  141. if($next == 1 or $goshoot == 1) { // 슛
  142. $temp = mt_rand(1,5);
  143. if($temp == 1) outputaddhome($teamname[$home]." 레이업 슛을 시도합니다!");
  144. if($temp == 2) outputaddhome($teamname[$home]." 원핸드 슛!");
  145. if($temp == 3) outputaddhome($teamname[$home]." 페이드 어웨이 슛!");
  146. if($temp == 4) outputaddhome($teamname[$home]." 미들 점프 슛!");
  147. if($temp == 5) outputaddhome($teamname[$home]." 훅 슛!");
  148. $ball = 3;
  149. $goshoot = 0;
  150. continue;
  151. }
  152. else if($next == 2) { // 패스
  153. $temp = mt_rand(1,3);
  154. if($temp == 1) outputaddhome($teamname[$home]."! 성공적인 바운드 패스~");
  155. if($temp == 2) outputaddhome($teamname[$home]." 앞선수에게 짧은 패스");
  156. if($temp == 3) outputaddhome($teamname[$home]." 기막힌 오버헤드 패스!");
  157. continue;
  158. }
  159. else if($next == 3) { // 인터셉트
  160. $temp = mt_rand(1,3);
  161. if($temp == 1) outputaddaway($teamname[$away]." 날카로운 인터셉트~");
  162. if($temp == 2) outputaddaway($teamname[$away]." 가 공을 가로챘어!");
  163. if($temp == 3) outputaddaway($teamname[$away]." 날아오는 공을 캐치했어");
  164. $ball = 2;
  165. continue;
  166. }
  167. else if($next == 4) { // 돌파
  168. $temp = mt_rand(1,3);
  169. if($temp == 1) outputaddhome($teamname[$home]." 공을 공격수에게 앨리웁!");
  170. if($temp == 2) outputaddhome($teamname[$home]." 폭풍같은 돌파!");
  171. if($temp == 3) outputaddhome($teamname[$home]." 적 수비수를 따돌렸어!");
  172. $goshoot = 1;
  173. continue;
  174. }
  175. }
  176. else if($ball == 2){ // away팀 볼소유
  177. $next = mt_rand(1,4);
  178. if($next == 1 or $goshoot == 1) { // 슛
  179. $temp = mt_rand(1,5);
  180. if($temp == 1) outputaddaway($teamname[$away]." 레이업 슛을 시도합니다!");
  181. if($temp == 2) outputaddaway($teamname[$away]." 원핸드 슛!");
  182. if($temp == 3) outputaddaway($teamname[$away]." 페이드 어웨이 슛!");
  183. if($temp == 4) outputaddaway($teamname[$away]." 미들 점프 슛!");
  184. if($temp == 5) outputaddaway($teamname[$away]." 훅 슛!");
  185. $ball = 4;
  186. $goshoot = 0;
  187. continue;
  188. }
  189. else if($next == 2) { // 패스
  190. $temp = mt_rand(1,3);
  191. if($temp == 1) outputaddaway($teamname[$away]."! 성공적인 바운드 패스~");
  192. if($temp == 2) outputaddaway($teamname[$away]." 앞선수에게 짧은 패스");
  193. if($temp == 3) outputaddaway($teamname[$away]." 기막힌 오버헤드 패스!");
  194. continue;
  195. }
  196. else if($next == 3) { // 인터셉트
  197. $temp = mt_rand(1,3);
  198. if($temp == 1) outputaddhome($teamname[$home]." 날카로운 인터셉트~");
  199. if($temp == 2) outputaddhome($teamname[$home]." 볼을 가로챘어!");
  200. if($temp == 3) outputaddhome($teamname[$home]." 스틸!");
  201. $ball = 1;
  202. continue;
  203. }
  204. else if($next == 4) { // 돌파
  205. $temp = mt_rand(1,3);
  206. if($temp == 1) outputaddaway($teamname[$away]." 볼을 공격수에게 앨리웁!");
  207. if($temp == 2) outputaddaway($teamname[$away]." 폭풍같은 돌파!");
  208. if($temp == 3) outputaddaway($teamname[$away]." 적 수비수를 따돌렸어!");
  209. $goshoot = 1;
  210. continue;
  211. }
  212. }
  213. else if($ball == 3){ // home팀 슛팅
  214. $next = mt_rand(1,5);
  215. if($next == 1 or $next == 2){ // 골인
  216. $temp = mt_rand(1,3);
  217. if($temp == 1) outputaddhomegoal($teamname[$home]." 득점~");
  218. if($temp == 2) outputaddhomegoal($teamname[$home]." 고올~인!");
  219. if($temp == 3) outputaddhomegoal($teamname[$home]." 골!");
  220. $ball = 2;
  221. $temp = mt_rand(1,2);
  222. if($temp == 1) outputaddaway($teamname[$away]." 골라인 패스");
  223. if($temp == 2) outputaddaway($teamname[$away]." 바로 경기를 속행!");
  224. $countplus++;
  225. $homeplus++;
  226. continue;
  227. }
  228. else if($next == 3 or $next == 4){ // 노골
  229. $temp = mt_rand(1,3);
  230. if($temp == 1) outputaddhome($teamname[$home]." 아깝게 노골~");
  231. if($temp == 2) outputaddhome($teamname[$home]." 공이 골대를 벗어났어");
  232. if($temp == 3) outputaddhome($teamname[$home]." 이런 볼이 튀어나왔어!");
  233. $ball = 5;
  234. continue;
  235. }
  236. else if($next == 5){
  237. $temp = mt_rand(1,3);
  238. if($temp == 1) outputaddaway($teamname[$away]." 환상적인 블로킹!");
  239. if($temp == 2) outputaddaway($teamname[$away]." 볼을 쳐냈어!");
  240. if($temp == 3) outputaddaway($teamname[$away]." 수비벽에 막혔어!");
  241. $ball = 2;
  242. continue;
  243. }
  244. }
  245. else if($ball == 4){ // away팀 슛팅
  246. $next = mt_rand(1,5);
  247. if($next == 1 or $next == 2){ // 골인
  248. $temp = mt_rand(1,3);
  249. if($temp == 1) outputaddawaygoal($teamname[$away]." 득점~");
  250. if($temp == 2) outputaddawaygoal($teamname[$away]." 고올~인!");
  251. if($temp == 3) outputaddawaygoal($teamname[$away]." 골!");
  252. $ball = 1;
  253. $temp = mt_rand(1,2);
  254. if($temp == 1) outputaddhome($teamname[$home]." 골라인 패스");
  255. if($temp == 2) outputaddhome($teamname[$home]." 바로 경기를 속행!");
  256. $awaysplus++;
  257. $countplus++;
  258. continue;
  259. }
  260. else if($next == 3 or $next == 4){ // 노골
  261. $temp = mt_rand(1,3);
  262. if($temp == 1) outputaddaway($teamname[$away]." 아깝게 노골~");
  263. if($temp == 2) outputaddaway($teamname[$away]." 볼이 골대를 벗어났어");
  264. if($temp == 3) outputaddaway($teamname[$away]." 이런 볼이 튀어나오다니!");
  265. $ball = 5;
  266. continue;
  267. }
  268. else if($next == 5){
  269. $temp = mt_rand(1,3);
  270. if($temp == 1) outputaddhome($teamname[$home]." 환상적인 블로킹!");
  271. if($temp == 2) outputaddhome($teamname[$home]." 볼을 쳐냈어!");
  272. if($temp == 3) outputaddhome($teamname[$home]." 수비벽에 막혔어!");
  273. $ball = 1;
  274. continue;
  275. }
  276. }
  277. else if($ball == 5){
  278. $next = mt_rand(1,2);
  279. if($next == 1){
  280. outputaddhome($teamname[$home]." 리바운드!");
  281. $ball = 1;
  282. }
  283. else if($next == 2){
  284. outputaddaway($teamname[$away]." 리바운드!");
  285. $ball = 2;
  286. }
  287. continue;
  288. }
  289. }
  290. $_SESSION['count']=$_SESSION['count']+$counttemp+$countplus;
  291. $_SESSION['data'] = $output;
  292. $_SESSION['homescore']=$homescore+$homeplus;
  293. $_SESSION['awayscore']=$awayscore+$awayplus;
  294. ?>
  295. <!DOCTYPE html>
  296. <html>
  297. <head>
  298. <meta name="viewport" content="width=device-width, initial-scale=1">
  299. <meta charset="utf8">
  300. <title>Basket</title>
  301. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
  302. <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  303. <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
  304. <script type="text/javascript" src="js/jquery.js"></script>
  305. <script type="text/javascript">
  306. //interval 아이디를 저장하는 변수
  307. var interval = -1;
  308. var go = <?=$_SESSION['count']-$countplus-$counttemp?>;
  309. var homescore = <?=$homescore?>;
  310. var awayscore = <?=$awayscore?>;
  311. alert(homescore+" : "+awayscore);
  312. function updatescore(){
  313. $("#score").html(homescore+":"+awayscore);
  314. }
  315. updatescore();
  316. $(function() {
  317. $('html, body').animate({scrollTop:$(document).height()}, 'slow');
  318. interval = setInterval(function() {
  319. if(go <= <?=$_SESSION['count']?>){
  320. if($("#board li:eq("+go+")").hasClass('homegoal')){
  321. homescore++;
  322. }
  323. if($("#board li:eq("+go+")").hasClass('awaygoal')){
  324. awayscore++;
  325. }
  326. $("#board li:eq("+go+")").show('swing', function() {updatescore();});
  327. go++;
  328. $('html, body').animate({scrollTop:$(document).height()}, 'slow');
  329. }
  330. },1500);
  331. })
  332. </script>
  333. </head>
  334. <body>
  335. <div data-role="page" id="player">
  336. <div data-role="header" data-position="fixed" data-tap-toggle="false" data-id="persistent">
  337. <h1>대쉬보드</h1>
  338. </div><!-- /header -->
  339. <div data-role="content">
  340. <h1>현재카운트=<?=$_SESSION['count']-$countplus?>+<?=$countplus?></h1>
  341. <?=$team?><h1 id="score">0:0</h1><?=$awayname?>
  342. <ul data-role="listview" data-inset="true" id="board">
  343. <?=$output?>
  344. </ul>
  345. </div><!-- /content -->
  346. </div>
  347. </body>
  348. </html>