Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e95913
commit 740146b
Showing
5 changed files
with
211 additions
and
160 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Dominion; module UI; end; end; | ||
class Dominion::UI::NCurses < Dominion::Engine | ||
class BoardWindow < Window | ||
def initialize(*args) | ||
super | ||
end | ||
|
||
def coords | ||
[14, 80, 0, 0] | ||
end | ||
|
||
def title | ||
'Board' | ||
end | ||
|
||
def draw | ||
type_char = [ | ||
[:reaction, 'R'], | ||
[:attack, 'X'], | ||
[:treasure, 'T'], | ||
[:victory, 'V'], | ||
[:action, 'A'] | ||
] | ||
|
||
max_name_length = game.board.map {|pile| | ||
pile[0][:name].length | ||
}.max | ||
|
||
header, body = game.board.partition {|x| | ||
[ | ||
:copper, | ||
:silver, | ||
:gold, | ||
:estate, | ||
:duchy, | ||
:provence, | ||
:curse | ||
].include?(x.first[:key]) | ||
} | ||
|
||
header.each_with_index do |pile, i| | ||
card = pile.first | ||
|
||
print( :white, ' ' ) if i > 0 | ||
print( :yellow, card[:cost] ) | ||
print( :red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1] ) | ||
print( :blue, pile.size ) | ||
print( :white, " %s" % card[:name] ) | ||
end | ||
print( :white, "\n" ) | ||
body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| | ||
card = pile.first | ||
|
||
print( :white, ' ' ) | ||
print( :yellow, card[:cost] ) | ||
print( :red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1] ) | ||
print( :blue, '%-2i' % pile.size ) | ||
if game.card_active?(card) | ||
print( :white, " %-#{max_name_length}s " % card[:name], true ) | ||
else | ||
print( :white, " %-#{max_name_length}s " % card[:name] ) | ||
end | ||
|
||
print( :cyan_back, card[:cards] || ' ' ) | ||
print( :green_back, card[:actions] || ' ' ) | ||
print( :magenta_back, card[:buys] || ' ' ) | ||
print( :yellow_back, card[:gold] || ' ' ) | ||
|
||
print( :white, " %-#{max_name_length}s\n" % card[:description] ) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Dominion; module UI; end; end; | ||
class Dominion::UI::NCurses < Dominion::Engine | ||
class InputWindow < Window | ||
attr_accessor :input_buffer | ||
|
||
def initialize(game, input_buffer) | ||
super(game) | ||
self.input_buffer = input_buffer | ||
end | ||
|
||
def coords | ||
[1, 80, 24, 0] | ||
end | ||
|
||
def border | ||
false | ||
end | ||
|
||
def draw | ||
if game.prompt | ||
suggest = game.prompt[:autocomplete][:strategy][input_buffer].to_s | ||
|
||
print( game.prompt[:color] || :yellow_back, "%s %s" % [ | ||
game.prompt[:prompt], | ||
input_buffer | ||
]) | ||
|
||
fill = suggest[input_buffer.length..-1] | ||
|
||
if fill && fill.length > 0 | ||
print( :red, "%s" % fill ) | ||
end | ||
else | ||
print( :green_back, "%-80s" % " " ) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Dominion; module UI; end; end; | ||
class Dominion::UI::NCurses < Dominion::Engine | ||
class PlayAreaWindow < Window | ||
def initialize(*args) | ||
super | ||
end | ||
|
||
def coords | ||
[10, 80, 14, 0] | ||
end | ||
|
||
def title | ||
"Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ | ||
game.turn, | ||
game.player[:actions], | ||
game.player[:buys], | ||
game.treasure(game.player), | ||
game.player[:discard].length, | ||
game.player[:deck].length | ||
] | ||
end | ||
|
||
def draw | ||
print( :white, "Hand: " ) | ||
line_length = 6 | ||
game.player[:hand].each_with_index do |card, index| | ||
suffix = index == game.player[:hand].length - 1 ? '' : ', ' | ||
print( :white, card[:name] + suffix, game.card_active?(card) ) | ||
line_length += (card[:name] + suffix).length | ||
end | ||
|
||
# TODO: print ' ' doesn't work :( | ||
print( :white, " " * (77 - line_length) ) if line_length < 76 | ||
print( :white, "\n" ) | ||
|
||
played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") | ||
print( :white, played ) | ||
print( :white, " " * (77 - played.length) ) if played.length < 76 | ||
print( :white, "\n" ) | ||
|
||
unless game.player[:revealed].empty? | ||
revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") | ||
print( :white, revealed ) | ||
print( :white, " " * (77 - revealed.length) ) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.