-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.rb
49 lines (45 loc) · 1.1 KB
/
app.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
require 'bundler/setup'
Bundler.require :default
require './lib/piece'
require './lib/piece_bishop'
require './lib/piece_king'
require './lib/piece_knight'
require './lib/piece_pawn'
require './lib/piece_queen'
require './lib/piece_rook'
require './lib/game'
# also_reload "./lib/*/**.rb"
get '/' do
Game.all.each do |game|
game.destroy
end
Game.create
erb :index
end
get '/game' do
@message = ""
@game = Game.first
@black_pieces = Piece.all.where(white: false)
@white_pieces = Piece.all.where(white: true)
erb :game
end
post '/game' do
x_value = params.fetch('x_value').to_i
y_value = params.fetch('y_value').to_i
if piece = Piece.find(params.fetch('piece').to_i)
if piece.white == Game.first.white_turn
if piece.move?(x_value, y_value)
piece.move_it(x_value,y_value)
# if piece.promotion?
Game.first.turn
else
@message = "Invalid move! Try again."
@game = Game.first
@black_pieces = Piece.all.where(white: false)
@white_pieces = Piece.all.where(white: true)
erb :game
end
end
end
redirect '/game'
end