Skip to content
Snippets Groups Projects
Commit d2b46ec0 authored by Lappalainen Jukka-Pekka Tapio's avatar Lappalainen Jukka-Pekka Tapio
Browse files

Tee paina nappia animaatio.

parent 10336988
No related branches found
No related tags found
No related merge requests found
......@@ -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");
//
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment