master
commit
e6a0c07dc7
@ -0,0 +1,9 @@ |
|||||||
|
Basically, it's a slightly lower tech version of InvisibleCastle.com |
||||||
|
|
||||||
|
You use the dieroller.html to roll some dice, and then, use display.rb to view the resutls. Longterm goal is to emulate most of the functionality of Invisible castle. |
||||||
|
|
||||||
|
Currently uses the format: |
||||||
|
NdM for a roll of N dice with M sides. |
||||||
|
If you add a ! to the end of the roll line, dice will reroll if they roll the largest number |
||||||
|
|
||||||
|
If you add a > sign followed by a number, it will assume that you want to roll successes, and will only roll dice and count the number that come up higher than the number after the > sign |
@ -0,0 +1,2 @@ |
|||||||
|
require "mysql" |
||||||
|
$my = Mysql.connect('localhost', 'dice', 'Yqv8JPzsYew34YY7', 'dieroller') |
@ -0,0 +1,53 @@ |
|||||||
|
def roll(rollstring) |
||||||
|
if rollstring[rollstring.length-1] == "!" |
||||||
|
@explode = true |
||||||
|
rollstring = rollstring.chop |
||||||
|
else |
||||||
|
@explode = false |
||||||
|
end |
||||||
|
@token = rollstring.split("d") |
||||||
|
@total = 0 |
||||||
|
@retval = "" |
||||||
|
|
||||||
|
if @token[1].include? ">" |
||||||
|
temp = @token[1].split(">") |
||||||
|
@token[1] = temp[0] |
||||||
|
diff = temp[1] |
||||||
|
successes(@token[0].to_i, @token[1].to_i, diff.to_i) |
||||||
|
@retval = @retval.to_s + " Successes: " + @total.to_s |
||||||
|
else |
||||||
|
@token[0].to_i.times do |
||||||
|
adddie(@token[1].to_i) |
||||||
|
end |
||||||
|
@retval = @retval.to_s + " Total: " + @total.to_s |
||||||
|
end |
||||||
|
return @retval |
||||||
|
end |
||||||
|
|
||||||
|
def onedie(min,max) |
||||||
|
return(rand(max)+min) |
||||||
|
end |
||||||
|
|
||||||
|
def adddie(size) |
||||||
|
singleroll = onedie(1,size) |
||||||
|
@retval = @retval + " " + singleroll.to_s |
||||||
|
if @explode |
||||||
|
if singleroll == size |
||||||
|
adddie(size) |
||||||
|
end |
||||||
|
end |
||||||
|
@total = @total.to_i + singleroll.to_i |
||||||
|
end |
||||||
|
|
||||||
|
def successes(num, size, diff) |
||||||
|
num.times do |
||||||
|
singleroll = onedie(1,size) |
||||||
|
@retval = @retval + " " + singleroll.to_s |
||||||
|
if @explode |
||||||
|
if singleroll == size |
||||||
|
successes(1, size, diff) |
||||||
|
end |
||||||
|
end |
||||||
|
@total = @total+1 if singleroll.to_i >= diff |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,8 @@ |
|||||||
|
<html> |
||||||
|
<form action="roller.rb" method="post"> |
||||||
|
<p>Die Roll<input type="text" name="rollstring" /></p> |
||||||
|
<p>User<input type="text" name="user" /></p> |
||||||
|
<p>Game<input type="text" name="game" /></p> |
||||||
|
<input type="submit" value="Roll Them Bones" /> |
||||||
|
</form> |
||||||
|
</html> |
@ -0,0 +1,36 @@ |
|||||||
|
#!/usr/bin/ruby |
||||||
|
require "cgi" |
||||||
|
require "./db" |
||||||
|
cgi = CGI.new |
||||||
|
clause = "" |
||||||
|
emptyclause = 0 |
||||||
|
if cgi.has_key?("user") |
||||||
|
unless cgi.params["user"][0]=="" |
||||||
|
clause = " WHERE user='" + cgi.params["user"][0] +"'" |
||||||
|
emptyclause = 1 |
||||||
|
end |
||||||
|
end |
||||||
|
if cgi.has_key?("game") |
||||||
|
unless cgi.params["game"][0]=="" |
||||||
|
if emptyclause == 1 |
||||||
|
clause = clause + " AND " |
||||||
|
else |
||||||
|
clause = " WHERE " |
||||||
|
end |
||||||
|
clause = clause + "game ='" + cgi.params['game'][0] + "'" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
print '<html>' |
||||||
|
print ' <form action="display.rb" method="post">' |
||||||
|
print ' User<input type="text" name="user" />' |
||||||
|
print ' Game<input type="text" name="game" />' |
||||||
|
print ' <input type="submit" value="Display Rolls" />' |
||||||
|
print ' </form>' |
||||||
|
print '</html>' |
||||||
|
|
||||||
|
|
||||||
|
result = $my.query("SELECT * from rolls" + clause) |
||||||
|
result.num_rows.times do |
||||||
|
puts result.fetch_row.join("\s") + "<br />" |
||||||
|
end |
@ -0,0 +1,6 @@ |
|||||||
|
#!/usr/bin/ruby |
||||||
|
require "./db" |
||||||
|
result = $my.query("SELECT * from rolls") |
||||||
|
result.num_rows.times do |
||||||
|
puts result.fetch_row.join("\s") + "<br />" |
||||||
|
end |
@ -0,0 +1,8 @@ |
|||||||
|
#!/usr/bin/ruby |
||||||
|
require "./db" |
||||||
|
require "./die" |
||||||
|
require "cgi" |
||||||
|
cgi = CGI.new |
||||||
|
result = roll(cgi.params["rollstring"][0].to_s) |
||||||
|
$my.query("INSERT INTO rolls set result='" + cgi.params["rollstring"][0] + "', roll='" + result.to_s + "', user='" + cgi.params["user"][0] + "', game='" + cgi.params["game"][0] + "'") |
||||||
|
puts result |
Loading…
Reference in new issue