Commit 7fdf9abd authored by 神楽坂玲奈's avatar 神楽坂玲奈

版本0.3.0

parent 7f4e6bb8
...@@ -8,7 +8,7 @@ require 'rake/gempackagetask' ...@@ -8,7 +8,7 @@ require 'rake/gempackagetask'
Windows = RUBY_PLATFORM["mingw"] || RUBY_PLATFORM["mswin"] Windows = RUBY_PLATFORM["mingw"] || RUBY_PLATFORM["mswin"]
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = 'mycard' s.name = 'mycard'
s.version = '0.2.1' s.version = '0.3.0'
s.extra_rdoc_files = ['README.txt', 'LICENSE.txt'] s.extra_rdoc_files = ['README.txt', 'LICENSE.txt']
s.summary = 'a card game' s.summary = 'a card game'
s.description = s.summary s.description = s.summary
......
...@@ -19,11 +19,13 @@ class Iduel < Game ...@@ -19,11 +19,13 @@ class Iduel < Game
def connect def connect
require 'socket' require 'socket'
require 'open-uri' require 'open-uri'
begin
@conn = TCPSocket.open(Server, Port) @conn = TCPSocket.new(Server, Port) #TODO: 阻塞优化,注意login。下面注释掉的两句实现connect无阻塞,但是login依然会阻塞所以只优化这里没有意义
#@conn = Socket.new(:INET, :STREAM)
@conn.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace @conn.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
@recv = Thread.new do @recv = Thread.new do
begin begin
#@conn.connect Socket.pack_sockaddr_in(Port, Server)
recv @conn.gets(RS) while @conn recv @conn.gets(RS) while @conn
rescue => exception rescue => exception
Game_Event.push Game_Event::Error.new(exception.class.to_s, exception.message) Game_Event.push Game_Event::Error.new(exception.class.to_s, exception.message)
...@@ -32,10 +34,6 @@ class Iduel < Game ...@@ -32,10 +34,6 @@ class Iduel < Game
self.exit self.exit
end end
end end
rescue => exception
Game_Event.push Game_Event::Error.new(exception.class.to_s, exception.message)
$log.error [exception.inspect, *exception.backtrace].join("\n")
end
end end
def login(username, password) def login(username, password)
......
...@@ -3,9 +3,10 @@ class Window_Login ...@@ -3,9 +3,10 @@ class Window_Login
def clicked def clicked
case @index case @index
when :login when :login
Widget_Msgbox.new("iduel", "正在登陆")
$scene.draw #强制重绘一次,下面会阻塞
$game = Iduel.new $game = Iduel.new
$game.login(@username_inputbox.value, @password_inputbox.value) $game.login(@username_inputbox.value, @password_inputbox.value)
Widget_Msgbox.new("iduel", "正在登陆")
when :register when :register
require 'launchy' require 'launchy'
Launchy.open(Iduel::Register_Url) Launchy.open(Iduel::Register_Url)
......
...@@ -8,7 +8,8 @@ class Replay ...@@ -8,7 +8,8 @@ class Replay
action = action.escape if action.is_a? Action action = action.escape if action.is_a? Action
@file.write action + "\n" @file.write action + "\n"
end end
def save(filename="#{Time.now.strftime("%Y%m%d%H%M%S")}_#{$game.room.player1.name}(#{$game.room.player1.id})_#{$game.room.player2.name}(#{$game.room.player2.id}).txt") def save(filename="#{$game.room.player1.name}(#{$game.room.player1.id})_#{$game.room.player2.name}(#{$game.room.player2.id})_#{Time.now.strftime("%m%d%H%M")}.txt")
p filename
close close
File.rename(@file.path, File.expand_path(filename, ReplayPath)) File.rename(@file.path, File.expand_path(filename, ReplayPath))
end end
......
...@@ -21,7 +21,11 @@ class Scene ...@@ -21,7 +21,11 @@ class Scene
start start
while $scene == self while $scene == self
update update
@@fpstimer.wait_frame do @@fpstimer.wait_frame{draw}
end
terminate
end
def draw
if @background if @background
$screen.put(@background,0,0) $screen.put(@background,0,0)
else else
...@@ -33,9 +37,6 @@ class Scene ...@@ -33,9 +37,6 @@ class Scene
@font.draw_blended_utf8($screen, "%.1f" % @@fpstimer.real_fps, 0, 0, 0xFF, 0xFF, 0xFF) @font.draw_blended_utf8($screen, "%.1f" % @@fpstimer.real_fps, 0, 0, 0xFF, 0xFF, 0xFF)
$screen.update_rect(0,0,0,0) $screen.update_rect(0,0,0,0)
end end
end
terminate
end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# ● 开始处理 # ● 开始处理
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
......
...@@ -142,7 +142,12 @@ class Scene_Duel < Scene ...@@ -142,7 +142,12 @@ class Scene_Duel < Scene
if event.room == $game.room if event.room == $game.room
@player_lp_window.player = $game.room.player1 @player_lp_window.player = $game.room.player1
@opponent_lp_window.player = $game.room.player2 @opponent_lp_window.player = $game.room.player2
notify_send("mycard", "对手加入房间") player = $game.room.player1 == $game.user ? $game.room.player2 : $game.room.player1
if player
notify_send("对手加入房间", "#{player.name}(#{player.id})")
else
notify_send("对手离开房间", "对手离开房间")
end
end end
end end
end end
...@@ -173,7 +178,9 @@ class Scene_Duel < Scene ...@@ -173,7 +178,9 @@ class Scene_Duel < Scene
super super
end end
def notify_send(title, msg) def notify_send(title, msg)
puts "notify-send -i graphics/system/icon.ico #{title} #{msg}" command = "notify-send -i graphics/system/icon.ico #{title} #{msg}"
system("notify-send -i graphics/system/icon.ico #{title} #{msg}") command = "start ruby/bin/#{command}".encode "GBK" if RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
system(command)
$log.info command
end end
end end
\ No newline at end of file
...@@ -9,13 +9,24 @@ class Scene_Watch < Scene_Duel ...@@ -9,13 +9,24 @@ class Scene_Watch < Scene_Duel
def create_action_window def create_action_window
end end
def action(action) def action(action)
if action.from_player == :me end
def start
super super
$game.action Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})进入了观战")
end end
def handle(event)
case event
when Event::KeyDown
case event.sym
when Key::F10
$game.action Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})离开了观战")
$game.leave
else
super
end end
def start else
super super
#$game.action Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})进入了观战") end
end end
def handle_game(event) def handle_game(event)
case event case event
......
# To change this template, choose Tools | Templates require_relative 'scene_watch'
# and open the template in the editor.
class Window_RoomChat < Window class Window_RoomChat < Window
WLH=16 WLH=16
require_relative 'widget_scrollbar' require_relative 'widget_scrollbar'
...@@ -8,12 +6,7 @@ class Window_RoomChat < Window ...@@ -8,12 +6,7 @@ class Window_RoomChat < Window
Opponent_Color = [0,0x66,0] Opponent_Color = [0,0x66,0]
def initialize(x, y, width, height) def initialize(x, y, width, height)
super(x,y,width,height-WLH) super(x,y,width,height-WLH)
@chat_input = Widget_InputBox.new(@x,@y+@height,@width,WLH){|text| @chat_input = Widget_InputBox.new(@x,@y+@height,@width,WLH){|text|($scene.is_a?(Scene_Watch) ? $game : $scene).action Action::Chat.new(true, text)}
$game.action = Action::Chat.new(true, text)
action.from_player = :me
$scene.action action
}
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14)
@contents.fill_rect(0,0,@width, @height, 0x99FFFFFF) @contents.fill_rect(0,0,@width, @height, 0x99FFFFFF)
@scroll = Widget_ScrollBar.new(@x+@width-20,@y,@height,0) @scroll = Widget_ScrollBar.new(@x+@width-20,@y,@height,0)
......
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