class GameController < ApplicationController
def index
@games = Game.all
respond_to do |format|
format.html
end
end
def start_game
session[:round] ||= 1
session[:points] ||= 0
@round = session[:round]
@points = session[:points]
end
def next_round
session[:round] += 1
session[:points] += 1200
@round = session[:round]
@points = session[:points]
end
def generate_round
numbers = Array.new(6){rand(9)}
@addition = []
@display = numbers
numbers.inject do |s, i|
@addition << s + i
@addition.last
end
end
def new
if @round == nil
start_game
generate_round
else
generate_round
end
if session[:addition]
if not session[:addition].index(params[:guess].to_i).nil?
puts "Correct."
next_round
else
puts 'Game over.'
end
end
session[:addition] = @addition
respond_to do |format|
format.html
end
end
end
嘿家伙, 我试图把这个迷你游戏放在红宝石,这取决于猜测数字。 添加每个猜测点后,等级增加1。这个循环有什么问题?
但是就目前的代码而言,我在第二轮卡住了。 很可能是因为某些原因重置了这些变量,但我似乎可以指出它是什么。
将不胜感激任何形式的帮助。
::编辑::更新
代码。问题解决了! 感谢您的帮助@ blackbird07,@robertodecurnex和@ fl00r!
好奇,什么是Ruby中的“不”?我不熟悉它......然后我又是一个Ruby新手。 – Meltemi
这些东西在控制器中做了什么? – fl00r
这是几乎昨天你的问题的转贴:http://stackoverflow.com/questions/6654978/how-to-one-up-for-points-and-rounds-in-a-game – thedaian