作者:iamlaosong

在网上看到一个用HTML5制作的智力游戏,有相当的难度。每个方块一面橙色,一面蓝色。点击一个方块,这个方块的颜色会翻转,并且,与它邻接的方块的颜色也会翻转。使拼板全部变成蓝色, 你就算过关了。游戏规则很简单,实现起来也不难,想到Excel单元格可以变颜色,试着用VBA写了一个。

1、初始化

Public Level As Integer
Public color1, color2, ClickNo As LongSub auto_open()Level = 1color1 = 33022          'orangecolor2 = 16711680       'bluehint = "这是一个智力游戏,有相当的难度。级别L有L*L个方块,方块一面橙色,一面蓝色。"hint = hint & Chr(13) & "双击任一个方块,这个方块的颜色会翻转,并且,与它邻接的方块的颜色也会翻转。"hint = hint & Chr(13) & "使L*L个方块全部变成蓝色, 你就算过关了。双击任一无色单元格可重新开始!"hint = hint & Chr(13) & Chr(13) & "(Ver:20151016 )是否从第一关开始?"If MsgBox(hint, vbYesNo, "iamlaosong") = vbYes ThenRows("1:50").Delete Shift:=xlUpElseFor i = 1 To 50'Debug.Print Cells(1, i).Interior.ColorIf Cells(1, i).Interior.Color <> color1 And Cells(1, i).Interior.Color <> color2 Then Exit ForNext iIf i > 1 Then Level = i - 1End IfinitEnd SubSub init()Range(Cells(1, Level), Cells(Level, Level + 2)).ClearContentsRange(Cells(1, 1), Cells(Level, Level)).SelectSelection.RowHeight = 48Selection.ColumnWidth = 8'set colorSelection.Interior.Color = color1'set borderWith Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous.ColorIndex = 0.TintAndShade = 0.Weight = xlMediumEnd WithWith Selection.Borders(xlEdgeTop).LineStyle = xlContinuous.ColorIndex = 0.TintAndShade = 0.Weight = xlMediumEnd WithWith Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous.ColorIndex = 0.TintAndShade = 0.Weight = xlMediumEnd WithWith Selection.Borders(xlEdgeRight).LineStyle = xlContinuous.ColorIndex = 0.TintAndShade = 0.Weight = xlMediumEnd WithWith Selection.Borders(xlInsideVertical).LineStyle = xlContinuous.ColorIndex = 0.TintAndShade = 0.Weight = xlThinEnd WithWith Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous.ColorIndex = 0.TintAndShade = 0.Weight = xlThinEnd WithRange("A1").SelectIf Level = 1 Then MsgBox "开始第" & Level & "关!"ClickNo = 0
End Sub

2、检查是否通关

Public Sub CheckWin()'Range(Cells(1, 1), Cells(Level, Level)).Select'If Selection.Interior.Color = color2 ThenFor i = 1 To LevelFor j = 1 To LevelIf Cells(i, j).Interior.Color <> color2 Then Exit ForNext jIf j <= Level Then Exit ForNext iIf i > Level ThenLevel = Level + 1MsgBox "恭喜你,你赢了!现在开始第" & Level & "关!"initEnd IfCells(1, Level + 2) = "双击次数:" & ClickNoClickNo = ClickNo + 1
End Sub

3、改变颜色

这个程序不放在模块中,而是放在对象sheet1的BeforeDoubleClick事件响应程序中。

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)If ActiveCell.Row <= Level And ActiveCell.Column <= Level Then'currentIf Selection.Interior.Color = color1 ThenSelection.Interior.Color = color2ElseSelection.Interior.Color = color1End If'topIf ActiveCell.Row > 1 ThenIf ActiveCell.Offset(-1, 0).Interior.Color = color1 ThenActiveCell.Offset(-1, 0).Interior.Color = color2ElseActiveCell.Offset(-1, 0).Interior.Color = color1End IfEnd If'bottomIf ActiveCell.Row < Level ThenIf ActiveCell.Offset(1, 0).Interior.Color = color1 ThenActiveCell.Offset(1, 0).Interior.Color = color2ElseActiveCell.Offset(1, 0).Interior.Color = color1End IfEnd If'leftIf ActiveCell.Column > 1 ThenIf ActiveCell.Offset(0, -1).Interior.Color = color1 ThenActiveCell.Offset(0, -1).Interior.Color = color2ElseActiveCell.Offset(0, -1).Interior.Color = color1End IfEnd If'rightIf ActiveCell.Column < Level ThenIf ActiveCell.Offset(0, 1).Interior.Color = color1 ThenActiveCell.Offset(0, 1).Interior.Color = color2ElseActiveCell.Offset(0, 1).Interior.Color = color1End IfEnd IfElseauto_openEnd If'exit edit stateCancel = TrueCheckWin
End Sub

4、程序界面

下载游戏:点击打开链接

