コード例 #1
0
ファイル: TrafficGrid.cs プロジェクト: raethlo/RushHour
 public TrafficGrid(TrafficGrid g)
 {
     this.Cars = new List<Car>();
     foreach (var car in g.Cars)
     {
         var c = new Car();
         c.Orientation = car.Orientation;
         c.Length = car.Length;
         c.X = car.X;
         c.Y = car.Y;
         c.Color = car.Color;
         this.Cars.Add(c);
     }
     this.Dimension = g.Dimension;
     this.Occupancy = this.Occupancy = new bool[g.Dimension, g.Dimension];
     this.genOccupancy();
 }
コード例 #2
0
ファイル: TrafficGrid.cs プロジェクト: raethlo/RushHour
        //funkcia, ktora vytvori novu konfiguraci mriezky tym,ze pohneme nejakym autom
        public TrafficGrid Move(Car car, Direction direction, int distance)
        {
            TrafficGrid result = new TrafficGrid(this);
            Car actualCar = result.Cars.Find(c => c.Color == car.Color);

            //if (CanMove(actualCar,direction) < distance) throw new Exception("Cant move that far");

            int newX = actualCar.X, newY = actualCar.Y;

            switch (actualCar.Orientation)
            {
                case Orientation.Vertical:
                    switch (direction)
                    {
                        case Direction.Up:
                            for (int i = 0; i < actualCar.Length; i++)
                            {
                                result.Occupancy[actualCar.X, actualCar.Y + i] = false;
                            }
                            for (int i = 0; i < actualCar.Length; i++)
                            {
                                result.Occupancy[actualCar.X, actualCar.Y - distance + i] = true;
                            }
                            newY -= distance;
                            break;
                        case Direction.Down:
                            for (int i = 0; i < actualCar.Length; i++)
                            {
                                result.Occupancy[actualCar.X, actualCar.Y + i] = false;

                            }
                            for (int i = 0; i < actualCar.Length; i++)
                            {
                                result.Occupancy[actualCar.X, actualCar.Y + distance + i] = true;
                            }
                            newY += distance;
                            break;
                        default:
                            break;
                    }
                    break;
                case Orientation.Horizontal:
                    switch (direction)
                    {
                        case Direction.Left:
                            for (int i = 0; i < actualCar.Length; i++)
                            {
                                result.Occupancy[actualCar.X + i, actualCar.Y] = false;
                            }
                            for (int i = 0; i < actualCar.Length; i++)
                            {
                                result.Occupancy[actualCar.X - distance + i, actualCar.Y] = true;
                            }
                            newX -= distance;
                            break;
                        case Direction.Right:
                            for (int i = 0; i < actualCar.Length; i++)
                            {
                                result.Occupancy[actualCar.X+i, actualCar.Y] = false;
                            }
                            for (int i = 0; i < actualCar.Length; i++)
                            {
                                result.Occupancy[actualCar.X + distance + i, actualCar.Y] = true;
                            }
                            newX +=distance;
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    break;
            }

            actualCar.X = newX;
            actualCar.Y = newY;

            return result;
        }