怎么在页面制作一三个骰子点数概率击骰子是骰子开始转动然后随机显示一个点数

想转html5游戏开,这是学习练手的东西,最开始是用面向过程的方式实现,后面用面向对象的方式实现(被坑了)……
演示地址:/detail/ss8pkzrc
&meta charset=&utf-8&/&
&title&掷色子的游戏&/title&
&td align=&center&&
&canvas id=&game& width=&400& height=&300& style=&border:1px solid #c3c3c3&&
你的游览器不支持html5的画布元素,请升级到IE9+或使用firefox、chrome这类高级的智能游览器!
&/canvas&&br/&
&input id=&button& type=&button& onclick=&javascript:stage.play();& value=&开始掷骰子&/&
游戏规则:&br/&
1、一个玩家、两个色子,每个色子有1-6个点,点数随机出现,点数是2-12中的任意数字&br/&
2、如果玩家第一次抛出 7 或者 11,则本回合胜利 进行下一回合&br/&
3、如果玩家抛出2、3、12 则回合失败 进行下一回合&br/&
4、抛出其他数字4、5、6、7、8、9、10 记录点数和,并继续掷色子&br/&
5、当玩家掷出7 则本回合失败 进行下一回合&br/&
6、当玩家抛出的点数和与上一次的相同,本局胜利 进行下一回合&br/&
7、当玩家抛出的点数和与上一次的不同,本局失败,进行下一回合&br/&
后期扩展:&br/&
这个游戏有押注和积分的功能,尚无思路,所以没有实现&br/&
&td colspan=&2&&
&div id=&log&&&/div&
游戏规则:
一个玩家、两个色子,每个色子有1-6个点,点数随机出现,点数是2-12中的任意数字
如果玩家第一次抛出 7 或者 11,则本回合胜利 进行下一回合
如果玩家抛出2、3、12 则回合失败 进行下一回合
抛出其他数字4、5、6、7、8、9、10 记录点数和,并继续掷色子
当玩家掷出7 则本回合失败 进行下一回合
当玩家抛出的点数和与上一次的相同,本局胜利 进行下一回合
当玩家抛出的点数和与上一次的不同,本局失败,进行下一回合
game:{游戏对象
Stage={场景对象
add(thing) //添加一个物件
addEvent(type,handler)
redraw() //重绘所有thing对象
Thing = {//物件对象
draw(canvas)//传入一个canvas画板对象用于绘制thing
isScope(x,y) //传入鼠标相对于canvas的位置,返回boolean,
//用于判断鼠标是否在thing的范围 true在,false不在
addEvent(type,handler) //公开方法 //给物件设置时间
定义我们自己的场景对象
掷色子的场景内需要:
1、两个色子 色子一号 色子二号
2、一个公告板 显示本局信息
3、三个按钮 重现开始
function Stage(canvas){
this.canvas = document.getElementById(canvas);
this.ctx = this.canvas.getContext('2d');
this.ctx.lineWidth = 1;
this.ctx.strokeStyle = 'rgb(255,0,0)';
this.width = this.canvas.
this.height = this.canvas.
this.things = [];
this.addEvent = [];
this.rule = {};
Stage.prototype.setings = function(){};
Stage.prototype.draw = function(){
for(var thing in this.things){
if(this.things[thing] instanceof Array){
for(var i=0;i&this.things[thing].i++){
this.things[thing][i].init();
Stage.prototype.add = function(thing){
if(!thing){}
if(this.things['disc'] == undefined){
this.things['disc'] = [];
if(this.things['callBoard'] == undefined){
this.things['callBoard'] = [];
if(thing instanceof Disc){
this.things['disc'].push(thing);
if(thing instanceof CallBoard){
this.things['callBoard'].push(thing);
Stage.prototype.play = function(){
this.clean();
for(var i=0;i&this.things['disc'].i++){
this.things['disc'][i].random_porints();
this.rule.init(this);
this.rule.run();
this.log();
if(!this.rule.hasNext){
var self =
document.getElementById('button').onclick = function(){
self.redraw();
document.getElementById('button').value = '重置游戏';
document.getElementById('button').value = '再抛一次';
Stage.prototype.redraw = function(){
this.clean();
this.things = {};
this.setings();
var self =
document.getElementById('button').onclick = function(){
self.play();
document.getElementById('button').value = '开始掷骰子';
Stage.prototype.log = function(){
var html = document.getElementById('log').innerHTML;
var tmp = this.rule.notice1.str +'&'+ this.rule.notice2.str +'&'+ this.rule.notice3.str +'&&';
tmp += (this.rule.integral.length & 0 ? ('上一次点数[&font color=&red&&'+this.rule.integral.join(',')+'&/font&]'):'')+this.rule.hasNext+'&br/&';
document.getElementById('log').innerHTML = html +
Stage.prototype.clean = function(){
for(var i=0;i&this.things['disc'].i++){
this.things['disc'][i].clean();
for(var i=0;i&this.things['callBoard'].i++){
this.things['callBoard'][i].clean();
function Disc(x,y,stage){
this.stage =
this.init();
Disc.prototype.init = function(){
this.width = 170;
this.height = this.
this.porints = 1;
this.draw();
this.draw_porints();
Disc.prototype.draw = function(){
this.stage.ctx.beginPath();
this.stage.ctx.strokeRect(this.x,this.y,this.width,this.height);
this.stage.ctx.closePath();
this.stage.ctx.stroke();
Disc.prototype.random_porints = function(){
this.clean();
var tmp = 0;
tmp = Math.floor(Math.random() * 7);
}while(tmp &= 0 || tmp & 6)
this.porints =
this.draw_porints();
Disc.prototype.draw_porints = function(){
var radius = this.width/7;
if(this.porints == 1){//当只有1个点的时候,点位于正方形的正中间(width/2,height/2) 半径为width/4
draw_porint(this.x + (this.width/2),this.y + (this.height/2),this.width/4,this.stage);
}else if(this.porints == 2){//当有两个点时,第一个点位于(width/2,(height/7)*2,第二个点位于(width/2,(height/7)*5)
draw_porint(this.x + (this.width/2),this.y + ((this.height/7)*2),radius,this.stage);
draw_porint(this.x + (this.width/2),this.y + ((this.height/7)*5),radius,this.stage);;
}else if(this.porints == 3){
draw_porint(this.x + ((this.width/10)*2),this.y + ((this.height/10)*2),radius,this.stage);
draw_porint(this.x + ((this.width/10)*5),this.y + ((this.height/10)*5),radius,this.stage);
draw_porint(this.x + ((this.width/10)*8),this.y + ((this.height/10)*8),radius,this.stage);
}else if(this.porints == 4){
draw_porint(this.x + ((this.width/7)*2),this.y + ((this.height/7)*2),radius,this.stage);
draw_porint(this.x + ((this.width/7)*5),this.y + ((this.height/7)*2),radius,this.stage);
draw_porint(this.x + ((this.width/7)*2),this.y + ((this.height/7)*5),radius,this.stage);
draw_porint(this.x + ((this.width/7)*5),this.y + ((this.height/7)*5),radius,this.stage);
}else if(this.porints == 5){
draw_porint(this.x + ((this.width/10)*2),this.y + ((this.height/10)*2),radius,this.stage);
draw_porint(this.x + ((this.width/10)*2),this.y + ((this.height/10)*8),radius,this.stage);
draw_porint(this.x + ((this.width/10)*5),this.y + ((this.height/10)*5),radius,this.stage);
draw_porint(this.x + ((this.width/10)*8),this.y + ((this.height/10)*2),radius,this.stage);
draw_porint(this.x + ((this.width/10)*8),this.y + ((this.height/10)*8),radius,this.stage);
}else if(this.porints == 6){
draw_porint(this.x + ((this.width/7)*2),this.y + ((this.height/10)*2),radius,this.stage);
draw_porint(this.x + ((this.width/7)*5),this.y + ((this.height/10)*2),radius,this.stage);
draw_porint(this.x + ((this.width/7)*2),this.y + ((this.height/10)*5),radius,this.stage);
draw_porint(this.x + ((this.width/7)*5),this.y + ((this.height/10)*5),radius,this.stage);
draw_porint(this.x + ((this.width/7)*2),this.y + ((this.height/10)*8),radius,this.stage);
draw_porint(this.x + ((this.width/7)*5),this.y + ((this.height/10)*8),radius,this.stage);
Disc.prototype.redraw = function(){
this.clean();
this.porints = 1;
this.draw_porints();
Disc.prototype.clean = function(){
this.stage.ctx.clearRect(this.x,this.y,this.width,this.height);
function draw_porint(x,y,radius,stage){
stage.ctx.beginPath();
stage.ctx.arc(x,y,radius,0,2*Math.PI,false);
stage.ctx.closePath();
stage.ctx.fill();
function CallBoard(x,y,stage){
this.width = 360;
this.height = 50;
this.stage =
this.notices = [];
this.init();
CallBoard.prototype.init = function(){
this.stage.ctx.beginPath();
this.stage.ctx.strokeRect(this.x,this.y,this.width,this.height);
this.stage.ctx.closePath();
this.stage.ctx.stroke();
this.draw();
CallBoard.prototype.draw = function(){
for(var i =0;i&this.notices.i++){
this.notices[i].init();
CallBoard.prototype.redraw = function(){
this.clean();
this.init();
this.draw();
CallBoard.prototype.clean = function(){
this.stage.ctx.clearRect(this.x,this.y,this.width,this.height);
CallBoard.prototype.add = function(notice){
if(!notice){}
this.notices.push(notice);
function Notice(x,y,str,callBoard){
this.str =
this.width = 150;
this.height = 10;
this.stage = callBoard.
if(str == undefined){
this.init();
this.init(str);
Notice.prototype.init = function(){
this.stage.ctx.fillText('暂无',this.x,this.y);
Notice.prototype.init = function(str){
if(str != ''){
this.str =
this.stage.ctx.fillText(this.str,this.x,this.y);
Notice.prototype.draw = function(str){
this.init(str);
Notice.prototype.redraw = function(str){
this.stage.ctx.clearRect(this.x,this.y-9,this.width,this.height);
this.draw(str);
function Rule(){
this.disc1 = {};
this.disc2 = {};
this.notice1 = {};
this.notice2 = {};
this.notice3 = {};
this.count = 0;
this.integral = [];
this.hasNext =
Rule.prototype.init = function(stage){
this.disc1 = stage.things['disc'][0];
this.disc2 = stage.things['disc'][1];
this.notice1 = stage.things['callBoard'][0].notices[0];
this.notice2 = stage.things['callBoard'][0].notices[1];
this.notice3 = stage.things['callBoard'][0].notices[2];
this.count = this.disc1.porints + this.disc2.
this.notice1.redraw('色子1号当前点数为: '+this.disc1.porints+' 点');
this.notice2.redraw('色子2号当前点数为: '+this.disc2.porints+' 点');
this.notice3.redraw('当前点数和为:'+this.count+'点。');
Rule.prototype.run = function(){
var str = this.notice3.
this.notice3.width = 348;
if(this.integral.length == 0){
if(this.count == 7 || this.count == 11){
str += '你的运气真好一把就赢了,继续加油哦!';
this.notice3.redraw(str);
this.hasNext =
if(this.count == 2 || this.count == 3 || this.count == 12){
str += '你也太衰了吧!第一把就输了,再来一把试试!';
this.notice3.redraw(str)
this.hasNext =
if(this.count &=4 && this.count &= 10){
this.integral.push(this.count);
str += '请再抛一次骰子!';
this.notice3.redraw(str);
this.hasNext =
if(this.count == 7 || this.count != this.integral[this.integral.length - 1]){
str += '不好意思,你输了……!';
this.notice3.redraw(str);
this.hasNext =
if(this.count == this.integral[this.integral.length - 1]){
str += '你太厉害了,竟然抛出和上一次一样的点数!恭喜你赢了!';
this.notice3.redraw(str);
this.hasNext =
var stage = new Stage('game');
stage.setings = function(){
var x1 = 20,y1 = 20;
var x2 = 210,y2 = 20;
var callBoard = new CallBoard(20,200,stage);
callBoard.add(new Notice(30,220,'色子1号,尚无点数。',callBoard));
callBoard.add(new Notice(220,220,'色子2号,尚无点数。',callBoard));
callBoard.add(new Notice(30,240,'当前尚无点数和。',callBoard));
stage.add(new Disc(x1,y1,stage));
stage.add(new Disc(x2,y2,stage));
stage.add(callBoard);
stage.rule = new Rule();
stage.setings();
以上所述就是本文的全部内容了,希望能够对大家学习js+html5有所帮助。
android 游戏之场景的实现以及拓展应用照片浏览器
有些天没有写博客了,最近一直在为游戏打基础,主要因为之前是做应用,对游戏还不够了解.(这里瞎扯一点,我之所以转游戏,一方面:因为应用比较简单,开发人员跳级性的增长,加上HTML5的流行,如果HTML5移动上面完全铺开的话,后面可想而知...第二嘛:挣钱多,这也是我要转行的最主要的因素,
android 显示本地html,js和css文件应该放在什么目录下 在线等 用webview显示一个本地index.html文件(别人写好的,我只管在android上用浏览器显示出来),index.html放在assets文件夹下,这个index.html导入了很多js和css文件,这些文件放在另外的三个文件夹中,index.html中导入js的语
Android如何判断是双卡双待 大家好!对于Android手机,我如何判断当前使用的是双卡双待机子?如何判断出正在使用的是哪张卡?以及如何获取当时正在使用的那张卡的信息,例如IMSI等。
谢谢大家。
------最佳解决方案-------------------- 隔壁兄弟开发双卡双待,还真没有在framework加入接口判断是不是双卡双待,或者正在用那张卡。我想你是做第三方应用吧。各家的解
(转) Android中数据存储的5种方法
原址:http://apps./share/detail/
Android中数据存储的5种方法
简介:这是Android中数据存储的5中方法的详细页面,介绍了和手机软件,Android Android中数据存储的5中方法有关的知识, Android数据存储 Android提供了5种方式存储数
android 如何编译单双卡版本 1.打开工程目录/mtk/make 找到对应的贵司的工程.mak 这个文件,如果是单卡将文件中的GEMINI = no, 如果是双卡设置为yes
2.回到您的根目录,运行 ./mk xxx javaoptgen (其中xxx表示工程名)
运行完后,请到framework /base/mediatek 下查看Feature
Android签名制作apk
Android程序发布和签名可以查看SDK中 /android/devel/sign-publish.html
参考 eclipse+ADT 进行android应用签名
android apk签名(为什么 如何做 验证) 这篇文章其实就是根据
关于修改Android开机画面的方法和问题(rle制作工具,raw制作工具,很实用)
老大交给我来修改平板的开机画面,总共存在三个画面: 1.在uboot中加载并显示第一个画面,由于在平板上不方便截图,只是提一下,这个部分不是我做的,跟同事交流完了再写上来 2.Android启动时的第一个画面,源代码部分和分析教程请参考这个部分网址: http://blog.csdn.net/luoshengy
Android的联通性---Bluetooth(五)
作为连接的服务端 当你想要连接两个设备时,一个必须通过持有一个打开的BluetoothServerSocket对象来作为服务端。服务套接字的用途是监听输入的连接请求,并且在一个连接请求被接收时,提供一个BluetoothSocket连接对象。在从BluetoothServerSocket对象中获取BluetoothSocket时,Bluet
SlidingMenu和ActionBarSherlock结合做出出色的App布局,Facebook 和 Path 2.0 滑动式菜单都可以实现(android页面布局效果)
先上图看看效果:
SlidingMenu is currently used in some awesome Android apps. Here's a list of some of them:
代码下载网站:h
android 操作sdcard中的多媒体文件(一)——音乐列表的制作
最近做了一个android音乐播放器,个人感觉最难的就是“后台播放”以及有关“播放列表”的部分,但是总算是找到了实现的方式。不同的人实现的方式可能不一样,这里我就分享一下自己对“播放列表”这个模块的一些实现方法,“后台播放”会在下一篇博文中进行介绍,希望大家也能分享一下自己的一些思路。
android开机动画制作与播放原理简介
android开机动画制作与播放原理简介
谁都想拥有一个华丽漂亮的开机动画,这让人心情舒畅,android是怎么来实现的?怎么制作一个自己的开机动画?这里揭开android开机动画的神秘面纱。
1、制作开关机动画 1.1 开机动画的位置
system/media/bootanimati
android赛车游戏设计 http://download.csdn.net/detail/zxkhzxk/4027872 刚刚设计的一个小赛车游戏,直接把工程导入Eclipse运行即可,大部分源码加了注释,readme文件介绍的操作说明,不足之处,多多指教。 QQ: Email: [emailprotected]
android与PC通过Socket通信(可实现及时游戏的通信)
打算把单机斗地主做成网络版的。 总结了下基本的通信模块 client: package com.SocketC import java.io.BufferedR import java.io.InputStreamR import java.io.PrintW import java
android 扑克类游戏请教 最近看了LiveHoldemPokerPro/store/apps/details?id=com.dragonplay.liveholdempro&feature=search_result
自己也想做一个类似的扑克牌游戏
最主要想实现
webview无法加载本地html
package pan.mei.B import java.util.T import java.util.TimerT import android.app.A import ponentN import android.content.In
想做一款android游戏,不知道有什么好的题材,欢迎大家一起讨论,共同开发。 想做一款android游戏,不知道有什么好的题材,欢迎大家一起讨论,共同开发。
------最佳解决方案-------------------- 休闲就跑酷这种吧,貌似好多这种游戏,好多还很火
------其他解决方案-------------------- 不一定3D,很多玩家不喜欢3D,平面的跳跃忍
Android2.2,2.3,4.0 中如何使用GPU硬件加速原理 和游戏3D性能的提升
/viewthread.php?tid=&bbsid=648
http://blog.csdn.net/martingang/article/details/8142120
/aokikyon/item
Android开发之Handler(五)几种常见的传值方式
前面介绍handler的时候,也用到过几种传值方式,今天来总结一下,并且重点说一下bundle方式,代码如下:
package com.handlerT import android.app.A import android.os.B impor
Android中级第二讲--制作索页面,使用TextWatcher
博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved !
大家好,如果有人因为要做一个随“输入框内容改变”,带动相关数据同时也发生改变的搜索页面,而不知所措的时候,那么可以来看看这篇博客。
大家可能都用过onClickListener或者o
android 数据储存——网络存储(5)
前面介绍的几种存储都是将数据存储在本地设备上,除此之外,还有一种存储(获取)数据的方式,通过网络来实现数据的存储和获取,下面看一个在Android上调用WebService的例子。 注意在Android的早期版本中,曾经支持过进行XMPP Service和Web Service的远程访问。Android SDK 1.0以后的版本对它以前的A
android网游开发之socket的简单设计和实现
对于普通应用的网络模块一般使用http文本协议,在android开发中使用http协议比较简单,sdk已经做了很好的封装了,具体使用方法可以参考我的这篇博文 。而在游戏开发中,可以结合使用http和socket,当然了http协议底层也是基于tcp协议的。http协议是无连接、无状态的,每次连接只能处理一个请求,然后就断了,而且发一个请求需要
想问下android/ios跨平台开发问题 请问有谁了解跨这两个平台开发、移植么,想做个项目,希望能同时放上两个平台,好像有些开发工具是支持的,希望谈谈这方面的经验
------解决方案-------------------- 服务器HTML5应用--
------解决方案-------------------- PhoneGap
------解决方案--------------
关于基站定位 下面链接是一个简单的基站定位,但是他是通过google获取经纬度的,考虑到google在国内不稳定,想找其他方法取代。也就是有没有其他的方法将基站信息转换成经纬度信息。
/rayee/archive//2336101.html
另外,关于HTML5的API获取经纬度,我已经尝试过了,对手机的兼容性比较差,百度高德
要不大家一起开发个小游戏怎么样? RT
自学最大的阻碍就是自己不要到要做些什么?
要不大家一起做个小游戏,有什么创意的可以提出来。每个人按照一个主线网里面添加功能。不图别的
一是自己自娱自乐,二是学点东西。
------最佳解决方案-------------------- 可以模仿别人应用实现应用中的功能
------其他解决方案--------------------
Android学习10-----Android组件通信 (5) Service
基本组成:
在 Android 系统开发中, Service 是一个重要的组成部分,如果某些程序是不希望用户看见的,那么可以将这些程序定义在 Service 中,这样就可以完成程序的后台运行(也可以在不现实界面的形式下运行 ),即 Service 实际上相当于是一个没有图形界面的 Acti
为launcher添加仿HTC的preview(开源,附源码) 最近有时间了,顺便把之前做的一点东西慢慢整理出来,让大家一起研究,讨论下。
Android原生自带的preview不是很好看,很喜欢HTC的,之前看到ADW上也有那样的preview,所以将它提取出来,放入了原生的android2.2中。闲不说,直接上图,有图有真相:
原生的,未修改版本:(B
android版---V5浏览器开发历程(1)选型
目前V5浏览器已经开发到1.7.6版本!每天都在绞尽脑汁的想,如何才能做到极致,做到极致才可能有码农的天空。
Android和iPhone的浏览都是使用webkit内核。 webkit内核是苹果最先搞的,后来苹果把它开源了,不过苹果自己还继续在发展webkit。虽然 Android和iPhone浏览器使用相同的内核(版本等方面有差异),
原创Android开发文章集合贴
  Testin杯征文比赛已然过去3月有余,现在重新翻阅下之前的文章,也觉受益匪浅,文章精彩与否再其次,都是大家精心制作,原创文章~~   现在特地总结出来,希望对学习或者从事Android开发的朋友们有一点启发or帮助~~    游戏引擎DIY /android-.html 你还在用notifyDat
android 3d游戏研究(一)(边学边写,多谢高手指正,鞠躬) :声音 很久以前就想学习3d的,但一直没有时间,最近能闲点,所以开始学习3d的;
今天先写声音:
游戏中的声音可以分为两种,背景音乐和动作音乐;
他们有什么区别:背景音乐,相对与动作音乐它的存在时间要长,所以按这样的方式我将其引用分为两种:一般音乐播放(背景音乐),池播放(动作音乐)
(1)池播放:
代码实现:
——— android 可伸缩的listview 但不是ExpandableList
——— android 可伸缩的listview 但不是ExpandableList
这个activity的功能 就类似于经常见到的js手风琴菜单一样的效果
activity代码:
package com.lp. import java.ut
Android Fragment详解(五):Fragment与Activity通讯
与activity通讯 尽管fragment的实现是独立于activity的,可以被用于多个activity,但是每个activity所包含的是同一个fragment的不同的实例。 Fragment可以调用getActivity()方法很容易的得到它所在的activity的对象,然后就可以查找activity中的
Android之制作漂亮的缓存界面
先贴上两张图展示界面:
上面的字体会动态显示,这种效果在我们启动一个应用程序时,经常使用
代码如下: UIDemoActivity的代码: public class UIDemoActivity extends Activity { /** Called when the activity is first created. */
Android之旅二 资源文件的访问
1、 我们在创建一个工程的时候,会发现与src目录相并列有两个文件夹,res和assets,这两个都是放资源文件的,区别是assets中放的是原生文件,程序不能直接访问,必须通过AssetManager类以二进制的形式读取,而res中的文件可以直接通过R类访问。 2、 在代码中我们可以使用Context的getResources()方法得到Resouces对
Android中Widget的使用示例
Android中Widget的使用示例
之前已经写过通过重绘整个背景的方式,实现物体移动。今天要讲的是, 如何通过移动widget,view等控件,实现部分重绘。结合之前发Droiddraw工具,使用AbsoluteLayout,可以随意放置控件在任何位置。 package com.
import android.app.A i
android dip与px之间的换算工具
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.0 Transitional//EN&& &HTML&&HEAD& &META content=&text/ charset=utf-8& http-equiv=Content-
关于phonegap+sencha touch开发的基础问题!! 小弟新手,刚刚配好了环境。 按照网上的教程 写好了index.html
&!DOCTYPE html& &html& &head& &title&SenchaTest&/title& &!-- Sencha Touch work --&
百度地图的问题 我想实现的效果是
譬如说.地图上有5个标记.他们分别距离大概100米;
在地图没缩小的时候.只显示一个标记.那个标记写着5,表示那个标记那个地方有5个小标记.
然后我地图放大的时候.放大到一定距离.那5个标记就显示出来..
------解决方案-------------------- 好像没这么智能,你的代码里面能获取到当前放大级别
当级缩放比率改变并且放大级别大于12
Android 中的 Service 全面总结
/newcj/archive//2061370.html#
Android ListView和Adapter的基础
链接:/xiaowenji/archive//1900579.html
Android Tombstone/Crash的log分析和定位
http://www.rosoo.net/a/38.html

我要回帖

更多关于 骰子图片很多点数 的文章

 

随机推荐