【VBA研究】智力游戏-蓝色方块相关推荐

  1. 方块填数 “数独”是当下炙手可热的智力游戏。一般认为它的起源是“拉丁方块”,是大数学家欧拉于1783年发明的。 如图[1.jpg]所示:6x6的小格被分为6个部分(图中用不同的颜色区分),每个部

    /* 方块填数 "数独"是当下炙手可热的智力游戏.一般认为它的起源是"拉丁方块",是大数学家欧拉于1783年发明的. 如图[1.jpg]所示:6x6的小格被分为 ...

  2. 信息系html5论文,基于HTML5的智力游戏设计电子信息工程本科学生毕业论文.doc

    基于HTML5的智力游戏设计电子信息工程本科学生毕业论文 本科学生毕业论文(设计) 题目(中文):基于HTML5的智力游戏设计 (英文):Design of Intelligent Game Base ...

  3. html5游戏任务书,基于HTML5的智力游戏设计 毕业论文(设计).docx

    PAGE 本科学生毕业论文(设计) 题目(中文):基于HTML5的智力游戏设计 (英文):Design of Intelligent Game Based on HTML5 姓 名 学 号 院 (系) ...

  4. 智力游戏界的三大不可思议

    中国人发明的"华容道", 法国人发明的"独立钻石"和匈牙利人发明的"魔术方块"(简称"魔方")被称为智力游戏界的三大不可 ...

  5. CocosCreator之KUOKUO带你入门3D小游戏-躲避方块

    本次引擎2.1.0 编辑工具VSCode 目标:3D小游戏躲避方块 2.1.0版本已经出来好几天了,虽然有些地方还不够完善, 但是毕竟是能写3D游戏了,简单的来写一个,嘻嘻. console.log( ...

  6. 游戏HTML翻翻乐,大班智力游戏——翻翻乐.doc

    大班智力游戏--翻翻乐 [活动目标] 1.在玩的过程中进行按规律排列及比较10以内数的大小. 2.培养合作意识,养成遵守规则的好习惯. [活动准备] 1.格子图棋谱若干. 2.收集黄.红两种颜色的饮料 ...

  7. 四宫格效果 css_【深度教研】智力游戏“九宫格” 集体教研活动纪实

    [关键词]教研要建立过程模式,规范管理,分层推进,各负其责,及时反馈,展示总结.让教研的过程成为全体教师共同成长的过程.       游戏和材料不是一次性的制作和一次性的使用,其价值在于反复玩,玩中学 ...

  8. 智力游戏(搬山游戏)

    /**************************************** * File Name : game.c * Creat Data : 2015.1.30 * Author : Z ...

  9. flash静态的农夫走路_智力游戏过河|智力游戏过河flash合集下载 _单机游戏下载...

    智力游戏过河,过河游戏是经典的益智游戏了,需要很高的IQ,能很好锻炼逻辑能力,经典的过河游戏有人鬼过河,农夫过河,高IQ过河,青蛙过河等等.跑跑车为您提供的智力游戏过河flash合集,包含了这一些游戏 ...

  10. “数独”是一种智力游戏,一般认为起源于“正交拉丁方”,经日本人推广后风靡全球。

    递归回溯算法完成数独求解. "数独"是一种智力游戏,一般认为起源于"正交拉丁方",经日本人推广后风靡全球.如下图是一个数独的示例,玩家需要根据 9 × 9 盘面 ...

最新文章

  1. JQ实现导航效果(附效果图)
  2. lintcode:Unique Characters 判断字符串是否没有重复字符
  3. ORACLE 回滚段详解
  4. Mybatis3源码分析(05)-加载Configuration-加载MappedStatement
  5. git通过authorized_keys来管理用户的权限(二)
  6. SpringMVC-方法四种类型返回值总结,你用过几种?
  7. layui循环数据并渲染_从简单到复杂三维图形渲染管线
  8. poj2387TillCowsComHome Dijlstra
  9. 盲人方便的使用计算机输入文字,中文信息学报盲人用计算机软件系统中的语音和自然语言处理技术Ξ.PDF...
  10. 3张报表搞定财务分析
  11. 拦截器ConnectInterceptor
  12. LeetCode-210 Course Schedule II
  13. 国内比较好的几大酷站收藏网分享
  14. 中英文对照 —— 航空航天航海、交通运输工具
  15. SQL语句详解(二)——select基本查询操作
  16. H5在微信下载app
  17. 【Excel】两组行数不同数据做二维柱状图
  18. python有架构师吗_运维架构师-Python 自动化运维开发-021
  19. html js表单,HTML HTML 表单 - 闪电教程JSRUN
  20. 怎么保证促销商品不会超卖

热门文章

  1. 关于j2me mmapi的player接口的一些理解.
  2. linux使用光盘镜像(ISO)作为软件源安装软件
  3. 误入 GitHub 游戏区,结果意外地收获颇丰
  4. Mac顶部菜单栏(Menubar)卡死
  5. seo秘籍,seo秘籍-自学seo零基础知识入门优化教程
  6. 关于Flume断点续传(防止重复消费)的解决方案
  7. python掷骰子实验代码_Python Tkinter实例——模拟掷骰子
  8. 计算机维修培训教材,计算机芯片级维修--芯片级维修培训教材.doc
  9. 帝国cms没有标题图片就显示默认图片
  10. 【ubuntu系统下装win10双系统】