Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
esimerkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tie
ohj1
2024s
esimerkit
Commits
d844201e
Commit
d844201e
authored
6 months ago
by
Vesa Lappalainen
Browse files
Options
Downloads
Patches
Plain Diff
luento14 taulukolla
parent
2acd942f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
luennot/luento14/LaskeMatka/LaskeMatka.cs
+16
-15
16 additions, 15 deletions
luennot/luento14/LaskeMatka/LaskeMatka.cs
with
16 additions
and
15 deletions
luennot/luento14/LaskeMatka/LaskeMatka.cs
+
16
−
15
View file @
d844201e
using
System.Collections.Generic
;
using
Jypeli
;
using
Jypeli
;
//
using
System.Collections.Generic
;
/// @author Vesa Lappalainen
/// @version 22.10.2012
...
...
@@ -30,10 +30,10 @@ public class LaskeMatka : PhysicsGame
/// <summary>Koordinaatit piirretyille pisteille</summary>
//
private Vector[] pisteet = new Vector[10]; // taulukolle
//
private int lkm = 0;
// taulukolle
private
Vector
[]
pisteet
=
new
Vector
[
10
];
// taulukolle
private
int
lkm
;
//
= 0;
// attribuutti on 0 ilmankin = 0;
// taulukolle
private
readonly
List
<
Vector
>
pisteet
=
new
List
<
Vector
>();
// listalle
//
private readonly List<Vector> pisteet = new List<Vector>(); // listalle
private
readonly
DoubleMeter
yhteismatka
=
new
DoubleMeter
(
200
);
private
Label
matkanaytto
;
...
...
@@ -66,8 +66,8 @@ public class LaskeMatka : PhysicsGame
/// </summary>
private
void
LaskeMatkaNayttoon
()
{
//
double dist = SummaaEtaisyydet(pisteet, lkm); // Taulukolle
double
dist
=
SummaaEtaisyydet
(
pisteet
);
// Listalle
double
dist
=
SummaaEtaisyydet
(
pisteet
,
lkm
);
// Taulukolle
//
double dist = SummaaEtaisyydet(pisteet); // Listalle
yhteismatka
.
Value
=
dist
;
}
...
...
@@ -76,12 +76,13 @@ public class LaskeMatka : PhysicsGame
/// Lasketaan listassa olevien pisteiden vöisten etäisyyksien summa
/// </summary>
/// <param name="pisteet"></param>
/// <param name="lkm">käytettyjen alkioiden lukumäärä</param>
/// <returns></returns>
//
public static double SummaaEtaisyydet(Vector[] pisteet, int lkm) // taulukolle
public
static
double
SummaaEtaisyydet
(
List
<
Vector
>
pisteet
)
// listalle
public
static
double
SummaaEtaisyydet
(
Vector
[]
pisteet
,
int
lkm
)
// taulukolle
//
public static double SummaaEtaisyydet(List<Vector> pisteet) // listalle
{
double
d
=
0
;
int
lkm
=
pisteet
.
Count
;
// listalle
//
int lkm = pisteet.Count; // listalle
if
(
lkm
<
2
)
return
0
;
Vector
p1
=
pisteet
[
0
];
for
(
int
i
=
1
;
i
<
lkm
;
i
++)
...
...
@@ -101,7 +102,7 @@ public class LaskeMatka : PhysicsGame
/// <param name="canvas"></param>
private
void
PiirraPisteidenValisteViivat
(
Canvas
canvas
)
{
int
lkm
=
pisteet
.
Count
;
// listalle
//
int lkm = pisteet.Count; // listalle
if
(
lkm
<
2
)
return
;
canvas
.
BrushColor
=
Color
.
Green
;
Vector
p1
=
pisteet
[
0
];
...
...
@@ -143,8 +144,8 @@ public class LaskeMatka : PhysicsGame
ClearGameObjects
();
Add
(
matkanaytto
);
//
pisteet = new Vector[100]; lkm = 0; // taulukolle
pisteet
.
RemoveRange
(
0
,
pisteet
.
Count
);
// listalle
pisteet
=
new
Vector
[
100
];
lkm
=
0
;
// taulukolle
//
pisteet.RemoveRange(0, pisteet.Count); // listalle
LaskeMatkaNayttoon
();
}
...
...
@@ -158,8 +159,8 @@ public class LaskeMatka : PhysicsGame
{
// siirretään sininen pisteen kohdalle
klikattuPiste
.
Position
=
piste
;
//
if ( lkm < pisteet.Length ) { pisteet[lkm] = piste; lkm++; } // taulukolle
pisteet
.
Add
(
piste
);
// listalle
if
(
lkm
<
pisteet
.
Length
)
{
pisteet
[
lkm
]
=
piste
;
lkm
++;
}
// taulukolle
//
pisteet.Add(piste); // listalle
LuoPallo
(
this
,
piste
,
pallonKoko
,
Color
.
Black
);
LaskeMatkaNayttoon
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment