Commit 0e7ae05a authored by 神楽坂玲奈's avatar 神楽坂玲奈

卡片操作初步

parent ed27ab0c
......@@ -110,6 +110,9 @@ class Action
from_field.delete_at from_pos
end
end
p @to_pos
p self
to_field = case @to_pos
when Integer
player_field.field
......@@ -138,8 +141,8 @@ class Action
end
end
class Set < Move
def initialize(from_player, from_pos, to_pos)
super(from_player, from_pos, to_pos, :set)
def initialize(from_player, from_pos, to_pos, card)
super(from_player, from_pos, to_pos, card, nil, :set)
end
end
class Activate < Move; end
......@@ -157,7 +160,7 @@ class Action
end
class ReturnToHand < Move
def initialize(from_player, from_pos, card)
super(from_player, from_pos, card, :hand)
super(from_player, from_pos, :hand, card)
end
end
class ReturnToDeck < Move
......
......@@ -10,7 +10,8 @@ class Card
@all = []
@count = @db.get_first_value("select COUNT(*) from YGODATA") rescue 0
@db.results_as_hash = true
PicPath = '/media/44CACC1DCACC0D5C/game/yu-gi-oh/YGODATA/YGOPIC'
#PicPath = '/media/44CACC1DCACC0D5C/game/yu-gi-oh/YGODATA/YGOPIC'
PicPath = 'E:/game/yu-gi-oh/YGODATA/YGOPIC'
CardBack = Surface.load "graphics/field/card.png"
class << self
def find(id, order_by=nil)
......@@ -19,30 +20,32 @@ class Card
@all[id] || old_new(@db.get_first_row("select * from YGODATA where id = #{id}"))
when Symbol
row = @db.get_first_row("select * from YGODATA where name = '#{id}'")
@all[row['id'].to_i] || old_new(row)
row && (@all[row['id'].to_i] || old_new(row))
when Hash
old_new(id)
when nil
Card.find(1).instance_eval{@image = CardBack} unless @all[1]
@all[1]
else
sql = "select * from YGODATA where " << id
sql << " order by #{order_by}" if order_by
@db.execute(sql).collect {|row|@all[row['id'].to_i] || old_new(row)}
end
end
def all
if @all.size != @count
sql = "select * from YGODATA where id not in (#{@all.keys.join(', ')})"
@db.execute(sql).each{|row|old_new(row)}
end
@all
end
def cache
@all
end
alias old_new new
def new(id)
find(id)
end
else
sql = "select * from YGODATA where " << id
sql << " order by #{order_by}" if order_by
@db.execute(sql).collect {|row|@all[row['id'].to_i] || old_new(row)}
end
end
def all
if @all.size != @count
sql = "select * from YGODATA where id not in (#{@all.keys.join(', ')})"
@db.execute(sql).each{|row|old_new(row)}
end
@all
end
def cache
@all
end
alias old_new new
def new(id)
find(id)
end
def load_from_ycff3(db = "E:/game/yu-gi-oh/YGODATA/YGODAT.mdb")
require 'win32ole'
conn = WIN32OLE.new('ADODB.Connection')
......@@ -141,7 +144,7 @@ class Card
Card.cache[@id] = self
end
def image
@image ||= Surface.load "#{PicPath}/#{@id-1}.jpg"
@image ||= Surface.load "#{PicPath}/#{@id-1}.jpg" rescue Surface.load "graphics/field/card.png"
end
def image_small
@image_small ||= image.transform_surface(0,0,54.0/image.w, 81.0/image.h,0)
......
......@@ -10,7 +10,8 @@ class Deck
attr_accessor :side
attr_accessor :extra
attr_accessor :temp
DeckPath = '/media/44CACC1DCACC0D5C/game/yu-gi-oh/deck'
#DeckPath = '/media/44CACC1DCACC0D5C/game/yu-gi-oh/deck'
DeckPath = 'E:/game/yu-gi-oh/deck'
def initialize(main, side=[], extra=[], temp=[])
@main = main
@side = side
......
class Game_Card
def initialize(card)
@card = card
end
def method_missing(method, *args)
@card.send(method, *args)
end
class Game_Card < Card
#attr_reader :card
attr_accessor :position
#def initialize(card)
# @card = card
#end
#def method_missing(method, *args)
# @card.send(method, *args)
#end
end
\ No newline at end of file
......@@ -23,7 +23,7 @@ class Game_Field
attr_accessor :hand
attr_accessor :graveyard
attr_accessor :removed
def initialize(deck = nil)
@lp = 8000
if deck
......@@ -33,80 +33,9 @@ class Game_Field
@deck = Array.new(60, Card.find(nil))
@extra = Array.new(15, Card.find(nil))
end
@field = []
@field = Array.new(11)
@hand = []
@graveyard = []
@removed = []
end
end
__END__
=begin
def field #场上
player_field + opponent_field
end
def player_field #自己场上
@player[0,11]
end
def opponent_field #对方场上
@opponent[0,11]
end
def fieldcard #场地魔法卡
@player[0] || @opponent[0]
end
def player_fieldcard #自己的场地魔法卡
@player[0]
end
def opponent_fieldcard #对方的场地魔法卡
@opponent[0]
end
def player_deck #自己的卡组
@player[11, 60]
end
def player_extra #自己的额外卡组
@player[61, 15]
end
def player_hand #自己的手卡
@player[226, 60]
end
def opponent_hand #对方的手卡
@opponent[161, 60]
end
def graveyard #墓地
player_grave + opponent_grave
end
def player_grave #自己的墓地
@player[11, 75]
end
def opponent_grave #对方的墓地
@opponent[11, 75]
end
def removed #除外区
@player + @opponent
end
def player_removed #自己的除外区
@player[151, 75]
end
def opponent_removed #对方的除外区
@opponent[151, 75]
end
def spelltraps #魔限
player_spelltrap + opponent_spelltrap
end
def player_spelltraps #自己的魔限
@player[1,5]
end
def opponent_spelltraps #对方的魔限
@opponent[1,5]
end
def monsters #怪兽
player_monsters + opponent_monsters
end
def player_monsters #自己的怪兽
@player[6,5]
end
def opponent_monsters #对方的怪兽
@opponent[6,5]
end
=end
\ No newline at end of file
end
\ No newline at end of file
......@@ -34,7 +34,7 @@ class Iduel
Event.push Error.new(0)
end
info.chomp!(RS)
info.encode! "UTF-8"
info.encode! "UTF-8", :invalid => :replace, :undef => :replace
puts ">> #{info}"
Event.push Event.parse info
end
......
#encoding: UTF-8
require_relative 'action'
class Action
CardFilter = /(<(?:\[.*?\]\[(?:.*?)\]){0,1}[\s\d]*>|一张怪兽卡|一张魔\/陷卡)/.to_s
......@@ -29,7 +30,8 @@ class Action
def self.parse_card(card)
if index = card.rindex("[")
index += 1
Card.find(card[index, card.rindex("]")-index].to_sym)
name = card[index, card.rindex("]")-index].to_sym
Card.find(name) || Card.new('id' => 0, 'number' => :"00000000", 'name' => name, 'card_type' => :通常怪兽, 'stats' => "", 'archettypes' => "", 'mediums' => "")
else
Card.find(nil)
end
......@@ -98,21 +100,18 @@ class Action
"里侧表示"
end
end
def self.escape_card(card)
if [:通常魔法, :永续魔法, :装备魔法, :场地魔法, :通常陷阱, :永续陷阱, :反击陷阱].include? card.card_type
if card.position == :set
"一张魔/陷卡"
else
"<[#{card.card_type}][#{card.name}] >"
end
else
if card.position == :set
"一张怪兽卡"
else
"<[#{card.card_type}][#{card.name}] #{card.atk} #{card.def}>"
end
def self.escape_position_short(position)
case position
when :attack
"表攻"
when :defense
"表守"
when :set
"里守"
end
end
def self.escape_phase(phase)
case phase
when :DP
......@@ -170,7 +169,7 @@ class Action
when /从#{PosFilter}~特殊召唤#{CardFilter}#{PosFilter}#{PositionFilter}/
SpecialSummon.new from_player, parse_pos($1), parse_pos($3), card($2), msg, parse_position($4)
when /从手卡~取#{CardFilter}盖到#{PosFilter}/
Set.new from_player, parse_pos($2), parse_card($1)
Set.new from_player, :hand, parse_pos($2), parse_card($1)
when /将#{CardFilter}从~#{PosFilter}~送往墓地/
SendToGraveyard.new(from_player, parse_pos($2), parse_card($1))
when /将#{PosFilter}#{CardFilter}从游戏中除外/
......@@ -192,35 +191,57 @@ class Action
system("pause")
end
end
def escape
case self
when FirstToGo
def run
$iduel.action self if @from_player
end
class FirstToGo
def escape
"[#{@id}] ◎→[11年3月1日禁卡表]先攻"
when Reset
"[#{@id}] ◎→[11年3月1日禁卡表] Duel!!"
when ChangePhase
end
end
class Reset
def escape
"[#{@id}] ◎→[11年3月1日禁卡表] Duel!!"
end
end
class ChangePhase
def escape
"[#{@id}] ◎→#{Action.escape_phase(@phase)}"
end
end
def run
$iduel.action self if @from_player
class Turn_End
def escape
"[#{@id}] ◎→=[0:0:0]==回合结束==<0>=[0]\r\n"+ @field.escape
end
end
end
=begin
LP:8000
手卡数:5
卡组:38
墓地:0
除外:0
前场:
<>
<>
<>
<>
<>
后场:<><><><><>
场地|<无>
◎→\\
=end
\ No newline at end of file
class Game_Field
def escape
"LP:#{@lp}\r\n手卡:#{@hand.size}\r\n卡组:#{@deck.size}\r\n墓地:#{@graveyard.size}\r\n除外:#{@removed.size}\r\n前场:\r\n" +
@field[6..10].collect{|card|" <#{"#{escape_position_short(card)}|#{card.position == :set ? '??' : "[#{card.card_type}][#{card.name}] #{card.atk}#{' '+card.def.to_s}"}" if card}>\r\n"}.join +
"后场:" +
@field[1..5].collect{|card|"<#{card.position == :set ? '??' : card.escape if card}>"}.join +
"\r\n场地|<#{@field[0] ? @field[0].escape : '无'}>\r\n" +
"◎→\\"
end
end
class Card
def escape
if [:通常魔法, :永续魔法, :装备魔法, :场地魔法, :通常陷阱, :永续陷阱, :反击陷阱].include? @card_type
if @position == :set
"一张魔/陷卡"
else
"<[#{@card_type}][#{@name}] >"
end
else
if @position == :set
"一张怪兽卡"
else
"<[#{@card_type}][#{@name}] #{@atk} #{@def}>"
end
end
end
end
#encoding: UTF-8
Iduel::Event = Class.new #避开SDL::Event问题,所以没有用class Iduel::Event::Event
class Iduel::Event
@queue = []
......
#encoding: UTF-8
$: << "/usr/lib"
alias gbk_puts puts
def puts(*args)
gbk_puts(*(args.collect{|item|item.encode "UTF-8"}))
gbk_puts(*(args.collect{|item|item.encode "GBK", :invalid => :replace, :undef => :replace}))
end
def p(*args)
print(args.collect{|item|item.inspect.encode "UTF-8"}.join("\n")+"\n") rescue print(args.join("\n")+"\n")
print(args.collect{|item|item.inspect.encode "GBK", :invalid => :replace, :undef => :replace}.join("\n")+"\n") rescue print(args.join("\n")+"\n")
end
def filesize_inspect(size)
......
......@@ -32,7 +32,7 @@ class Scene_Duel < Scene
@phases_window = Window_Phases.new(124, 357)
@turn_player = true
@player_field = Game_Field.new(Deck.load("test1.TXT"))
@player_field = Game_Field.new Deck.load("test1.TXT")
@opponent_field = Game_Field.new
@player_field_window = Window_Field.new(4, 398, @player_field, true)
......@@ -48,7 +48,8 @@ class Scene_Duel < Scene
@turn_player = !@turn_player
@phase = 0
@phases_window.player = @turn_player
Action::Turn_End.new(field)
Action::Turn_End.new(true, "Turn End", @player_field.lp, @player_field.hand.size, @player_field.deck.size, @player_field.graveyard.size, @player_field.removed.size, @player_field, 1).run
else
@phase = @phases_window.phase = phase
@phases_window.refresh
......@@ -60,15 +61,26 @@ class Scene_Duel < Scene
def first_to_go
Action::FirstToGo.new(true).run
end
def handle(event)
case event
when Event::MouseMotion
@phases_window.mousemoved event.x, event.y
self.windows.reverse.each do |window|
if window.include? event.x, event.y
@active_window = window
@active_window.mousemoved(event.x, event.y)
break
end
end
when Event::MouseButtonDown
case event.button
when Mouse::BUTTON_LEFT
@phases_window.mousemoved event.x, event.y
@phases_window.clicked
@active_window.mousemoved(event.x, event.y)
@active_window.clicked
when 4
@active_window.cursor_up
when 5
@active_window.cursor_down
end
when Event::MouseButtonUp
case event.button
......@@ -81,6 +93,10 @@ class Scene_Duel < Scene
@phases_window.index = @phase
end
end
when Mouse::BUTTON_RIGHT
if @player_field_window.action_window
@player_field_window.action_window.next
end
end
when Event::KeyDown
case event.sym
......@@ -95,6 +111,11 @@ class Scene_Duel < Scene
super
end
end
def handle_iduel(event)
case event
when Iduel::Event::Action
......
......@@ -33,6 +33,7 @@ class Window
def destroy
@destroted = true
@contents.destroy if @contents
$scene.windows.delete self
end
def destroted?
@destroted
......
# To change this template, choose Tools | Templates
# and open the template in the editor.
class Window_Action < Window_List
def initialize(x,y,list,list_available=Array.new(list.size, true))
super(x,y,100,list.size*WLH,300)
@list = list
@item_max = @list.size
@font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16)
refresh
self.index = @list.find_index(true) || 0
end
def index=(index)
super(index) if index
end
def draw_item(index, status=0)
case status
when 0
@font.draw_blended_utf8(@contents, @list[index] , 0, index*WLH, 0x00,0x00,0x00)
when 1
@font.draw_blended_utf8(@contents, @list[index] , 0, index*WLH, 0x00,0x00,0xFF)
end
end
def next
if index = @list[@index.next...@list.size].find_index(true)
self.index = index
elsif index = @list[0..@index].find_index(true)
self.index = index
else
self.index = (@index + 1) % @list.size
end
end
def mousemoved(x,y)
self.index = (y - @y) / WLH
end
end
class Window_Config < Window
def initialize(x,y)
super(x,y,$screen.w, $screen.h)
@checkbox = Surface.load 'graphics/system/checkbox.png'
@button = Surface.load 'graphics/system/button.png'
@background = Surface.load 'graphics/config/background.png'
@contents = Surface.load 'graphics/config/background.png'
@font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 20)
@index = nil
@items = {
:fullscreen => [0,0,120,WLH],
:avatar_cache => [220, WLH,@button.w/3, @button.h],
......@@ -52,7 +54,7 @@ class Window_Config < Window
clear(*item_rect(@index))
draw_item(@index, 0)
end
if index.nil? or !index.is_a?(Symbol)
if index.nil? or index.is_a?(Emulator)
@index = nil
else
@index = index
......
......@@ -4,34 +4,85 @@
#  title
#==============================================================================
class Window_Field
class Window_Field < Window
require 'card'
require 'window_action'
Field_Pos = [[56,0], #场地魔法
[140, 84], [234,84], [328,84],[422,84], [516, 84], #后场
[140, 0], [234, 0], [328, 0],[422, 0], [516, 0]] #前场
Extra_Pos = [56,84] #额外卡组
Graveyard_Pos = [598,0] #墓地
Removed_Pos = [657,0] #除外区
Deck_Pos = [598, 84]
Hand_Pos = [0, 201, 62, 8] #手卡: x, y, width, 间距
Card_Size = [Card::CardBack.w, Card::CardBack.h]
attr_reader :action_window
def initialize(x, y, field,player=true)
@x = x
@y = y
@width = 711
@height = 282
super(x,y,711,282)
@field = field
@player = player
@items = {
:deck => Deck_Pos + Card_Size,
:extra => Extra_Pos + Card_Size,
:removed => Removed_Pos + Card_Size,
:graveyard => Graveyard_Pos + Card_Size,
}
refresh
end
def refresh
@items.each_key{|index|draw_item(index)}
hand_width = @field.hand.size * Hand_Pos[2] + (@field.hand.size-1) * Hand_Pos[3]
hand_x = (@width - hand_width) / 2
$scene.refresh_rect(@x,@y,@width,@height) do
if @player
@field.field.each_with_index {|card, index|Surface.blit(card.image_small, 0,0,0,0, $screen, @x+Field_Pos[index][0], @y+Field_Pos[index][1]) if card}
@field.hand.each_with_index {|card, index|Surface.blit(card.image_small, 0,0,0,0, $screen, @x+hand_x+index*Hand_Pos[2], @y+Hand_Pos[1]) if card}
else
@field.field.each_with_index {|card, index|Surface.transform_blit(card.image_small, $screen, 180, 1, 1, 0, 0, @x+@width-Field_Pos[index][0], @y+@height-Field_Pos[index][1],0) if card}
@field.hand.each_with_index {|card, index|Surface.blit(card.image_small, 0,0,0,0, $screen, @x+@width-hand_x-index*Hand_Pos[2]-card.image_small.w, @y+@height-Hand_Pos[1]-card.image_small.h) if card}
#if @player
#
@field.field.each_with_index {|card, index|@contents.put(card.image_small, Field_Pos[index][0], Field_Pos[index][1]) if card}
@field.hand.each_with_index {|card, index|@contents.put(card.image_small, hand_x+index*Hand_Pos[2], Hand_Pos[1]) if card}
#else
#Surface.transform_blit(@field.deck.first.image_small, @contents, 180, 1, 1, 0, 0, @width-Deck_Pos[0], @height-Deck_Pos[1],0) if !@field.deck.empty?
# @field.field.each_with_index {|card, index|Surface.transform_blit(card.image_small, @contents, 180, 1, 1, 0, 0, @width-Field_Pos[index][0], @height-Field_Pos[index][1],0) if card}
# @field.hand.each_with_index {|card, index|Surface.blit(card.image_small, 0,0,0,0, @contents, @width-hand_x-index*Hand_Pos[2]-card.image_small.w, @height-Hand_Pos[1]-card.image_small.h) if card}
#end
end
def draw_item(index, status=0)
case index
when :deck
@contents.put(@field.deck.first.image_small, Deck_Pos[0], Deck_Pos[1]) if !@field.deck.empty?
when :extra
@contents.put(@field.extra.first.image_small, Extra_Pos[0], Extra_Pos[1]) if !@field.extra.empty?
when :removed
@contents.put(@field.removed.first.image_small, Removed_Pos[0], Removed_Pos[1]) if !@field.removed.empty?
when :graveyard
@contents.put(@field.graveyard.first.image_small, Graveyard_Pos[0], Graveyard_Pos[1]) if !@field.graveyard.empty?
end
end
def item_rect(index)
@items[index]
end
def index=(index)
return if index == @index
if @index
clear(*item_rect(@index))
draw_item(@index, 0)
end
if index.nil? or !@items.has_key?(index)
@index = nil
@action_window.destroy if @action_window
@action_window = nil
else
@index = index
draw_item(@index, 1)
@action_window = Window_Action.new(@x+@items[index][0],@y+@items[index][1],["测试动作1", "测试动作2", "测试动作3"])
end
end
def mousemoved(x,y)
self.index = @items.each do |index, item_rect|
if x.between?(@x+item_rect[0], @x+item_rect[0]+item_rect[2]) and y.between?(@y+item_rect[1], @y+item_rect[1]+item_rect[3])
break index
end
end
end
#def clicked
end
\ No newline at end of file
#encoding: UTF-8
class Window_User < Window_List
WLH = 20
def initialize(x, y, user)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment