.net实现微信大转盘
来源:互联网 发布:调查问卷制作软件 编辑:程序博客网 时间:2024/05/20 04:25
本人参考网上一个php微信大转盘案例修改了一个.net版本的微信大转盘。
原php微信大转盘教程网址:
幸运大转盘-Jquery_PHP实现的抽奖程序(上)http://www.helloweba.com/view-blog-215.html
幸运大转盘-Jquery_PHP实现的抽奖程序(下)http://www.helloweba.com/view-blog-216.html
原教程提供html无后台程序大转盘源码,提供php后台大转盘实现方式,各位博友可在原网址下载或学习,以下讲解本人修改的.net后台实现方式。
源码下载地址:http://download.csdn.net/detail/kangjiaaa/6835779
前台关键代码:
<!DOCTYPE HTML>
<html>
<head>
<meta name="keywords" content="html5,本地存储" />
<meta name="description" content="Helloweba演示平台,演示XHTML、CSS、jquery、PHP案例和示例" />
<title>幸运大转盘-jQuery+PHP实现的抽奖程序</title>
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<style type="text/css">
.demo{width:417px; height:417px; position:relative; margin:50px auto}
#disk{width:417px; height:417px; background:url(disk.jpg) no-repeat}
#start{width:163px; height:320px; position:absolute; top:46px; left:130px;}
#start img{cursor:pointer}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="jQueryRotate.2.2.js"></script>
<script type="text/javascript" src="jquery.easing.min.js"></script>
<script type="text/javascript">
$(function () {
$("#startbtn").click(function () {
lottery();
});
});
function lottery() {
$.ajax({
type: 'POST',
url: 'go.aspx',
dataType: 'json',
cache: false,
error: function (data) {
alert("出现错误");
return false;
},
success: function (json) {
$("#startbtn").unbind('click').css("cursor", "default");
var a = json.angle; //角度
var p = json.prize; //奖项
$("#startbtn").rotate({
duration: 3000, //转动时间
angle: 0,
animateTo: 1800 + a, //转动角度
easing: $.easing.easeOutSine,
callback: function () {
var con = confirm('恭喜你,中得' + p + '\n还要再来一次吗?');
if (con) {
lottery();
} else {
return false;
}
}
});
}
});
}
</script>
</head>
<body>
<div id="main">
<div class="msg"></div>
<div class="demo">
<div id="disk"></div>
<div id="start"><img src="start.png" id="startbtn"></div>
</div>
<div class="ad_demo"><script src="/js/ad_js/ad_demo.js" type="text/javascript"></script></div><br/>
</div>
</body>
</html>
<html>
<head>
<meta name="keywords" content="html5,本地存储" />
<meta name="description" content="Helloweba演示平台,演示XHTML、CSS、jquery、PHP案例和示例" />
<title>幸运大转盘-jQuery+PHP实现的抽奖程序</title>
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<style type="text/css">
.demo{width:417px; height:417px; position:relative; margin:50px auto}
#disk{width:417px; height:417px; background:url(disk.jpg) no-repeat}
#start{width:163px; height:320px; position:absolute; top:46px; left:130px;}
#start img{cursor:pointer}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="jQueryRotate.2.2.js"></script>
<script type="text/javascript" src="jquery.easing.min.js"></script>
<script type="text/javascript">
$(function () {
$("#startbtn").click(function () {
lottery();
});
});
function lottery() {
$.ajax({
type: 'POST',
url: 'go.aspx',
dataType: 'json',
cache: false,
error: function (data) {
alert("出现错误");
return false;
},
success: function (json) {
$("#startbtn").unbind('click').css("cursor", "default");
var a = json.angle; //角度
var p = json.prize; //奖项
$("#startbtn").rotate({
duration: 3000, //转动时间
angle: 0,
animateTo: 1800 + a, //转动角度
easing: $.easing.easeOutSine,
callback: function () {
var con = confirm('恭喜你,中得' + p + '\n还要再来一次吗?');
if (con) {
lottery();
} else {
return false;
}
}
});
}
});
}
</script>
</head>
<body>
<div id="main">
<div class="msg"></div>
<div class="demo">
<div id="disk"></div>
<div id="start"><img src="start.png" id="startbtn"></div>
</div>
<div class="ad_demo"><script src="/js/ad_js/ad_demo.js" type="text/javascript"></script></div><br/>
</div>
</body>
</html>
go.aspx后台cs代码:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class go : System.Web.UI.Page
{
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class go : System.Web.UI.Page
{
//模拟的奖池
public IList<Prize> prize_arr
{
get {
return new List<Prize>{
new Prize{pid = 1, min =new int[]{1},max=new int[]{29},odds = 1,prize = "一等奖"},
new Prize{pid = 2, min =new int[]{302},max=new int[]{328},odds = 2,prize = "二等奖"},
new Prize{pid = 3, min =new int[]{242},max=new int[]{268},odds = 5,prize = "三等奖"},
new Prize{pid = 4, min =new int[]{182},max=new int[]{208},odds = 7,prize = "四等奖"},
new Prize{pid = 5, min =new int[]{122},max=new int[]{148},odds = 10,prize = "五等奖"},
new Prize{pid = 6, min =new int[]{62},max=new int[]{88},odds = 10,prize = "六等奖"},
new Prize{pid = 7, min =new int[]{32,92,152,212,272,332},max=new int[]{58,118,178,238,298,358},odds = 50,prize = "七等奖"},
};
}
}
public IList<Prize> prize_arr
{
get {
return new List<Prize>{
new Prize{pid = 1, min =new int[]{1},max=new int[]{29},odds = 1,prize = "一等奖"},
new Prize{pid = 2, min =new int[]{302},max=new int[]{328},odds = 2,prize = "二等奖"},
new Prize{pid = 3, min =new int[]{242},max=new int[]{268},odds = 5,prize = "三等奖"},
new Prize{pid = 4, min =new int[]{182},max=new int[]{208},odds = 7,prize = "四等奖"},
new Prize{pid = 5, min =new int[]{122},max=new int[]{148},odds = 10,prize = "五等奖"},
new Prize{pid = 6, min =new int[]{62},max=new int[]{88},odds = 10,prize = "六等奖"},
new Prize{pid = 7, min =new int[]{32,92,152,212,272,332},max=new int[]{58,118,178,238,298,358},odds = 50,prize = "七等奖"},
};
}
}
//根据奖品数量/中奖几率随机获取中奖项id
public int getRand(List<int> proArr)
{
int result = 0;
var proSum = proArr.Sum();
Random ranDom = new Random();
for (var i = 0; i < proArr.Count; i++)
{
var ranNum = ranDom.Next(1, proSum);
if (ranNum < proArr[i])
{
result = i + 1;
}
else {
proSum -= proArr[i];
}
}
return result;
}
protected void Page_Load(object sender, EventArgs e)
{
var proArr = new List<int>();//几率的集合
foreach (var i in prize_arr) {
proArr.Add(i.odds);
}
var rid = getRand(proArr);//中奖id
var res = prize_arr[rid - 1];//中奖项
var min = res.min;
var max = res.max;
var angle = 0;
var prize = string.Empty;
var ranDom = new Random();
//如果此奖项在转盘上有多个格子
if (min.Length > 1 && max.Length > 1)
{
var i = ranDom.Next(0, 5);
angle = ranDom.Next(min[i], max[i]);
}
else {
angle = ranDom.Next(min[0], max[0]);
}
prize = res.prize;
Response.Write("{\"angle\" : " + angle + ",\"prize\" : \"" + prize + "\"}");
Response.End();
}
//奖项类
public class Prize
{
public int pid {get;set;}//奖项编号id
public int[] min{get;set;}//最小转动角度
public int[] max{get;set;}//最大转动角度
public string prize{get;set;}//奖项名称
public int odds {get;set;}//概率
}
}
public int getRand(List<int> proArr)
{
int result = 0;
var proSum = proArr.Sum();
Random ranDom = new Random();
for (var i = 0; i < proArr.Count; i++)
{
var ranNum = ranDom.Next(1, proSum);
if (ranNum < proArr[i])
{
result = i + 1;
}
else {
proSum -= proArr[i];
}
}
return result;
}
protected void Page_Load(object sender, EventArgs e)
{
var proArr = new List<int>();//几率的集合
foreach (var i in prize_arr) {
proArr.Add(i.odds);
}
var rid = getRand(proArr);//中奖id
var res = prize_arr[rid - 1];//中奖项
var min = res.min;
var max = res.max;
var angle = 0;
var prize = string.Empty;
var ranDom = new Random();
//如果此奖项在转盘上有多个格子
if (min.Length > 1 && max.Length > 1)
{
var i = ranDom.Next(0, 5);
angle = ranDom.Next(min[i], max[i]);
}
else {
angle = ranDom.Next(min[0], max[0]);
}
prize = res.prize;
Response.Write("{\"angle\" : " + angle + ",\"prize\" : \"" + prize + "\"}");
Response.End();
}
//奖项类
public class Prize
{
public int pid {get;set;}//奖项编号id
public int[] min{get;set;}//最小转动角度
public int[] max{get;set;}//最大转动角度
public string prize{get;set;}//奖项名称
public int odds {get;set;}//概率
}
}
0 0
- .net实现微信大转盘
- Canvas实现微信大转盘抽奖代码
- Android实现转盘效果
- java实现转盘抽奖;
- SurfaceView 实现 转盘抽奖
- SurfaceView 实现 转盘抽奖
- 网易彩票,转盘实现
- Android实现抽奖转盘
- libgdx 实现转盘功能
- Unity 转盘的实现
- 转盘抽奖js实现
- 抽奖转盘实现 surfaceView
- COCOS抽奖转盘实现
- 微信大转盘|刮刮乐
- 微信大转盘游戏
- Android转盘菜单的实现
- 利用jqueryRotare实现抽奖转盘
- 利用jqueryRotare实现抽奖转盘
- 黑马程序员——学习笔记14.Java反射机制
- First Day
- 【Codility】Max-profit ★★
- poj刷题存档(2)
- CentOS 5.5安装与配置Postfix
- .net实现微信大转盘
- excel文件的格式设置及文件创建
- OpWeb——MySQL同步模块(2)
- 黑马程序员——学习笔记15.学习反射时张老师提到的两个思考题
- 关于web文档的语言
- java ssh中文乱码问题综合
- struts2+spring+mybatis入门教程二之配置struts2
- JDBC连接Oracle数据库
- android HttpURLConnection类的getInputStream方法返回中文显示乱码问题