Пример #1
0
        //新增车位
        private void button2_Click(object sender, EventArgs e)
        {
            string type = cmbCarType.SelectedItem.ToString();

            if (string.IsNullOrEmpty(type))
            {
                MessageBox.Show("请选择车类型后再新增车位....");
                return;
            }
            DateTime     time         = Convert.ToDateTime(dateTimePicker1.Text);
            bool         isDeleted    = checkBox1.Checked ? true : false;
            int          needPosition = Convert.ToInt32(txtPosition.Text);
            CarPositions car          = new CarPositions();

            car.CarType        = type;
            car.CreateDateTime = time;
            car.IsDeleted      = isDeleted;
            car.NeedPosition   = needPosition;

            CarPositionDal dal = new CarPositionDal();
            int            n   = dal.Add(car);

            if (n <= 0)
            {
                MessageBox.Show("新增失败");
            }
            else
            {
                MessageBox.Show("新增成功");
                GetData();
            }
        }
Пример #2
0
        //修改车位信息
        private void btnRessetting_Click(object sender, EventArgs e)
        {
            try
            {
                string       plate        = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                int          id           = Convert.ToInt32(plate);
                string       type         = cmbCarType.SelectedItem.ToString();
                DateTime     time         = Convert.ToDateTime(dateTimePicker1.Text);
                bool         isDeleted    = checkBox1.Checked ? true : false;
                int          needPosition = Convert.ToInt32(txtPosition.Text);
                CarPositions car          = new CarPositions();
                car.Id             = id;
                car.CarType        = type;
                car.CreateDateTime = time;
                car.IsDeleted      = isDeleted;
                car.NeedPosition   = needPosition;

                CarPositionDal dal = new CarPositionDal();
                int            n   = dal.UpdateById(car);
                if (n <= 0)
                {
                    MessageBox.Show("修改失败");
                }
                else
                {
                    MessageBox.Show("修改成功");
                    GetData();
                }
            }
            catch
            {
            }
        }
Пример #3
0
        //添加新车位
        public int Add(CarPositions car)
        {
            string sql = "insert into T_CarPositions(CarType,NeedPosition,CreateDateTime,IsDeleted) values(@CarType,@NeedPosition,@CreateDateTime,@IsDeleted)";

            return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter[]
            {
                new SqlParameter {
                    ParameterName = "@CarType", Value = car.CarType
                },
                new SqlParameter {
                    ParameterName = "@NeedPosition", Value = car.NeedPosition
                },
                new SqlParameter {
                    ParameterName = "@CreateDateTime", Value = car.CreateDateTime
                },
                new SqlParameter {
                    ParameterName = "@IsDeleted", Value = car.IsDeleted
                }
            }));
        }
Пример #4
0
        //根据id修改车位信息
        public int UpdateById(CarPositions car)
        {
            string sql = "update T_CarPositions set CarType=@CarType,NeedPosition=@NeedPosition,CreateDateTime=@CreateDateTime,IsDeleted=@IsDeleted where id=@id";

            return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter[]
            {
                new SqlParameter {
                    ParameterName = "@CarType", Value = car.CarType
                },
                new SqlParameter {
                    ParameterName = "@NeedPosition", Value = car.NeedPosition
                },
                new SqlParameter {
                    ParameterName = "@CreateDateTime", Value = car.CreateDateTime
                },
                new SqlParameter {
                    ParameterName = "@IsDeleted", Value = car.IsDeleted
                },
                new SqlParameter {
                    ParameterName = "@id", Value = car.Id
                }
            }));
        }
Пример #5
0
    Bot(StreamReader reader, StreamWriter writer, SendMsg join)
    {
        this.writer = writer;
        string line;

        send(join);

        while ((line = reader.ReadLine()) != null)
        {
            MsgWrapper msg = JsonConvert.DeserializeObject <MsgWrapper>(line);
            switch (msg.msgType)
            {
            case "yourCar":
                YourCar yourCar = JsonConvert.DeserializeObject <YourCar>(line);
                myCar    = new Car();
                myCar.id = yourCar.data;
                break;

            case "carPositions":
                CarPositions carPositions = JsonConvert.DeserializeObject <CarPositions>(line);
                UpdateCarPositions(carPositions.data);
                currentGameTick = carPositions.gameTick;
                //Console.WriteLine("Car startlaneindex:"+myCar.piecePosition.lane.startLaneIndex+" Car endlaneIndex:"+myCar.piecePosition.lane.endLaneIndex+" Current tick: "+carPositions.gameTick+ " Speed: "+myCar.speed);
                send(DetermineAction());
                previousAngle = myCar.angle;
                if (previousAngle < 0)
                {
                    previousAngle = -previousAngle;
                }
                prevThrottle = throttle;
                break;

            case "join":
                Console.WriteLine("Joined");
                break;

            case "crash":
                CrashMsg crashMsg = JsonConvert.DeserializeObject <CrashMsg>(line);
                if (myCar.HasId(crashMsg.data))                         //Houston we have crashed...
                {
                    constant           = constant * 0.9;
                    maxSpeedMultiplier = constant * friction;
                    Console.WriteLine("#######CRASH!!##############");
                    Console.WriteLine("Speed: " + myCar.speed);
                    Console.WriteLine("############################");
                }
                break;

            case "gameInit":
                Console.WriteLine("Race init");
                GameInit gameInit = JsonConvert.DeserializeObject <GameInit>(line);
                currentTrack = CreateTrack(gameInit);
                otherCars    = new Cars(gameInit.data.race.cars);
                otherCars.cars.Remove(otherCars.GetCarById(myCar.id));
                break;

            case "gameEnd":
                Console.WriteLine("Race ended");
                break;

            case "gameStart":
                Console.WriteLine("Race starts");
                currentGameTick = 0;
                send(new Ping());
                break;

            case "turboAvailable":
                turboAvailable = true;
                Turbo turbo = JsonConvert.DeserializeObject <Turbo>(line);
                turboDetails    = turbo.data;
                currentGameTick = turbo.gameTick;
                break;

            case "lapFinished":
                LapFinished lapFinished = JsonConvert.DeserializeObject <LapFinished>(line);
                if (myCar.HasId(lapFinished.data.car))
                {
                    if (lapMaxAngle < 10)
                    {
                        constant           = constant * 1.4;
                        maxSpeedMultiplier = constant * friction;
                    }
                    else if (lapMaxAngle < 20)
                    {
                        constant           = constant * 1.3;
                        maxSpeedMultiplier = constant * friction;
                    }
                    else if (lapMaxAngle < 30)
                    {
                        constant           = constant * 1.2;
                        maxSpeedMultiplier = constant * friction;
                    }
                    else if (lapMaxAngle < 50)
                    {
                        constant           = constant * 1.1;
                        maxSpeedMultiplier = constant * friction;
                    }
                    Console.WriteLine("Lap finished, new spdmulti: " + maxSpeedMultiplier);
                }
                break;

            default:
                Console.WriteLine(line);
                break;
            }
        }
    }