书籍详情
JavaScript网页游戏制作轻松学
作者:程晨 著
出版社:人民邮电出版社
出版时间:2017-08-01
ISBN:9787115462381
定价:¥49.00
购买这本书可以去
内容简介
JavaScript是一种直译式脚本语言,它的一个很大的优势就是绝大多数浏览器都包含了JavaScript的解释器,这样我们在学习JavaScript时不需要安装任何开发软件,只要写一个网页文件,嵌入JavaScript代码就能在浏览器中进行代码的调试,非常方便。对于硬件爱好者来说,学习JavaScript还有一个好处就是能让自己的硬件作品更贴近IoT(物联网)应用。了解了JavaScript,我们能够在显示的页面上实现更多的效果,同时,目前有很多硬件也支持用JavaScript来编程。本书以制作国际象棋、五子棋、弹球、贪吃蛇、拼图、打飞机等经典游戏为例,带你从零起步,学习JavaScript的编程方法,适合对游戏和编程感兴趣的初学者阅读。而且本书融入了创客的项目式思路,在一个个实例的制作过程中学习知识,语言通俗易懂,图文并茂,会带给你与以往内容枯燥的编程教程完全不同的全新体验。
作者简介
程晨 创客布道师、创客教育践行者,拥有十多年嵌入式开发经验,技术方面涉猎广泛,先后主持参与十多项军民科研产品的研发,拥有多项发明专利。少年创学院联合创始人兼院长、泺喜教育联合创始人兼技术总监,兼任Intel软件创新大使、中国电子学会全国青少年机器人技术等级考试标准工作组副组长、中国教育技术协会数字教育资源专业委员会专家的职务。第1本Arduino中文书作者,编著、翻译开源硬件、3D打印、机器人、智能硬件、物联网等领域相关图书十多本,长期在《无线电》杂志刊登技术类文章。参与录制CCTV《原来如此》节目,录制多套开源硬件项目视频教程。曾任北京航空航天大学、北京邮电大学特聘讲师,参与清华大学、北京科技大学等多所高校的创新性课程设计。
目录
01 认识JavaScript.................................................................................1
1.1 缘起...............................................................................................................1
1.2 历史...............................................................................................................1
1.3 特性...............................................................................................................2
02 类型和变量.........................................................................................4
2.1 浏览器中的控制台..........................................................................................4
2.2 数字和运算符.................................................................................................5
2.3 变量...............................................................................................................6
2.4 变量命名规则.................................................................................................7
2.5 字符串.......................................................................................................... 8
2.5.1 连接字符串… ………………………………………………………………………… 9
2.5.2 获取字符串的长度… ……………………………………………………………… 10
2.5.3 获取单个字符… …………………………………………………………………… 10
2.5.4 截取字符串… ……………………………………………………………………… 11
2.5.5 大小写转化… ……………………………………………………………………… 11
2.6 逻辑运算..................................................................................................... 12
2.6.1 布尔类型… ………………………………………………………………………… 12
2.6.2 逻辑运算符… ……………………………………………………………………… 12
2.6.3 关系运算符… ……………………………………………………………………… 14
2.7 underfined 和null...................................................................................... 16
2.8 原始类型..................................................................................................... 16
2.8.1 鉴别原始类型… …………………………………………………………………… 16
2.8.2 原始方法… ………………………………………………………………………… 17
03 数组................................................................................................18
3.1 创建数组..................................................................................................... 18
3.2 访问数组元素.............................................................................................. 18
3.3 修改数组元素.............................................................................................. 19
3.4 应用数组..................................................................................................... 20
3.4.1 查看数组长度… …………………………………………………………………… 20
3.4.2 添加数组元素… …………………………………………………………………… 20
3.4.3 删除数组元素… …………………………………………………………………… 21
3.4.4 数组相加… ………………………………………………………………………… 22
3.4.5 查找元素的序号… ………………………………………………………………… 22
3.4.6 将数组转换成字符串… …………………………………………………………… 23
04 对话框.............................................................................................24
4.1 HTML 基础................................................................................................. 24
4.2 嵌入JavaScript 代码.................................................................................. 25
4.3 对话框........................................................................................................ 27
4.3.1 输入对话框… ……………………………………………………………………… 27
4.3.2 确定对话框… ……………………………………………………………………… 29
4.3.3 if 语句… …………………………………………………………………………… 31
4.3.4 警告对话框… ……………………………………………………………………… 32
4.4 DOM.......................................................................................................... 33
4.4.1 用ID 标识元素……………………………………………………………………… 33
4.4.2 选中元素… ………………………………………………………………………… 34
4.4.3 替换文本内容… …………………………………………………………………… 34
05 绘制国际象棋棋盘.............................................................................37
5.1 canvas 元素............................................................................................... 37
5.2 绘制方块..................................................................................................... 38
5.3 绘制方框..................................................................................................... 39
5.4 绘制棋盘..................................................................................................... 41
5.5 循环结构..................................................................................................... 42
5.5.1 while 语句… ………………………………………………………………………… 42
5.5.2 do-while 语句… …………………………………………………………………… 43
5.5.3 for 循环……………………………………………………………………………… 44
06 五子棋.............................................................................................48
6.1 基本绘图方式.............................................................................................. 48
6.1.1 绘制线条… ………………………………………………………………………… 48
6.1.2 填充路径… ………………………………………………………………………… 49
6.1.3 绘制圆弧和圆… …………………………………………………………………… 50
6.2 绘制棋盘..................................................................................................... 51
6.3 鼠标交互..................................................................................................... 52
6.4 绘制棋子..................................................................................................... 54
6.5 黑子和白子................................................................................................. 56
6.6 获胜判断..................................................................................................... 59
6.7 函数............................................................................................................ 63
6.7.1 函数的形式… ……………………………………………………………………… 63
6.7.2 落子函数… ………………………………………………………………………… 64
6.7.3 获胜检测函数… …………………………………………………………………… 65
07 弹球游戏..........................................................................................69
7.1 对象............................................................................................................ 69
7.2 对象的方法................................................................................................. 70
7.3 定时功能..................................................................................................... 71
7.4 边界判断..................................................................................................... 72
7.5 增加挡板..................................................................................................... 73
7.6 键盘交互..................................................................................................... 74
08 贪吃蛇.............................................................................................78
8.1 构造函数..................................................................................................... 78
8.2 原型方法..................................................................................................... 78
8.3 贪吃蛇游戏的框架....................................................................................... 79
8.4 贪吃蛇的移动.............................................................................................. 80
8.5 贪吃蛇的控制.............................................................................................. 82
8.6 添加苹果..................................................................................................... 83
8.7 吃苹果........................................................................................................ 84
8.8 生成新苹果................................................................................................. 86
8.9 显示分数..................................................................................................... 87
8.9.1 设置文本基线… …………………………………………………………………… 90
8.9.2 设置文本的大小和字体… ………………………………………………………… 91
8.10 游戏结束................................................................................................... 93
8.11 碰撞检测................................................................................................... 93
09 拼图游戏........................................................................................100
9.1 显示图片................................................................................................... 100
9.2 图形的变化............................................................................................... 102
9.3 拼图游戏说明............................................................................................ 104
9.4 显示局部图片............................................................................................ 105
9.5 图片编号................................................................................................... 107
9.6 移动拼图................................................................................................... 108
9.7 打乱拼图................................................................................................... 112
9.8 拼图状态判断............................................................................................ 115
10 飞行射击游戏................................................................................. 121
10.1 图片处理................................................................................................. 121
10.2 绘制飞机................................................................................................. 122
10.3 子弹射击................................................................................................. 123
11 游戏引擎........................................................................................ 128
11.1 什么是游戏引擎...................................................................................... 128
11.2 Quintus 游戏引擎................................................................................... 128
11.3 网页初始化............................................................................................. 129
11.4 场景和精灵............................................................................................. 130
11.5 精灵控制................................................................................................. 132
11.6 调试功能................................................................................................. 133
11.7 GMP 游戏引擎....................................................................................... 135
11.8 js 文件下载............................................................................................. 136
11.9 真·射击游戏.......................................................................................... 137
11.10 游戏优化............................................................................................... 144
1.1 缘起...............................................................................................................1
1.2 历史...............................................................................................................1
1.3 特性...............................................................................................................2
02 类型和变量.........................................................................................4
2.1 浏览器中的控制台..........................................................................................4
2.2 数字和运算符.................................................................................................5
2.3 变量...............................................................................................................6
2.4 变量命名规则.................................................................................................7
2.5 字符串.......................................................................................................... 8
2.5.1 连接字符串… ………………………………………………………………………… 9
2.5.2 获取字符串的长度… ……………………………………………………………… 10
2.5.3 获取单个字符… …………………………………………………………………… 10
2.5.4 截取字符串… ……………………………………………………………………… 11
2.5.5 大小写转化… ……………………………………………………………………… 11
2.6 逻辑运算..................................................................................................... 12
2.6.1 布尔类型… ………………………………………………………………………… 12
2.6.2 逻辑运算符… ……………………………………………………………………… 12
2.6.3 关系运算符… ……………………………………………………………………… 14
2.7 underfined 和null...................................................................................... 16
2.8 原始类型..................................................................................................... 16
2.8.1 鉴别原始类型… …………………………………………………………………… 16
2.8.2 原始方法… ………………………………………………………………………… 17
03 数组................................................................................................18
3.1 创建数组..................................................................................................... 18
3.2 访问数组元素.............................................................................................. 18
3.3 修改数组元素.............................................................................................. 19
3.4 应用数组..................................................................................................... 20
3.4.1 查看数组长度… …………………………………………………………………… 20
3.4.2 添加数组元素… …………………………………………………………………… 20
3.4.3 删除数组元素… …………………………………………………………………… 21
3.4.4 数组相加… ………………………………………………………………………… 22
3.4.5 查找元素的序号… ………………………………………………………………… 22
3.4.6 将数组转换成字符串… …………………………………………………………… 23
04 对话框.............................................................................................24
4.1 HTML 基础................................................................................................. 24
4.2 嵌入JavaScript 代码.................................................................................. 25
4.3 对话框........................................................................................................ 27
4.3.1 输入对话框… ……………………………………………………………………… 27
4.3.2 确定对话框… ……………………………………………………………………… 29
4.3.3 if 语句… …………………………………………………………………………… 31
4.3.4 警告对话框… ……………………………………………………………………… 32
4.4 DOM.......................................................................................................... 33
4.4.1 用ID 标识元素……………………………………………………………………… 33
4.4.2 选中元素… ………………………………………………………………………… 34
4.4.3 替换文本内容… …………………………………………………………………… 34
05 绘制国际象棋棋盘.............................................................................37
5.1 canvas 元素............................................................................................... 37
5.2 绘制方块..................................................................................................... 38
5.3 绘制方框..................................................................................................... 39
5.4 绘制棋盘..................................................................................................... 41
5.5 循环结构..................................................................................................... 42
5.5.1 while 语句… ………………………………………………………………………… 42
5.5.2 do-while 语句… …………………………………………………………………… 43
5.5.3 for 循环……………………………………………………………………………… 44
06 五子棋.............................................................................................48
6.1 基本绘图方式.............................................................................................. 48
6.1.1 绘制线条… ………………………………………………………………………… 48
6.1.2 填充路径… ………………………………………………………………………… 49
6.1.3 绘制圆弧和圆… …………………………………………………………………… 50
6.2 绘制棋盘..................................................................................................... 51
6.3 鼠标交互..................................................................................................... 52
6.4 绘制棋子..................................................................................................... 54
6.5 黑子和白子................................................................................................. 56
6.6 获胜判断..................................................................................................... 59
6.7 函数............................................................................................................ 63
6.7.1 函数的形式… ……………………………………………………………………… 63
6.7.2 落子函数… ………………………………………………………………………… 64
6.7.3 获胜检测函数… …………………………………………………………………… 65
07 弹球游戏..........................................................................................69
7.1 对象............................................................................................................ 69
7.2 对象的方法................................................................................................. 70
7.3 定时功能..................................................................................................... 71
7.4 边界判断..................................................................................................... 72
7.5 增加挡板..................................................................................................... 73
7.6 键盘交互..................................................................................................... 74
08 贪吃蛇.............................................................................................78
8.1 构造函数..................................................................................................... 78
8.2 原型方法..................................................................................................... 78
8.3 贪吃蛇游戏的框架....................................................................................... 79
8.4 贪吃蛇的移动.............................................................................................. 80
8.5 贪吃蛇的控制.............................................................................................. 82
8.6 添加苹果..................................................................................................... 83
8.7 吃苹果........................................................................................................ 84
8.8 生成新苹果................................................................................................. 86
8.9 显示分数..................................................................................................... 87
8.9.1 设置文本基线… …………………………………………………………………… 90
8.9.2 设置文本的大小和字体… ………………………………………………………… 91
8.10 游戏结束................................................................................................... 93
8.11 碰撞检测................................................................................................... 93
09 拼图游戏........................................................................................100
9.1 显示图片................................................................................................... 100
9.2 图形的变化............................................................................................... 102
9.3 拼图游戏说明............................................................................................ 104
9.4 显示局部图片............................................................................................ 105
9.5 图片编号................................................................................................... 107
9.6 移动拼图................................................................................................... 108
9.7 打乱拼图................................................................................................... 112
9.8 拼图状态判断............................................................................................ 115
10 飞行射击游戏................................................................................. 121
10.1 图片处理................................................................................................. 121
10.2 绘制飞机................................................................................................. 122
10.3 子弹射击................................................................................................. 123
11 游戏引擎........................................................................................ 128
11.1 什么是游戏引擎...................................................................................... 128
11.2 Quintus 游戏引擎................................................................................... 128
11.3 网页初始化............................................................................................. 129
11.4 场景和精灵............................................................................................. 130
11.5 精灵控制................................................................................................. 132
11.6 调试功能................................................................................................. 133
11.7 GMP 游戏引擎....................................................................................... 135
11.8 js 文件下载............................................................................................. 136
11.9 真·射击游戏.......................................................................................... 137
11.10 游戏优化............................................................................................... 144
猜您喜欢