PHP lucky big turntable source code, supports ThinkPHP, big turntable thinkphp

Source: Internet
Author: User

PHP lucky big turntable source code, supports ThinkPHP, big turntable thinkphp
HTML code

The Code is based on thinkphp. If not, you can modify the url path.

 
 
  1. Charset = "UTF-8">
  2. Name = "keywords" content = "lucky big turntable, cnsecer.com"/>
  3. Name = "description" content = "lucky big turntable"/>
  4. Lucky big Turntable
  5. Type = "text/css">
  6. . Demo {width: pixel PX; height: pixel PX; position: relative; margin: 50 pxauto}
  7. # Disk {width: pixel PX; height: pixel PX; background: url (_ STATIC _/images/disk.jpg) no-repeat}
  8. # Start {width: 163px; height: 320px; position: absolute; top: 46px; left: 130px ;}
  9. # Start img {cursor: pointer}
  10. Src = "http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js">
  11. Type = "text/javascript" src = "_ STATIC _/js/jQueryRotate.2.2.js">
  12. Type = "text/javascript" src = "_ STATIC _/js/jquery. easing. min. js">
  13. Type = "text/javascript">
  14. $ (Function (){
  15. $ ("# Startbtn"). click (function (){
  16. Lottery ();
  17. });
  18. });
  19. Function lottery (){
  20. $. Ajax ({
  21. Type: 'post ',
  22. Url: '{: U (\ 'game/run \')} ', // change the submitted address to your own
  23. DataType: 'json ',
  24. Cache: false,
  25. Error: function (){
  26. Alert ('error! ');
  27. Returnfalse;
  28. },
  29. Success: function (json ){
  30. $ ("# Startbtn" 2.16.unbind('click'mirror.css ("cursor", "default ");
  31. Var a = json. angle; // angle
  32. Var p = json. prize; // Award
  33. $ ("# Startbtn"). rotate ({
  34. Duration: 3000, // rotation time
  35. Angle: 0,
  36. AnimateTo: 1800 + a, // Rotation Angle
  37. Easing: $. easing. easeOutSine,
  38. Callback: function (){
  39. Var con = confirm ('Congratulations, do you have to come back again in '+ p +' \ n? ');
  40. If (con ){
  41. Lottery ();
  42. } Else {
  43. Returnfalse;
  44. }
  45. }
  46. });
  47. }
  48. });
  49. }
  50. Id = "main">
  51. Class = "msg">
  52. Class = "demo">
  53. Id = "disk">
  54. Id = "start"> src = "_ STATIC _/images/start.png" id = "startbtn">
  55. Id = "footer">

Background processing code
 
 
  1. Php
  2. NamespaceHome \ Controller;
  3. UseThink \ Controller;
  4. ClassGameControllerextendsBaseController {
  5. Publicfunction index (){
  6. $ This-> display ("index ");
  7. }
  8. Publicfunction run (){
  9. $ ProArr = array ();
  10. // V is the sum of the winning probability, preferably an integer multiple of 100. id is the prize number min max, which is the largest and the smallest angle respectively.
  11. $ Prize_arr = array (
  12. '0' => array ('id' => 1, 'Min' => 1, 'max '=> 29, 'prize' => 'first prize ', 'V' => 0 ),
  13. '1' => array ('id' => 2, 'Min' => 302, 'max '=> 328, 'prize' => 'second prize ', 'V' => 0 ),
  14. '2' => array ('id' => 3, 'Min' => 242, 'max '=> 268, 'prize' => 'third prize ', 'V' => 0 ),
  15. '3' => array ('id' => 4, 'Min' => 182, 'max '=> 208, 'prize' => '4 ', 'V' => 0 ),
  16. '4' => array ('id' => 5, 'Min' => 122, 'max '=> 148, 'prize' => 'fifth runner ', 'V' => 0 ),
  17. '5' => array ('id' => 6, 'Min' => 62, 'max '=> 88, 'prize' => '6 ', 'V' => 0 ),
  18. '6' => array ('id' => 7, 'Min' => array (152,212,272,332, 58,118,178,238,298,358), 'Max' => array ), 'prize' => '7', 'V' => 100)
  19. );
  20. // Obtain a random Prize
  21. Foreach ($ prize_arr as $ v ){
  22. $ ProArr [$ v ['id'] = $ v ['V'];
  23. }
  24. $ Rid = $ this-> getRand ($ proArr); // obtain the award id based on the probability.
  25. $ Res = $ prize_arr [$ rid-1]; // medium Award
  26. // Dd ($ res); die;
  27. $ Min = $ res ['Min'];
  28. $ Max = $ res ['Max'];
  29. If ($ res ['id'] = 7) {// 7.
  30. $ I = mt_rand (0, 5 );
  31. $ Result ['angle '] = mt_rand ($ min [$ I], $ max [$ I]);
  32. } Else {
  33. $ Result ['angle '] = mt_rand ($ min, $ max); // randomly generate an angle
  34. }
  35. $ Result ['prize'] = $ res ['prize'];
  36. Echo json_encode ($ result );
  37. }
  38. Protectedfunction getRand ($ proArr ){
  39. $ Result = '';
  40. // The total probability precision of the probability Array
  41. $ ProSum = array_sum ($ proArr );
  42. // Probability array Loop
  43. Foreach ($ proArr as $ key => $ proCur ){
  44. $ RandNum = mt_rand (1, $ proSum );
  45. If ($ randNum <= $ proCur ){
  46. $ Result = $ key;
  47. Break;
  48. } Else {
  49. $ ProSum-= $ proCur;
  50. }
  51. }
  52. Unset ($ proArr );
  53. Return $ result;
  54. }
  55. }

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.