zoukankan      html  css  js  c++  java
  • 关灯游戏

    非原创,几乎完全借鉴了此处的代码,我主要添加了几个关卡.

    暑假里就尝试过搞这个,一直没成功,今天看到这个代码眼前一亮啊,感谢paradox2同学.

    code:

    stagelist = {{{1, 1}, {1, 2}, {1, 4}, {1, 5}, {2, 1}, {2, 3}, {2, 
         5}, {3, 2}, {3, 3}, {3, 4}, {4, 1}, {4, 3}, {4, 5}, {5, 1}, {5, 
         2}, {5, 4}, {5, 5}}, {{1, 1}, {1, 2}, {1, 4}, {2, 3}, {2, 4}, {2,
          5}, {3, 1}, {3, 2}, {4, 3}, {4, 4}, {4, 5}, {5, 1}, {5, 2}, {5, 
         4}}, {{1, 1}, {1, 2}, {1, 4}, {1, 5}, {2, 4}, {3, 1}, {3, 2}, {3,
          3}, {4, 1}, {4, 4}, {5, 4}, {5, 5}}, {{1, 1}, {1, 3}, {1, 
         5}, {2, 1}, {2, 3}, {2, 5}, {4, 3}, {4, 5}, {5, 2}, {5, 3}, {5, 
         5}}, {{1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 1}, {2, 2}, {2,
          3}, {2, 4}, {2, 5}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 
         1}, {4, 2}, {4, 3}, {4, 4}, {4, 5}, {5, 1}, {5, 2}, {5, 3}, {5, 
         4}, {5, 5}}};
    
    stage = Table[
       MapIndexed[If[MemberQ[i, #2], 0, 1] &, 
        Array[1 &, {5, 5}], {2}], {i, stagelist}];
    
    Manipulate[
     EventHandler[Dynamic[ArrayPlot[matrix, Mesh -> True]], 
      "MouseDown" :> (clickPoint = MousePosition["Graphics"];
        currentPoint = {6 - Ceiling[clickPoint][[2]], 
          Ceiling[clickPoint][[1]]}; changeMethod[currentPoint];
        If[Count[Flatten[matrix], 1] == 25, MessageDialog["你赢了!"]])], 
     Row[Button[Style[#, 40, Bold], matrix = stage[[#]], 
         Background -> Pink, ImageSize -> {74, 58}] & /@ Range[5]], 
     Initialization -> {matrix = stage[[1]];
       changeMethod[point_] := 
        Module[{a, b}, a = point[[1]]; b = point[[2]];
         list = 
          Select[{{a + 1, b}, {a - 1, b}, {a, b - 1}, {a, b + 1}, {a, b}},
            0 < #[[1]] < 6 && 
             0 < #[[2]] < 6 &]; (matrix[[#[[1]], #[[2]]]] = 
             1 - matrix[[#[[1]], #[[2]]]]) & /@ list]}]

  • 相关阅读:
    JavaScript--Function类型(11)
    CSS--清除浮动
    JavaScript--正则表达式(笔记)
    JavaScript--模块化编程(笔记)
    原生javascript-图片滚动按需加载
    原生javascript-图片按钮切换
    原生javascript-图片弹窗交互效果
    对CSS了解-overflow:hidden
    对CSS了解-选择器权重
    TaskTimer
  • 原文地址:https://www.cnblogs.com/mymma/p/2680505.html
Copyright © 2011-2022 走看看