public virtual object Clone()
        {
            PassengerWithSingleTicket tmp = new PassengerWithSingleTicket();

            tmp.name = this.name;
            tmp.x    = this.x;
            tmp.y    = this.y;
            tmp.NumbersOfTripsLeft = this.NumbersOfTripsLeft;
            tmp.years              = this.years;
            tmp.active             = this.active;
            tmp.cash               = this.cash;
            tmp.NumbersOfTripsUsed = this.NumbersOfTripsUsed;
            foreach (var VARIABLE in TripInfo)
            {
                tmp.TripInfo.Add(new Tuple <string, int, int, DateTime>(VARIABLE.Item1, VARIABLE.Item2, VARIABLE.Item3, VARIABLE.Item4));
            }
            return(tmp);
        }
Ejemplo n.º 2
0
        public void KeyDown(KeyEventArgs e)
        {
            const int dx = 10;
            const int dy = 10;

            switch (e.Key)
            {
            case Key.W:
                foreach (Passenger el in passengers)
                {
                    if (el != null && el.InTravel == false)
                    {
                        el.Move(0, -dy);
                    }
                }
                break;

            case Key.A:
                foreach (Passenger el in passengers)
                {
                    if (el != null && el.InTravel == false)
                    {
                        el.Move(-dx, 0);
                    }
                }
                break;

            case Key.D:
                foreach (Passenger el in passengers)
                {
                    if (el != null && el.InTravel == false)
                    {
                        el.Move(dx, 0);
                    }
                }
                break;

            case Key.S:
                foreach (Passenger el in passengers)
                {
                    if (el != null && el.InTravel == false)
                    {
                        el.Move(0, dy);
                    }
                }
                break;

            case Key.Up:
                foreach (Passenger el in passengers)
                {
                    if (el != null && el.InTravel == false)
                    {
                        el.Move(0, -dy);
                    }
                }
                break;

            case Key.Left:
                foreach (Passenger el in passengers)
                {
                    if (el != null && el.InTravel == false)
                    {
                        el.Move(-dx, 0);
                    }
                }
                break;

            case Key.Right:
                foreach (Passenger el in passengers)
                {
                    if (el != null && el.InTravel == false)
                    {
                        el.Move(dx, 0);
                    }
                }
                break;

            case Key.Down:
                foreach (Passenger el in passengers)
                {
                    if (el != null && el.InTravel == false)
                    {
                        el.Move(0, dy);
                    }
                }
                break;

            case Key.C:
                foreach (var VARIABLE in passengers.ToArray())
                {
                    if (VARIABLE.isActive() == true && VARIABLE is PassengerWithSingleTicket == true)
                    {
                        PassengerWithSingleTicket k = new PassengerWithSingleTicket();
                        k    = (PassengerWithSingleTicket)(VARIABLE as PassengerWithSingleTicket).Clone();
                        k.x += 20;
                        k.y += 20;
                        passengers.Add(k);
                    }
                }
                break;

            case Key.Delete:
                for (int i = 0; i < passengers.Count; i++)
                {
                    if (passengers[i].isActive())
                    {
                        passengers[i].Remove();
                        passengers.Remove(passengers[i]);
                        i--;
                    }
                }
                break;

            case Key.Insert:
            {
                foreach (var VARIABLE in Transports)
                {
                    VARIABLE.Pause();
                }
                WasPaused = true;
                CreateNewPassenger newPassenger = new CreateNewPassenger();
                newPassenger.ShowDialog();
                if (newPassenger.DialogResult == true)
                {
                    if (newPassenger.TypeOfMicroObject == 1)
                    {
                        Passenger s = new Passenger(
                            newPassenger.MyName,
                            newPassenger.MyYears,
                            newPassenger.X,
                            newPassenger.Y,
                            newPassenger.Active
                            );
                        passengers.Add(s);
                    }
                    if (newPassenger.TypeOfMicroObject == 2)
                    {
                        PassengerWithSingleTicket s = new PassengerWithSingleTicket(
                            newPassenger.MyName,
                            newPassenger.MyYears,
                            newPassenger.X,
                            newPassenger.Y,
                            newPassenger.Active,
                            newPassenger.NumbersOfTrips,
                            newPassenger.Cash
                            );
                        passengers.Add(s);
                    }
                    if (newPassenger.TypeOfMicroObject == 3)
                    {
                        PreferentialPassenger s = new PreferentialPassenger(
                            newPassenger.MyName,
                            newPassenger.MyYears,
                            newPassenger.X,
                            newPassenger.Y,
                            newPassenger.Active,
                            newPassenger.Cash,
                            newPassenger.TypeOfPREFERNTIAL
                            );
                        passengers.Add(s);
                    }
                }
            }
                foreach (var VARIABLE in Transports)
                {
                    VARIABLE.Resume();
                }
                WasPaused = false;
                break;

            case Key.Escape:
                for (int i = 0; i < passengers.Count; i++)
                {
                    if (passengers[i].isActive())
                    {
                        passengers[i].active = false;
                    }
                }
                break;
            }
            foreach (var pass in passengers)
            {
                pass.Draw();
            }
        }