《The Essential Guide to HTML5》学习笔记(二)

距离上一次看这本书已经有半年多了,发现这些处理HTML5函数怎么都这么生疏啊,果然技术这东西是要经常用的,不用的话看过之后就什么都不剩下了。五一放假没去哪里玩,还是把这些东西复习复习吧,很快也要到公司去实习了,先准备准备。

Rock, Paper, Scissors 

【游戏说明】

剪刀石头布游戏,你在屏幕上点击选择剪刀、石头、布之中的一种,计算机随机生成一个和你PK,你赢了得一分,输了减一分,平了零分。这个游戏比较简单,就当复习知识

【学习重点】

1、用setInerval函数模拟逐渐变大的效果

2、设置游戏的音效,使用audio标签

【细节备忘】

input{text-align:center;font:inherit;color: inherit;} //如果要设置font和color属性和父元素一样,可以设置为inherit

Javascript中变量的作用域问题,如下两个函数:

 1         function Throw(sx,sy, smargin,swidth,sheight,rectcolor,picture){ 
 2           this.sx = sx; 
 3           this.sy = sy; 
 4           this.swidth = swidth; 
 5           this.bwidth = swidth + 2*smargin; 
 6           this.bheight = sheight + 2*smargin; 
 7           this.sheight = sheight; 
 8           this.fillstyle = rectcolor; 
 9           this.draw = drawThrow; 
10           this.img = new Image();  //实现图片预加载
11           this.img.src = picture; 
12           this.smargin = smargin; 
13         } 
14         function drawThrow() { 
15             ctx.strokeStyle = "rgb(0,0,0)"; 
16             ctx.strokeRect(this.sx,this.sy,this.bwidth,this.bheight);   //this.sx,this.sy分别是Throw函数中的this.sx,this.sy
17             ctx.fillStyle = this.fillstyle; 
18             ctx.fillRect(this.sx,this.sy,this.bwidth,this.bheight); 
19             ctx.drawImage(this.img,this.sx+this.smargin,this.sy+this.smargin,this.swidth,this.sheight); 
20         } 

实现图像逐渐变大效果:

 1  tid  =  setInterval(flyin,100);    //这里是不停调用
 2 function flyin() {  
 3             ctx.drawImage(compimg,70,100,size,size); 
 4             size +=5; 
 5             if (size>50) {    //如果达到一定的尺寸就停止调用,size为全局变量,初值是15
 6             clearInterval(tid); 
 7             ctx.fillText(result, 200,100,250); 
 8             document.f.score.value = String(newscore); 
 9             } 
10         } 

 音效暂时先不理了= =

 

 

  

转载于:https://www.cnblogs.com/mrlaker/archive/2013/04/29/3050833.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Theres been considerable enthusiasm about the new capabilities of HTML5, and even suggestions that no other technologies or products are necessary to produce dynamic, engrossing, interactive web sites. That may be overstating things, but it is true the new features are exciting. It now is possible, using just HTML5, Cascading Style Sheets, and JavaScript, to draw lines, arcs, circles and ovals on the screen and specify events and event handling to produce animation and respond to user actions. You can include video and audio on your web site with standard controls, or place the video or audio in your application exactly when needed. You can create forms that validate the input and provide immediate feedback to users. You can use a facility similar to cookies to store information on the client computer. And you can use new elements, such as header and footer, to help structure your documents. This book is based on my teaching practices and past writings. Delving into the features of a technology or general programming concepts is best done when there is a need. Games, especially familiar and simple ones, supply the need and thus the motivation and much of the explanation. When learning a new programming language, my first step is to program the game of craps. If I can build a ballistics simulation with animation, such as the slingshot game, and make a video or audio clip play when a specific condition occurs, I am happy. If I can construct my own maze of walls, draw a stick figure for hangman, and store information on the player's computer, I am ecstatic. And thats what we do in this book. As you see how to build these simple games, youll build your expertise as well. This goal of this book, developed with considerable help from the friends of ED staff and the technical reviewer, is to prepare you to produce your own web sites, including games and other dynamic applications, with a gentle introduction to the essentials of HTML5 and programming. At the time of writing this book, not all browsers support all the HTML5 features. The applications have been tested using Chrome, FireFox, and Safari.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值