1.    using System;
2.     using System.Runtime.InteropServices;
3.
4.    namespace PocketDice
5.    {
6.
7.         public class Launcher 
8.         { 
9.              public class ProcessInfo 
10.            { 
11.                public IntPtr hProcess; 
12.                public IntPtr hThread; 
13.                public Int32 ProcessId; 
14.                public Int32 ThreadId; 
15.            } 
16.
17.            [DllImport("CoreDll.DLL", SetLastError=true)] 
18.            private extern static 
19.                int CreateProcess( String imageName, 
20.                String cmdLine, 
21.                IntPtr lpProcessAttributes, 
22.                IntPtr lpThreadAttributes, 
23.                Int32 boolInheritHandles, 
24.                Int32 dwCreationFlags, 
25.                IntPtr lpEnvironment, 
26.                IntPtr lpszCurrentDir, 
27.                byte [] si, 
28.                ProcessInfo pi ); 
29.
30.            [DllImport("CoreDll.dll")] 
31.            private extern static 
32.                Int32 GetLastError(); 
33.
34.            [DllImport("CoreDll.dll")] 
35.            private extern static 
36.                Int32 WaitForSingleObject( IntPtr Handle, 
37.                Int32 Wait); 
38.
39.

40.            public static bool CreateProcess( String ExeName, String CmdLine, ProcessInfo pi ) 
41.            { 
42.                Int32 INFINITE; 
43.                unchecked {INFINITE = (int)0xFFFFFFFF;} 
44.
45.                if ( pi == null ) 
46.                      pi = new ProcessInfo(); 
47.                byte [] si = new byte[128]; 
48.                CreateProcess(ExeName, CmdLine, IntPtr.Zero,
 IntPtr.Zero, 
49.                    0, 0, IntPtr.Zero, IntPtr.Zero, si, pi); 
50.                WaitForSingleObject(pi.hProcess,INFINITE); 
51.                return true; 
52.            } 
53.
54.            public static void OpenWebPage(string sPage) 
55.            { 
56.                CreateProcess("iexplore.exe", sPage, null); 
57.            } 
58.     
59.            private Launcher() 
60.            { 
61.        } 
62.    } 
63.  } 
7.2.7  Scoring.csģ 
ģʵַļ㡣Ϸĺģ飬Ϸ÷ֶڱģмġ
1.    using System;
2.     
3.    namespace PocketDice 
4.    { 
5.     
6.        publicclass Scoring 
7.        { 
8.             private Scoring() 
9.             { 
10.            } 
11.     
12.            // ----------------------------------------------------
13.            // ÷ֺ 
14.            //----------------------------------------------------
15.     
16.            publicstaticint ScoreAces(SingleDie[] dice) 
17.            { 
18.                int ret = 0; 
19.                for (int i=0; i<dice.Length; i++) 
20.                { 
21.                    if (dice[i].Value == PocketDiceValue.Ace) ret += 1; 
22.                } 
23.                return ret; 
24.            } 
25.     
26.            public static int ScoreTwos(SingleDie[] dice) 
27.            { 
28.                int ret = 0; 
29.                for (int i=0; i<dice.Length; i++) 
30.                { 
31.                    if (dice[i].Value == PocketDiceValue.Two) ret += 2; 
32.                } 
33.                return ret; 
34.            } 
35.
36.            public static int ScoreThrees(SingleDie[] dice) 
37.            { 
38.                int ret = 0; 
39.                for (int i=0; i<dice.Length; i++) 
40.                { 
41.                    if (dice[i].Value == PocketDiceValue.Three) ret += 3; 
42.                } 
43.                return ret; 
44.            } 
45.
46.            public static int ScoreFours(SingleDie[] dice) 
47.           { 
48.               int ret = 0; 
49.               for (int i=0; i<dice.Length; i++) 
50.              { 
51.                  if (dice[i].Value == PocketDiceValue.Four) ret += 4; 
52.              } 
53.              return ret; 
54.          } 
55.
56.          public static int ScoreFives(SingleDie[] dice) 
57.         { 
58.             int ret = 0; 
59.             for (int i=0; i<dice.Length; i++) 
60.             { 
61.                 if (dice[i].Value == PocketDiceValue.Five) ret += 5; 
62.             } 
63.             return ret; 
64.         } 
65.
66.         public static int ScoreSixes(SingleDie[] dice) 
67.         { 
68.             int ret = 0; 
69.             for (int i=0; i<dice.Length; i++) 
70.             { 
71.                 if (dice[i].Value == PocketDiceValue.Six) ret += 6; 
72.             } 
73.             return ret; 
74.         } 
75.
76.         public static int Score3OfAKind(SingleDie[] dice) 
77.         { 
78.             int diceValues = 0; 
79.             int[] values = new int[6]; 
80.             for (int i=0; i<dice.Length; i++) 
81.             { 
82.                 diceValues += (int)dice[i].Value; 
83.                 values[((int)dice[i].Value) - 1]++; 
84.             } 
85.
86.             // Ҫ 
87.             for (int i=0; i < values.Length; i++) 
88.             { 
89.                 if (values[i] >= 3) 
90.                     return diceValues; 
91.             } 
92.
93.             // ûзͣ0 
94.             return 0; 
95.         } 
96.
97.         public static int Score4OfAKind(SingleDie[] dice) 
98.         { 
99.             int diceValues = 0; 
100.            int[] values = new int[6]; 
101.            for (int i=0; i<dice.Length; i++) 
102.            { 
103.                diceValues += (int)dice[i].Value; 
104.                values[((int)dice[i].Value) - 1]++; 
105.            } 
106.
107.            // Ҫĸ 
108.            for (int i=0; i < values.Length; i++) 
109.            { 
110.                if (values[i] >= 4) 
111.                    return diceValues; 
112.            } 
113.
114.            // ûзĸͣ0 
115.            return 0; 
116.        } 
117.
118.        public static int Score5OfAKind(SingleDie[] dice) 
119.        { 
120.            int[] values = new int[6]; 
121.            for (int i=0; i<dice.Length; i++) 
122.        { 
123.            values[((int)dice[i].Value) - 1]++; 
124.        } 
125.
126.        // Ҫ 
127.        for (int i=0; i < values.Length; i++) 
128.        { 
129.            if (values[i] >= 5) 
130.                 return 50; 
131.        } 
132.
133.        // ûзͣ0 
134.        return 0; 
135.    } 
136.
137.    public static int ScoreStraight(SingleDie[] dice) 
138.    { 
139.        // Ϊ A-2-3-4-5, 2-3-4-5-6 40,  
140.        // 3-4-5-6-A straight
141.     
142.        bool[]  values  =  new  bool[6] {false,false,false,false,
false,false};
143.
144.         for (int i=0; i < dice.Length; i++) 
145.        { 
146.            values[((int) dice[i].Value) - 1] = true; 
147.        } 
148.
149.        if (values[0] && values[1] && values[2] && values[3] && 
values[4]) 
150.            return 40; 


151.        else if (values[1] && values[2] && values[3] && values[4] && values[5]) 
152.            return 40;
153.        else if (values[2] && values[3] && values[4] && values[5] && values[0])
154.            return 40; 
155.        else 
156.            return 0; 
157.    } 
158.
159.    public static int ScoreFlush(SingleDie[] dice) 
160.    { 
161.        // Ϊflush40 C ͬĴ 
162.        PocketDiceSuit suit = dice[0].Suit; 
163.        for (int i=1; i<dice.Length; i++) 
164.        { 
165.        if (dice[i].Suit != suit) 
166.                 return 0; 
167.        } 
168.
169.        return 40; 
170.    } 
171.
172.    public static int ScoreChance(SingleDie[] dice) 
173.    { 
174.        int ret =0; 
175.        for (int i = 0; i<dice.Length; i++) 
176.        { 
177.            ret += (int) dice[i].Value; 
178.        } 
179.        return ret; 
180.    } 
181.
182.    public static int ScoreFullHouse(SingleDie[] dice) 
183.    { 
184.        int[] values = new int[6]; 
185.        for (int i=0; i<dice.Length; i++) 
186.        { 
187.            values[((int)dice[i].Value) - 1]++; 
188.        } 
189.
190.        // һֵ() 
191.        bool b3 =false; 
192.        bool b2 = false; 
193.        for (int i=0; i<values.Length; i++) 
194.        { 
195.            if (values[i] == 5) 
196.                return 25; 
197.            if (values[i] == 3) 
198.                b3 = true; 
199.            if (values[i] == 2) 
200.                b2 = true; 
201.        } 
202.        if (b3 && b2) return 25; else return 0; 
203.
204.    } 
205.
206.    public static int ScoreReds(SingleDie[] dice) 
207.    { 
208.        int score = 0; 
209.        for (int i=0; i<dice.Length; i++) 
210.       { 
211.            if (dice[i].SuitIsRed == false) return 0; 
212.            score += (int) dice[i].Value; 
213.        } 
214.        return score; 
215.    } 
216.     
217.    publicstaticint ScoreBlacks(SingleDie[] dice) 
218.    { 
219.        int score = 0; 
220.        for (int i=0; i<dice.Length; i++) 
221.        { 
222.            if (dice[i].SuitIsBlack == false) return 0; 
223.            score += (int) dice[i].Value; 
224.        } 
225.        return score; 
226.    } 
227.     
228.           
229.    publicstaticint ScoreStraightFlush(SingleDie[] dice) 
230.    { 
231.        int score = ScoreFlush(dice) + ScoreStraight(dice); 
232.        if (score == 80) return score; elsereturn 0; 
233.    } 
234.     
235.     
236.   } 
237.  } 
