Skip to content
Snippets Groups Projects
Commit 3d2ef4ea authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

live15 alku

parent aa82c006
No related branches found
No related tags found
No related merge requests found
Showing
with 441 additions and 0 deletions
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/projectSettingsUpdater.xml
/.idea.live15.iml
/contentModel.xml
/modules.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?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
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?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
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
/// @author vesal
/// @version 22.10.2023
/// <summary>
/// Kokeilaan taulukon kasvatusta
/// </summary>
public class KasvataTaulukkoa
{
/// <summary>
/// Kasvatetaan taulukkoa
/// </summary>
public static void Main()
{
int[] luvut = {3, 2, 5, 99};
int lkm = 4;
int[] t = luvut;
Array.Resize(ref luvut, 8);
luvut[4] = 55;
lkm = 5;
luvut[2] = 105;
for (int i=0; i<lkm; i++) Console.Write(luvut[i] + " ");
Console.WriteLine();
for (int i=0; i<lkm; i++) Console.Write(t[i] + " ");
Console.WriteLine();
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
</Project>
using Jypeli;
namespace LaskeMatka;
/// @author Vesa Lappalainen
/// @version 20.10.2020
///
/// <summary>
/// Piirretään näyttöön pisteitä ja lasketaan niiden välisiä etäisyyksiä
/// </summary>
public class LaskeMatka : PhysicsGame
{
/// <summary>Koordinaatistoakselit</summary>
private Axis akselit; // Atribuutti
private PhysicsObject klikattuPiste;
private const double x1 = -5;
private const double x2 = 20;
private const double y1 = -5;
private const double y2 = 20;
private const double pallonKoko = (y2 - y1) / 300;
private readonly Vector[] pisteet = new Vector[10]; // taulukolle
private int lkm = 0; // taulukolle
private readonly DoubleMeter yhteismatka = new DoubleMeter(0);
private Label matkanaytto;
public override void Begin()
{
Level.Background.Color = Color.White;
akselit = new Axis(x1, y1, x2, y2);
klikattuPiste = LuoPallo(this, Vector.Zero, 1.5 * pallonKoko, Color.Blue);
Camera.ZoomTo(x1, y1, x2, y2);
matkanaytto = new Label("0.0");
matkanaytto.BindTo(yhteismatka);
Add(matkanaytto);
matkanaytto.Position = new Vector(400, 300);
matkanaytto.DoubleFormatString = "{0:0.000} m";
AsetaOhjaimet();
LaskeMatkaNayttoon();
}
/// <summary>
/// Lasketaan matka ja laitetaan tulos näyttöön
/// </summary>
private void LaskeMatkaNayttoon()
{
double dist = SummaaEtaisyydet(pisteet, lkm); // Taulukolle
yhteismatka.Value = dist;
}
/// <summary>
/// Lasketaan listassa olevien pisteiden vöisten etäisyyksien summa
/// </summary>
/// <param name="pisteet"></param>
/// <param name="lkm">paljonko käytetty</param>
/// <returns></returns>
public static double SummaaEtaisyydet(Vector[] pisteet, int lkm) // taulukolle
{
double d = 0;
if (lkm < 2) return 0;
Vector p1 = pisteet[0];
for (int i = 1; i < lkm; i++)
{
Vector p2 = pisteet[i];
double s = Vector.Distance(p1, p2);
d += s;
p1 = p2;
}
return d;
}
/// <summary>
/// Asetetaan ohjaimet peliä varten. F1 ja ESC.
/// Kuunnellaan hiiren paikkaa ja siirretään merkkipisteen sen mukaan mihin klikattu
/// Samoin kuunnellaan puhelimelta sormella tökkäisyä.
/// </summary>
private void AsetaOhjaimet()
{
Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
Mouse.IsCursorVisible = true;
// Keyboard.Listen(Key.Delete, ButtonState.Pressed, PoistaPisteet, "Poistaa kaikki pisteet");
Mouse.Listen(MouseButton.Left, ButtonState.Pressed, delegate { LisaaPiste(Mouse.PositionOnWorld); }, "Laita piste");
// Mouse.Listen(MouseButton.Right, ButtonState.Pressed, PoistaPisteet, "Laita piste");
// TouchPanel.Listen(ButtonState.Pressed, delegate(Touch kosketus) { SiirraMerkkipisteet(kosketus.PositionOnWorld); }, null);
// TouchPanel.ListenGesture(GestureType.VerticalDrag, delegate(Touch touch) { KysyKoordinaatti(); }, "Kysy");
PhoneBackButton.Listen(Exit, "Lopeta peli");
}
/// <summary>
/// Lisätään piste näyttöön ja listaan
/// </summary>
/// <param name="piste">paikka johon sininen piste</param>
private void LisaaPiste(Vector piste)
{
// siirretään sininen pisteen kohdalle
klikattuPiste.Position = piste;
if ( lkm < pisteet.Length ) { pisteet[lkm] = piste; lkm++; } // taulukolle
// pisteet.Add(piste); // listalle
LuoPallo(this, piste, pallonKoko, Color.Black);
LaskeMatkaNayttoon();
}
/// <summary>
/// Piirretään viivat pisteiden välille.
/// </summary>
/// <param name="canvas"></param>
private void PiirraPisteidenValisteViivat(Canvas canvas)
{
if (lkm < 2) return;
canvas.BrushColor = Color.Green;
Vector p1 = pisteet[0];
for (int i = 1; i < lkm; i++)
{
Vector p2 = pisteet[i];
canvas.DrawLine(p1, p2);
p1 = p2;
}
}
/// <summary>
/// Lisätään peliin pallo
/// </summary>
/// <param name="game">peli johon pallo lisätään</param>
/// <param name="p">pallon keskipiste</param>
/// <param name="r">pallon säde</param>
/// <param name="color">pallon väri</param>
/// <returns>lisätyn pallon viite</returns>
public static PhysicsObject LuoPallo(PhysicsGame game, Vector p, double r, Color color)
{
PhysicsObject pallo = new PhysicsObject(r * 2, r * 2, Shape.Circle);
pallo.Position = p;
pallo.Color = color;
game.Add(pallo);
return pallo;
}
/// <summary>
/// Tämä tehdään aina kun ruutua pitää päivittää
/// </summary>
/// <param name="canvas">Piirtoalue, johon voi piirtää</param>
protected override void Paint(Canvas canvas)
{
akselit.Draw(canvas);
PiirraPisteidenValisteViivat(canvas);
}
}
/// <summary>
/// Luokka koordinaatiston piirtämistä varten
/// </summary>
public class Axis
{
private readonly double x1, x2, y1, y2;
public Color Color { set; get; }
/// <summary>
/// Alustetaan koordinaatisto haluttuihin rajoihin
/// </summary>
/// <param name="x1">alueen vasemman alakulman x</param>
/// <param name="y1">alueen vasemman alakulman y</param>
/// <param name="x2">alueen vasemman yläkulman x</param>
/// <param name="y2">alueen vasemman yläkulman y</param>
public Axis(double x1, double y1, double x2, double y2)
{
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
Color = Color.Black;
}
/// <summary>
/// Piirretään koordinaatisto niin, että tulee x ja y akselit ja niihin
/// yhden välein pikkutikkuja.
/// </summary>
/// <param name="canvas">Canvas-olio, johon piirto tehdään</param>
public void Draw(Canvas canvas)
{
canvas.BrushColor = Color;
double t = (y2 - y1) / 200; // tikkujen koko
// X-akseli
canvas.DrawLine(new Vector(x1, 0), new Vector(x2, 0));
// Tikut X-akselille 0:sta lähtien kumpaankin suuntaan
for (double x = 0; x >= x1; x -= 1.0) canvas.DrawLine(new Vector(x, -t), new Vector(x, t));
for (double x = 0; x <= x2; x += 1.0) canvas.DrawLine(new Vector(x, -t), new Vector(x, t));
// Y -akseli
canvas.DrawLine(new Vector(0, y1), new Vector(0, y2));
// Tikut Y-akselille 0:sta lähtien kumpaankin suuntaan
for (double y = 0; y >= y1; y -= 1.0) canvas.DrawLine(new Vector(-t, y), new Vector(t, y));
for (double y = 0; y <= y2; y += 1.0) canvas.DrawLine(new Vector(-t, y), new Vector(t, y));
}
}
<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>
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace LaskeMatka
{
/// <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 LaskeMatka();
game.Run();
}
}
}
\ No newline at end of file
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
/// @author Vesa Lappalainen
/// @version 22.10.2023
/// <summary>
/// Tutkitaan listojen käyttäytymistä
/// </summary>
public class Listat
{
/// <summary>
/// Esimerkki listoista
/// </summary>
public static void Main()
{
int[] taulukko = { 3, 5, 6, 99, 5, 5, 2, 23 };
// taulukko = new int[6];
int tkoko = taulukko.Length;
Console.WriteLine(String.Join(" ", taulukko) + " koko: " + tkoko);
taulukko[1] = 9;
int suurin = Suurin(taulukko);
Console.WriteLine("Suurin: " + suurin);
}
/// <summary>
/// Etsitään taulukon suurin
/// </summary>
/// <param name="luvut">lista josta suurinta etsitään</param>
/// <returns>listan suurin tai 0 jos lista tyhjä</returns>
/// <example>
/// <pre name="test">
/// int[] lista = {5,3,8,7};
/// Suurin(lista) === 8;
/// Suurin(new int[]{1,2,3}) === 3;
/// Suurin(new int[]{4,2,3}) === 4;
/// Suurin(new int[]{1,5,3}) === 5;
/// Suurin(new int[0]) === 0;
/// </pre>
/// </example>
public static int Suurin(int[] luvut)
{
if (luvut.Length == 0) return 0;
int suurin = luvut[0];
foreach (int luku in luvut)
if (luku > suurin) suurin = luku;
return suurin;
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KasvataTaulukkoa", "KasvataTaulukkoa\KasvataTaulukkoa.csproj", "{B099DBC9-FA97-401D-A15D-6AB3BD56C6DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaskeMatka", "LaskeMatka\LaskeMatka.csproj", "{0C3C7C0A-B68B-4BF9-987B-43F2D55613C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Listat", "Listat\Listat.csproj", "{C64228A6-8056-4C07-AA9A-F4959B1BF9CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B099DBC9-FA97-401D-A15D-6AB3BD56C6DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B099DBC9-FA97-401D-A15D-6AB3BD56C6DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B099DBC9-FA97-401D-A15D-6AB3BD56C6DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B099DBC9-FA97-401D-A15D-6AB3BD56C6DD}.Release|Any CPU.Build.0 = Release|Any CPU
{0C3C7C0A-B68B-4BF9-987B-43F2D55613C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C3C7C0A-B68B-4BF9-987B-43F2D55613C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C3C7C0A-B68B-4BF9-987B-43F2D55613C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C3C7C0A-B68B-4BF9-987B-43F2D55613C0}.Release|Any CPU.Build.0 = Release|Any CPU
{C64228A6-8056-4C07-AA9A-F4959B1BF9CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C64228A6-8056-4C07-AA9A-F4959B1BF9CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C64228A6-8056-4C07-AA9A-F4959B1BF9CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C64228A6-8056-4C07-AA9A-F4959B1BF9CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/modules.xml
/.idea.luento15.iml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?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
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment