diff --git "a/Harjoitusty\303\266/Harjoitusty\303\266.sln" "b/Harjoitusty\303\266/Harjoitusty\303\266.sln" index 6cec5f0a3328c290b73ddd506cfd4f62e424f9ef..41d7fd57e6d0535760aff60cc1e4399a0b2b7dc7 100644 --- "a/Harjoitusty\303\266/Harjoitusty\303\266.sln" +++ "b/Harjoitusty\303\266/Harjoitusty\303\266.sln" @@ -1,16 +1,23 @@  Microsoft Visual Studio Solution File, Format Version 12.00 + Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lokkihunter", "Lokkihunter\Lokkihunter.csproj", "{B39A6F49-1760-412C-B9CA-CFC5407D155D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LokkihunterTest", "LokkihunterTest\LokkihunterTest.csproj", "{B2103F2D-F650-4902-BC1F-AB855E7C2EE9}" +EndProject Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Release|Any CPU.Build.0 = Release|Any CPU + {B2103F2D-F650-4902-BC1F-AB855E7C2EE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2103F2D-F650-4902-BC1F-AB855E7C2EE9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2103F2D-F650-4902-BC1F-AB855E7C2EE9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2103F2D-F650-4902-BC1F-AB855E7C2EE9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection EndGlobal diff --git "a/Harjoitusty\303\266/Harjoitusty\303\266.sln.ctbackup" "b/Harjoitusty\303\266/Harjoitusty\303\266.sln.ctbackup" new file mode 100644 index 0000000000000000000000000000000000000000..6cec5f0a3328c290b73ddd506cfd4f62e424f9ef --- /dev/null +++ "b/Harjoitusty\303\266/Harjoitusty\303\266.sln.ctbackup" @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lokkihunter", "Lokkihunter\Lokkihunter.csproj", "{B39A6F49-1760-412C-B9CA-CFC5407D155D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B39A6F49-1760-412C-B9CA-CFC5407D155D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git "a/Harjoitusty\303\266/Lokkihunter/Lokkihunter.cs" "b/Harjoitusty\303\266/Lokkihunter/Lokkihunter.cs" index 6087c7c672f950eb54e7cb0e95c7c5a7332749ed..6be41eaaad70b9060f9f1dfc664406ae46713efc 100644 --- "a/Harjoitusty\303\266/Lokkihunter/Lokkihunter.cs" +++ "b/Harjoitusty\303\266/Lokkihunter/Lokkihunter.cs" @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; using System.Net; +using System.Net.Sockets; +using System.Reflection.Metadata; using System.Xml; using Jypeli; using Jypeli.Assets; using Jypeli.Controls; using Jypeli.Widgets; +using SixLabors.ImageSharp.Memory; namespace Lokkihunter; @@ -194,19 +197,18 @@ public class Lokkihunter : PhysicsGame private static int tileWidth; private static int tileHeight; - //const int SeinanTormaysIgnoreRyhma = 10; - readonly Vector nopeusVasen = new Vector(200, 0); readonly Vector nopeusOikea = new Vector(-200, 0); + private PhysicsObject pekka; private PhysicsObject lokkiVasen; private PhysicsObject lokkiOikea; AssaultRifle pekkaAse; - private PhysicsObject oikeaReuna; - private PhysicsObject vasenReuna; + PhysicsObject oikeaReuna; + PhysicsObject vasenReuna; private readonly IntMeter kenttaNro = new IntMeter(0, 0, 10); @@ -215,6 +217,7 @@ public class Lokkihunter : PhysicsGame public override void Begin() { + UusiPeli(); AsetaOhjaimet(); } @@ -275,14 +278,11 @@ public class Lokkihunter : PhysicsGame var tiles = TileMap.FromStringArray(tasonKuva); tiles.SetTileMethod('A', LuoPekka, Color.Wheat); - tiles.SetTileMethod('v', LuoLokkiVasen, Color.Wheat); - tiles.SetTileMethod('o', LuoLokkiOikea, Color.Wheat); + tiles.SetTileMethod('v', LuoLokkiVasen, Color.Black); + tiles.SetTileMethod('o', LuoLokkiOikea, Color.Black); tiles.Execute(tileWidth, tileHeight); - AddCollisionHandler(lokkiVasen, VasenLokkiKaantyy); - AddCollisionHandler(lokkiOikea, OikeaLokkiKaantyy); - // alaReuna = Level.CreateBottomBorder(1, false); // alaReuna.IgnoresExplosions = true; // Add(alaReuna); @@ -291,33 +291,20 @@ public class Lokkihunter : PhysicsGame // ylaReuna.IgnoresExplosions = true; // Add(ylaReuna); - oikeaReuna = Level.CreateRightBorder(); - Add(oikeaReuna); + oikeaReuna = Level.CreateRightBorder(1.0, false); + oikeaReuna.Height = 1000; + oikeaReuna.X = 550; + oikeaReuna.Restitution = 1.0; - vasenReuna = Level.CreateLeftBorder(); - Add(vasenReuna); + vasenReuna = Level.CreateLeftBorder(1.0, false); + vasenReuna.Height = 1000; + vasenReuna.X = -550; + vasenReuna.Restitution = 1.0; Camera.ZoomToLevel(); } - - - -// /// <summary> -// /// Törmäävä muuttaa suuntaa mihin kulkee jos törmää annettuun kohteeseen. -// /// </summary> -// /// <param name="tormaava">mikä törmää kohteeseen</param> -// /// <param name="mihinTormaa">kohde johon törmätään</param> -// private void MuuttaaSuuntaa(PhysicsObject tormaava, PhysicsObject mihinTormaa) -// { -// if (tormaava.X == mihinTormaa.X) -// { -// -// } -// } - - /// <summary> /// Aliohjelma luo Pekan ja antaa sille aseen. /// </summary> @@ -416,7 +403,6 @@ public class Lokkihunter : PhysicsGame Shape = Shape.Rectangle, Restitution = 1.0 }; - // lokki.Image = ... return lokki; } @@ -424,7 +410,7 @@ public class Lokkihunter : PhysicsGame void LokkiLentaa(PhysicsObject lentaja, double vx) { - lentaja.Hit(new Vector(vx, 1.0)); + lentaja.Hit(new Vector(vx, 0.0)); } /// <summary> @@ -436,21 +422,26 @@ public class Lokkihunter : PhysicsGame /// <param name="lokki"></param> private void LuoLokkiVasen(Vector position, double width, double height, Color lokki) { - double vx = 80; lokkiVasen = LuoLokki(); - LokkiLentaa(lokkiVasen, vx); + LokkiLentaa(lokkiVasen, 150); lokkiVasen.Y = RandomGen.NextDouble(200, 350); lokkiVasen.Tag = "vasenlokki"; + lokkiVasen.Restitution = 1.0; Add(lokkiVasen); - // AddCollisionHandler(lokkiVasen, vasenReuna, Tormaavat); - // AddCollisionHandler(lokkiVasen, vasenReuna, Tormaavat); } - + /// <summary> + /// Luo oikeanpuoleisenlokin ja annetaan sille jokin satunnainen y-koordinaatti, mikä on eri + /// kuin vasemmanpuoleisen lokin. + /// </summary> + /// <param name="position"></param> + /// <param name="width"></param> + /// <param name="height"></param> + /// <param name="lokki"></param> private void LuoLokkiOikea(Vector position, double width, double height,Color lokki) { lokkiOikea = LuoLokki(); - LokkiLentaa(lokkiOikea, -80); + LokkiLentaa(lokkiOikea, -150); double y; do { @@ -459,47 +450,10 @@ public class Lokkihunter : PhysicsGame while (Math.Abs(y - lokkiVasen.Y) < 40); lokkiOikea.Y = y; lokkiOikea.Tag = "oikealokki"; + lokkiOikea.Restitution = 1.0; Add(lokkiOikea); } - - private void VasenLokkiKaantyy(PhysicsObject tormaava, PhysicsObject kohde) - { - if (kohde == oikeaReuna) - { - kohde.Hit(new Vector(-80, 1)); - } - else if (kohde == vasenReuna) - { - kohde.Hit(new Vector(-0, 1)); - } - } - - - private void OikeaLokkiKaantyy(PhysicsObject tormaava, PhysicsObject kohde) - { - if (kohde == oikeaReuna) - { - kohde.Hit(new Vector(-80, 1)); - } - else if (kohde == vasenReuna) - { - kohde.Hit(new Vector(80, 1)); - } - } - - - // void Tormaavat(PhysicsObject tormaaja, PhysicsObject kohde) - // { - // - // while (tormaaja = kohde) - // { - // - // } - // } - - - // void LisaaLaskurit() // { // kentanNro = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); @@ -524,7 +478,7 @@ public class Lokkihunter : PhysicsGame // // törmäys vasen ja oikea reuna - // pisteet + // pisteeta // kentät // kommentit koodiin // alkuvalikko diff --git "a/Harjoitusty\303\266/LokkihunterTest/LokkihunterTest.cs" "b/Harjoitusty\303\266/LokkihunterTest/LokkihunterTest.cs" new file mode 100644 index 0000000000000000000000000000000000000000..4837d60206a4e0630e54253e879f7480180303a5 --- /dev/null +++ "b/Harjoitusty\303\266/LokkihunterTest/LokkihunterTest.cs" @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Xml; +using Jypeli; +using Jypeli.Assets; +using Jypeli.Controls; +using Jypeli.Widgets; +using NUnit.Framework; +using static Lokkihunter.Lokkihunter; +using Lokkihunter; + +namespace TestLokkihunter +{ + [TestFixture] + [DefaultFloatingPointTolerance(0.000001)] + public class TestLokkihunter + { + [Test] + public void TestTarkistaLokkiOikeaReuna495() + { + Assert.AreEqual( true, TarkistaLokkiOikeaReuna(40, 400) , "in method TarkistaLokkiOikeaReuna, line 496"); + Assert.AreEqual( true, TarkistaLokkiOikeaReuna(0, 400) , "in method TarkistaLokkiOikeaReuna, line 497"); + Assert.AreEqual( true, TarkistaLokkiOikeaReuna(-400, 400) , "in method TarkistaLokkiOikeaReuna, line 498"); + Assert.AreEqual( true, TarkistaLokkiOikeaReuna(400, 400) , "in method TarkistaLokkiOikeaReuna, line 499"); + Assert.AreEqual( false, TarkistaLokkiOikeaReuna(500, 400) , "in method TarkistaLokkiOikeaReuna, line 500"); + } + [Test] + public void TestTarkistaLokkiVasenReuna516() + { + Assert.AreEqual( false, TarkistaLokkiVasenReuna(-40, -400) , "in method TarkistaLokkiVasenReuna, line 517"); + Assert.AreEqual( false, TarkistaLokkiVasenReuna(0, -400) , "in method TarkistaLokkiVasenReuna, line 518"); + Assert.AreEqual( false, TarkistaLokkiVasenReuna(400, -400) , "in method TarkistaLokkiVasenReuna, line 519"); + Assert.AreEqual( true, TarkistaLokkiVasenReuna(-400, -400) , "in method TarkistaLokkiVasenReuna, line 520"); + Assert.AreEqual( true, TarkistaLokkiVasenReuna(-500, -400) , "in method TarkistaLokkiVasenReuna, line 521"); + } + } +} + diff --git "a/Harjoitusty\303\266/LokkihunterTest/LokkihunterTest.csproj" "b/Harjoitusty\303\266/LokkihunterTest/LokkihunterTest.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..cb6cd3e26a4f8101f85c6ec6270feef71bcd27b5 --- /dev/null +++ "b/Harjoitusty\303\266/LokkihunterTest/LokkihunterTest.csproj" @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>net7.0</TargetFramework> + <IsPackable>false</IsPackable> + </PropertyGroup> + <ItemGroup> + <PackageReference Include="NUnit" Version="3.13.1"/> + <PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Lokkihunter\Lokkihunter.csproj"/> + </ItemGroup> +</Project>