Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ohj1ht
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
vepsanew
ohj1ht
Commits
696e32e9
Commit
696e32e9
authored
2 weeks ago
by
Vepsäläinen Noora Ella Julia
Browse files
Options
Downloads
Patches
Plain Diff
Koodin muokkaamista ja viimeistelyä
parent
fd67d657
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
Harjoitustyö/HenrinJuustoJahti/HenrinJuustoJahti.cs
+61
-34
61 additions, 34 deletions
Harjoitustyö/HenrinJuustoJahti/HenrinJuustoJahti.cs
with
61 additions
and
34 deletions
Harjoitustyö/HenrinJuustoJahti/HenrinJuustoJahti.cs
+
61
−
34
View file @
696e32e9
using
System
;
using
Jypeli
;
using
System.Collections.Generic
;
namespace
HenrinJuustoJahti
;
...
...
@@ -19,7 +20,7 @@ public class HenrinJuustoJahti : PhysicsGame
/// </summary>
private
const
double
HYPPYNOPEUS
=
750
;
/// <summary>
///
Julkinen p
elaaja.
///
P
elaaja.
/// </summary>
private
PlatformCharacter
pelaaja
;
/// <summary>
...
...
@@ -34,22 +35,14 @@ public class HenrinJuustoJahti : PhysicsGame
/// Juustojen määrä.
/// </summary>
private
int
juustojenMaara
;
/// <summary>
/// Juuston kuva.
/// </summary>
Image
juustoKuva
=
LoadImage
(
"Juusto.png"
);
/// <summary>
///
Hiirenloukun kuva.
///
Lista, johon tallennetaan kerättyjen juustojen määrä
/// </summary>
Image
hiirenloukkuKuva
=
LoadImage
(
"Hiirenloukku.png"
);
/// <summary>
/// Henri hiirulaisen kuva.
/// </summary>
Image
henrinKuva
=
LoadImage
(
"Henri.png"
);
private
readonly
List
<
int
>
keratytJuustot
=
new
List
<
int
>();
/// <summary>
/// Tämä ohjelma kutsuu aliohjelmia ja
pyö
ritt
ää peliä
.
/// Tämä ohjelma kutsuu aliohjelmia ja
suo
ritt
aa ne
.
/// </summary>
public
override
void
Begin
()
{
...
...
@@ -63,7 +56,7 @@ public class HenrinJuustoJahti : PhysicsGame
/// </summary>
private
void
LuoKentta
()
{
Level
.
Background
.
Color
=
Color
.
SkyBlue
;
Level
.
Background
.
Color
=
Color
.
Lavender
;
LisaaTaso
(
new
Vector
(
0
,
-
200
),
1600
,
40
);
LisaaPelaaja
(
new
Vector
(
0
,
-
180
),
40
,
40
);
LuoTasot
();
...
...
@@ -99,7 +92,7 @@ public class HenrinJuustoJahti : PhysicsGame
Random
rng
=
new
Random
();
juustojenMaara
=
0
;
for
(
int
rivi
=
0
;
rivi
<
8
;
rivi
++)
// Määrittää, kuinka korkealle tasoja luodaan.
for
(
int
rivi
=
0
;
rivi
<
5
;
rivi
++)
// Määrittää, kuinka korkealle tasoja luodaan.
{
for
(
int
sarake
=
-
2
;
sarake
<=
2
;
sarake
++)
{
...
...
@@ -107,9 +100,10 @@ public class HenrinJuustoJahti : PhysicsGame
double
tasoY
=
y
+
rivi
*
150
+
rng
.
Next
(-
20
,
20
);
PhysicsObject
taso
=
LisaaTaso
(
new
Vector
(
tasoX
,
tasoY
),
100
,
20
);
bool
onVihollinen
=
rng
.
Next
(
100
)
<
30
;
LisaaJuustoTaiLoukku
(
new
Vector
(
taso
.
Position
.
X
,
taso
.
Position
.
Y
+
(
taso
.
Height
/
2
)
+
10
),
20
,
20
,
onVihollinen
);
if
(!
onVihollinen
)
bool
onHiirenloukku
=
rng
.
Next
(
100
)
<
30
;
LisaaJuustoTaiLoukku
(
new
Vector
(
taso
.
Position
.
X
,
taso
.
Position
.
Y
+
(
taso
.
Height
/
2
)
+
10
),
20
,
20
,
onHiirenloukku
);
if
(!
onHiirenloukku
)
{
juustojenMaara
++;
}
...
...
@@ -125,24 +119,25 @@ public class HenrinJuustoJahti : PhysicsGame
/// <param name="paikka"></param>
/// <param name="leveys"></param>
/// <param name="korkeus"></param>
/// <param name="on
Vihollinen
"></param>
private
void
LisaaJuustoTaiLoukku
(
Vector
paikka
,
double
leveys
,
double
korkeus
,
bool
on
Vihollinen
=
false
)
/// <param name="on
Hiirenloukku
"></param>
private
void
LisaaJuustoTaiLoukku
(
Vector
paikka
,
double
leveys
,
double
korkeus
,
bool
on
Hiirenloukku
=
false
)
{
PhysicsObject
esine
=
new
PhysicsObject
(
leveys
,
korkeus
,
Shape
.
Circle
);
esine
.
Position
=
paikka
;
esine
.
IgnoresExplosions
=
true
;
if
(
on
Vihollinen
)
if
(
on
Hiirenloukku
)
{
esine
.
Color
=
Color
.
Red
;
esine
.
Tag
=
"vihollinen"
;
esine
.
Tag
=
"hiirenloukku"
;
Image
hiirenloukkuKuva
=
LoadImage
(
"Hiirenloukku.png"
);
esine
.
Image
=
hiirenloukkuKuva
;
esine
.
Size
*=
5
;
}
else
{
esine
.
Color
=
Color
.
Yellow
;
esine
.
Tag
=
"tahti"
;
esine
.
Tag
=
"juusto"
;
Image
juustoKuva
=
LoadImage
(
"Juusto.png"
);
esine
.
Image
=
juustoKuva
;
esine
.
Size
*=
4
;
}
...
...
@@ -161,14 +156,14 @@ public class HenrinJuustoJahti : PhysicsGame
pelaaja
=
new
PlatformCharacter
(
leveys
,
korkeus
);
pelaaja
.
Position
=
paikka
;
pelaaja
.
Mass
=
4.0
;
pelaaja
.
Color
=
Color
.
Gray
;
Image
henrinKuva
=
LoadImage
(
"Henri.png"
)
;
pelaaja
.
Image
=
henrinKuva
;
pelaaja
.
Size
*=
1.5
;
Add
(
pelaaja
);
AddCollisionHandler
(
pelaaja
,
"
tahti
"
,
TormaaJuustoon
);
AddCollisionHandler
(
pelaaja
,
"
vihollinen
"
,
PelaajaKuolee
);
AddCollisionHandler
(
pelaaja
,
"
juusto
"
,
TormaaJuustoon
);
AddCollisionHandler
(
pelaaja
,
"
hiirenloukku
"
,
PelaajaKuolee
);
}
/// <summary>
...
...
@@ -214,6 +209,8 @@ public class HenrinJuustoJahti : PhysicsGame
{
juusto
.
Destroy
();
pistelaskuri
.
Value
+=
1
;
keratytJuustot
.
Add
(
1
);
MessageDisplay
.
Clear
();
// Poistaa edelliset viestit
MessageDisplay
.
Add
(
"JEEEEE löysit JUUSTOA!"
);
...
...
@@ -233,12 +230,14 @@ public class HenrinJuustoJahti : PhysicsGame
{
Label
viesti
=
new
Label
(
"VOI EI, jäit kiinni HIIRENLOUKKUUN :("
);
viesti
.
TextColor
=
Color
.
White
;
viesti
.
Color
=
Color
.
Red
;
viesti
.
Font
=
new
Font
(
50
);
viesti
.
X
=
0
;
viesti
.
Y
=
0
;
Add
(
viesti
);
pelaaja
.
Destroy
();
hiirenloukku
.
Destroy
();
Timer
.
SingleShot
(
2
,
Exit
);
}
...
...
@@ -247,30 +246,57 @@ public class HenrinJuustoJahti : PhysicsGame
/// </summary>
private
void
Voitto
()
{
Label
voittoViesti
=
new
Label
(
"HYVÄ LÖYSIT KAIKKI JUUSTOT!!!"
);
voittoViesti
.
TextColor
=
Color
.
Green
;
int
juustojenSumma
=
keratytJuustot
.
Count
;
double
kulunutAika
=
Laskekulunutaika
();
Label
voittoViesti
=
new
Label
(
$" HYVÄ!! Löysit Henrille
{
juustojenSumma
}
JUUSTOA!\n Juustojahdissasi "
+
$"kesti
{
kulunutAika
:
F2
}
sekuntia!"
);
voittoViesti
.
TextColor
=
Color
.
White
;
voittoViesti
.
Color
=
Color
.
Green
;
voittoViesti
.
Font
=
new
Font
(
50
);
voittoViesti
.
Position
=
Vector
.
Zero
;
Add
(
voittoViesti
);
Timer
.
SingleShot
(
2
.0
,
Exit
);
Timer
.
SingleShot
(
5
.0
,
Exit
);
}
/// <summary>
/// Tämä aliohjelma
kerää tietoa kerättyjen
juustojen
luku
määrä
stä
.
/// Tämä aliohjelma
näyttää kerättyjen pisteiden eli
juustojen määrä
n
.
/// </summary>
private
void
LuoPistelaskuri
()
{
pistelaskuri
=
new
IntMeter
(
0
);
pistenaytto
=
new
Label
();
pistenaytto
.
X
=
Screen
.
Left
+
100
;
pistenaytto
.
Y
=
Screen
.
Top
-
40
;
pistenaytto
.
Position
=
LaskeSijaintiRuudulla
(
90
,
50
);
pistenaytto
.
TextColor
=
Color
.
Black
;
pistenaytto
.
Color
=
Color
.
White
;
pistenaytto
.
Title
=
"
Pistee
t: "
;
pistenaytto
.
Title
=
"
Kerätyt juusto
t: "
;
pistenaytto
.
BindTo
(
pistelaskuri
);
Add
(
pistenaytto
);
}
/// <summary>
/// Tämä aliohjelma laskee kuinka kauan peli kestää.
/// </summary>
/// <returns></returns>
private
double
Laskekulunutaika
()
{
double
aika
=
Time
.
SinceStartOfGame
.
TotalSeconds
;
return
aika
;
}
/// <summary>
/// Tämä aliohjelma laskee halutun objektin sijainnin ruudulla suhteessa reuniin.
/// </summary>
/// <param name="leveys"></param>
/// <param name="korkeus"></param>
/// <returns></returns>
private
Vector
LaskeSijaintiRuudulla
(
double
leveys
,
double
korkeus
)
{
double
x
=
Screen
.
Left
+
leveys
;
double
y
=
Screen
.
Top
-
korkeus
;
return
new
Vector
(
x
,
y
);
}
}
\ No newline at end of file
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