Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ohj1htlokkihunter
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
sulasaal
ohj1htlokkihunter
Commits
1d44caef
Commit
1d44caef
authored
1 year ago
by
Sulasalmi Aleksi Sakari
Browse files
Options
Downloads
Patches
Plain Diff
peli loppuu järkevästi
parent
0252eead
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Harjoitustyö/Lokkihunter/Lokkihunter.cs
+25
-117
25 additions, 117 deletions
Harjoitustyö/Lokkihunter/Lokkihunter.cs
with
25 additions
and
117 deletions
Harjoitustyö/Lokkihunter/Lokkihunter.cs
+
25
−
117
View file @
1d44caef
...
@@ -71,79 +71,18 @@ public class Lokkihunter : PhysicsGame
...
@@ -71,79 +71,18 @@ public class Lokkihunter : PhysicsGame
" "
,
" "
,
" p "
,
" p "
,
};
};
/// <summary>
/// <summary>
/// Edustaa eri tasoja pelissä.
/// Edustaa eri tasoja pelissä.
/// </summary>
/// </summary>
private
static
readonly
string
[]
kentta3
=
{
private
static
readonly
string
[]
kentta3
=
{
" "
,
" l "
,
" l "
,
" l "
,
" l "
,
" l "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" p "
,
};
/// <summary>
/// Edustaa eri tasoja pelissä.
/// </summary>
private
static
readonly
string
[]
kentta4
=
{
" "
,
" l "
,
" l "
,
" l "
,
" l "
,
" l "
,
" "
,
" l "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" p "
,
};
/// <summary>
/// Edustaa eri tasoja pelissä.
/// </summary>
private
static
readonly
string
[]
kentta5
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" p "
,
};
/// <summary>
/// Edustaa eri tasoja pelissä.
/// </summary>
private
static
readonly
string
[]
kentta6
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" l "
,
" l "
,
" l "
,
" l "
,
" l "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
...
@@ -152,14 +91,11 @@ public class Lokkihunter : PhysicsGame
...
@@ -152,14 +91,11 @@ public class Lokkihunter : PhysicsGame
" p "
,
" p "
,
};
};
/// <summary>
/// <summary>
/// Tasoja sisältävä taulukko, jota käytetään pelissä.
/// Tasoja sisältävä taulukko, jota käytetään pelissä.
/// </summary>
/// </summary>
private
static
readonly
string
[][]
kenttalista
=
private
static
readonly
string
[][]
kenttalista
=
{
kentta0
,
kentta1
,
kentta2
,
kentta3
,
kentta4
,
kentta5
,
kentta6
};
{
kentta0
,
kentta1
,
kentta2
,
kentta3
};
/// <summary>
/// <summary>
/// Taulukko värejä, jotka edustavat tason ylägradientteja.
/// Taulukko värejä, jotka edustavat tason ylägradientteja.
...
@@ -299,10 +235,15 @@ public class Lokkihunter : PhysicsGame
...
@@ -299,10 +235,15 @@ public class Lokkihunter : PhysicsGame
{
{
ClearAll
();
ClearAll
();
GC
.
Collect
();
GC
.
Collect
();
if
(
kenttaNro
==
kenttalista
.
Length
-
1
)
Exit
();
if
(
kenttaNro
.
Value
<
kenttalista
.
Length
)
if
(
kenttaNro
.
Value
<
kenttalista
.
Length
)
{
{
kenttaNro
.
Value
++;
kenttaNro
.
Value
++;
if
(
kenttaNro
==
kenttalista
.
Length
-
1
)
{
NaytaViesti
(
"Peli läpi!"
,
2
);
Timer
.
CreateAndStart
(
1
,
Exit
);
}
}
}
lokkeja
.
Value
=
LaskeLokit
(
kenttalista
[
kenttaNro
]);
lokkeja
.
Value
=
LaskeLokit
(
kenttalista
[
kenttaNro
]);
...
@@ -310,12 +251,13 @@ public class Lokkihunter : PhysicsGame
...
@@ -310,12 +251,13 @@ public class Lokkihunter : PhysicsGame
string
[]
tasonKuva
=
kenttalista
[
i
];
string
[]
tasonKuva
=
kenttalista
[
i
];
if
(
i
>=
alaVarit
.
Length
)
i
=
alaVarit
.
Length
-
1
;
if
(
i
>=
alaVarit
.
Length
)
i
=
alaVarit
.
Length
-
1
;
Level
.
Background
.
CreateGradient
(
alaVarit
[
i
],
ylaVarit
[
i
]);
Level
.
Background
.
CreateGradient
(
alaVarit
[
i
],
ylaVarit
[
i
]);
Level
.
Background
.
Image
=
taustanKuva
;
Level
.
Background
.
Image
=
Image
.
Flip
(
taustanKuva
);
tileWidth
=
800
/
tasonKuva
[
0
].
Length
;
tileWidth
=
800
/
tasonKuva
[
0
].
Length
;
tileHeight
=
480
/
kenttalista
.
Length
;
tileHeight
=
480
/
kenttalista
.
Length
;
var
tiles
=
TileMap
.
FromStringArray
(
tasonKuva
);
var
tiles
=
TileMap
.
FromStringArray
(
tasonKuva
);
Level
.
Background
.
Image
=
taustanKuva
;
Level
.
Background
.
Image
=
Image
.
Flip
(
taustanKuva
);
tiles
.
SetTileMethod
(
'p'
,
LuoPekka
,
Color
.
Wheat
);
tiles
.
SetTileMethod
(
'p'
,
LuoPekka
,
Color
.
Wheat
);
tiles
.
SetTileMethod
(
'l'
,
LuoLokki
,
Color
.
Black
);
tiles
.
SetTileMethod
(
'l'
,
LuoLokki
,
Color
.
Black
);
tiles
.
Execute
(
tileWidth
,
tileHeight
);
tiles
.
Execute
(
tileWidth
,
tileHeight
);
...
@@ -338,19 +280,11 @@ public class Lokkihunter : PhysicsGame
...
@@ -338,19 +280,11 @@ public class Lokkihunter : PhysicsGame
/// Siirrytään seuraavaan tasoon, jos viimeinen taso, niin peli läpi.
/// Siirrytään seuraavaan tasoon, jos viimeinen taso, niin peli läpi.
/// </summary>
/// </summary>
private
void
TasoPelattu
()
private
void
TasoPelattu
()
{
{
if
(
kenttaNro
.
Value
==
kenttalista
.
Length
-
1
)
if
(
lokkeja
.
Value
>
0
)
return
;
{
SeuraavaKentta
();
NaytaViesti
(
"Peli läpi!"
,
2
);
AsetaOhjaimet
();
}
LisaaPelaajanPistelaskuri
();
if
(
lokkeja
.
Value
<=
0
)
{
SeuraavaKentta
();
NaytaViesti
(
"Taso läpi!"
,
1
);
AsetaOhjaimet
();
LisaaPelaajanPistelaskuri
();
}
}
}
...
@@ -380,13 +314,9 @@ public class Lokkihunter : PhysicsGame
...
@@ -380,13 +314,9 @@ public class Lokkihunter : PhysicsGame
FireRate
=
5.0
,
FireRate
=
5.0
,
ProjectileCollision
=
AmmusOsui
,
ProjectileCollision
=
AmmusOsui
,
Position
=
pekka
.
Position
+
new
Vector
(
pekka
.
Width
/
2
,
0
),
Position
=
pekka
.
Position
+
new
Vector
(
pekka
.
Width
/
2
,
0
),
Angle
=
Angle
.
FromDegrees
(
90
)
Angle
=
Angle
.
FromDegrees
(
90
),
Image
=
haulikonKuva
};
};
if
(
pekkaAse
.
Ammo
.
Value
==
0
)
{
NaytaIlmoitus
(
"Game over!"
,
Color
.
Red
);
}
pekkaAse
.
Image
=
haulikonKuva
;
pekka
.
Add
(
pekkaAse
);
pekka
.
Add
(
pekkaAse
);
}
}
...
@@ -495,7 +425,7 @@ public class Lokkihunter : PhysicsGame
...
@@ -495,7 +425,7 @@ public class Lokkihunter : PhysicsGame
/// <returns>palauttaa lokkien määrän</returns>
/// <returns>palauttaa lokkien määrän</returns>
private
static
int
LaskeLokit
(
string
[]
level
)
private
static
int
LaskeLokit
(
string
[]
level
)
{
{
int
lokkiMaara
=
-
1
;
int
lokkiMaara
=
-
1
;
foreach
(
string
row
in
level
)
foreach
(
string
row
in
level
)
{
{
lokkiMaara
+=
row
.
Count
(
c
=>
c
==
'l'
);
lokkiMaara
+=
row
.
Count
(
c
=>
c
==
'l'
);
...
@@ -505,25 +435,6 @@ public class Lokkihunter : PhysicsGame
...
@@ -505,25 +435,6 @@ public class Lokkihunter : PhysicsGame
}
}
/// <summary>
/// Näytetään teksti näytöllä valitulla värillä
/// </summary>
/// <param name="teksti">näytettävä teksti</param>
/// <param name="vari">pohjaväri, jolla näytetään</param>
private
void
NaytaIlmoitus
(
string
teksti
,
Color
vari
)
{
Label
label
=
new
Label
(
teksti
)
{
Font
=
Font
.
Default
,
Width
=
400
,
Height
=
200
,
Color
=
vari
,
BorderColor
=
Color
.
Black
};
Add
(
label
);
}
/// <summary>
/// <summary>
/// Aliohjelma näyttää jonkin tekstin kohdassa (0,0) tietyn ajan
/// Aliohjelma näyttää jonkin tekstin kohdassa (0,0) tietyn ajan
/// </summary>
/// </summary>
...
@@ -559,7 +470,6 @@ public class Lokkihunter : PhysicsGame
...
@@ -559,7 +470,6 @@ public class Lokkihunter : PhysicsGame
{
{
MaxValue
=
10
MaxValue
=
10
};
};
Label
naytto
=
new
Label
();
Label
naytto
=
new
Label
();
naytto
.
BindTo
(
laskuri
);
naytto
.
BindTo
(
laskuri
);
naytto
.
X
=
x
;
naytto
.
X
=
x
;
...
@@ -568,7 +478,6 @@ public class Lokkihunter : PhysicsGame
...
@@ -568,7 +478,6 @@ public class Lokkihunter : PhysicsGame
naytto
.
BorderColor
=
Level
.
Background
.
Color
;
naytto
.
BorderColor
=
Level
.
Background
.
Color
;
naytto
.
Color
=
Level
.
Background
.
Color
;
naytto
.
Color
=
Level
.
Background
.
Color
;
Add
(
naytto
);
Add
(
naytto
);
return
laskuri
;
return
laskuri
;
}
}
}
}
\ 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