diff --git a/Harkkatyo/.idea/.idea.Harkkatyo/.idea/.gitignore b/Harkkatyo/.idea/.idea.Harkkatyo/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e4e6de70f1c6e6c2ffaef0b2db3adcecd57989e0 --- /dev/null +++ b/Harkkatyo/.idea/.idea.Harkkatyo/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/contentModel.xml +/projectSettingsUpdater.xml +/.idea.Harkkatyo.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Harkkatyo/.idea/.idea.Harkkatyo/.idea/encodings.xml b/Harkkatyo/.idea/.idea.Harkkatyo/.idea/encodings.xml new file mode 100644 index 0000000000000000000000000000000000000000..df87cf951fb4858ab7a76b68dd479c98b2df2404 --- /dev/null +++ b/Harkkatyo/.idea/.idea.Harkkatyo/.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/Harkkatyo/.idea/.idea.Harkkatyo/.idea/indexLayout.xml b/Harkkatyo/.idea/.idea.Harkkatyo/.idea/indexLayout.xml new file mode 100644 index 0000000000000000000000000000000000000000..7b08163cebc50fb3e777eea4881b68fcebc10590 --- /dev/null +++ b/Harkkatyo/.idea/.idea.Harkkatyo/.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/Harkkatyo/.idea/.idea.Harkkatyo/.idea/vcs.xml b/Harkkatyo/.idea/.idea.Harkkatyo/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..6c0b8635858dc7ad44b93df54b762707ce49eefc --- /dev/null +++ b/Harkkatyo/.idea/.idea.Harkkatyo/.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/Harkkatyo/Harkkatyo.sln b/Harkkatyo/Harkkatyo.sln new file mode 100644 index 0000000000000000000000000000000000000000..ee1a416a011667d361b75fca02643a3813bf3970 --- /dev/null +++ b/Harkkatyo/Harkkatyo.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Harkkatyo", "Harkkatyo\Harkkatyo.csproj", "{3C7BD4BB-6FAE-4565-9066-5B29352AF18A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3C7BD4BB-6FAE-4565-9066-5B29352AF18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C7BD4BB-6FAE-4565-9066-5B29352AF18A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C7BD4BB-6FAE-4565-9066-5B29352AF18A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C7BD4BB-6FAE-4565-9066-5B29352AF18A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Harkkatyo/Harkkatyo/Harkkatyo.cs b/Harkkatyo/Harkkatyo/Harkkatyo.cs new file mode 100644 index 0000000000000000000000000000000000000000..b93256a88799a3e490cc2567f40b3b88e816f0c7 --- /dev/null +++ b/Harkkatyo/Harkkatyo/Harkkatyo.cs @@ -0,0 +1,264 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using FontStashSharp.Interfaces; +using Jypeli; +using Jypeli.Assets; +using Jypeli.Controls; +using Jypeli.Widgets; + +namespace Harkkatyo; + +/// @author Markus Vaajala +/// @version 15.11.2023 +/// <summary> +/// +/// </summary> +public class Harkkatyo : PhysicsGame +{ + private Label tekstikentta; + private Label vastauskentta; + private int vastaus; + private IntMeter pistelaskuri; + private IntMeter voimamittari; + + public override void Begin() + { + Camera.ZoomToLevel(); + LuoKentta(this); + ArvotaanLasku(); + + PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); + Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); + } + + public void LuoKentta(PhysicsGame peli) + { + PiirraPaaRuutu(peli, 0, 0); // Piirtää valkoisen pääruuduun, johon tulee laskutehtävä; + PiirraNollaJaMiinus(peli, 0, 0); // Piirtää napit nollalle ja miinusmerkille; + PiirraNappaimet(peli, -170, y: 200); // Piirtää näppäimet 1-9 peliin + PiirraPisteLaskuri(peli, 0, 0); // Piirtää valkoisen ruudun oikeaan yläkulmaan + //PiirraEdistysPalkki(peli, 0, 0); // Piirretään neliö alkamaan alakulmasta + //PiirraAikaLaskuri(peli, 0, 0); // Piirretään laskuri aikaa varten + PiirraVastaus(peli, 0, 0); // Piirtää valkoisen vastausnapin + LuoPistelaskuri(0, 0); // Tekee pistelaskurin oikeaan yläkulmaan + EdistysPalkki(0,0); // Piirtää oikealle kasvavan edistymispalkin + + // Luodaan yläpalkkiin kenttä, johon tulee tehtäviä + tekstikentta = new Label(300, 20, " "); + tekstikentta.X = 0; + tekstikentta.Y = Screen.Top - 100; + peli.Add(tekstikentta); + + //Luodaan yläpalkkiin kenttä, johon käyttäjä syöttää vastaukset + vastauskentta = new Label(300, 20, " "); + vastauskentta.X = 50; + vastauskentta.Y = Screen.Top - 100; + peli.Add(vastauskentta); + } + // Piirretään ruutu, johon kysyttävä tehtävä ja syötettävä vastaus ilmestyvät + public static void PiirraPaaRuutu(PhysicsGame peli, double x, double y) + { + + PhysicsObject p1; + p1 = new PhysicsObject(450, 140, Shape.Rectangle); + p1.X = x; + p1.Y = y + 300; + peli.Add(p1); + } + // Piirretään vastausnappi, jolla vahvistetaan syötetty vastaus + public void PiirraVastaus(PhysicsGame peli, + double x, double y) + { + + PhysicsObject vastausnappi; + vastausnappi = new PhysicsObject(80, 80, Shape.Rectangle); + vastausnappi.X = x + 300; + vastausnappi.Y = y + 250; + peli.Add(vastausnappi); + Label vastaus = new Label(70.0, 30.0, "Check"); + vastaus.X = x+290; + vastaus.Y = y+240; + peli.Add(vastaus); + peli.Mouse.ListenOn(vastausnappi, MouseButton.Left, ButtonState.Pressed, TarkistaVastaus, null); + } + + + // Luodaan edistymispalkki, joka kasvaa kun vastaus on oikein + + public void EdistysPalkki(double x, double y) + { + voimamittari = new IntMeter(0); + voimamittari.MaxValue = 80; + + ProgressBar voimapalkki = new ProgressBar(200, 50); + + voimapalkki.X = x+440; + voimapalkki.Y = y-100; + voimapalkki.BarColor = Color.Green; + voimapalkki.BorderColor = Color.White; + voimapalkki.Angle = Angle.FromDegrees(270); + voimapalkki.BindTo(voimamittari); + Add(voimapalkki); + } + // Luodaan pistelaskuri, joka kasvattaa pistemaaraa yhdella,cd /c kun vastaus on oikein + public void LuoPistelaskuri(double x, double y) + { + pistelaskuri = new IntMeter(0); + + Label pistenaytto = new Label(); + pistenaytto.X = x + 430; + pistenaytto.Y = y + 330; + pistenaytto.TextColor = Color.Black; + pistenaytto.Title = "Pisteet: "; + + pistenaytto.BindTo(pistelaskuri); + Add(pistenaytto); + } + // Luodaan aliohjelma, joka tarkistaa onko syötetty vastaus oikein. + public void TarkistaVastaus() + { + int numero1 = vastaus; + if (vastauskentta.Text.Equals(" " + numero1)) + { + pistelaskuri.Value += 1; + ArvotaanLasku(); + vastauskentta.Text = " "; + voimamittari.Value += 5; + } + else + { + pistelaskuri.Value -= 1; + ArvotaanLasku(); + vastauskentta.Text = " "; + voimamittari.Value -= 1; + } + + + + } + // Luodaan aliohjelma, joka piirtää näppäimen + public void PiirraNappain(PhysicsGame peli, + double x, double y, int tag) + { + PhysicsObject nappain; + nappain = new PhysicsObject(80, 80, Shape.Rectangle); + nappain.X = x; + nappain.Y = y; + nappain.Tag = tag; + peli.Add(nappain); + Label numeroNappain = new Label(70.0, 30.0, tag + ""); + numeroNappain.X = x; + numeroNappain.Y = y; + Add(numeroNappain); + peli.Mouse.ListenOn(nappain, MouseButton.Left, ButtonState.Pressed, Klikattiin, null, nappain); + } + // Piirretään näppäin nollalle ja miinusmerkille + public void PiirraNollaJaMiinus(PhysicsGame peli, + double x, double y) + { + PhysicsObject nolla; + nolla = new PhysicsObject(80, 80, Shape.Rectangle); + nolla.X = x+10; + nolla.Y = y-160; + nolla.Tag = 0; + peli.Add(nolla); + Label nollaNappi = new Label(70.0, 30.0, 0 + ""); + nollaNappi.X = x+10; + nollaNappi.Y = y-160; + peli.Add(nollaNappi); + peli.Mouse.ListenOn(nolla, MouseButton.Left, ButtonState.Pressed, Klikattiin, null, nolla); + + PhysicsObject p12; + p12 = new PhysicsObject(80, 80, Shape.Rectangle); + p12.X = x + 200; + p12.Y = y+110; + peli.Add(p12); + Label miinus = new Label(120.0, 50.0,"-"); + miinus.X = x+200; + miinus.Y = y+110; + peli.Add(miinus); + + + } + // Piirretään näppäimet 1-9 silmukalla ja lisätään tagit hiirelläklikkailua varten + public void PiirraNappaimet(PhysicsGame peli, + double x, double y) + { + int tag = 1; + for (int rivi=1; rivi <= 3; rivi++) + { + for (int sarake = 1; sarake <= 3; sarake++) + { + PiirraNappain(peli, 90*sarake+x, -90*rivi+y, tag); + tag++; + } + + } + + + } + // Luodaan aliohjelma, joka kirjoittaa vastauskenttään klikatun numeron + public void Klikattiin(PhysicsObject klikattu) + { + int numero = int.Parse(klikattu.Tag.ToString()); + vastauskentta.Text += numero + ""; + + } + // Luodaan vasempaan yläkulmaan laskurin ruutu, jossa rullaa aika + public static void PiirraAikaLaskuri(PhysicsGame peli, + double x, double y) + { + PhysicsObject p13; + p13 = new PhysicsObject(150, 100, Shape.Rectangle); + p13.X = x-450; + p13.Y = y+340; + peli.Add(p13); + } + // Luodaan oikeaan yläkulmaan laskurin ruutu, jossa rullaa pisteet + public static void PiirraPisteLaskuri(PhysicsGame peli, + double x, double y) + { + PhysicsObject p14; + p14 = new PhysicsObject(150, 100, Shape.Rectangle); + p14.X = x+450; + p14.Y = y+340; + peli.Add(p14); + } + // Luodaan oikeaan reunaan edistyspalkki, joka kasvaa oikeista vastauksista + /*public static void PiirraEdistysPalkki(PhysicsGame peli, + double x, double y) + { + PhysicsObject p15; + p15 = new PhysicsObject(60, 300, Shape.Rectangle); + p15.X = x+465; + p15.Y = y-5; + peli.Add(p15); + }*/ + + + // Luodaan ohjelma, joka arpoo laskutehtäviä ylhäällä olevaan ruutuun + public void ArvotaanLasku() + { + + int luku = RandomGen.NextInt(10); + int luku1 = RandomGen.NextInt(10); + string[] taulukko = { " * ", " + " }; + string merkki = taulukko[RandomGen.NextInt(0,2)]; + if (merkki == taulukko[0]) + vastaus = luku * luku1; + if (merkki == taulukko[1]) + vastaus = luku + luku1; + tekstikentta.Text = luku + merkki + luku1 + " = "; + + + + + + + } + + + + +} diff --git a/Harkkatyo/Harkkatyo/Harkkatyo.csproj b/Harkkatyo/Harkkatyo/Harkkatyo.csproj new file mode 100644 index 0000000000000000000000000000000000000000..fb98d03a9ae4d4aa96925e3188b491c8294da81d --- /dev/null +++ b/Harkkatyo/Harkkatyo/Harkkatyo.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/Harkkatyo/Harkkatyo/Ohjelma.cs b/Harkkatyo/Harkkatyo/Ohjelma.cs new file mode 100644 index 0000000000000000000000000000000000000000..3f449df505cd0b1ad1ae9c1f29185aa0faf28551 --- /dev/null +++ b/Harkkatyo/Harkkatyo/Ohjelma.cs @@ -0,0 +1,26 @@ +#region Using Statements + +using System; +using System.Collections.Generic; +using System.Linq; + +#endregion + +namespace Harkkatyo +{ + /// <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 Harkkatyo(); + game.Run(); + } + } +} \ No newline at end of file