Beispiel #1
0
        public void Run()
        {
            PirateGame pirateGame = null;
            string str = "";
            while (true)
            {
                try
                {
                    string str1 = Console.ReadLine().TrimEnd(new char[] { '\r', '\n' });
                    if (str1.ToLower() == "ready")
                    {
                        pirateGame = new PirateGame(str);
                        pirateGame.FinishTurn();
                        str = "";
                    }
                    else if (str1.ToLower() != "go")
                    {
                        str = string.Concat(str, str1, "\n");
                    }
                    else
                    {
                        pirateGame.Update(str);
                        if (!pirateGame.ShouldRecoverErrors())
                        {
                            this.bot.DoTurn(pirateGame);
                        }
                        else
                        {
                            try
                            {
                                this.bot.DoTurn(pirateGame);
                            }
                            catch (Exception exception1)
                            {
                                Exception exception = exception1;
                                pirateGame.Debug("Exception occured during doTurn: \n{0}",
                                    new object[] { exception.ToString() });
                            }
                        }
                        pirateGame.CancelCollisions();
                        pirateGame.FinishTurn();
                        str = "";
                    }

                }
                catch (IOException oException)
                {
                    break;
                }
                catch (Exception exception2)
                {
                    Console.Error.WriteLine(exception2.ToString());
                    Console.Error.Flush();
                }
                finally
                {
                    this.client.WriteByte(0);
                    this.client.Flush();
                }
            }
        }
Beispiel #2
0
        public void Run()
        {
            PirateGame pirateGame = null;
            string     str        = "";

            while (true)
            {
                try
                {
                    string str1 = Console.ReadLine().TrimEnd(new char[] { '\r', '\n' });
                    if (str1.ToLower() == "ready")
                    {
                        pirateGame = new PirateGame(str);
                        pirateGame.FinishTurn();
                        str = "";
                    }
                    else if (str1.ToLower() != "go")
                    {
                        str = string.Concat(str, str1, "\n");
                    }
                    else
                    {
                        pirateGame.Update(str);
                        if (!pirateGame.ShouldRecoverErrors())
                        {
                            this.bot.DoTurn(pirateGame);
                        }
                        else
                        {
                            try
                            {
                                this.bot.DoTurn(pirateGame);
                            }
                            catch (Exception exception1)
                            {
                                Exception exception = exception1;
                                pirateGame.Debug("Exception occured during doTurn: \n{0}",
                                                 new object[] { exception.ToString() });
                            }
                        }
                        pirateGame.CancelCollisions();
                        pirateGame.FinishTurn();
                        str = "";
                    }
                }
                catch (IOException oException)
                {
                    break;
                }
                catch (Exception exception2)
                {
                    Console.Error.WriteLine(exception2.ToString());
                    Console.Error.Flush();
                }
                finally
                {
                    this.client.WriteByte(0);
                    this.client.Flush();
                }
            }
        }