forked from samuelcouch/sms-battleship
-
Notifications
You must be signed in to change notification settings - Fork 0
/
battleship.rb
69 lines (56 loc) · 1.59 KB
/
battleship.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'sinatra'
require 'sendgrid-ruby'
grid = [['a1', 'b1', 'c1', 'd1', 'e1'],
['a2', 'b2', 'c2', 'd2', 'e2'],
['a3', 'b3', 'c3', 'd3', 'e3'],
['a4', 'b4', 'c4', 'd4', 'e4'],
['a5', 'b5', 'c5', 'd5', 'e5']]
class Player
attr_accessor :name, :ship
def initialize(name)
@name = name
@ship = Ship.new()
end
end
class Ship
attr_accessor :row, :col, :location, :sunk
def initialize()
@row = (0..4).to_a.sample
@col = (0..4).to_a.sample
@location = grid[@col][@row]
end
def is_sunk?
@sunk.is_sunk?
end
end
post '/' do
subject = params[:subject]
case Responses
when subject.include? "Challenge"
puts "It's between 1 and 5"
subject_array = subject.split
challengee = subject_array[1]
mail = SendGrid::Mail.new do |m|
m.to = challengee
m.from = '[email protected]'
m.subject = 'You\'ve been challenged!'
m.text = 'Your fellow coworker/friend just challenged you to a game of battleship. To play, reply by putting a Letter between A and E and a number between 1 and 5 in the subject line'
end
puts client.send(mail)
mail = SendGrid::Mail.new do |m|
m.to = challenger
m.from = '[email protected]'
m.subject='Prepare'
m.text='You\'ve sent out an invite, waiting for a response...
Here\'s something to keep you company: https://www.youtube.com/watch?v=nfWlot6h_JM'
end
puts client.sent(mail)
when subject.length = 2
hit = subject
#if hit
when String
puts "You passed a string"
else
200
end
end