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

版本0.3.0

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