This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pawn < Piece | |
def first_move?(y) | |
#Allowed to move 1 or 2 spaces. | |
if (color: :white && y_position: 1) || (color: :black && y_position: 6) | |
return true | |
if (y_position - y) < 3 | |
else | |
return false | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pawn < Piece | |
def valid_move?(x,y) | |
#First move. Allowed to move 1 or 2 spaces. | |
if self.x_position #how to say this is the first move?? | |
return false if (self.x_position - x).abs > 2 || (self.y_position - y).abs > 2 | |
#All moves. Allowed to move 1 space. | |
return false if (self.x_position - x).abs > 1 || (self.y_position - y).abs > 1 | |
#Up 1 and horizonal to capture. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class King < Piece | |
def self.type | |
where(type: 'king') | |
end | |
def valid_move?(x, y) | |
# King can move one square at a time in any direction. Move not valid if current position - new position | |
# is greater than the absolute value of 1. | |
return false if (self.x_position - x).abs > 1 || (self.y_position - y).abs > 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PBJ | |
attr_accessor :pbutter, :jelly | |
def initialize(pbutter, jelly) | |
@pbutter = pbutter | |
@jelly = jelly | |
end | |
def make | |
puts "Spread #{@pbutter} peanut butter and #{@jelly} jelly on bread. Bam!" |