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
jutalapp
ohj1ht
Commits
d2b46ec0
Commit
d2b46ec0
authored
1 year ago
by
Lappalainen Jukka-Pekka Tapio
Browse files
Options
Downloads
Patches
Plain Diff
Tee paina nappia animaatio.
parent
10336988
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kivi-sakset-paperi/Ohjelma.cs
+2
-2
2 additions, 2 deletions
kivi-sakset-paperi/Ohjelma.cs
kivi-sakset-paperi/kivi-sakset-paperi.cs
+55
-21
55 additions, 21 deletions
kivi-sakset-paperi/kivi-sakset-paperi.cs
with
57 additions
and
23 deletions
kivi-sakset-paperi/Ohjelma.cs
+
2
−
2
View file @
d2b46ec0
...
...
@@ -20,8 +20,8 @@ namespace kivi_sakset_paperi
[
STAThread
]
static
void
Main
()
{
Console
.
WriteLine
(
"Rock, Paper, Scissors Game"
);
//
Console.WriteLine("Rock, Paper, Scissors Game");
//
// var player1 = new Pelaaja("Human");
// var player2 = new Pelaaja("Computer");
//
...
...
This diff is collapsed.
Click to expand it.
kivi-sakset-paperi/kivi-sakset-paperi.cs
+
55
−
21
View file @
d2b46ec0
...
...
@@ -4,6 +4,7 @@ using Jypeli;
using
Jypeli.Assets
;
using
Jypeli.Controls
;
using
Jypeli.Widgets
;
using
kivi_sakset_paperi.luokat
;
namespace
kivi_sakset_paperi
;
...
...
@@ -17,36 +18,69 @@ public class kivi_sakset_paperi : Game
private
Image
paperi
;
private
Image
kivi
;
private
Image
sakset
;
private
Label
peliOtsikko
;
public
override
void
Begin
()
{
// Lataa kuvat
paperi
=
LoadImage
(
"Paper.png"
);
kivi
=
LoadImage
(
"Rock.png"
);
sakset
=
LoadImage
(
"Scissors.png"
);
peliOtsikko
=
new
Label
(
"Valitse Kivi paperi Sakset"
);
asetaPelipoyta
();
// Luo peli oliot
GameObject
olio1
=
new
GameObject
(
paperi
);
GameObject
olio2
=
new
GameObject
(
kivi
);
GameObject
olio3
=
new
GameObject
(
sakset
);
//Asetellaan
olio1
.
Position
=
new
Vector
(-
350
,
0
);
olio2
.
Position
=
new
Vector
(
0
,
0
);
olio3
.
Position
=
new
Vector
(
350
,
0
);
peliOtsikko
.
Position
=
new
Vector
(
0
,
300
);
// Lisää pelioliot.
Add
(
olio1
);
Add
(
olio2
);
Add
(
olio3
);
Add
(
peliOtsikko
);
Mouse
.
ListenOn
(
olio1
,
MouseButton
.
Left
,
ButtonState
.
Pressed
,
suoritaNapinPainallus
,
"Focus on mouse over"
,
olio1
);
Mouse
.
ListenOn
(
olio2
,
MouseButton
.
Left
,
ButtonState
.
Pressed
,
suoritaNapinPainallus
,
"Focus on mouse over"
,
olio2
);
Mouse
.
ListenOn
(
olio3
,
MouseButton
.
Left
,
ButtonState
.
Pressed
,
suoritaNapinPainallus
,
"Focus on mouse over"
,
olio3
);
PhoneBackButton
.
Listen
(
ConfirmExit
,
"Lopeta peli"
);
Keyboard
.
Listen
(
Key
.
Escape
,
ButtonState
.
Pressed
,
ConfirmExit
,
"Lopeta peli"
);
}
private
void
asetaPelipoyta
()
/// <summary>
/// Handle the mouse hover effect.
/// </summary>
/// <param name="obj">The game object that was hovered over.</param>
private
void
suoritaNapinPainallus
(
GameObject
obj
)
{
// Load the images
paperi
=
LoadImage
(
"Paper.png"
);
kivi
=
LoadImage
(
"Rock.png"
);
sakset
=
LoadImage
(
"Scissors.png"
);
obj
.
Width
+=
5
;
obj
.
Height
+=
5
;
// Create GameObjects from these images
GameObject
object1
=
new
GameObject
(
paperi
);
GameObject
object2
=
new
GameObject
(
kivi
);
GameObject
object3
=
new
GameObject
(
sakset
);
//Asetellaan
object1
.
Position
=
new
Vector
(-
350
,
0
);
object2
.
Position
=
new
Vector
(
0
,
0
);
object3
.
Position
=
new
Vector
(
350
,
0
);
// Optionally, after a short delay, you can scale it back down for a hover effect
Timer
.
SingleShot
(
0.5
,
()
=>
{
obj
.
Width
-=
5.0
;
});
}
private
string
DetermineWinner
(
Valinta
playerChoice
,
Valinta
computerChoice
)
{
if
(
playerChoice
==
computerChoice
)
return
"It's a draw"
;
// Add GameObjects to the game for them to be visible
Add
(
object1
);
Add
(
object2
);
Add
(
object3
);
if
((
playerChoice
==
Valinta
.
Kivi
&&
computerChoice
==
Valinta
.
Sakset
)
||
(
playerChoice
==
Valinta
.
Sakset
&&
computerChoice
==
Valinta
.
Paperi
)
||
(
playerChoice
==
Valinta
.
Paperi
&&
computerChoice
==
Valinta
.
Kivi
))
{
return
"You win"
;
}
else
{
return
"Computer wins"
;
}
}
}
\ 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