Exemplo n.º 1
0
        //private SpeechSynthesizer _ss = new SpeechSynthesizer();

        /// <summary>
        /// Sprawdza w panelu dowodzenia ruchy flot(w szczególnoœci czy ktoœ atakuje).
        /// </summary>
        public void CheckAttack()
        {
            string html = Navigator.GoHome();

            if (html != null)
            {
                List <FleetMove> moves = FleetMove.ParseEnemy(html);
                Console.WriteLine("Fleet moves:");
                foreach (FleetMove move in moves)
                {
                    Console.WriteLine("{0} {1} {2}", move.Mission, move.Start, move.End);
                }
                if (Regex.IsMatch(html, "Wrogie floty"))
                {
                    Console.WriteLine("Wrogie floty.");
                    //_ss.Speak("Enemy fleet is approaching.");
                }
                if (UnderAttack(moves))
                {
                    Console.WriteLine("You are under attack.");
                    //_ss.Speak("You are under attack.");
                }
                else
                if (Spying(moves))
                {
                    Console.WriteLine("Someone is spying you.");
                    //_ss.Speak("Someone is spying you.");
                }
                else
                {
                    Console.WriteLine("There is no enemy moves.");
                    //_ss.Speak("There is no enemy moves.");
                }
                int count = GetMessages(html);
                if (count > 0)
                {
                    string message = string.Format("You've got {0} message{1}.", count, count > 1 ? "s" : "");
                    Console.WriteLine(message);
                    //_ss.Speak(message);
                }
                else
                {
                    Console.WriteLine("There is no new message(s)");
                }
            }
            else
            {
                Console.WriteLine("Server error, no response.");
            }
        }
        public static List <FleetMove> ParseEnemyT(string html)
        {
            /*wrogi atak wrogie floty
             * <td class=bg_rot>	        Atak	            </td>
             * <td class=bg_rot>
             * <a class="bau" onmouseover="this.T_TITLECOLOR='#000000';this.T_BORDERCOLOR='#E6EFFF';this.T_TITLE='Zestawienie floty';
             * this.T_LEFT=1;this.T_WIDTH=200;this.T_BGCOLOR='#EDEDED';return escape('6 Transmiter<br>673 Statek wojenny<br>')">
             * Info</a>
             * </td>
             * <td class=bg_rot>	        <a class="bau" >Info</a>	    </td>
             * <td class=bg_rot>	    Galera 1 [02:178:10]	    </td>
             * <td class=bg_rot>	        bob10 [02:179:07]	    </td>
             */
            List <FleetMove> moves   = new List <FleetMove>();
            string           pattern =
                @"<td class=bg_rot>\s*(?<mission>[^<]+)</td>\s*" +
                @"<td class=bg_rot>\s*<a class[^\(]+\('(?<fleet>[^']*)'[^<]+</a>\s*</td>\s*" +
                @"<td class=bg_rot>\s*<a class[^>]+>\s*(?<towar>Info)</a>\s*</td>\s*" +
                @"<td class=bg_rot>\s*[^\[]+\[(?<start>[^\]]+)\]\s*</td>\s*" +
                @"<td class=bg_rot>\s*[^\[]+\[(?<end>[^\]]+)\]\s*</td>\s*";
            Regex regex = new Regex(pattern);

            if (regex.IsMatch(html))
            {
                foreach (Match match in regex.Matches(html))
                {
                    FleetMove move = new FleetMove();

                    string           fleet  = match.Groups["fleet"].ToString().Trim();
                    OrderFleetParser parser = new OrderFleetParser(move.Fleet);
                    parser.Parse(fleet);

                    string             resource = match.Groups["towar"].ToString().Trim().Replace(".", "");
                    MoveResourceParser parser2  = new MoveResourceParser(move.Resource);
                    parser2.Parse(resource);

                    move.Mission = match.Groups["mission"].ToString().Trim();
                    move.Start   = match.Groups["start"].ToString().Trim();
                    move.End     = match.Groups["end"].ToString().Trim().Replace("\n", "");

                    moves.Add(move);
                }
            }
            return(moves);
        }
Exemplo n.º 3
0
        public static List <FleetMove> Parse(string html)
        {
            /*moj atak powracajace floty
             * <td class=bg_gruen>        Atak            </td>
             * <td class=bg_gruen>
             * <a class="bau" onmouseover="this.T_TITLECOLOR='#000000';this.T_BORDERCOLOR='#E6EFFF';this.T_TITLE='Zestawienie floty';this.T_LEFT=1;
             * this.T_WIDTH=200;this.T_BGCOLOR='#EDEDED';return escape('1 Transmiter<br>')">
             * Info</a></td>
             * <td class=bg_gruen>
             * <a class="bau" onmouseover="this.T_TITLECOLOR='#000000';this.T_BORDERCOLOR='#E6EFFF';this.T_TITLE='Towar do transportowania';
             * this.T_LEFT=1;this.T_WIDTH=200;this.T_BGCOLOR='#EDEDED';return escape('Brak')">
             * Info</a></td>
             * <td class=bg_gruen>	    Kolonia [02:61:09]	    </td>
             * <td class=bg_gruen>	        Kolonia [02:60:02]	    </td>
             * <td class=bg_gruen>
             * <a href="#" onclick="sendMessage(4210)">hdmn749 <img src="img/email.gif?__cv=3" width="14" height="10" alt="Wyœlij wiadomoœæ	" border="0" >
             * </a></td>
             */
            /*wrogi atak wrogie floty
             * <td class=bg_rot>	        Atak	            </td>
             * <td class=bg_rot>
             *  <a class="bau" onmouseover="this.T_TITLECOLOR='#000000';this.T_BORDERCOLOR='#E6EFFF';this.T_TITLE='Zestawienie floty';this.T_LEFT=1;this.T_WIDTH=200;this.T_BGCOLOR='#EDEDED';return escape('6 Transmiter<br>673 Statek wojenny<br>')">Info</a>
             * </td>
             * <td class=bg_rot>	        <a class="bau" >Info</a>	    </td>
             * <td class=bg_rot>	    Galera 1 [02:178:10]	    </td>
             * <td class=bg_rot>	        bob10 [02:179:07]	    </td>
             */
            //return escape('1 Transmiter<br>')">
            //return escape('55.605 ¯elazo<br>54.163 Metal<br>16.156 Kryptonit<br>66.492 Spice<br>')">
            List <FleetMove> moves   = new List <FleetMove>();
            string           pattern =
                @"<td class=bg_gruen>\s*(?<mission>[^<]+)</td>\s*" +
                @"<td class=bg_gruen>\s*<a class[^\(]+\('(?<fleet>[^']*)'[^<]+</a>\s*</td>\s*" +
                @"<td class=bg_gruen>\s*<a class[^\(]+\('(?<towar>[^']*)'[^<]+</a>\s*</td>\s*" +
                @"<td class=bg_gruen>\s*[^\[]+\[(?<start>[^\]]+)\]\s*</td>\s*" +
                @"<td class=bg_gruen>\s*[^\[]+\[(?<end>[^\]]+)\]\s*</td>\s*";
            Regex regex = new Regex(pattern);

            if (regex.IsMatch(html))
            {
                foreach (Match match in regex.Matches(html))
                {
                    FleetMove move = new FleetMove();

                    string           fleet  = match.Groups["fleet"].ToString().Trim();
                    OrderFleetParser parser = new OrderFleetParser(move.Fleet);
                    parser.Parse(fleet);

                    string             resource = match.Groups["towar"].ToString().Trim().Replace(".", "");
                    MoveResourceParser parser2  = new MoveResourceParser(move.Resource);
                    parser2.Parse(resource);

                    move.Mission = match.Groups["mission"].ToString().Trim();
                    move.Start   = match.Groups["start"].ToString().Trim();
                    move.End     = match.Groups["end"].ToString().Trim().Replace("\n", "");

                    moves.Add(move);
                }
            }
            return(moves);
        }