//timer private void timer1_Tick(object sender, EventArgs e) { ticksIgjen--; if (ticksIgjen <= 0) { timer1.Stop(); var setScore = new SetHighscore(poeng); setScore.ShowDialog(); var list = new HighscoreList(Highscore.FromFile("highscore.xml")); list.ShowDialog(); Close(); return; } if (torpedo != null) { torpedo.FrameTick((float)0.1); if (torpedo.Position.Y <= 0) { torpedo = null; } } //genererer en båt med tilfeldig avstand etter en viss sannsynlighet pr. bilderute Random rnd = new Random(); int prb = rnd.Next(250); if (prb == 1) { var theSkiff = new Skiff(); theSkiff.Speed = (rnd.Next(1, 5)); theSkiff.Position = new PointF(-(ClientSize.Width), rnd.Next(50, 200)); boats.Add(theSkiff); System.Console.WriteLine("Skiff added. Speed: " + theSkiff.Speed + ", distance: " + theSkiff.Position.Y); soundPlayer.playNewSkiff(); theSkiff.FrameTick((float)0.1); } if (prb == 2) { { var theFerry = new Ferry(); theFerry.Speed = (rnd.Next(1, 5)); theFerry.Position = new PointF(-(ClientSize.Width), rnd.Next(50, 200)); boats.Add(theFerry); System.Console.WriteLine("Ferry added. Speed: " + theFerry.Speed + ", distance: " + theFerry.Position.Y); soundPlayer.playNewFerry(); theFerry.FrameTick((float)0.1); } } if (prb == 3) { { var theTitanic = new Titanic(); theTitanic.Speed = (rnd.Next(1, 5)); theTitanic.Position = new PointF(-(ClientSize.Width), rnd.Next(50, 200)); boats.Add(theTitanic); System.Console.WriteLine("Titanic added. Speed: " + theTitanic.Speed + ", distance: " + theTitanic.Position.Y); soundPlayer.playNewTitanic(); theTitanic.FrameTick((float)0.1); } } //FrameTick'er båtene foreach (var boat in boats) { boat.FrameTick((float)0.1); } Refresh(); }