
因為沒有bubble的圖,所以bubble都長成方塊的樣子。
基本上遊戲的計分方法是:
消去n個方塊,得n*(n-1)分
若n>10則分數x3
最後消去所有方塊,得額外的1000分
最後消去剩下不到5個方塊,得額外的500分
最後消去剩下不到10個方塊,得額外的100分

為何女王的紀錄可以那麼高分!告訴我秘訣吧!
最後,請享用:
http://www.badongo.com/file/13537956
PS. 如果出現「應用程式正常初始失敗」訊息,請安裝.Net 2.0環境
Aaron Liu的部落格,紀錄我的生活點點滴滴
Aaron Liu的部落格,紀錄我的生活點點滴滴


// Low Level Keyboard Hook
public class KeyboardHook
{
// System Code: Low Level Keyboard Hook
private const int WH_KEYBOARD_LL = 13;
// System Event Code: Key Down Event
private const int WM_KEYDOWN = 0x100;
// System Event Code: System Key Down Event
private const int WM_SYSKEYDOWN = 0x104;
// Stores the handle to the Keyboard hook procedure.
private static int s_KeyboardHookHandle;
//是否只由這個Global Hook抓取鍵盤事件
public static bool globalControlOnly = false;
//Private KeyDown Event, 與GlobalKeyDown配合使用
private static event KeyEventHandler _globalKeyDown;
// Public KeyDown Event
// 每次只能一個Event Handler處理這個Event
// 加入和解除EventHandler時會自動安裝和解除Hook
public static event KeyEventHandler GlobalKeyDown
{
add
{
KeyboardHook.HookKeyboard();
KeyboardHook._globalKeyDown += value;
}
remove
{
KeyboardHook._globalKeyDown -= value;
KeyboardHook.UnhookKeyboard();
}
}
// 當hook抓到key event時的處理程序
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
// Hook handle
private static int m_HookHandle = 0;
// Keyboard Hook函式指標
private static HookProc m_KbdHookProc;
// WinAPI 取得Module Handle
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
// WinAPI 加入Hook
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
// WinAPI 解除Hook
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
// WinAPI 將Event傳給下一個Hook,如不執行此項,則只有這個Hook會被執行
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
private static void HookKeyboard()
{
if (m_HookHandle == 0)
{
KeyboardHook.s_KeyboardHookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, m_KbdHookProc,
Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
using (Process curProcess = Process.GetCurrentProcess())
{
using (ProcessModule curModule = curProcess.MainModule)
{
m_KbdHookProc = new HookProc(KeyboardHookProc);
m_HookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, m_KbdHookProc, GetModuleHandle(curModule.ModuleName), 0);
}
}
if (m_HookHandle == 0)
{
throw new Exception("Install Global Keyboard Hook Faild.");
}
}
}
private static void UnhookKeyboard()
{
if (m_HookHandle != 0)
{
bool ret = UnhookWindowsHookEx(m_HookHandle);
if (ret)
{
m_HookHandle = 0;
}
else
{
throw new Exception("Uninstall Global Keyboard Hook Faild.");
}
}
}
private static int KeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
bool handled = false;
if(nCode >= 0)
{
if ((int)wParam == WM_KEYDOWN || (int)wParam == WM_SYSKEYDOWN)
{
KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
Keys keyData = (Keys)MyKeyboardHookStruct.VirtualKeyCode;
KeyEventArgs e = new KeyEventArgs(keyData);
if (KeyboardHook.globalControlOnly)
{
e.Handled = true;
}
else
{
e.Handled = false;
}
_globalKeyDown.Invoke(null, e);
handled = e.Handled;
}
}
if (KeyboardHook.globalControlOnly) return -1;
return CallNextHookEx(s_KeyboardHookHandle, nCode, wParam, lParam);
}
[StructLayout(LayoutKind.Sequential)]
private struct KeyboardHookStruct
{
///
/// Specifies a virtual-key code. The code must be a value in the range 1 to 254.
///
public int VirtualKeyCode;
///
/// Specifies a hardware scan code for the key.
///
public int ScanCode;
///
/// Specifies the extended-key flag, event-injected flag, context code, and transition-state flag.
///
public int Flags;
///
/// Specifies the Time stamp for this message.
///
public int Time;
///
/// Specifies extra information associated with the message.
///
public int ExtraInfo;
}
}
private void KeyboardHook_KeyDown(object sender, KeyEventArgs e)
{
string key = e.KeyCode.ToString(); //取得KeyCode字串
//TODO: 加入處理KeyDown事件的程式
}
KeyboardHook.globalControlOnly = true; //只有Global KeyDown會起作用,其他程式不能攔截鍵盤事件
KeyboardHook.GlobalKeyDown += KeyboardHook_KeyDown;
KeyboardHook.GlobalKeyDown -= KeyboardHook_KeyDown;
/// <summary>
/// 播放狀態
/// </summary>
public enum PlayState
{
Stopped, //視訊停止
Paused, //視訊暫停
Playing, //視訊播放中
Init //尚未開啟任何影片檔
};
/// <summary>
/// 播放Video物件
/// </summary>
public class Video
{
private const int WMGraphNotify = 0x0400 + 13;
public const int VolumeFull = 0;
public const int VolumeSilence = -10000;
private DirectShowLib.IGraphBuilder graphBuilder = null;
private DirectShowLib.IMediaControl mediaControl = null;
private DirectShowLib.IMediaEventEx mediaEventEx = null;
private DirectShowLib.IVideoWindow videoWindow = null;
private DirectShowLib.IBasicAudio basicAudio = null;
private DirectShowLib.IBasicVideo basicVideo = null;
private DirectShowLib.IMediaSeeking mediaSeeking = null;
private DirectShowLib.IMediaPosition mediaPosition = null;
private DirectShowLib.IVideoFrameStep frameStep = null;
private string filePath = string.Empty;
private bool _FullScreen = false;
private int _Volume = VolumeFull;
public PlayState State = PlayState.Init;
private double currentPlaybackRate = 1.0;
private Size _size = new Size(0, 0);
private IntPtr hDrain = IntPtr.Zero;
#if DEBUG
private DsROTEntry rot = null;
#endif
/// <summary>
/// 裝載視訊物件的Container
/// </summary>
public Control Owner;
/// <summary>
/// 是否全螢幕模式
/// </summary>
public bool FullScreen
{
get
{
return _FullScreen;
}
set
{
if (this.State == PlayState.Init)
{
throw new Exception("No video file has been opened");
}
if (value != _FullScreen)
{
int hr = 0;
OABool lMode;
if (value)
{
//設定為全螢幕
hr = this.videoWindow.get_MessageDrain(out hDrain);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_MessageDrain(Owner.Handle);
DsError.ThrowExceptionForHR(hr);
lMode = OABool.True;
hr = this.videoWindow.put_FullScreenMode(lMode);
DsError.ThrowExceptionForHR(hr);
}
else
{
//回復視窗模式
lMode = OABool.False;
hr = this.videoWindow.put_FullScreenMode(lMode);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_MessageDrain(hDrain);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.SetWindowForeground(OABool.True);
DsError.ThrowExceptionForHR(hr);
}
}
this._FullScreen = value;
}
}
/// <summary>
/// 取得/設定寬度
/// </summary>
public int Width
{
get
{
return _size.Width;
}
set
{
if (this.State == PlayState.Init)
{
throw new Exception("No video file has been opened");
}
int hr = 0;
this.Owner.Width = value;
hr = this.videoWindow.SetWindowPosition(0, 0, value, _size.Height);
DsError.ThrowExceptionForHR(hr);
this._size.Height = value;
}
}
/// <summary>
/// 取得/設定高度
/// </summary>
public int Height
{
get
{
return _size.Height;
}
set
{
if (this.State == PlayState.Init)
{
throw new Exception("No video file has been opened");
}
int hr = 0;
this.Owner.Height = value;
hr = this.videoWindow.SetWindowPosition(0, 0, _size.Width, value);
DsError.ThrowExceptionForHR(hr);
this._size.Height = value;
}
}
/// <summary>
/// 取得目前影片的長度(秒數)
/// </summary>
public long Duration
{
get
{
if (State == PlayState.Init)
{
return 0;
}
else
{
int hr = 0;
long dur;
hr = this.mediaSeeking.GetDuration(out dur);
DsError.ThrowExceptionForHR(hr);
TimeSpan t = new TimeSpan(dur);
return (long)t.TotalSeconds;
}
}
}
/// <summary>
/// 目前的位置(秒數)
/// </summary>
public long Position
{
get
{
if (State == PlayState.Init)
{
return 0;
}
else
{
int hr = 0;
long pos, stop;
hr = this.mediaSeeking.GetPositions(out pos, out stop);
TimeSpan t = new TimeSpan(pos);
return (long)t.TotalSeconds;
}
}
set
{
if (this.State == PlayState.Init)
{
throw new Exception("No video file has been opened");
}
if (Position < 0 || Position > Duration)
{
throw new Exception("Position out of range");
}
int hr = 0;
TimeSpan t = new TimeSpan(0, 0,(int)value);
DsLong newPosition = new DsLong(t.Ticks);
hr = this.mediaSeeking.SetPositions(newPosition, AMSeekingSeekingFlags.AbsolutePositioning, null, AMSeekingSeekingFlags.NoPositioning);
}
}
/// <summary>
/// 目前的音量大小 0~100
/// </summary>
public int Volume
{
get
{
return this._Volume / 100 + 100;
}
set
{
if (value > 100 || value < 0)
{
throw new Exception("Volume must between 0 to 100");
}
int hr = 0;
this._Volume = (value - 100) * 100;
hr = this.basicAudio.put_Volume(this._Volume);
}
}
/// <summary>
/// 初始化Video物件
/// </summary>
/// <param name="owner">Video附著的Container 通常是一個Pannel或Form</param>
public Video(ref Control owner)
{
this.Owner = owner;
}
/// <summary>
/// 開啟視訊檔
/// </summary>
/// <param name="filePath">視訊檔案路徑</param>
/// <param name="autoPlay">開啟後是否自動播放</param>
public void Open(string filePath, bool autoPlay)
{
int hr = 0;
if (!System.IO.File.Exists(filePath))
{
throw new Exception("File " + filePath + "Not Found!");
}
if (State != PlayState.Init)
{
CloseVideo();
}
//取得檔案stream
this.graphBuilder = (DirectShowLib.IGraphBuilder)new FilterGraph();
hr = this.graphBuilder.RenderFile(filePath, null);
DsError.ThrowExceptionForHR(hr);
//Get DirectShow Control interfaces
this.mediaControl = (DirectShowLib.IMediaControl)this.graphBuilder;
this.mediaEventEx = (DirectShowLib.IMediaEventEx)this.graphBuilder;
this.mediaSeeking = (DirectShowLib.IMediaSeeking)this.graphBuilder;
this.mediaPosition = (DirectShowLib.IMediaPosition)this.graphBuilder;
this.videoWindow = this.graphBuilder as DirectShowLib.IVideoWindow;
this.basicVideo = this.graphBuilder as DirectShowLib.IBasicVideo;
this.basicAudio = this.graphBuilder as DirectShowLib.IBasicAudio;
if (!IsVideo())
{
throw new Exception("The File Is Not A Video File Or The Codec Is Unsupported!");
}
//Set the playback event handle object
//hr = this.mediaEventEx.SetNotifyWindow(this.Owner.Handle, WMGraphNotify, IntPtr.Zero);
//DsError.ThrowExceptionForHR(hr);
//Set the video owner object to contain the vidwo window
hr = this.videoWindow.put_Owner(this.Owner.Handle);
DsError.ThrowExceptionForHR(hr);
//Set video window layout
hr = this.videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr);
//Get vedio size
int lHeight, lWidth;
hr = this.basicVideo.GetVideoSize(out lWidth, out lHeight);
DsError.ThrowExceptionForHR(hr);
//set owner object size as video size
this.Owner.Width = lWidth;
this.Owner.Height = lHeight;
this._size.Width = lWidth;
this._size.Height = lHeight;
hr = this.videoWindow.SetWindowPosition(0, 0, lWidth, lHeight);
DsError.ThrowExceptionForHR(hr);
GetFrameStepInterface();
this._FullScreen = false;
this.currentPlaybackRate = 1.0;
this.State = PlayState.Stopped;
this.filePath = filePath;
if (autoPlay)
{
Play();
}
}
/// <summary>
/// 播放視訊檔
/// </summary>
public void Play()
{
if (State == PlayState.Stopped || State == PlayState.Paused)
{
int hr = 0;
hr = this.mediaControl.Run();
DsError.ThrowExceptionForHR(hr);
this.State = PlayState.Playing;
}
}
/// <summary>
/// 停止播放視訊檔
/// </summary>
public void Stop()
{
if (State == PlayState.Playing || State == PlayState.Paused)
{
int hr = 0;
//停止播放
hr = this.mediaControl.Stop();
DsError.ThrowExceptionForHR(hr);
//回到第一個影格
DsLong pos = new DsLong(0);
hr = this.mediaSeeking.SetPositions(pos, AMSeekingSeekingFlags.AbsolutePositioning, null, AMSeekingSeekingFlags.NoPositioning);
//顯示第一個影格
hr = this.mediaControl.Pause();
this.State = PlayState.Stopped;
}
}
/// <summary>
/// 停止播放視訊檔
/// </summary>
public void Pause()
{
if (State == PlayState.Playing)
{
int hr = 0;
hr = this.mediaControl.Pause();
DsError.ThrowExceptionForHR(hr);
this.State = PlayState.Paused;
}
}
/// <summary>
/// 前進
/// </summary>
/// <param name="second">前進的秒數</param>
public void Forward(int second)
{
if (Position + second < Duration)
{
Position += second;
}
else
{
Position = Duration;
}
}
/// <summary>
/// 倒退
/// </summary>
/// <param name="second">倒退的秒數</param>
public void Backward(int second)
{
if (Position - second > 0)
{
Position -= second;
}
else
{
Position = 0;
}
}
/// <summary>
/// 視訊檔案是否是一個被支援的視訊檔?
/// </summary>
/// <returns>true = 是; false = 否</returns>
private bool IsVideo()
{
int hr = 0;
OABool lVisible;
bool result = true;
if ((this.videoWindow == null) || (this.basicVideo == null))
{
//是一個Audio檔(沒有視訊,只有音訊)
result = false;
}
hr = this.videoWindow.get_Visible(out lVisible);
if (hr < 0)
{
// 視訊檔使用的Codec不被支援的或根本不是視訊檔
if (hr == unchecked((int)0x80004002)) //E_NOINTERFACE
{
result = false;
}
else
DsError.ThrowExceptionForHR(hr);
}
return result;
}
/// <summary>
/// 取得格放時要用的IVideoFrameStep介面
/// </summary>
/// <returns>true = 可以取得格放介面 false = 無法取得格放介面</returns>
private bool GetFrameStepInterface()
{
int hr = 0;
DirectShowLib.IVideoFrameStep frameStepTest = null;
// Get the frame step interface, if supported
frameStepTest = (DirectShowLib.IVideoFrameStep)this.graphBuilder;
// Check if this decoder can step
hr = frameStepTest.CanStep(0, null);
if (hr == 0)
{
this.frameStep = frameStepTest;
return true;
}
else
{
this.frameStep = null;
return false;
}
}
/// <summary>
/// 關閉視訊檔
/// </summary>
public void CloseVideo()
{
int hr = 0;
//停止播放
if (this.mediaControl != null)
hr = this.mediaControl.Stop();
// Clear global flags
this.State = PlayState.Stopped;
this.FullScreen = false;
//關閉DirectShow Control Interfece
CloseInterfaces();
this.filePath = string.Empty;
this.State = PlayState.Init;
}
/// <summary>
/// 關閉DirectShow的Control Interface
/// </summary>
private void CloseInterfaces()
{
int hr = 0;
try
{
lock (this)
{
// Relinquish ownership (IMPORTANT!) after hiding video window
if (this.videoWindow != null)
{
hr = this.videoWindow.put_Visible(OABool.False);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_Owner(IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
}
if (this.mediaEventEx != null)
{
hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
}
#if DEBUG
if (rot != null)
{
rot.Dispose();
rot = null;
}
#endif
// Release and zero DirectShow interfaces
if (this.mediaEventEx != null)
this.mediaEventEx = null;
if (this.mediaSeeking != null)
this.mediaSeeking = null;
if (this.mediaPosition != null)
this.mediaPosition = null;
if (this.mediaControl != null)
this.mediaControl = null;
if (this.basicAudio != null)
this.basicAudio = null;
if (this.basicVideo != null)
this.basicVideo = null;
if (this.frameStep != null)
this.frameStep = null;
if (this.graphBuilder != null)
Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;
GC.Collect();
}
}
catch(Exception ex)
{
throw new Exception("Video close faild:\r\n" + ex.Message);
}
}
}
Copyright © 2008 牛腦袋 | Design by Smashing Wordpress Themes - Blogger template by Zona Chrome
Template Brought by : blogger templates