谈谈酒吧里的骰子游戏的游戏方式

扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
下载作业帮安装包
扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
求两人的情趣游戏玩法 扑克牌 骰子什么的都行 可以开放一点的 越有新意越好
扫二维码下载作业帮
拍照搜题,秒出答案,一键查看所有搜题记录
可以买情侣扑克 就是封面是秘密的事的那个~两个人一起玩扑克 可以猜21点呐 金钩钓鱼呀 争上游什么的 然后谁赢了就又可以摇色子的权利~而且哈 那个扑克牌上还有石头剪子布 你俩可以随机抽一张 然后两个人定输赢 然后摇色子 这样很有情趣的~我们就这么玩~
为您推荐:
其他类似问题
扫描下载二维码【游戏】史上最牛逼摇骰子,营销夜店人必备40种酒吧、K...
【游戏】史上最牛逼摇骰子,营销夜店人必备40种酒吧、K...时间:Please watch has WIFI coverage ...
栏目:作者:点击上方蓝字快速关注杭州最潮的微信!准备好打开眼界吧!注意:请在有WIFI覆盖的区域观看Note:
微信热点文章Posts - 189,
Articles - 7,
Comments - 1
没钱上进,有钱任性。-
"身处这个行业,半年不学习就该失业了!必须不断学习新知识。"
14:25 by Benoly, ... 阅读,
《HTML5游戏开发》,该书出版于2011年,似乎有些老,可对于我这样没有开发过游戏的人来说,却比较有吸引力,选择自己感兴趣的方向来学习html5,css3,相信会事半功倍。不过值得注意的是,该书的游戏是些小的游戏,内容相对比较基础,而且html5标准已经正式发布,可能会和书中所描述有少许出处。当然了,书中的小游戏还是比较不错的,适合我这样的前端开发不咋地的来练手,学习方式是在以自己的思路实现之后,再来看书中的实现思路,因为每个人有自己的开发习惯。1.预备知识在做第一个骰子游戏开发前,必须知道在html5中,如何绘制矩形和圆形
/*获取2d绘图上下文
var ctx = document.getElementById('diceCanvas').getContext('2d')
/*绘制矩形
ctx.lineWidth = 1
ctx.strokeStyle = '#000'
ctx.strokeRect(100,50,100,100)
ctx.fillStyle = '#f00'
ctx.fillRect(100,50,100,100)
/*绘制圆形或弧形.关闭路径,如果不关闭,这绘制的是不闭合的半圆
ctx.lineWidth = 1
ctx.strokeStyle = '#000'
ctx.beginPath()
ctx.arc(200,200,50,0,2*Math.PI*90/360,false)
ctx.closePath()
ctx.stroke()
2.实现思路设计和思考整个游戏中涉及的对象,包括骰子和游戏玩法。为了简化在绘制每个圆点的时候对坐标的定位计算,我选择九宫格的布局,所以增加了个九宫格坐标对象3.代码
/*九宫格坐标图*/
function NineBlockBoxMap(squareSize){
var size = squareSize/3,
maps = [[],[],[]],
for(x=0; x&n; x++){
for(y=0; y&n; y++){
maps[x][y] = {x : x*size + size/2, y : y*size + size/2}
//alert(maps[x][y].x+'|'+maps[x][y].y)
this.maps = maps
NineBlockBoxMap.prototype.locate = function(x,y,offsetX,offsetY){
var map = this.maps[x][y]
return {x:map.x+offsetX,y:map.y+offsetY}
function Dice(){
function clearCanvas(){
//WARNNING : 不能清除整个Canvas画布,而是要清除当前骰子尺寸的部分画布,因为整个画布有多个骰子
//ctx.clearRect(0,0,opts.canvasWidth,opts.canvasHeight)
ctx.clearRect(opts.diceX,opts.diceY,opts.diceWidth+2*opts.diceLineWidth,opts.diceHeight+2*opts.diceLineWidth)
function dotRandom(){
return Math.floor(Math.random()*6+1)
function drawDots(num){
var doDraw = function(points){
var point,i
for(i=0; i&points. i++){
point = points[i]
ctx.beginPath()
ctx.arc(point.x,point.y,opts.dotRadius,0,Math.PI*2,false)
ctx.closePath()
ctx.fill()
var points = []
//根据1-6的骰子点数在九宫格图中绘制1-6个圆点
switch(num){
points.push(maps.locate(1,1,opts.diceX,opts.diceY))
points.push(maps.locate(0,1,opts.diceX,opts.diceY))
points.push(maps.locate(2,1,opts.diceX,opts.diceY))
points.push(maps.locate(2,0,opts.diceX,opts.diceY))
points.push(maps.locate(1,1,opts.diceX,opts.diceY))
points.push(maps.locate(0,2,opts.diceX,opts.diceY))
points.push(maps.locate(0,0,opts.diceX,opts.diceY))
points.push(maps.locate(0,2,opts.diceX,opts.diceY))
points.push(maps.locate(2,0,opts.diceX,opts.diceY))
points.push(maps.locate(2,2,opts.diceX,opts.diceY))
points.push(maps.locate(0,0,opts.diceX,opts.diceY))
points.push(maps.locate(0,2,opts.diceX,opts.diceY))
points.push(maps.locate(1,1,opts.diceX,opts.diceY))
points.push(maps.locate(2,0,opts.diceX,opts.diceY))
points.push(maps.locate(2,2,opts.diceX,opts.diceY))
points.push(maps.locate(0,0,opts.diceX,opts.diceY))
points.push(maps.locate(0,2,opts.diceX,opts.diceY))
points.push(maps.locate(0,1,opts.diceX,opts.diceY))
points.push(maps.locate(2,1,opts.diceX,opts.diceY))
points.push(maps.locate(2,0,opts.diceX,opts.diceY))
points.push(maps.locate(2,2,opts.diceX,opts.diceY))
alert(num + ' num must be 1~6')
ctx.fillStyle = opts.dotFillStyle
doDraw(points)
function drawDice(){
//绘制骰子矩形
ctx.lineWidth = opts.diceLineWidth
ctx.strokeStyle = opts.diceStrokeStyle
ctx.strokeRect(opts.diceX,opts.diceY,opts.diceWidth,opts.diceHeight)
//绘制骰子上的圆点
var num = dotRandom()
drawDots(num)
return num
function extend(opt1,opt2){
opt1 = opt1||{}
opt2 = opt2||{}
for(name in opt2){
opt1[name] = opt1[name]||opt2[name]
return opt1
init : function(options){
opts = extend(options,{
canvasId : 'diceCanvas',
canvasWidth : 400,
canvasHeight : 400,
diceWidth : 90,
diceHeight : 90,
diceX : 50,
diceY : 50,
diceLineWidth : 5,
diceStrokeStyle : '#000',
dotFillStyle : '#000',
dotRadius : 10
var canvas = document.getElementById(opts.canvasId)
if(canvas==null||canvas.tagName !== 'CANVAS'){
alert('element must be canvas tag.')
ctx = canvas.getContext('2d')
maps = new NineBlockBoxMap(opts.diceWidth)
return this
throwDice : function(onThrow){
//清除当前骰子的绘图区域
clearCanvas()
var num = drawDice()
if(typeof onThrow === 'function'){
onThrow(num)
return this
}//end-Dice
/*游戏规则
2个骰子之和(2-12)
第一次(7,11) 胜
第一次(2,3,12 )输
第一次 (4,5,6,8,9,10),继续 (第二次(7)输,如果正好和之前相同的点数则 胜,否则继续)
var GameResult = {Lose:-1,Unknown:0,Win:1}
var rule = function GameRule(){
var throwCount = 0
var continual = false
var previousSum = 0
getResult : function(sum){
var result = GameResult.Unknown,
sum = parseInt(sum)
throwCount++
if( throwCount==1 ){
if( sum==7||sum==11 ){
result = GameResult.Win
else if( sum==2||sum==3||sum==12 ){
result = GameResult.Lose
else if(throwCount&1 && continual){
if(throwCount==2&&sum==7){
result = GameResult.Lose
else if(sum==previousSum){
result = GameResult.Win
previousSum = sum
continual = ( result==GameResult.Unknown )
return result
reset : function(result){
if(result==GameResult.win||result==GameResult.Lose){
throwCount = 0
continual = false
previousSum = 0
var throwDiceButton = document.getElementById('throwDiceButton')
var dice1TextBox = document.getElementById('dice1TextBox')
var dice2TextBox = document.getElementById('dice2TextBox')
var resultTextBox = document.getElementById('resultTextBox')
var dice1 = new Dice().init()
var dice2 =new Dice().init({diceX : 200,diceY : 50,})
throwDiceButton.onclick = function(){
var result = GameResult.Unknown
//投掷骰子1
dice1.throwDice(function(num){
dice1TextBox.value = num
sum += num
//投掷骰子2
dice2.throwDice(function(num){
dice2TextBox.value = num
sum += num
result = rule.getResult(sum)
rule.reset(result)
if(result==GameResult.Win){
resultTextBox.value = 'You Win : ' + sum
else if(result==GameResult.Lose){
resultTextBox.value = 'You Lose : ' + sum
resultTextBox.value = 'Play again : ' + sum
4.优化和完善精简代码和抽象,增加记录得分,初始一定金额等效功能,使其更像是个赌博游戏。html5+原生js实现的一个简易双色子游戏 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 20时,
想转html5游戏开,这是学习练手的东西,最开始是用面向过程的方式实现,后面用面向对象的方式实现(被坑了)……演示地址:/detail/ss8pkzrc
代码片段(2)
game-2.html&~&13KB&&&&
&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();
2.&[图片] QQ图片55.png&&&&
开源中国-程序员在线工具:
相关的代码(115)
[JavaScript]
[JavaScript]
[JavaScript]
[JavaScript]
[JavaScript]
[JavaScript]
[JavaScript]
[JavaScript]
[JavaScript]
[JavaScript]
开源从代码分享开始
D2-Studio的其它代码C语言(138)
算法设计(126)
蓝桥杯(138)
& & 编写函数模拟掷骰子的游戏(两个骰子)。第一次掷的时候,如果点数之和为7或11则获胜;如果点数之和为2、3或12则落败;其他情况下的点数之和称为“目标”,游戏继续。在后续的投掷中,如果玩家再次掷出“目标”点数则获胜,掷出7则落败,其他情况都忽略,游戏继续进行。每局游戏结束时,程序询问用户是否再玩一次,如果用户输入的回答不是y或Y,程序会显示胜败的次数然后终止。
#include&stdio.h&
#include&stdlib.h&
#include&time.h&
int main()
int winCount, lostC
int first,
winCount=lostCount=0;
srand(time(0));
first=rand()%6+1;
second=rand()%6+1;
printf(&%d %d\n&,first,second);
target=first+
if(target==7 || target==11)
printf(&you win\n&);
winCount++;
if(target==2 || target==3 || target==12)
printf(&you lost\n&);
lostCount++;
printf(&proceed or not?&);
input=getchar();
while(input=='Y' || input=='y')
first=rand()%6+1;
second=rand()%6+1;
printf(&%d %d\n&,first,second);
if(target==first+second){
printf(&you win\n&);
winCount++;
if (first+second==7){
printf(&you lost\n&);
lostCount++;
printf(&proceed or not?&);
getchar();
input=getchar();
printf(&win=%d, lost=%d\n&,winCount, lostCount);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:245311次
积分:5350
积分:5350
排名:第4785名
原创:290篇
转载:21篇
评论:55条}

我要回帖

更多关于 谈谈酒吧里的骰子游戏 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信