1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > html掷骰子游戏的代码 掷骰子的小程序 HTML5

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

时间:2021-03-07 02:40:24

相关推荐

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元素。

点数:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。