public bool proveri(Brod b) { if (b.Pozicija) // horizontalno { if (b.X < 0 || b.X >= 10 || b.Y < 0 || b.Y + b.Golemina >= 10) { return(false); } for (int i = b.Y; i < b.Y + b.Golemina; i++) { if (mapa[b.X][i] == 1) { return(false); } } return(true); } else { if (b.Y < 0 || b.Y >= 10 || b.X < 0 || b.X + b.Golemina >= 10) { return(false); } for (int i = b.X; i < b.X + b.Golemina; i++) { if (mapa[i][b.Y] == 1) { return(false); } } return(true); } }
public bool proveri(Brod b) { if (b.nasoka == Brod.Nasoka.Horizontalno) // horizontalno { if (b.X < 0 || b.X >= 10 || b.Y < 0 || b.Y + b.Golemina >= 10) { return(false); } for (int i = b.Y; i < b.Y + b.Golemina; i++) { if (mapa[b.X][i] == Sostojba.Brod) { return(false); } } return(true); } else { if (b.Y < 0 || b.Y >= 10 || b.X < 0 || b.X + b.Golemina >= 10) { return(false); } for (int i = b.X; i < b.X + b.Golemina; i++) { if (mapa[i][b.Y] == Sostojba.Brod) { return(false); } } return(true); } }
public void napolniSlucajno() { Console.WriteLine("OVDE!RANDOM!!!!"); int i = 2; Random rand = new Random(); Thread.Sleep(rand.Next(0, 100)); while (i < 6) { Brod b; if (rand.Next(0, 2) == 1) { b = new Brod(i, Brod.Nasoka.Horizontalno, rand.Next(0, 10), rand.Next(0, 10)); } else { b = new Brod(i, Brod.Nasoka.Vertikalno, rand.Next(0, 10), rand.Next(0, 10)); } if (proveri(b)) { i++; dodajBrodNaMapa(b); } } }
public void napolniSlucajno() { int i = 2; Random rand = new Random(); while (i < 6) { Brod b = new Brod(i, rand.Next(0, 2) == 1, rand.Next(0, 10), rand.Next(0, 10)); if (proveri(b)) { i++; dodajBrodNaMapa(b); } } }
public void dodajBrodNaMapa(Brod b) { if (proveri(b)) { if (b.Pozicija) // horizontalno { for (int i = b.Y; i < b.Y + b.Golemina; i++) { mapa[b.X][i] = 1; } } else { for (int i = b.X; i < b.X + b.Golemina; i++) { mapa[i][b.Y] = 1; } } Brodovi.Add(b); } }
public void dodajBrodNaMapa(Brod b) { if (proveri(b)) { if (b.nasoka == Brod.Nasoka.Horizontalno) // horizontalno { for (int i = b.Y; i < b.Y + b.Golemina; i++) { mapa[b.X][i] = Sostojba.Brod; } } else { for (int i = b.X; i < b.X + b.Golemina; i++) { mapa[i][b.Y] = Sostojba.Brod; } } Brodovi.Add(b); } }