简单/硬级别,数独,使用html和ruby中的<form> </form>

时间:2013-09-22 23:47:55

标签: html ruby forms sudoku

我正在尝试完成我的数独游戏。获得了基本功能,但我无法弄清楚如何让Hard Game按钮创建默认Easy Game的难度版本。我知道表单标签需要包含一些有关需要发送的信息,但我不明白如何组织这些信息。

目前,我正在努力使“硬游戏”按钮完全按照默认游戏按钮执行操作,只需使用.rb文件中略微更改的红宝石代码。目前,我的HTML代码如下所示:

<html>
<head>
<title>sudoku game</title>
 <!--link to css stylesheet-->

 <link href="/stylesheets/application.css" rel="stylesheet" type="text/css">

</head>
<body>
    <h1>U * k * o * d * U * s</h1> 
<div id="flash">
  <%= flash[:notice] %>
</div>
    <div id="sudoku">
        <form action="/" method="post"> 
            <!--one div for each row -->
        <% 3.times do |row| %>
            <div class="row">hackpad
                <% 3.times do |box| %>
                    <div class="box">
                        <!---each box will have nine cells-->
                        <% 3.times do |cell_row| %>
                            <div class="cell-row">
                                <% 3.times do |cell| %>



                                <%= partial :cell, :locals=>{:cell_index => row*27+box*3+cell_row*9+cell} %> 
                                <% end %>
                            </div>
                        <% end %>
                    </div>
                <% end %>   
            </div>
        <% end %>

      <!-- all boxes, rows and cells -->
      <button>Check solution</button>
    </form>

    <form action="/hard" method="post">
    <button>Hard Game</button>
    </form>         

    <form action="/reset" method="get">
    <button>Reset Game</button>
    </form>

    <form action="/solution" method="get">
    <button>Give Up</button>
    </form>
</div>

用于生成新拼图的ruby代码是:

def puzzle(sudoku)
    # sudoku = sudoku.dup
  sudoku.map.with_index do |sudoku,index|
    if Random.rand(100)<45
      sudoku
    end
  end
end

此代码与我想用于生成更难游戏的代码之间的区别在于45被替换为15.就是它。

我知道这不是生成各种难度谜题的最复杂方法,但我只是想了解如果你想发布相同内容的略微修改版本,表单按钮是如何工作的。

我不断收到的错误消息包括:

  

/ hard的NoMethodError   未定义的方法`[]'为nil:NilClass

0 个答案:

没有答案