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

pong private

parent f710101f
No related branches found
No related tags found
No related merge requests found
public class Pisin3
{
public static void Main()
{
string pisin = PisinJono("Kissa", "Kana", "Krokotiili");
System.Console.WriteLine(pisin);
}
// BYCODEBEGIN
/// <summary>
/// Palauttaa pisinmmän jonon kolmesta
/// </summary>
/// <param name="a">eka jono</param>
/// <param name="b">toka jono</param>
/// <param name="c">kolmas jono</param>
/// <returns>pisin jonoista a,b,c</returns>
/// <example>
/// <pre name="test">
/// PisinJono("a", "23", "kissa") === "kissa";
/// PisinJono("abba", "23", "kiva") === "abba";
/// PisinJono("abba", "a23456", "kiva") === "a23456";
/// </pre>
/// </example>
public static string PisinJono(string a, string b, string c)
{
string voittaja = a;
if (voittaja.Length < b.Length) voittaja = b;
if (voittaja.Length < c.Length) voittaja = c;
return voittaja;
}
// BYCODEEND
}
\ 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 NUnit.Framework;
using static Pisin3;
[TestFixture]
[DefaultFloatingPointTolerance(0.000001)]
public class TestPisin3
{
[Test]
public void TestPisinJono18()
{
Assert.AreEqual( "kissa", PisinJono("a", "23", "kissa") , "in method PisinJono, line 19");
Assert.AreEqual( "abba", PisinJono("abba", "23", "kiva") , "in method PisinJono, line 20");
Assert.AreEqual( "a23456", PisinJono("abba", "a23456", "kiva") , "in method PisinJono, line 21");
}
}
<?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="..\Pisin3\Pisin3.csproj"/>
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using Jypeli;
using Jypeli.Assets;
using Jypeli.Controls;
using Jypeli.Widgets;
namespace Pong;
public class Pong : PhysicsGame
{
Vector nopeusYlos = new Vector(0, 200);
Vector nopeusAlas = new Vector(0, -200);
private readonly Vector nopeusYlos = new Vector(0, 200);
private readonly Vector nopeusAlas = new Vector(0, -200);
PhysicsObject pallo;
PhysicsObject maila1;
PhysicsObject maila2;
private PhysicsObject pallo; // attribuutti
private PhysicsObject maila1;
private PhysicsObject maila2;
PhysicsObject vasenReuna;
PhysicsObject oikeaReuna;
private PhysicsObject vasenReuna;
private PhysicsObject oikeaReuna;
IntMeter pelaajan1Pisteet;
IntMeter pelaajan2Pisteet;
private IntMeter pelaajan1Pisteet;
private IntMeter pelaajan2Pisteet;
public override void Begin()
{
LuoKentta();
......@@ -30,7 +27,8 @@ public class Pong : PhysicsGame
AloitaPeli();
}
void LuoKentta()
private void LuoKentta()
{
pallo = new PhysicsObject(40.0, 40.0);
pallo.Shape = Shape.Circle;
......@@ -70,7 +68,8 @@ public class Pong : PhysicsGame
Camera.ZoomToLevel();
}
PhysicsObject LuoMaila(double x, double y)
private PhysicsObject LuoMaila(double x, double y)
{
PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
maila.Shape = Shape.Rectangle;
......@@ -82,13 +81,15 @@ public class Pong : PhysicsGame
return maila;
}
void LisaaLaskurit()
private void LisaaLaskurit()
{
pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0);
pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0);
}
IntMeter LuoPisteLaskuri(double x, double y)
private IntMeter LuoPisteLaskuri(double x, double y)
{
IntMeter laskuri = new IntMeter(0);
laskuri.MaxValue = 10;
......@@ -105,7 +106,8 @@ public class Pong : PhysicsGame
return laskuri;
}
void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde)
private void KasittelePallonTormays(PhysicsObject _, PhysicsObject kohde)
{
if (kohde == oikeaReuna)
{
......@@ -117,13 +119,15 @@ public class Pong : PhysicsGame
}
}
void AloitaPeli()
private void AloitaPeli()
{
Vector impulssi = new Vector(500.0, 0.0);
pallo.Hit(impulssi * pallo.Mass);
}
void AsetaOhjaimet()
private void AsetaOhjaimet()
{
Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos);
Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);
......@@ -152,7 +156,7 @@ public class Pong : PhysicsGame
ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
}
void AsetaNopeus(PhysicsObject maila, Vector nopeus)
private void AsetaNopeus(PhysicsObject maila, Vector nopeus)
{
if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom))
{
......

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pong", "Pong\Pong.csproj", "{58322014-B6BC-4FE8-A137-0667D2DBE36A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pisin3", "Pisin3\Pisin3.csproj", "{3BE14AEB-4902-4DD6-A99C-881F7789FE81}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pisin3Test", "Pisin3Test\Pisin3Test.csproj", "{33A76487-FB7E-4BF0-9112-BCF67D7CF54A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.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
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Release|Any CPU.Build.0 = Release|Any CPU
{3BE14AEB-4902-4DD6-A99C-881F7789FE81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BE14AEB-4902-4DD6-A99C-881F7789FE81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BE14AEB-4902-4DD6-A99C-881F7789FE81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BE14AEB-4902-4DD6-A99C-881F7789FE81}.Release|Any CPU.Build.0 = Release|Any CPU
{33A76487-FB7E-4BF0-9112-BCF67D7CF54A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33A76487-FB7E-4BF0-9112-BCF67D7CF54A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33A76487-FB7E-4BF0-9112-BCF67D7CF54A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33A76487-FB7E-4BF0-9112-BCF67D7CF54A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pong", "Pong\Pong.csproj", "{58322014-B6BC-4FE8-A137-0667D2DBE36A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pisin3", "Pisin3\Pisin3.csproj", "{3BE14AEB-4902-4DD6-A99C-881F7789FE81}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58322014-B6BC-4FE8-A137-0667D2DBE36A}.Release|Any CPU.Build.0 = Release|Any CPU
{3BE14AEB-4902-4DD6-A99C-881F7789FE81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BE14AEB-4902-4DD6-A99C-881F7789FE81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BE14AEB-4902-4DD6-A99C-881F7789FE81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BE14AEB-4902-4DD6-A99C-881F7789FE81}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
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