I've been successful extracting character data with position data from pdfs but when I am trying to extract words with position data the text doesn't always come out as single words. Things like Saskatchewan could be split into S A SKA TCH EWAN. Is there anyway to fix this? I came across similar issues but the answers were for older versions of itextsharp.
public class TextLocationStrategy : LocationTextExtractionStrategy
{
public static List<PdfText> CharacterResult = new List<PdfText>();
public static List<PdfText> WordResult = new List<PdfText>();
protected override bool IsChunkAtWordBoundary(TextChunk chunk, TextChunk previousChunk)
{
float dist = chunk.GetLocation().DistanceFromEndOf(previousChunk);
if (dist < -chunk.GetLocation().GetCharSpaceWidth() || dist > chunk.GetLocation().GetCharSpaceWidth() / 4.0f)
{
return true;
}
return false;
}
public override void EventOccurred(IEventData data, EventType type)
{
try
{
if (!type.Equals(EventType.RENDER_TEXT))
{
return;
}
TextRenderInfo renderInfo = (TextRenderInfo)data;
string curFont = renderInfo.GetFont().GetFontProgram().ToString();
float curFontSize = renderInfo.GetFontSize();
IList<TextRenderInfo> text = renderInfo.GetCharacterRenderInfos();
string curText = renderInfo.GetText();
if (curText != " " && !curText.Contains(' '))
{
Vector wordStart = renderInfo.GetBaseline().GetStartPoint();
Vector wordEnd = renderInfo.GetAscentLine().GetEndPoint();
Rectangle wordRect = new Rectangle(wordStart.Get(0), wordStart.Get(1), wordEnd.Get(0) - wordStart.Get(0), wordEnd.Get(1) - wordStart.Get(1));
PdfText chunk = new PdfText
{
Text = curText,
Rectangle = wordRect,
FontFamily = curFont,
FontSize = Convert.ToInt32(curFontSize),
SpaceWidth = renderInfo.GetSingleSpaceWidth(),
HorizontalScaling = renderInfo.GetHorizontalScaling(),
Leading = renderInfo.GetLeading(),
CharacterSpacing = renderInfo.GetCharSpacing(),
StartPoint = new Autodesk.AutoCAD.Geometry.Point3d(wordStart.Get(0), wordStart.Get(1), 0.0),
EndPoint = new Autodesk.AutoCAD.Geometry.Point3d(wordEnd.Get(0), wordEnd.Get(1), 0.0)
};
WordResult.Add(chunk);
}
foreach (TextRenderInfo t in text)
{
string letter = t.GetText();
Vector letterStart = t.GetBaseline().GetStartPoint();
Vector letterEnd = t.GetAscentLine().GetEndPoint();
Rectangle letterRect = new Rectangle(letterStart.Get(0), letterStart.Get(1), letterEnd.Get(0) - letterStart.Get(0), letterEnd.Get(1) - letterStart.Get(1));
if (letter != " " && !letter.Contains(' '))
{
PdfText chunk = new PdfText
{
Text = letter,
Rectangle = letterRect,
FontFamily = curFont,
FontSize = Convert.ToInt32(curFontSize),
SpaceWidth = t.GetSingleSpaceWidth(),
HorizontalScaling = t.GetHorizontalScaling(),
Leading = t.GetLeading(),
CharacterSpacing = t.GetCharSpacing(),
StartPoint = new Autodesk.AutoCAD.Geometry.Point3d(letterStart.Get(0), letterStart.Get(1), 0.0),
EndPoint = new Autodesk.AutoCAD.Geometry.Point3d(letterEnd.Get(0), letterEnd.Get(1), 0.0)
};
CharacterResult.Add(chunk);
}
}
}
catch (Exception ex)
{
ErrorManager.ReportError(ex);
}
}
public List<PdfText> GetCharacterData()
{
List<PdfText> retVal = new List<PdfText>();
try
{
retVal = CharacterResult;
}
catch (Exception ex)
{
ErrorManager.ReportError(ex);
}
return retVal;
}
public List<PdfText> GetWordData()
{
List<PdfText> retVal = new List<PdfText>();
try
{
retVal = WordResult;
}
catch (Exception ex)
{
ErrorManager.ReportError(ex);
}
return retVal;
}
}
public class PdfText
{
public string Text { get; set; }
public Rectangle Rectangle { get; set; }
public string FontFamily { get; set; }
public int FontSize { get; set; }
public float SpaceWidth { get; set; }
public float CharacterSpacing { get; set; }
public float Leading { get; set; }
public float HorizontalScaling { get; set; }
public Point3d StartPoint { get; set; }
public Point3d EndPoint { get; set; }
}
Related
So I've made this form that acts as a cake shop. I have everything working perfectly except for the price. For some reason it isn't displaying properly and shows "$22.60" every time. I'm thinking there might be something wrong with the method
public virtual double CalculateCakeCost()
{
return CAKE_PRICE + (LAYER_PRICE * NumOfLayers);
}
from class "Cake" since it seems to return the cake price, but not add it up with the bracket values. The calculate cost with tax method from the class "CustomCake" also seems to be working fine. You can read the rest of the code is down below and please tell me if there is a problem, because I don't see anything wrong.
namespace Lab_OrderCake_The_Bakery_
{
public partial class frmOrderCake : Form
{
Cake objcake;
CustomCake objcustcake;
Customer objcustomer;
Order objorder;
public frmOrderCake()
{
InitializeComponent();
}
private void btnOrder_Click(object sender, EventArgs e)
{
//flavour
if (radVanilla.Checked == true)
{
txtRadFlavour.Text = "Vanilla";
}
if (radChocolate.Checked == true)
{
txtRadFlavour.Text = "Chocolate";
}
if (radBanana.Checked == true)
{
txtRadFlavour.Text = "Banana";
}
if (radLemonBerry.Checked == true)
{
txtRadFlavour.Text = "Lemon banana";
}
//layers
if (rad1layer.Checked == true)
{
numRadLayers.Value = 1;
}
if (rad2layers.Checked == true)
{
numRadLayers.Value = 2;
}
if (rad3layers.Checked == true)
{
numRadLayers.Value = 3;
}
if (rad4layers.Checked == true)
{
numRadLayers.Value = 4;
}
//occassion
if (radAnniversary.Checked == true)
{
txtRadOcc.Text = "Anniversary";
}
if (radBirthday.Checked == true)
{
txtRadOcc.Text = "Birthday";
}
if (radRetirement.Checked == true)
{
txtRadOcc.Text = "Retirement";
}
if (radWedding.Checked == true)
{
txtRadOcc.Text = "Wedding";
}
//size
if (rad6inch.Checked == true)
{
numRadSize.Value = 6;
}
if (rad8inch.Checked == true)
{
numRadSize.Value = 8;
}
if (rad10inch.Checked == true)
{
numRadSize.Value = 10;
}
if (rad12inch.Checked == true)
{
numRadSize.Value = 12;
}
//design
if (radPolka.Checked == true)
{
txtRadDesign.Text = "Polka Dots";
}
if (rad8inch.Checked == true)
{
txtRadDesign.Text = "Edible Images";
}
if (rad10inch.Checked == true)
{
txtRadDesign.Text = "Fondant Bow";
}
if (rad12inch.Checked == true)
{
txtRadDesign.Text = "3D Figures";
}
objcake = new Cake(txtRadFlavour.Text, (int)numRadLayers.Value);
objcustomer = new Customer(txtFName.Text, txtLName.Text);
objcustcake = new CustomCake(txtRadFlavour.Text, (int)numRadLayers.Value, txtRadOcc.Text,
(int)numRadSize.Value, txtRadDesign.Text);
objorder = new Order();
lblOutOrder.Text = objcustomer.ToString() + objcustcake.ToString() + objorder.ToString();
}
}
namespace CakeClasses
{
public class Cake
{
public int NumOfLayers { get; set; }
public string Flavour { get; set; }
public double Price { get; set; }
public const double CAKE_PRICE = 20;
public const int LAYER_PRICE = 3;
public Cake()
{
Flavour = "";
NumOfLayers = 0;
}
public Cake(string flavour, int numLayers)
{
NumOfLayers = numLayers;
Flavour = flavour;
}
**public virtual double CalculateCakeCost()
{
return CAKE_PRICE + (LAYER_PRICE * NumOfLayers);
}**
public override string ToString()
{
return " " + Flavour + " flavoured cake with " + NumOfLayers + " layer(s)";
}
}
}
namespace CakeClasses
{
public class Order
{
public Customer Customer { get; set; }
public Cake Cake { get; set; }
public int NumOfCakes { get; set; }
public Order()
{
Customer = new Customer();
Cake = new Cake();
NumOfCakes = 1;
}
public Order(string fName, string lName, string flavour, int numLayers, string occasion, int
diameter, string design)
{
Customer = new Customer(fName, lName);
Cake = new CustomCake(flavour, numLayers, occasion,diameter,design);
NumOfCakes = 1;
}
public Order(string fName, string lName, string flavour, int numLayers)
{
Customer = new Customer(fName, lName);
Cake = new Cake(flavour, numLayers);
NumOfCakes = 1;
}
public double CalculateCostWithTax()
{
return Cake.CalculateCakeCost() * 1.13;
}
public override string ToString()
{
return "for the total cost of " + CalculateCostWithTax().ToString("C");
}
}
}
namespace CakeClasses
{
public class CustomCake : Cake
{
public string Occasion { get; set; }
public int Size { get; set; }
public string Design { get; set; }
private double DesignCost { get; set; }
public CustomCake(string flavour, int numLayers,string occasion, int diameter, string design)
:base(flavour,numLayers)
{
Occasion = occasion;
Size = diameter;
Design = design;
switch (Design)
{
case "Polka Dots":
DesignCost = 5;
break;
case "Edible Images":
DesignCost = 12;
break;
case "Fondant Bow":
DesignCost = 10;
break;
default:
DesignCost = 15;
break;
}
}
public override double CalculateCakeCost()
{
return base.CalculateCakeCost() + Size + DesignCost;
}
public override string ToString()
{
return base.ToString() + " with " + Design + " design for " + Occasion + " occassion and
size is " + Size + " inches " ;
}
}
}
Try replacing following line in your code:
objorder = new Order();
with:
objorder = new Order("First Name","Last Name",txtRadFlavour.Text, (int)numRadLayers.Value);
I trying to import data from excel and for each two connected column i store the data into two dimensional list except the last column which will be in a 1D list. i wanna assign an id for each set of data the code get to be able to build a dictionary later for them.
that means for the first( valLat and valLng together ) i want to assign id = 1 and so on for each List
for (int i = 2; i <= rowCount; i++)
{
var pickLocation = new PickLocation();
var valLat = ((Excel.Range)wks.Cells[i, PickLocation.ColumnLat]).Value;
var valLng = ((Excel.Range)wks.Cells[i, PickLocation.ColumnLng]).Value;
if (!(valLat == null) & !(valLng == null))
{
pickLocation.Lat = Convert.ToDouble(valLat);
pickLocation.Lng = Convert.ToDouble(valLng);
ListPickLocations.Add(pickLocation);
}
var setLocation = new SetLocation();
valLat = ((Excel.Range)wks.Cells[i, SetLocation.ColumnLat]).Value;
valLng = ((Excel.Range)wks.Cells[i, SetLocation.ColumnLng]).Value;
if (!(valLat == null) & !(valLng == null))
{
setLocation.Lat = Convert.ToDouble(valLat); ;
setLocation.Lng = Convert.ToDouble(valLng);
ListSetlocations.Add(setLocation);
}
var craneLocation = new CraneLocation();
valLat = ((Excel.Range)wks.Cells[i, CraneLocation.ColumnLat]).Value;
valLng = ((Excel.Range)wks.Cells[i, CraneLocation.ColumnLng]).Value;
if (!(valLat == null) & !(valLng == null))
{
craneLocation.Lat = Convert.ToDouble(valLat); ;
craneLocation.Lng = Convert.ToDouble(valLng);
ListCranelocations.Add(craneLocation);
}
var weight = ((Excel.Range)wks.Cells[i, 10]).Value;
if (!(weight == null))
{
Weights.Add(Convert.ToDouble(weight));
}
var clearance = ((Excel.Range)wks.Cells[2, 12]).Value;
if (!(clearance == null))
{
Clearance = clearance;
}
}
}
}
}
}
public class PickLocation
{
public double Lat { get; set; }
public double Lng { get; set; }
public static int ColumnLat { get; } = 4;
public static int ColumnLng { get; } = 5;
}
public class CraneLocation
{
public double Lat { get; set; }
public double Lng { get; set; }
public static int ColumnLat { get; } = 1;
public static int ColumnLng { get; } = 2;
}
public class SetLocation
{
public double Lat { get; set; }
public double Lng { get; set; }
public static int ColumnLat { get; } = 7;
public static int ColumnLng { get; } = 8;
}
I have a project programmed in C# NET 3.5 in WPF which start very well in debug. However for example, in my TemplateColor.cs class I have this:
using System;
using System.Windows.Media;
namespace EWIN_THEME_MAKER.ThemeMaker
{
public class TemplateColor
{
private int _id;
private string _name;
private string _toneName;
public int ID
{
get
{
return this._id;
}
set
{
this._id = value;
}
}
public int AllVerticalPos
{
get;
set;
}
public int AllHorizontalPos
{
get;
set;
}
public int HuePageNum
{
get;
set;
}
public int HuePos
{
get;
set;
}
public int TonePaneNum
{
get;
set;
}
public int TonePos
{
get;
set;
}
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
string[] array = this._name.Split(new char[]
{
'_'
});
this._toneName = array[0];
if (array.Length > 1)
{
this.HuePageNum = int.Parse(array[1]);
}
}
}
public string ToneName
{
get
{
return this._toneName;
}
set
{
this._toneName = value;
}
}
public Color DarkColor
{
get;
set;
}
public Color MainColor
{
get;
set;
}
public Color LightColor
{
get;
set;
}
public Color ShadowColor
{
get;
set;
}
public byte ShadowA
{
get;
set;
}
public Color GrowColor
{
get;
set;
}
public Color TextShadowColor
{
get;
set;
}
public Color TextMainColor
{
get;
set;
}
public Color TextSelectColor
{
get;
set;
}
public double TextShadowPosition
{
get;
set;
}
public Brush DarkColorBrush
{
get
{
return new SolidColorBrush(this.DarkColor);
}
}
public Brush MainColorBrush
{
get
{
return new SolidColorBrush(this.MainColor);
}
}
public Brush LightColorBrush
{
get
{
return new SolidColorBrush(this.LightColor);
}
}
public Brush ShadowColorBrush
{
get
{
return new SolidColorBrush(this.ShadowColor);
}
}
public Brush GrowColorBrush
{
get
{
return new SolidColorBrush(this.GrowColor);
}
}
public Brush TextShadowColorBrush
{
get
{
return new SolidColorBrush(this.TextShadowColor);
}
}
public Brush TextMainColorBrush
{
get
{
return new SolidColorBrush(this.TextMainColor);
}
}
public Brush TextSelectColorBrush
{
get
{
return new SolidColorBrush(this.TextSelectColor);
}
}
public TemplateColor()
{
this.ID = -1;
this.AllVerticalPos = -1;
this.AllHorizontalPos = -1;
this.HuePageNum = -1;
this.HuePos = -1;
this.TonePaneNum = -1;
this.TonePos = -1;
this.Name = "---";
this.DarkColor = default(Color);
this.MainColor = default(Color);
this.LightColor = default(Color);
this.ShadowColor = default(Color);
this.ShadowA = 0;
this.GrowColor = default(Color);
this.TextShadowColor = default(Color);
this.TextMainColor = default(Color);
this.TextSelectColor = default(Color);
this.TextShadowPosition = 0.0;
}
}
}
In this code, there are multiple errors of this kind:
An exception of type 'System.StackOverflowException
For example I take this part of the code there:
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
string[] array = this._name.Split(new char[]
{
'_'
});
this._toneName = array[0];
if (array.Length > 1)
{
this.HuePageNum = int.Parse(array[1]);
}
}
}
So, in the next lines of this code there is an infinite call? I do not know how to correct this error.
string[] array = this._name.Split(new char[]
And...
this.HuePageNum = int.Parse(array[1]);
How do we predict and correct these errors?
My problem is now solved.
Solution: Increasing the size of the stack
Thanks to all!
If I execute my CircleRadius inside my InitializeComponent immediately then I see it on the map, but if I want to create it once I load my data (loadPins function) then It does not appear on the map. It seems like it has to be loaded immediately or else it will not load. How can I adjust the code so it gets puts on hold until It gets added?
XAML and my customMap:
<local:CustomMap x:Name="mymap" MapType="Street" IsShowingUser="true"/>
The Code:
public MapPage()
{
InitializeComponent();
loadPins ();
/*
var position = new Position (56.264945, 12.579809);
mymap.Circle = new CustomCircle {
Position = position,
Radius = 2500
};
*/
// If I use the code above then I get a circleradius on the map.
}
async void loadPins ()
{
var getEnd = await phpApi.getEnd ();
foreach (var currentItems in getEnd ["results"]) {
latstring = currentItems ["Lat"].ToString ();
lngstring = currentItems ["Lng"].ToString ();
var storeLng = Double.Parse (lngstring, CultureInfo.InvariantCulture);
var storeLat = Double.Parse (latstring, CultureInfo.InvariantCulture);
var pin = new Pin ();
pin.Position = new Position (storeLat, storeLng);
pin.Label = "Test";
pin.Address = "-";
mymap.Circle = new CustomCircle {
Position = pin.Position,
Radius = 100000
}; //I cannot see this one on the map.
mymap.Pins.Add (pin);
}
}
This is my customMap:
public class CustomMap : Map
{
public MapContentType ContentType { get; set; }
public double CircleRadius { get; set; }
public List<Position> Positions { get; set; }
public CustomCircle Circle { get; set; }
public CustomMap()
{
this.ContentType = MapContentType.Normal;
this.CircleRadius = 500;
this.Positions = new List<Position> ();
}
}
And my CustomCircle:
public class CustomCircle
{
public Position Position { get; set; }
public double Radius { get; set; }
}
And my renderer:
public class CustomMapRendererCircle : MapRenderer
{
MKCircleRenderer circleRenderer;
protected override void OnElementChanged (ElementChangedEventArgs<View> e)
{
base.OnElementChanged (e);
if (e.OldElement != null) {
var nativeMap = Control as MKMapView;
nativeMap.OverlayRenderer = null;
var nativeMapCircle = Control as MKMapView;
nativeMapCircle.OverlayRenderer = null;
}
if (e.NewElement != null) {
var formsMapCircle = (CustomMap)e.NewElement;
var nativeMapCircle = Control as MKMapView;
var circle = formsMapCircle.Circle;
nativeMapCircle.OverlayRenderer = GetOverLayRendererTwo;
if (circle != null) {
var circleOverlay = MKCircle.Circle (new CoreLocation.CLLocationCoordinate2D (circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
nativeMapCircle.AddOverlay (circleOverlay);
}
}
}
MKOverlayRenderer GetOverLayRendererTwo (MKMapView mapView, IMKOverlay overlay)
{
if (circleRenderer == null) {
circleRenderer = new MKCircleRenderer (overlay as MKCircle);
circleRenderer.FillColor = UIColor.Green;
circleRenderer.Alpha = 0.2f;
}
return circleRenderer;
}
}
}
you might be facing a well known bug with iOS build
try using this tweak,put the code which is not working inside a time for some delaying , for me this worked
if(Device.OS == TargetPlatform.Android)
customMap.MoveToRegion (MapSpan.FromCenterAndRadius (customMap.CustomPins [0].Pin.Position, Distance.FromMiles (55.0)));
if (Device.OS == TargetPlatform.iOS) {
Device.StartTimer (TimeSpan.FromMilliseconds (500), () => {
customMap.MoveToRegion (MapSpan.FromCenterAndRadius (customMap.CustomPins [0].Pin.Position, Distance.FromMiles (55.0)));
return false;
});
}
}
To start off I am new to C# and I am in need of some help. I a class that contains a list. I can set the items in the list from the application but not from the class(where it needs to be done). I am also needing to move an event to class as well. This works in the app as well. Any help with this is greatly appreciated. Below is the code from my class:
namespace CarRace
{
class Cars
{
public string Name { get; set; }
public int StartPOS { get; set; }
public int Speed { get; set; }
public int CurPOS { get; set; }
public double Location { get; set; }
public Cars(string Name, int StartPOS, int Speed, int CurPOS, long Location)
{
this.Name = Name;
this.StartPOS = StartPOS;
this.Speed = Speed;
this.CurPOS = 0;
this.Location = 0;
}
public static int CompareCurrentLocation(Cars c1, Cars c2)
{
return c2.Location.CompareTo(c1.Location);
}
}
}
I am needing to add this to the class:
if (File.Exists("NewRace.xml"))
{
XDocument doc = XDocument.Load("NewRace.xml");
var nCars = doc.Descendants("Car").Select(x => new Cars("", 0, 0, 0, 0)
{
Name = x.Attribute("Name").Value,
StartPOS = int.Parse(x.Attribute("StartPOS").Value),
Speed = int.Parse(x.Attribute("Speed").Value),
CurPOS = 0
});
}
And this:
int p = 1;
int prevPOS = 1;
DateTime? PrevTime;
double dist = 0;
double PrevLoc = 0;
if (i == 0)
{
return;
}
foreach (var car in RaceList)
{
dist = (((car.Speed * 1609.344) * 1) / 1609.344) / 3600;
car.Location = car.Location + dist;
}
Comparison<Cars> compLoc = Cars.CompareCurrentLocation;
RaceList.Sort(compLoc);
PrevTime = DateTime.Now;
foreach (var car in RaceList)
{
if (car.Location != PrevLoc)
{
car.CurPOS = p;
}
else
{
car.CurPOS = prevPOS;
}
prevPOS = car.CurPOS;
PrevLoc = car.Location;
p++;
}
Thanks
Thanks for all of your replies. I tried the car.speed/3600 but only get
back 0 for that so I did the long way. I did get everything working
the way I needed it to.
That's because you are doing an integer division (car.Speed is of type int) so the fractional part of the result is discarded. Since the car's speed is less than 3600 this would hence always result in zero. You can avoid this by casting car.Speed to a double first - this should produce the result you want:
dist = (double)car.Speed / 3600;
Thanks for all of your replies. I tried the car.speed/3600 but only get back 0 for that so I did the long way. I did get everything working the way I needed it to. I am a rookie at this and any tips are greatly appreciated. Below is the code I have updated to.
namespace CarRace
{
class Cars
{
public string Name { get; set; }
public int StartPOS { get; set; }
public int CurPOS { get; set; }
public int Speed { get; set; }
public double Location { get; set; }
public string Make { get; set; }
private static List<Cars> CarList;
private static string ProgPart;
public Cars(string Name, int StartPOS, int CurPOS, int Speed, double Location, string Make)
{
this.Name = Name;
this.StartPOS = StartPOS;
this.CurPOS = CurPOS;
this.Speed = Speed;
this.Location = Location;
this.Make = Make;
}
public static List<Cars> FillList()
{
return CarList;
}
public static void Main()
{
try
{
bool Prog = false;
//Get Part to display
while (!Prog)
{
Console.WriteLine("Select the part you would like to test.(1 or 2)");
ProgPart = Console.ReadLine();
if (ProgPart == "1" || ProgPart == "2")
{
Prog = true;
}
}
Console.WriteLine("----------------------------------------");
//Read XML File and set the CarList
if (File.Exists("NewRace.xml"))
{
XDocument doc = XDocument.Load("NewRace.xml");
var nCars = doc.Descendants("Car").Select(x => new Cars("", 0, 0, 0, 0, "")
{
Name = x.Attribute("Name").Value,
StartPOS = int.Parse(x.Element("StartPOS").Value),
CurPOS = 0,
Speed = int.Parse(x.Element("Speed").Value),
Location = double.Parse(x.Element("Location").Value),
Make = x.Attribute("Make").Value
});
CarList = new List<Cars>();
foreach (var car1 in nCars)
{
if (ProgPart == "1")
{
CarList.Add(new Cars(car1.Name, car1.StartPOS, car1.CurPOS, car1.Speed, car1.Location, car1.Make));
}
else
{
CarList.Add(new Cars(car1.Name, car1.StartPOS, car1.CurPOS, 0, car1.Location, car1.Make));
}
}
}
else
{
Console.WriteLine("File Not Found!");
Console.ReadKey();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static int CompareCurrentLocation(Cars c1, Cars c2)
{
return c2.Location.CompareTo(c1.Location);
}
public static Boolean UpdateLeaderBoard(long i)
{
try
{
int p = 1;
int prevPOS = 1;
DateTime? PrevTime;
double dist = 0;
double prevLocation = 0;
if (i == 0)
{
return false;
}
foreach (var car in CarList)
{
if (ProgPart == "2")
{
switch (car.Make)
{
case "300ZX":
//Slow continuous gain of speed by percentage after 60 with top speed of 320.
if (i <= 15)
{
car.Speed = car.Speed + (60 / 10);
}
else if (car.Speed < 320)
{
double percent = (double)(car.Speed * .1);
if ((Convert.ToInt32(car.Speed + percent)) > 320)
{
car.Speed = 320;
}
else
{
car.Speed = Convert.ToInt32(car.Speed + (percent));
}
}
break;
case "Camero":
//0-60 4 seconds 60-220 20 seconds Top 220
if (i <= 4)
{
car.Speed = car.Speed + (60 / 4);
}
else if (i <= 20)
{
car.Speed = car.Speed + 10;
}
break;
case "Mustang":
//0-top(210) 25 seconds
if (car.Speed <= 200)
{
car.Speed = car.Speed + (200 / 20);
}
break;
case "VW Bug":
//Constant Speed
car.Speed = 165;
break;
default:
Console.WriteLine("Make not found");
break;
}
}
//Set Cars Current Location
dist = (((car.Speed * 1609.344) * 1) / 1609.344) / 3600;
car.Location = car.Location + dist;
}
//Sort list by location
Comparison<Cars> compLoc = Cars.CompareCurrentLocation;
CarList.Sort(compLoc);
PrevTime = DateTime.Now;
//Set the Current Position
foreach (var car in CarList)
{
if (car.Location != prevLocation)
{
car.CurPOS = p;
}
else
{
car.CurPOS = prevPOS;
}
prevPOS = car.CurPOS;
prevLocation = car.Location;
p++;
}
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
}