Skip to content

dustin-chan/Chess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess

A ruby terminal Chess game.

Instructions

In your CLI run "ruby board.rb" to play a game of Chess.

Controls

  • Arrow keys to move
  • Enter to select spaces

Technologies

  • Ruby

Features

Rendering

If a piece is selected the board will render the valid moves for that piece in a different color than the rest of the board.

  def render
    until false
      system("clear")
      board.rows.each_with_index do |row,i|
        row.each_with_index do |col,j|
          pos = [i,j]
          symbol = board[pos].symbol
          color = board[pos].color
          unless pos == cursor.pos
            if cursor.selected != nil && cursor.selected.pos == pos
              print print " #{symbol} ".send(color).on_blue.blink
            elsif cursor.selected != nil && cursor.selected.valid_moves.include?(pos)
              print " #{symbol} ".send(color).on_magenta
            else
              if i.even? && j.even?
                print " #{symbol} ".send(color).on_white
              elsif i.odd? && j.odd?
                print " #{symbol} ".send(color).on_white
              else
                print " #{symbol} ".send(color).on_black
              end
            end
          else
            print " #{symbol} ".send(color).on_red
          end
        end
        puts ""
      end
      cursor.get_input
    end
  end

Movement Modules

The use of modules significantly reduced the amount of code necessary.

class Queen < Piece
  include Slideable

  def symbol
    "♕"
  end

  protected
  def move_dirs
    diagonal_dirs + horizontal_dirs
  end
end

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages