Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Harjoitustyö
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
alkarant
Harjoitustyö
Commits
c55d7c9f
Commit
c55d7c9f
authored
2 weeks ago
by
alkarant
Browse files
Options
Downloads
Patches
Plain Diff
tehty korjauksia
parent
af003c45
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
NumeronArvaus.cs
+23
-9
23 additions, 9 deletions
NumeronArvaus.cs
with
23 additions
and
9 deletions
NumeronArvaus.cs
+
23
−
9
View file @
c55d7c9f
...
...
@@ -6,13 +6,23 @@ using Jypeli;
namespace
NumeronArvaus
;
/// @author alper
/// @version
2
0.0
2
.2025
/// @version 0
3
.0
4
.2025
/// <summary>
/// Numeron arvaus peli, jossa pelaaja koittaa arvata numeron väliltä 1-100
/// </summary>
public
class
NumeronArvaus
:
Game
{
/// <summary>
/// Pelin minimiarvo satunnaislukua varten.
/// </summary>
private
const
int
MinArvo
=
1
;
/// <summary>
/// Pelin maksimiarvo satunnaislukua varten.
/// </summary>
private
const
int
MaxArvo
=
100
;
/// <summary>
/// Arvottu numero, joka on piilotettu käyttäjältä.
/// </summary>
...
...
@@ -54,9 +64,13 @@ public class NumeronArvaus : Game
public
override
void
Begin
()
{
// Arvotaan satunnainen numero väliltä 1-100
_arvottuNumero
=
RandomGen
.
NextInt
(
1
,
101
);
_arvottuNumero
=
RandomGen
.
NextInt
(
MinArvo
,
MaxArvo
+
1
);
//laskuri joka laskee pelaajan yritykset
_yritykset
=
new
IntMeter
(
0
);
_arvausHistoria
.
Clear
();
// tyhjentää arvasuhistorian pelin alkaessa
_arvausHistoria
.
Clear
();
// Taustakuva
Level
.
Background
.
CreateGradient
(
Color
.
DarkBlue
,
Color
.
Black
);
...
...
@@ -136,11 +150,11 @@ public class NumeronArvaus : Game
/// <summary>
/// Tarkistaa käyttäjän arvauksen ja näyttää vihjeitä.
/// </summary>
void
TarkistaArvaus
()
private
void
TarkistaArvaus
()
{
if
(
int
.
TryParse
(
_kayttajanSyote
,
out
int
pelaajanArvaus
))
{
if
(
pelaajanArvaus
<
1
||
pelaajanArvaus
>
100
)
if
(
pelaajanArvaus
<
MinArvo
||
pelaajanArvaus
>
MaxArvo
)
{
_vihjeteksti
.
Text
=
"Syötä luku väliltä 1-100!"
;
return
;
...
...
@@ -181,7 +195,7 @@ public class NumeronArvaus : Game
/// </summary>
/// <param name="uusiArvaus">Käyttäjän antama uusi arvaus.</param>
/// <returns>Arvaushistorian tekstimuodossa.</returns>
string
PaivitaArvausHistoria
(
int
uusiArvaus
)
private
string
PaivitaArvausHistoria
(
int
uusiArvaus
)
{
_arvausHistoria
.
Add
(
uusiArvaus
);
string
historiaTeksti
=
"Arvaukset: "
;
...
...
@@ -196,7 +210,7 @@ public class NumeronArvaus : Game
/// <summary>
/// Aloittaa pelin alusta.
/// </summary>
void
ResetoiPeli
()
private
void
ResetoiPeli
()
{
ClearAll
();
Begin
();
...
...
@@ -207,7 +221,7 @@ public class NumeronArvaus : Game
/// Lisää painettu numero syötteeseen.
/// </summary>
/// <param name="nappi">Painettu näppäin.</param>
void
LisaaMerkki
(
Key
nappi
)
private
void
LisaaMerkki
(
Key
nappi
)
{
if
(
_kayttajanSyote
.
Length
<
3
)
{
...
...
@@ -221,7 +235,7 @@ public class NumeronArvaus : Game
/// <summary>
/// Poistaa viimeisen numeron syötteestä.
/// </summary>
void
PoistaMerkki
()
private
void
PoistaMerkki
()
{
if
(
_kayttajanSyote
.
Length
>
0
)
{
...
...
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