diff --git a/luennot/live12/Kutsuminen/Kutsuminen.cs b/luennot/live12/Kutsuminen/Kutsuminen.cs index bdd4b47e2b289cf9e3b2a5bbe9a987269690cff8..64abe57a9d07e3df46025b11cacf60cf9a3b9ed7 100644 --- a/luennot/live12/Kutsuminen/Kutsuminen.cs +++ b/luennot/live12/Kutsuminen/Kutsuminen.cs @@ -101,7 +101,7 @@ public class Kutsuminen /// SuurimmanPaikka(new int[]{1,2,5,3}) === 2; /// SuurimmanPaikka(new int[]{7,2,5,3}) === 0; /// SuurimmanPaikka(new int[]{1,2,5,8}) === 3; - /// SuurimmanPaikka(new int[]{}) === -1; + /// SuurimmanPaikka(new int[]{}) === 1; /// </pre> /// </example> public static int SuurimmanPaikka(int[] t) diff --git a/luennot/live12/KutsuminenTest/KutsuminenTest.cs b/luennot/live12/KutsuminenTest/KutsuminenTest.cs index f457c709d04d0203960bf45ff29253142b0dc843..5ab979fa70ad800a4e5f3fb508b2829e70c6de88 100644 --- a/luennot/live12/KutsuminenTest/KutsuminenTest.cs +++ b/luennot/live12/KutsuminenTest/KutsuminenTest.cs @@ -42,7 +42,7 @@ using static Kutsuminen; Assert.AreEqual( 2, SuurimmanPaikka(new int[]{1,2,5,3}) , "in method SuurimmanPaikka, line 101"); Assert.AreEqual( 0, SuurimmanPaikka(new int[]{7,2,5,3}) , "in method SuurimmanPaikka, line 102"); Assert.AreEqual( 3, SuurimmanPaikka(new int[]{1,2,5,8}) , "in method SuurimmanPaikka, line 103"); - Assert.AreEqual( -1, SuurimmanPaikka(new int[]{}) , "in method SuurimmanPaikka, line 104"); + Assert.AreEqual( 1, SuurimmanPaikka(new int[]{}) , "in method SuurimmanPaikka, line 104"); } } diff --git a/luennot/live13/.idea/.idea.live13/.idea/.gitignore b/luennot/live13/.idea/.idea.live13/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f887d9fb90fa053b37b88850d1027774027b8784 --- /dev/null +++ b/luennot/live13/.idea/.idea.live13/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/projectSettingsUpdater.xml +/modules.xml +/contentModel.xml +/.idea.live13.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/luennot/live13/.idea/.idea.live13/.idea/encodings.xml b/luennot/live13/.idea/.idea.live13/.idea/encodings.xml new file mode 100644 index 0000000000000000000000000000000000000000..df87cf951fb4858ab7a76b68dd479c98b2df2404 --- /dev/null +++ b/luennot/live13/.idea/.idea.live13/.idea/encodings.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" /> +</project> \ No newline at end of file diff --git a/luennot/live13/.idea/.idea.live13/.idea/indexLayout.xml b/luennot/live13/.idea/.idea.live13/.idea/indexLayout.xml new file mode 100644 index 0000000000000000000000000000000000000000..7b08163cebc50fb3e777eea4881b68fcebc10590 --- /dev/null +++ b/luennot/live13/.idea/.idea.live13/.idea/indexLayout.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="UserContentModel"> + <attachedFolders /> + <explicitIncludes /> + <explicitExcludes /> + </component> +</project> \ No newline at end of file diff --git a/luennot/live13/.idea/.idea.live13/.idea/vcs.xml b/luennot/live13/.idea/.idea.live13/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..b2bdec2d71b6a5ce4ae49efc37516809c50e4d5e --- /dev/null +++ b/luennot/live13/.idea/.idea.live13/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$/../.." vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/luennot/live13/AngryLego/AngryLego.cs b/luennot/live13/AngryLego/AngryLego.cs new file mode 100644 index 0000000000000000000000000000000000000000..7083299ad246927ea255904590b99efea9f6b748 --- /dev/null +++ b/luennot/live13/AngryLego/AngryLego.cs @@ -0,0 +1,19 @@ +using Jypeli; + +namespace AngryLego; + +/// @author vesal +/// @version 16.10.2023 +/// <summary> +/// +/// </summary> +public class AngryLego : PhysicsGame +{ + public override void Begin() + { + // Kirjoita ohjelmakoodisi tähän + + PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); + Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); + } +} \ No newline at end of file diff --git a/luennot/live13/AngryLego/AngryLego.csproj b/luennot/live13/AngryLego/AngryLego.csproj new file mode 100644 index 0000000000000000000000000000000000000000..fb98d03a9ae4d4aa96925e3188b491c8294da81d --- /dev/null +++ b/luennot/live13/AngryLego/AngryLego.csproj @@ -0,0 +1,13 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>WinExe</OutputType> + <TargetFramework>net7.0</TargetFramework> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Jypeli.NET" Version="11.*"/> + <PackageReference Include="Jypeli.FarseerPhysics.NET" Version="2.*"/> + </ItemGroup> + +</Project> diff --git a/luennot/live13/AngryLego/Ohjelma.cs b/luennot/live13/AngryLego/Ohjelma.cs new file mode 100644 index 0000000000000000000000000000000000000000..d753cf9f0f9a9e3c964854adbfa4b9719b4a588a --- /dev/null +++ b/luennot/live13/AngryLego/Ohjelma.cs @@ -0,0 +1,26 @@ +#region Using Statements + +using System; +using System.Collections.Generic; +using System.Linq; + +#endregion + +namespace AngryLego +{ + /// <summary> + /// The main class. + /// </summary> + public static class Program + { + /// <summary> + /// The main entry point for the application. + /// </summary> + [STAThread] + static void Main() + { + using var game = new AngryLego(); + game.Run(); + } + } +} \ No newline at end of file diff --git a/luennot/live13/KentanMuokkaus/Content/tiili2.png b/luennot/live13/KentanMuokkaus/Content/tiili2.png new file mode 100644 index 0000000000000000000000000000000000000000..9842558e6b9afe69c0639ffae75fa36e54a8c81d Binary files /dev/null and b/luennot/live13/KentanMuokkaus/Content/tiili2.png differ diff --git a/luennot/live13/KentanMuokkaus/KentanMuokkaus.cs b/luennot/live13/KentanMuokkaus/KentanMuokkaus.cs new file mode 100644 index 0000000000000000000000000000000000000000..9728454b3ca56a3cf004c428c706c58514552c2f --- /dev/null +++ b/luennot/live13/KentanMuokkaus/KentanMuokkaus.cs @@ -0,0 +1,177 @@ +using Jypeli; + +namespace KentanMuokkaus; + +/// @author Vesa Lappalainen +/// @version 10.10.2020 +/// +/// <summary> +/// Ohjelmassa harjoitellaan 2-ulotteisen +/// merkkitaulukon (char[,]) hyodyntamista kentan +/// luomisessa. +/// </summary> +public class KentanMuokkaus : PhysicsGame +{ + private PhysicsObject pelaaja; // Liikuteltava pallo, jota pystytään + // liikuttamaan kaikista tämän luokan aliohjelmista + private const int KOKO = 20; // paljonko on yksittäisen palikan koko. + // huom const eli vakio! (ei voi muuttaa) + + /// <summary> + /// Asetetaan painovoima ja kutsutaan alustuksiin + /// liittyvia aliohjelmia. Aloitetaan peli. + /// Zoomataan kamera. + /// </summary> + public override void Begin() + { + // SetWindowSize(1000, 700); + Level.Width = 100; + Level.Height = 100; + char[,] kentta = { + {'P', '.', 'P'}, + {'.', 'O', 'n'}, + {'n', '.', 'P'}, + {'O', ' ', 'P'}, + }; + // Gravity = new Vector(0, -1000); + TeeKentta(kentta); + AsetaOhjaimet(); + Level.CreateBorders(); + Camera.ZoomToLevel(); + } + + + /// <summary> + /// Luodaan pelikentta 2-ulotteisen merkkitaulukon (char[,]) + /// avulla. Kutsutaan aliohjelmia eri merkeille luotujen merkitysten + /// perusteella. + /// </summary> + private void TeeKentta(char[,] kentta) + { + double alkuX = Level.Left + KOKO / 2.0 + 20; + double alkuY = Level.Top - KOKO / 2.0; + + + double y = alkuY; + + // Kaydaan rivit ja sarakkeet lapi. + // "Muutetaan" merkkitaulukko kentaksi siten + // etta tietyt merkit vastaavat tietyn kentalle lisattavan olion + // aliohjelmakutsua. Myos koordinaatit saadaan matriisista: + // Rivi toimii x-koordinaattina, ja sarake y-koordinaattina. + for (int iy = 0; iy < kentta.GetLength(0); iy++) + { + double x = alkuX; + for (int ix = 0; ix < kentta.GetLength(1); ix++) + { + char t = kentta[iy, ix]; + + switch (t) + { + case 'P': + LuoPalikka(x, y); + break; + case 'n': + LuoNelio(x, y); + break; + case 'O': + LuoYmpyra(x, y); + break; + case '.': + LuoPelaaja(x, y); + break; + } + x += KOKO; + } + y -= KOKO; + } + } + + + /// <summary> + /// Lisataan pallo kentalle ja annetaan pallolle massa. + /// </summary> + /// <param name="x">Pallon kp x-koordinaatti</param> + /// <param name="y">Pallon kp y-koordinaatti</param> + private void LuoPelaaja(double x, double y) + { + pelaaja = new PhysicsObject(KOKO / 2.0, KOKO / 2.0, Shape.Circle); + pelaaja.Position = new Vector(x, y); + pelaaja.Color = Color.Red; + Add(pelaaja); + } + + + /// <summary> + /// Lisataan staattinen suorakulmio (nelio) kentalle + /// annettuun paikkaan. + /// </summary> + /// <param name="x">Nelion kp x-koordinaatti</param> + /// <param name="y">Nelion kp y-koordinaatti</param> + private void LuoPalikka(double x, double y) + { + PhysicsObject palikka = PhysicsObject.CreateStaticObject(KOKO, KOKO); + Add(palikka); + palikka.Image = LoadImage("tiili2"); + palikka.Position = new Vector(x, y); + } + + + /// <summary> + /// Lisataan pieni staattinen suorakulmio (nelio) kentalle + /// annettuun paikkaan. + /// </summary> + /// <param name="x">Nelion kp x-koordinaatti</param> + /// <param name="y">Nelion kp y-koordinaatti</param> + private void LuoNelio(double x, double y) + { + PhysicsObject palikka = PhysicsObject.CreateStaticObject(KOKO / 2.0, KOKO / 2.0); + Add(palikka); + palikka.Color = Color.Blue; + palikka.Position = new Vector(x, y); + } + + + /// <summary> + /// Tehdaan staattinen ympyra + /// ja lisataan se pelikentalle + /// annettuun paikkaan. + /// </summary> + /// <param name="x">Ympyran kp x-koordinaatti</param> + /// <param name="y">Ympyran kp y-koordinaatti</param> + private void LuoYmpyra(double x, double y) + { + PhysicsObject pallo = PhysicsObject.CreateStaticObject(KOKO, KOKO, Shape.Circle); + this.Add(pallo); + pallo.Color = Color.Yellow; + pallo.Position = new Vector(x, y); + } + + + /// <summary> + /// Asetetaan nappaintenkuuntelijat. + /// </summary> + private void AsetaOhjaimet() + { + const int voima = 10; + Keyboard.Listen(Key.Up, ButtonState.Pressed, LiikutaPalloa, "Ylös", new Vector(0, voima)); + Keyboard.Listen(Key.Down, ButtonState.Pressed, LiikutaPalloa, "Alas", new Vector(0, -voima)); + Keyboard.Listen(Key.Left, ButtonState.Pressed, LiikutaPalloa, "Vasemmalle", new Vector(-voima, 0)); + Keyboard.Listen(Key.Right, ButtonState.Pressed, LiikutaPalloa, "Oikealle", new Vector(voima, 0)); + + // Ohjeiden näyttämistä varten. Paina F1 pelin aikana. + Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Ohjeet"); + + Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); + } + + /// <summary> + /// Aliohjelma liikuttaa palloa. + /// </summary> + /// <param name="suunta">Suunta, johon palloa liikutetaan.</param> + private void LiikutaPalloa(Vector suunta) + { + pelaaja.Hit(suunta); + } + +} \ No newline at end of file diff --git a/luennot/live13/KentanMuokkaus/KentanMuokkaus.csproj b/luennot/live13/KentanMuokkaus/KentanMuokkaus.csproj new file mode 100644 index 0000000000000000000000000000000000000000..a2c62819a2b88dec8226f0a6014d1e200185a3c9 --- /dev/null +++ b/luennot/live13/KentanMuokkaus/KentanMuokkaus.csproj @@ -0,0 +1,19 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>WinExe</OutputType> + <TargetFramework>net7.0</TargetFramework> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Jypeli.NET" Version="11.*"/> + <PackageReference Include="Jypeli.FarseerPhysics.NET" Version="2.*"/> + </ItemGroup> + + <ItemGroup> + <None Update="Content\tiili2.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + </ItemGroup> + +</Project> diff --git a/luennot/live13/KentanMuokkaus/Ohjelma.cs b/luennot/live13/KentanMuokkaus/Ohjelma.cs new file mode 100644 index 0000000000000000000000000000000000000000..43ed41cedb6dda3889704352fc55e10c56d16d14 --- /dev/null +++ b/luennot/live13/KentanMuokkaus/Ohjelma.cs @@ -0,0 +1,20 @@ +using System; + +namespace KentanMuokkaus +{ + /// <summary> + /// The main class. + /// </summary> + public static class Program + { + /// <summary> + /// The main entry point for the application. + /// </summary> + [STAThread] + static void Main() + { + using var game = new KentanMuokkaus(); + game.Run(); + } + } +} \ No newline at end of file diff --git a/luennot/live13/Kertausta2/Kertausta2.cs b/luennot/live13/Kertausta2/Kertausta2.cs new file mode 100644 index 0000000000000000000000000000000000000000..f452a8f7e26fc21b07bb72924d075c5d1a111ca0 --- /dev/null +++ b/luennot/live13/Kertausta2/Kertausta2.cs @@ -0,0 +1,28 @@ +using System; + +/// @author Vesa Lappalainen +/// @version 10.10.2021 +/// +/// <summary> +/// Esimerkkejä +/// </summary> +public class Kertausta2 +{ + public static void Main() + { + // BYCODEBEGIN + int a = 4; + int b = 8; + + int summa = a + b; + + Console.WriteLine($"a = {a}, b = {b}, summa = {summa}"); // 1 + + a--; + Console.WriteLine($"a = {a}, b = {b}, summa = {summa}"); // 2 + + b = 2; + Console.WriteLine($"a = {a}, b = {b}, summa = {summa}"); // 3 + // BYCODEEND + } +} \ No newline at end of file diff --git a/luennot/live13/Kertausta2/Kertausta2.csproj b/luennot/live13/Kertausta2/Kertausta2.csproj new file mode 100644 index 0000000000000000000000000000000000000000..df22a1ba07d539b07cf0adbaa6457daadeb433db --- /dev/null +++ b/luennot/live13/Kertausta2/Kertausta2.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net7.0</TargetFramework> + <ExternalConsole>true</ExternalConsole> + </PropertyGroup> + +</Project> diff --git a/luennot/live13/MjPilkkominen/MjPilkkominen.cs b/luennot/live13/MjPilkkominen/MjPilkkominen.cs new file mode 100644 index 0000000000000000000000000000000000000000..edfdcc137b12ed95094bae6dca21757adf286c74 --- /dev/null +++ b/luennot/live13/MjPilkkominen/MjPilkkominen.cs @@ -0,0 +1,19 @@ +using System; +using System.Text; +using System.Linq; +using System.Collections.Generic; + +/// @author Omanimi +/// @version 16.10.2023 +/// <summary> +/// +/// </summary> +public class MjPilkkominen +{ + /// <summary> + /// + /// </summary> + public static void Main() + { + } +} \ No newline at end of file diff --git a/luennot/live13/MjPilkkominen/MjPilkkominen.csproj b/luennot/live13/MjPilkkominen/MjPilkkominen.csproj new file mode 100644 index 0000000000000000000000000000000000000000..df22a1ba07d539b07cf0adbaa6457daadeb433db --- /dev/null +++ b/luennot/live13/MjPilkkominen/MjPilkkominen.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net7.0</TargetFramework> + <ExternalConsole>true</ExternalConsole> + </PropertyGroup> + +</Project> diff --git a/luennot/live13/Muuttujat/Muuttujat.cs b/luennot/live13/Muuttujat/Muuttujat.cs new file mode 100644 index 0000000000000000000000000000000000000000..807ff2ef83c7a6ac95f70d73b1e991dd66222d38 --- /dev/null +++ b/luennot/live13/Muuttujat/Muuttujat.cs @@ -0,0 +1,17 @@ +using System; +public class Muuttujat +{ + public static void Main(string[] args) + { + int[] t = { 3, 5, 9 }; + Kasvata(t[0], t); + Console.WriteLine(String.Join(" ",t)); + } + + public static int Kasvata(int a, int[] t) + { + a++; + t[1]++; + return t[2]-1; + } +} \ No newline at end of file diff --git a/luennot/live13/Muuttujat/Muuttujat.csproj b/luennot/live13/Muuttujat/Muuttujat.csproj new file mode 100644 index 0000000000000000000000000000000000000000..df22a1ba07d539b07cf0adbaa6457daadeb433db --- /dev/null +++ b/luennot/live13/Muuttujat/Muuttujat.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net7.0</TargetFramework> + <ExternalConsole>true</ExternalConsole> + </PropertyGroup> + +</Project> diff --git a/luennot/live13/live13.sln b/luennot/live13/live13.sln new file mode 100644 index 0000000000000000000000000000000000000000..96d59a714b6b0d3ad48d5a0ead991f67d3d7bb84 --- /dev/null +++ b/luennot/live13/live13.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KentanMuokkaus", "KentanMuokkaus\KentanMuokkaus.csproj", "{4F14ECAF-1218-40DC-B64F-D3321DBA52FB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AngryLego", "AngryLego\AngryLego.csproj", "{E80AAAAF-0691-472C-9CEE-A6E5AEEA4F1E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MjPilkkominen", "MjPilkkominen\MjPilkkominen.csproj", "{3CEE0E5E-6CCD-45AF-8C37-5F63662C65DD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Muuttujat", "Muuttujat\Muuttujat.csproj", "{1250A748-EFC4-403E-8874-039BCB3AD225}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kertausta2", "Kertausta2\Kertausta2.csproj", "{CD230C5F-C1AB-4A06-8381-2CAD3D5736E9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4F14ECAF-1218-40DC-B64F-D3321DBA52FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F14ECAF-1218-40DC-B64F-D3321DBA52FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F14ECAF-1218-40DC-B64F-D3321DBA52FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F14ECAF-1218-40DC-B64F-D3321DBA52FB}.Release|Any CPU.Build.0 = Release|Any CPU + {E80AAAAF-0691-472C-9CEE-A6E5AEEA4F1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E80AAAAF-0691-472C-9CEE-A6E5AEEA4F1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E80AAAAF-0691-472C-9CEE-A6E5AEEA4F1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E80AAAAF-0691-472C-9CEE-A6E5AEEA4F1E}.Release|Any CPU.Build.0 = Release|Any CPU + {3CEE0E5E-6CCD-45AF-8C37-5F63662C65DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3CEE0E5E-6CCD-45AF-8C37-5F63662C65DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3CEE0E5E-6CCD-45AF-8C37-5F63662C65DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3CEE0E5E-6CCD-45AF-8C37-5F63662C65DD}.Release|Any CPU.Build.0 = Release|Any CPU + {1250A748-EFC4-403E-8874-039BCB3AD225}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1250A748-EFC4-403E-8874-039BCB3AD225}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1250A748-EFC4-403E-8874-039BCB3AD225}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1250A748-EFC4-403E-8874-039BCB3AD225}.Release|Any CPU.Build.0 = Release|Any CPU + {CD230C5F-C1AB-4A06-8381-2CAD3D5736E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD230C5F-C1AB-4A06-8381-2CAD3D5736E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD230C5F-C1AB-4A06-8381-2CAD3D5736E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD230C5F-C1AB-4A06-8381-2CAD3D5736E9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal