コード例 #1
0
ファイル: ConfigCtrl.cs プロジェクト: jojozhuang/Projects
        public static Collection<NewCarInfo> GetCarsInMarket()
        {            
            try
            {
                XmlDocument objXmlDoc = GetMasterDataFile(Constants.FILE_CARSINMARKETMASTERDATA);
                if (objXmlDoc == null)
                    return null;

                DataView dv = GetData(objXmlDoc, "data/Cars");

                Collection<NewCarInfo> cars = new Collection<NewCarInfo>();

                for (int ix = 0; ix < dv.Table.Rows.Count; ix++)
                {
                    NewCarInfo car = new NewCarInfo();
                    car.CarId = DataConvert.GetInt32(dv.Table.Rows[ix][0]);
                    car.CarName = dv.Table.Rows[ix][1].ToString();
                    car.CarPrice = DataConvert.GetInt32(dv.Table.Rows[ix][2]);
                    cars.Add(car);
                }
                return cars;
            }
            catch (Exception ex)
            {
                LogHelper.Write("读取市场上汽车列表", ex);
                return null;
            }
        }
コード例 #2
0
ファイル: FrmBuildTeam.cs プロジェクト: jojozhuang/Projects
        private void btnBuildTeam_Click(object sender, EventArgs e)
        {
            try
            {
                _toolbuildteam = new ToolBuildTeam((AccountInfo)cmbAccount.SelectedItem);
                _toolbuildteam.MessageChanged += new KaixinBase.MessageChangedEventHandler(_toolbuildteam_MessageChanged);
                _toolbuildteam.ValidateCodeNeeded += new KaixinBase.ValidateCodeNeededEventHandler(_toolbuildteam_ValidateCodeNeeded);
                _toolbuildteam.BuildTeamFinished += new GamePark.BuildTeamFinishedEventHandler(_toolbuildteam_BuildTeamFinished);

                if (cmbAccount.Items.Count <= 0 || cmbAccount.SelectedIndex < 0)
                {
                    MessageBox.Show("请选择账号!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cmbAccount.Select();
                    return;
                }

                if (lstViewCarsInMarket.SelectedItems.Count == 0)
                {
                    MessageBox.Show("请在市场上的汽车列表里选择你需要组建的车队车型!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    lstViewCarsInMarket.Select();
                    return;
                }

                if (cmbMaxCarCount.Items.Count <= 0 || cmbMaxCarCount.SelectedIndex < 0)
                {
                    MessageBox.Show("请选择汽车数量!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cmbMaxCarCount.Select();
                    return;
                }

                _account = cmbAccount.Items[cmbAccount.SelectedIndex] as AccountInfo;

                if (_account == null)
                    return;

                _modelcar = new NewCarInfo();
                ListViewItem item = lstViewCarsInMarket.SelectedItems[0];
                if (item != null)
                {
                    _modelcar.CarId = DataConvert.GetInt32(item.SubItems[3].Text);
                    _modelcar.CarName = item.SubItems[1].Text;
                    _modelcar.CarPrice = DataConvert.GetInt32(item.SubItems[2].Text);
                }

                if (_modelcar.CarPrice < 70000)
                {
                    MessageBox.Show("按规则70000元以下的车型,同一款车只能拥有一辆!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    lstViewCarsInMarket.Select();
                    return;
                }
                if (_modelcar.CarPrice < 200000)
                {
                    if (MessageBox.Show("根据游戏规则,不能组建汽车单价低于200000的车队!是否继续?", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                    {
                        lstViewCarsInMarket.Select();
                        return;
                    }
                }

                _maxcarcount = DataConvert.GetInt32(cmbMaxCarCount.Items[cmbMaxCarCount.SelectedIndex].ToString());
                _exchange = ExchangeCar.Stop;
                if (rdbExpensive.Checked)
                    _exchange = ExchangeCar.Expensive;
                else if (rdbCheap.Checked)
                    _exchange = ExchangeCar.Cheap;

                SetControlStatus(false);
                
                _toolbuildteam._account = _account;
                _toolbuildteam._modelcar = _modelcar;
                _toolbuildteam._maxcarcount = _maxcarcount;
                _toolbuildteam._exchange = _exchange;
                _toolbuildteam._carsInMarket = _carsInMarket;
                _toolbuildteam.BuildTeamByThread();
            }
            catch (Exception ex)
            {
                Program.ShowMessageBox("FrmBuildTeam", ex);
            }
        }
コード例 #3
0
ファイル: GamePark.cs プロジェクト: jojozhuang/Projects
        private bool CanBuyTheCar(NewCarInfo newcar, Collection<int> blackbuylist)
        {
            if (!newcar.IsValid)
                return false;

            if (blackbuylist.Contains(newcar.CarId))
                return false;

            foreach (CarInfo car in _carList)
            {
                if (newcar.CarName == car.CarName)
                    return false;
            }

            return true;
        }
コード例 #4
0
ファイル: GamePark.cs プロジェクト: jojozhuang/Projects
        private void ReadAllCarsInMarket(bool printMessage)
        {
            if (printMessage)
                SetMessageLn("读取车市上的汽车信息...");

            this._allCarsInMarketList.Clear();

            int page = 0;
            do
            {
                int num;
                HH.DelayedTime = Constants.DELAY_1SECONDS;
                string content = HH.Get("http://www.kaixin001.com/app/app.php?aid=1040&url=market.php&start=" + page);
                content = JsonHelper.GetMid(content, "<table class=\"cheshi\">", "<br />");
                if (content != null)
                {
                    if (printMessage)
                        SetMessageLn("第" + (page / 8 + 1).ToString() + "页");

                    for (string info = JsonHelper.GetMid(content, "<td width=\"25%\">", "</div></div></td>", out num); info != null; info = JsonHelper.GetMid(content, "<td width=\"25%\">", "</div></div></td>", out num))
                    {
                        content = content.Substring(num);
                        NewCarInfo car = new NewCarInfo();
                        car.CarId = JsonHelper.GetMidInteger(info, "purchase(", ")");
                        if (car.CarId == -1)
                            car.CarId = JsonHelper.GetMidInteger(info, "purchase_vip(", ",");
                        car.CarName = JsonHelper.GetMid(info, "align=\"absmiddle\" /> ", "</div>");
                        car.CarPrice = JsonHelper.GetMidInteger(info, "价格:", "元");
                        if (car.CarId != 0 && car.CarName != string.Empty && car.CarPrice != -1)
                        {
                            this._allCarsInMarketList.Add(car);
                            if (printMessage)
                                SetMessageLn(car.ToString());
                        }
                    }
                    page += 8;
                }
                else
                {
                    return;
                }
            }
            while (true);
        }
コード例 #5
0
ファイル: GamePark.cs プロジェクト: jojozhuang/Projects
        private bool UpgradeTheCar(CarInfo oldcar, NewCarInfo newcar)
        {
            try
            {
                if (oldcar.CarName == newcar.CarName)
                    return false;

                SetMessageLn(string.Format("=>被换购的汽车:{0}({1})", oldcar.CarName, oldcar.CarPrice));
                string param = string.Format("verify={0}&carid={1}&color={2}&oldcarid={3}&interval={4}", new object[] { this._verifyCode, newcar.CarId, DataConvert.GetInt32(newcar.CarColor), oldcar.CarId, oldcar.CarPrice - newcar.CarPrice });
                string query = "";
                HH.DelayedTime = Constants.DELAY_2SECONDS;
                HH.Post("http://www.kaixin001.com/parking/updatecar.php", ref query, param);
                string content = HH.Get(string.Format("http://www.kaixin001.com/parking/updatecar.php{0}", query));
                if (GetBuildTeamFeedback(content))
                {
                    _parkcash -= newcar.CarPrice - oldcar.CarPrice;
                    _carprice += newcar.CarPrice - oldcar.CarPrice;
                    oldcar.CarId = newcar.CarId;
                    oldcar.CarName = newcar.CarName;
                    oldcar.CarPrice = newcar.CarPrice;
                    return true;
                }
                if (query.Contains("action=3"))
                    this._outofmoney = true;
                return false;
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (ThreadInterruptedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                LogHelper.Write("GamePark.UpgradeTheCar", ex, LogSeverity.Error);
                SetMessage("升级汽车失败!错误:" + ex.Message);
                return false;
            }
        }
コード例 #6
0
ファイル: GamePark.cs プロジェクト: jojozhuang/Projects
 private bool BuyTheCar(NewCarInfo newcar)
 {
     try
     {
         string query = "";
         HH.DelayedTime = Constants.DELAY_1SECONDS;                
         //HH.Post("http://www.kaixin001.com/!parking/purchase.php", ref query, string.Format("verify={0}&carid={1}&color={2}", this._verifyCode, newcar.CarId, DataConvert.GetInt32(newcar.CarColor)));
         //string content = HH.Get(string.Format("http://www.kaixin001.com/parking/purchase.php{0}", query));
         string content = HH.Post("http://www.kaixin001.com/!parking/purchase.php", ref query, string.Format("verify={0}&carid={1}&color={2}", this._verifyCode, newcar.CarId, DataConvert.GetInt32(newcar.CarColor)));
         //<script language="JavaScript">
         //window.location="/!parking/!purchase.php?action=2&carid=28&color=16776960";
         //</script>
         string navigationurl = JsonHelper.GetMid(content, "window.location=\"/", "\";");
         content = HH.Get(string.Format("http://www.kaixin001.com/{0}", navigationurl));
         if (PrintBuyFeedback(content))
         {
             _parkcash -= newcar.CarPrice;
             _carprice += newcar.CarPrice;
             CarInfo oldcar = new CarInfo();
             oldcar.CarId = newcar.CarId;
             oldcar.CarName = newcar.CarName;
             oldcar.CarPrice = newcar.CarPrice;
             oldcar.CarColor = newcar.CarColor;
             _carList.Add(oldcar);
             return true;
         }
         return false;
     }
     catch (ThreadAbortException)
     {
         throw;
     }
     catch (ThreadInterruptedException)
     {
         throw;
     }
     catch (Exception ex)
     {
         LogHelper.Write("GamePark.BuyTheCar", ex, LogSeverity.Error);
         SetMessage("购买新车失败!错误:" + ex.Message);
         return false;
     }
 }
コード例 #7
0
ファイル: GamePark.cs プロジェクト: jojozhuang/Projects
 private bool IsExistInMyCarList(NewCarInfo newcar)
 {
     foreach (CarInfo car in _carList)
     {
         if (newcar.CarName == car.CarName && newcar.CarColor == car.CarColor)
             return true;
     }
     return false;
 }
コード例 #8
0
ファイル: GamePark.cs プロジェクト: jojozhuang/Projects
        private Collection<NewCarInfo> FindNeedsBuildCars(NewCarInfo newcar)
        {
            Collection<NewCarInfo> newcars = new Collection<NewCarInfo>();
            for (int ix = 0; ix < 6; ix++)
            {
                NewCarInfo car = new NewCarInfo();
                car.CarId = newcar.CarId;
                car.CarName = newcar.CarName;
                car.CarPrice = newcar.CarPrice;
                switch (ix)
                {
                    case 0:
                        car.CarColor = CarColor.White;
                        break;
                    case 1:
                        car.CarColor = CarColor.Silver;
                        break;
                    case 2:
                        car.CarColor = CarColor.Black;
                        break;
                    case 3:
                        car.CarColor = CarColor.Red;
                        break;
                    case 4:
                        car.CarColor = CarColor.Blue;
                        break;
                    case 5:
                        car.CarColor = CarColor.Yellow;
                        break;
                }

                if (!IsExistInMyCarList(car))
                    newcars.Add(car);
            }

            return newcars;
        }
コード例 #9
0
ファイル: GamePark.cs プロジェクト: jojozhuang/Projects
        public void BuildTeam(AccountInfo account, NewCarInfo modelcar, int carcount, ExchangeCar exchange, Collection<NewCarInfo> carsInMarket)
        {
            TryCatchBlock th = new TryCatchBlock(delegate
            {             
                _module = Constants.MSG_BUILDTEAM;
                _outofmoney = false;
                //if (modelcar.CarPrice < 200000)
                //{
                //    SetMessageLn("根据游戏规则,不能组建汽车单价低于200000的车队!");
                //    OnBuildTeamFinished();
                //    return;
                //}

                _allCarsInMarketList = carsInMarket;

                SetMessageLn("开始组建车队...");

                if (!this.ValidationLogin(account))
                {
                    if (BuildTeamFinished != null)
                        BuildTeamFinished(null, 0, 0);
                    return;
                }

                string content = RequestParkHomePage();
                this.ReadCars(content, false);

                Collection<NewCarInfo> buildableCars = FindNeedsBuildCars(modelcar);
                if (buildableCars.Count <= 0)
                {
                    SetMessageLn("您已经拥有6辆该款车型的汽车,无需再换购!");
                }
                else
                {
                    int ix = 0;
                    int index = 0;
                    foreach (NewCarInfo newcar in buildableCars)
                    {
                        if (this._outofmoney)
                            break;

                        if (carcount > _carList.Count)
                        {
                            SetMessageLn(string.Format("需要组建的车辆#{0}({1}):{2}({3},{4}) ", ++index, (carcount > _carList.Count) ? "购买" : "换购", newcar.CarName, GetCarColor(newcar.CarColor), newcar.CarPrice));
                            BuyTheCar(newcar);
                        }
                        else
                        {
                            if (exchange == ExchangeCar.Stop)
                            {
                                SetMessageLn("达到最大汽车数量,停止操作!");
                                break;
                            }

                            SetMessageLn(string.Format("需要组建的车辆#{0}({1}):{2}({3},{4}) ", ++index, (carcount > _carList.Count) ? "购买" : "换购", newcar.CarName, GetCarColor(newcar.CarColor), newcar.CarPrice));

                            _carList = SortCarsList();
                            if (exchange == ExchangeCar.Expensive)
                            {
                                for (ix = _carList.Count - 1; ix >= 0; ix--)
                                {
                                    if (this._outofmoney || UpgradeTheCar(_carList[ix], newcar))
                                        break;
                                }
                            }
                            else
                            {
                                for (ix = 0; ix < _carList.Count; ix++)
                                {
                                    if (this._outofmoney || UpgradeTheCar(_carList[ix], newcar))
                                        break;
                                }
                            }
                        }
                    }
                }

                content = RequestParkHomePage();
                this.ReadCars(content, false);

                SetMessageLn("组建车队完成!");
                if (BuildTeamFinished != null)
                    BuildTeamFinished(_carList, _parkcash, _carprice);
            });
            base.ExecuteTryCatchBlock(th, "发生异常,组建车队失败!");
        }