html掷骰子游戏的代码,掷骰子的小程序 HTML5

掷骰子游戏

var ctx;

function init(){

ctx = document.getElementById("canvas").getContext('2d');

ctx.strokeStyle = "rgb(0,0,0)";

ctx.lineWidth = 5;

ctx.strokeRect(0,0,400,300);

ctx.fillStyle = "rgb(255,255,0)";

ctx.fillRect(20,20,80,80);

ctx.strokeRect(20,20,80,80);

var ch = 1 + Math.floor(Math.random()*6);

drawdice(ch);

document.f.pv.value = ch;

}

function drawdice(n)

{

ctx.fillStyle = "rgb(255,255,0)";

ctx.fillRect(25,25,70,70);

ctx.fillStyle = "rgb(255,0,0)";

ctx.lineWidth = 3;

ctx.strokeStyle = "rgb(0,0,0)";

switch(n){

case 1:

makepoint(60,60);

break;

case 2:

makepoint(60,45);

makepoint(60,75);

break;

case 3:

makepoint(80,40);

makepoint(60,60);

makepoint(40,80);

break;

case 4:

makepoint(45,45);

makepoint(75,45);

makepoint(45,75);

makepoint(75,75);

break;

case 5:

makepoint(40,40);

makepoint(80,40);

makepoint(60,60);

makepoint(40,80);

makepoint(80,80);

break;

case 6:

makepoint(45,35);

makepoint(75,35);

makepoint(45,60);

makepoint(75,60);

makepoint(45,85);

makepoint(75,85);

break;

}

}

function makepoint(x,y)

{

ctx.beginPath();

ctx.arc(x,y,8,0,2*Math.PI,true);

ctx.fill();

ctx.stroke();

}

抱歉,你的浏览器不支持HTML5的canvas元素。

点数:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值