public void startGame() { gameStarted = true; road b = FindObjectOfType <road>(); b.callingCreateRoad(); }
private IEnumerator MakeBox() { Camera c = GetComponent <Camera>(); RaycastHit hit; RaycastHit2D hit1; Physics.Raycast(c.ScreenPointToRay(Input.mousePosition), out hit, 200f, 1 << 8); if (hit.collider != null) { v = hit.collider.gameObject; hit1 = Physics2D.Raycast(Input.mousePosition, Input.mousePosition); if (!hit1 && v.name == "Lighter(Clone)") { road r = v.GetComponent <road>(); Destroy(r.a); Destroy(r.b); Destroy(r.e); Destroy(r.f); Destroy(r.w); Destroy(r.w2); Destroy(v); } } f1 = false; yield return(new WaitForSeconds(1)); f1 = true; }
private IEnumerator MakeBox() { road ro = GetComponent <road>(); if (!ro.s) { if (red) { ro.w.GetComponent <NavMeshObstacle>().enabled = true; ro.w.GetComponent <MeshCollider>().isTrigger = true; gameObject.GetComponent <Renderer>().material.color = Color.red; pusk = false; yield return(new WaitForSeconds(r)); pusk = true; red = !red; } else { gameObject.GetComponent <Renderer>().material.color = Color.green; ro.w.GetComponent <MeshCollider>().isTrigger = false; ro.w.GetComponent <NavMeshObstacle>().enabled = false; pusk = false; yield return(new WaitForSeconds(g)); pusk = true; red = !red; } } else { if (red) { ro.w.GetComponent <NavMeshObstacle>().enabled = true; ro.w2.GetComponent <NavMeshObstacle>().enabled = true; ro.w.GetComponent <MeshCollider>().isTrigger = true; gameObject.GetComponent <Renderer>().material.color = Color.red; pusk = false; yield return(new WaitForSeconds(r)); pusk = true; red = !red; } else { gameObject.GetComponent <Renderer>().material.color = Color.green; ro.w.GetComponent <NavMeshObstacle>().enabled = false; ro.w2.GetComponent <NavMeshObstacle>().enabled = false; ro.w.GetComponent <MeshCollider>().isTrigger = false; pusk = false; yield return(new WaitForSeconds(g)); pusk = true; red = !red; } } }
private void ExportMnRoads() { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { const int UncategorizedRoad = 100; // Remove old MN road types. Console.WriteLine("Deleting Minnesota roads..."); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); troutDashContext.roads.RemoveRange(minnesota.roads); troutDashContext.SaveChanges(); Console.WriteLine("Done deleting Minnesota roads."); Console.WriteLine("Getting Minnesota roads..."); var roadTypes = minnesota.road_types.ToDictionary(i => i.source); var roads = context.streets_load.ToList().Select(i => { var key = Convert.ToInt32(i.route_syst).ToString(); var roadTypeId = -1; if (i.route_syst == "1") { roadTypeId = 1; } else if (i.route_syst == "2") { roadTypeId = 2; } else { roadTypeId = roadTypes.ContainsKey(key) == false ? roadTypes.Single(j => j.Value.source == UncategorizedRoad.ToString()).Value.id : roadTypes[key].id; } var t = new road() { name = i.street_nam, local_name = "", state_gid = minnesota.gid, road_type_id = roadTypeId, Geom = i.Geom_4326 }; return(t); }).ToList(); Console.WriteLine("Saving Minnesota roads..."); troutDashContext.roads.AddRange(roads); troutDashContext.SaveChanges(); Console.WriteLine("Done saving Minnesota roads."); } }
public void GenerateRoad() { roadCount++; distance.text = "Distance: " + roadCount; PlayerPrefs.SetInt("distance", roadCount - 3); //int type = Random.Range(0, roads.Count); //GameObject newRoad = Instantiate(roads[type], new Vector3(3, 0, (roadCount*10)+2), Quaternion.identity) as GameObject; //Debug.Log(roadCount); GameObject newRoad = Instantiate(road, new Vector3(3, 0, (roadCount * 10) + 2), Quaternion.identity) as GameObject; road1 = road2; road2 = road3; road3 = road4; road4 = newRoad.GetComponent <road>(); //RoadPainting(); }
// Start is called before the first frame update void Start() { if (Physics.Raycast(transform.position, Vector3.down, out hit)) { Debug.Log("hit"); road Road = hit.transform.gameObject.GetComponent(typeof(road)) as road; int rnd = UnityEngine.Random.Range(0, Road.possibleDirections - 1); Debug.Log(rnd); if (rnd == 0) { path = Road.path1; } stoplicht = hit.transform.gameObject.GetComponent <road>().stoplicht[0]; } }
static void Main(string[] args) { try { Console.WriteLine("Enter number of cities:"); String s = Console.ReadLine(); int number = int.Parse(s); Point[] Cities = new Point[number]; double[,] w = new double[number, number]; for (int i = 0; i < number; i++) { for (int j = 0; j < number; j++) { w[i, j] = Double.PositiveInfinity; } } Console.WriteLine("Enter your choise:\n1. Generate Cities\n2. Enter Cities"); char choise = Convert.ToChar(Console.ReadLine()); switch (choise) { case '1': GenerateCities(); break; case '2': EnterCities(); break; default: Console.WriteLine("Incorrect input"); break; } Console.WriteLine("Enter number of roads:"); String s3 = Console.ReadLine(); int m = int.Parse(s3); int m1 = (number * (number - 1) / 2); if (m > m1) { m = m1; } road[] roads = new road[m1]; HashSet <road> AllRoads = new HashSet <road>(); road[] tree = new road[m1]; Intialize(); if (m > 0) { Console.WriteLine("Enter your choise:\n1. Generate Roads\n2. Enter Roads"); char choise1 = Convert.ToChar(Console.ReadLine()); switch (choise1) { case '1': GenerateRoads(); break; case '2': EnterRoads(); break; default: Console.WriteLine("Incorrect input"); break; } } bool[] visit = new bool[number]; int s4 = 0; PrimAlgorithm(); Output(); double GetDistance(Point point1, Point point2) { return(Math.Sqrt(Math.Pow((point1.GetX() - point2.GetX()), 2) + Math.Pow((point1.GetY() - point2.GetY()), 2))); } void Output() { for (int i = 0; i < s4; i++) { Console.WriteLine("\nRoad №" + (i + 1) + ":"); Console.WriteLine("City №" + tree[i].city1 + ":\nx: " + Cities[tree[i].city1 - 1].GetX() + "\ny: " + Cities[tree[i].city1 - 1].GetY()); Console.WriteLine("City №" + tree[i].city2 + ":\nx: " + Cities[tree[i].city2 - 1].GetX() + "\ny: " + Cities[tree[i].city2 - 1].GetY()); Console.WriteLine("Distance:" + tree[i].distance); } Console.WriteLine("Press any key to continue . . ."); Console.ReadKey(); } void GenerateCities() { Random random = new Random(); for (int i = 0; i < number; i++) { double x = random.Next(-100, 100); double y = random.Next(-100, 100); Cities[i] = new Point(x, y); } } void EnterCities() { for (int i = 0; i < number; i++) { Console.WriteLine("City №" + (i + 1) + "\nEnter x: "); String s1 = Console.ReadLine(); double x = double.Parse(s1); Console.WriteLine("Enter y: "); String s2 = Console.ReadLine(); double y = double.Parse(s2); Cities[i] = new Point(x, y); } } void Intialize() { int index = 0; for (int i = 0; i < number; i++) { for (int j = 0; j < number; j++) { if (i < j) { roads[index++] = new road(i, j, GetDistance(Cities[i], Cities[j])); w[i, j] = GetDistance(Cities[i], Cities[j]); w[j, i] = w[i, j]; } } } } void GenerateRoads() { Random random = new Random(); for (int i = 0; i < m; i++) { bool flag = true; while (flag) { int x = random.Next(0, number); int y = random.Next(0, number); if (AllRoads.Add(new road(x, y, 0)) && x != y) { roads[i] = new road(x - 1, y - 1, 0); w[x, y] = 0; w[y, x] = 0; flag = false; } } } } void EnterRoads() { for (int i = 0; i < m; i++) { Console.WriteLine("Road №" + (i + 1) + "\nEnter City №1: "); String s1 = Console.ReadLine(); int x = int.Parse(s1); Console.WriteLine("Enter City №2: "); String s2 = Console.ReadLine(); int y = int.Parse(s2); roads[i] = new road(x - 1, y - 1, 0); w[x - 1, y - 1] = 0; w[y - 1, x - 1] = 0; } } void PrimAlgorithm() { for (int i = 0; i < number; i++) { visit[i] = false; } bool e = true; double road = Double.PositiveInfinity; int v1 = -1; for (int i = 0; i < m1; i++) { if (road > roads[i].distance) { road = roads[i].distance; v1 = roads[i].city1; } } visit[v1] = true; while (e) { e = false; bool e1 = false; if (!e1) { int city1 = -1; int city2 = -1; double road1 = Double.PositiveInfinity; for (int i = 0; i < number; i++) { for (int j = 0; j < number; j++) { if ((visit[i] == true) && (visit[j] == false) && (w[i, j] < road1)) { city1 = i; city2 = j; road1 = w[i, j]; } } } if ((city1 != -1) && (city2 != -1)) { e1 = true; visit[city2] = true; tree[s4++] = new road(city1 + 1, city2 + 1, road1); } } for (int i = 0; i < number; i++) { if (visit[i] == false) { e = true; } } } } } catch { Console.WriteLine("Incorrect input"); Console.WriteLine("Press any key to continue . . ."); Console.ReadKey(); } }