简单抽奖代码(抽奖活动代码编写)
admin 发布:2022-12-19 07:24 100
今天给各位分享简单抽奖代码的知识,其中也会对抽奖活动代码编写进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
抽奖程序(用vb编写)
在窗体上添加一个command1,一个timer1,label1(0~5)
控件数组(添加一个label1,然后再复制5个,共6个,用来显示数字),代码如下:
Private
Sub
Command1_Click()
If
Command1.Caption
=
"抽奖"
Then
Command1.Caption
=
"停止"
Timer1.Enabled
=
True
Else
Timer1.Enabled
=
False
Command1.Caption
=
"抽奖"
End
If
End
Sub
Private
Sub
Form_Load()
Command1.Caption
=
"抽奖"
Timer1.Interval
=
50
Timer1.Enabled
=
False
End
Sub
Private
Sub
Timer1_Timer()
Randomize
For
i
=
To
5
Label1(i)
=
Int(10
*
Rnd)
Select
Case
Label1(i).Caption
Case
Label1(i).BackColor
=
RGB(0,
0,
0)
Label1(i).ForeColor
=
RGB(255,
255,
255)
Case
1
Label1(i).BackColor
=
RGB(128,
42,
42)
Label1(i).ForeColor
=
RGB(127,
213,
213)
Case
2
Label1(i).BackColor
=
RGB(255,
0,
0)
Label1(i).ForeColor
=
RGB(0,
255,
255)
Case
3
Label1(i).BackColor
=
RGB(255,
97,
0)
Label1(i).ForeColor
=
RGB(0,
158,
255)
Case
4
Label1(i).BackColor
=
RGB(255,
255,
0)
Label1(i).ForeColor
=
RGB(0,
0,
255)
Case
5
Label1(i).BackColor
=
RGB(0,
255,
0)
Label1(i).ForeColor
=
RGB(255,
0,
255)
Case
6
Label1(i).BackColor
=
RGB(0,
0,
255)
Label1(i).ForeColor
=
RGB(255,
0,
0)
Case
7
Label1(i).BackColor
=
RGB(160,
32,
240)
Label1(i).ForeColor
=
RGB(95,
223,
15)
Case
8
Label1(i).BackColor
=
RGB(192,
192,
192)
Label1(i).ForeColor
=
RGB(63,
63,
63)
Case
9
Label1(i).BackColor
=
RGB(255,
255,
255)
Label1(i).ForeColor
=
RGB(0,
0,
0)
End
Select
Next
End
Sub
用c语言编写一个简易的抽奖程序,
用data.txt文件保存以下内容:
13725528132 李桂荣
13725528131 李二来
13725528133 张荣刚
13725528130 荣南
13725528137 王三
13725528138 吴立
13725528139 郭德纲
13725528140 周星驰
13725528141 张曼玉
13725528142 张艺谋
13725528152 秦香莲
13725528162 潘金莲
13725528172 李大嘴
13725528182 展堂
//源代码如下
#include stdio.h
#include stdlib.h
#include time.h
#define MAX_NUM 9999
//定义保存人名和电话的数据结构
struct Person
{
char name[20];
char telno[15];
char award;
};
int num = 0; //统计人数
FILE *fp; //文件指针
Person persons[MAX_NUM]; //定义数组
int awarder_1[1] = {-1}; //一等奖
int awarder_2[2] = {-1, -1}; //二等奖
int awarder_3[5] = {-1, -1, -1, -1, -1};//三等奖
//读取文件
void readdata()
{
int i = 0; //数组下标
Person person;
//文件打开
fp = fopen("data.txt", "r");
if (fp == NULL)
{
printf("打开文件data.txt失败!\n");
return;
}
//当文件不为空
while (!feof(fp))
{
num ++;
fscanf(fp, "%s", person.telno);
fscanf(fp, "%s", person.name);
person.award = 'F';
persons[i++] = person;
}
}
//初始化标识
void init()
{
for(int i = 0; i num; i++)
{
persons[i].award = 'F';
}
}
//显示单个中奖信息
void info( int i)
{
printf("手机号码: %s 姓名: %s\n", persons[i].telno, persons[i].name);
}
void main()
{
char again = 'Y';
//读取文件
readdata();
printf("简单抽奖程序\n");
srand((long)time(0));
while(again == 'Y' || again == 'y')
{
//初始化标识
init();
printf("\n开始抽第一等奖(1名),按任意键开始...\n");
getchar();
awarder_1[0] = abs(rand() % num);
while (persons[awarder_1[0]].award == 'T')
{
awarder_1[0] = rand() % num;
}
persons[awarder_1[0]].award = 'T';
info(awarder_1[0]);
printf("\n开始抽第二等奖(2名)\n");
for (int i = 0; i 2; i++)
{
printf("\n第%d个二等奖,按任意键开始...\n", i+1);
getchar();
awarder_2[i] = rand() % num;
while (persons[awarder_2[i]].award == 'T')
{
awarder_2[i] = rand() % num;
}
persons[awarder_2[i]].award = 'T';
info(awarder_2[i]);
}
printf("\n\n开始抽第三等奖(5名)\n");
for (i = 0; i 5; i++)
{
printf("\n第%d个三等奖,按任意键开始...\n", i + 1);
getchar();
awarder_3[i] = rand() % num;
while (persons[awarder_3[i]].award == 'T')
{
awarder_3[i] = rand() % num;
}
persons[awarder_3[i]].award = 'T';
info(awarder_3[i]);
}
printf("\n是否重新开始抽奖?(Y or N)...\n");
again = getchar();
}
getchar();
return;
}
js实现可键盘控制的简单抽奖程序
本文实例为大家分享了js抽奖程序的编写代码,以及编写注意事项,感兴趣的小伙伴们可以参考一下
代码:
!DOCTYPE
html
html
lang="en"
head
meta
charset="UTF-8"
title简单抽奖(可用键盘)/title
style
*{margin:0;padding:0;}
.box{width:
400px;height:
300px;margin:50px
auto;background:
red}
.title{color:
#fff;font-size:
30px;font-weight:700px;padding:
50px
0;text-align:
center;height:40px;}
.btm{text-align:
center;padding:20px
0;}
.btm
a{display:
inline-block;width:
120px;height:60px;line-height:
60px;background:
#FEF097;margin:0
10px;text-decoration:
none;}
/style
script
var
data=['Iphone','Ipad','笔记本','相机','谢谢参与','充值卡','购物券'],
timer=null,//定时器
flag=0;//阻止多次回车
window.onload=function(){
var
play=document.getElementById('play'),
stop=document.getElementById('stop');
//
开始抽奖
play.onclick=playFun;
stop.onclick=stopFun;
//
键盘事件
document.onkeyup=function(event){
event
=
event
||
window.event;
//
回车键的code值:13
if(event.keyCode==13){
if(flag==0){
playFun();
flag=1;
}else{
stopFun();
flag=0;
}
}
}
function
playFun(){
var
title=document.getElementById('title');
var
play=document.getElementById('play');
clearInterval(timer);
timer=setInterval(function(){
var
random=Math.floor(Math.random()*data.length);
title.innerHTML=data[random];
},60);
play.style.background='#999';
}
function
stopFun(){
clearInterval(timer);
var
play=document.getElementById('play');
play.style.background='#FEF097';
}
}
/script
/head
body
div
class="box"
div
class="title"
id="title"淘家趣抽奖/div
div
class="btm"
a
href="javascript:;"
id="play"开始/a
a
href="javascript:;"
id="stop"停止/a
/div
/div
/body
/html
注意点:
1.随机数,取数组的其中一个;取0-n之间:Math.random()*(n+1)
2.定时器,开始抽奖时要停止前面的一次抽奖,不然会定时器重叠
3.按键操作,要判断是抽奖进行中,还是未开始,所有设置了变量
flag
想要学习更多关于javascript抽奖功能,请参考此专题:javascript实现抽奖功能
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
关于简单抽奖代码和抽奖活动代码编写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-17百度双十一活动,百度双十一活动主题
- 05-17做公司网页,做公司网页有什么简单的方法
- 05-12深圳seo公司的简单介绍
- 05-11设计一个简单的网页,独立站建站平台有哪些
- 05-09网页代码,网页代码快捷键
- 05-09hao123网址之家官网的简单介绍
- 05-07孝感seo的简单介绍
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接