diff --git a/Financial_Freedom/Financial_Freedom/Content/RouletteBG.png b/Financial_Freedom/Financial_Freedom/Content/RouletteBG.png new file mode 100644 index 0000000000000000000000000000000000000000..d01cba5d7ab994fda30f4e44c0305e837a498710 Binary files /dev/null and b/Financial_Freedom/Financial_Freedom/Content/RouletteBG.png differ diff --git a/Financial_Freedom/Financial_Freedom/Content/slotBG.png b/Financial_Freedom/Financial_Freedom/Content/slotBG.png new file mode 100644 index 0000000000000000000000000000000000000000..830606de2e4efd4d67770a8bea7787233547cc46 Binary files /dev/null and b/Financial_Freedom/Financial_Freedom/Content/slotBG.png differ diff --git a/Financial_Freedom/Financial_Freedom/Content/tyhjatausta.png b/Financial_Freedom/Financial_Freedom/Content/tyhjatausta.png new file mode 100644 index 0000000000000000000000000000000000000000..280534f0a2659de0aa4f48669376bbe67f7900e2 Binary files /dev/null and b/Financial_Freedom/Financial_Freedom/Content/tyhjatausta.png differ diff --git a/Financial_Freedom/Financial_Freedom/Data/toplistsave.txt b/Financial_Freedom/Financial_Freedom/Data/toplistsave.txt index 1bce4d67a7962f9177f065bfe7d86b925383e4ca..d68a3e65f486ffdf045a755a5655562dc7825966 100644 --- a/Financial_Freedom/Financial_Freedom/Data/toplistsave.txt +++ b/Financial_Freedom/Financial_Freedom/Data/toplistsave.txt @@ -29,7 +29,7 @@ </Item> <Item Index="3" Type="Jypeli.ScoreItem, Jypeli, Version=11.3.7.0, Culture=neutral, PublicKeyToken=null"> <Field Name="Name" Type="System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"> - <Value>miku</Value> + <Value>jonttu</Value> </Field> <Field Name="Score" Type="System.Double, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"> <Value>24999749975</Value> @@ -53,10 +53,10 @@ </Item> <Item Index="6" Type="Jypeli.ScoreItem, Jypeli, Version=11.3.7.0, Culture=neutral, PublicKeyToken=null"> <Field Name="Name" Type="System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"> - <Value>Jollu</Value> + <Value>-</Value> </Field> <Field Name="Score" Type="System.Double, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"> - <Value>6969696969</Value> + <Value>0</Val3ue> </Field> </Item> <Item Index="7" Type="Jypeli.ScoreItem, Jypeli, Version=11.3.7.0, Culture=neutral, PublicKeyToken=null"> diff --git a/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs b/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs index e7d017c78842815c4dad1ff72384bef6b52ea597..cf60bc9005266df6cb0bcaa18b7a8e4f03b3710a 100644 --- a/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs +++ b/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs @@ -11,6 +11,7 @@ using Jypeli; using Jypeli.Assets; using Jypeli.Controls; using Jypeli.Widgets; +using Microsoft.VisualBasic; using Silk.NET.Input; using Silk.NET.OpenAL; using Silk.NET.SDL; @@ -45,7 +46,6 @@ using Window = Jypeli.Window; namespace Financial_Freedom{ - public class Card // tehdään kortit { public string Suit { get; }// hakee pelikortin maan @@ -88,6 +88,45 @@ public class Card // tehdään kortit } } +public class RouletteBet +{ + public int Pocket { get; } // Panoskohteen nimi ("0", "00", "28", jne.) + public string Color { get; } // Väri ("Green", "Red", "Black") + public double Angle { get; } // Kulma-arvo asteina, jossa panoskohde sijaitsee pöydällä + + public RouletteBet(int pocket, string color, double angle) + { + Pocket = pocket; + Color = color; + Angle = angle; + } + + public override string ToString() + { + return $"{Pocket} {Color} at {Angle}"; + } +} + +public class RBetAmounts +{ + // Esim. betType voi olla numero ("36") tai sana ("Red") + public string BetType { get; set; } + // Panostettu rahamäärä + public double Amount { get; set; } + + public RBetAmounts(string betType, double amount) + { + BetType = betType; + Amount = amount; + } + + public override string ToString() + { + return $"{BetType}: {Amount}"; + } +} + + public class Financial_Freedom : PhysicsGame //alustellaan muuttujat { @@ -95,14 +134,24 @@ public class Financial_Freedom : PhysicsGame private double tsplinko = (1); //suurinpiirtein takaisinsaantikerroin plinkoalustoissa 0.85 kontrollikerroin DoubleMeter pistelaskuri; //heitäppä villi veikkaus mikä tämä voisi olla private Label panosLabel; // Label, joka näyttää panoksen no shit + private Label titleLabel; //panoksen titlelabel private double panos; // Alkustus panokselle private TaskCompletionSource<bool> panosAsetettu; + private bool removePanosLabelAfterPanos; // Tämä kenttä tallentaa, poistetaanko labelit private Label pistenaytto; private GameObject coinObject; private TaskCompletionSource<bool> animaatioValmis; private List<Card> pakka = new List<Card>(); // Tehdään pakasta luokan kenttä private List<Card> pelaajanKortit = new List<Card>(); // Pelaajan kortit kentäksi private List<Card> jakajanKortit; // Jakajan kortit kentäksi + private PushButton staybutton; + private PushButton hitbutton; + private PushButton ddbutton; + + private List<string> clickLog = new List<string>(); //ruletin panostuksen clikkailulogi + private GameObject doneButton = null; + private double realangle; + private List<RBetAmounts> bets = new List<RBetAmounts>(); private int peliKesken = 0; @@ -118,7 +167,7 @@ public class Financial_Freedom : PhysicsGame private bool AloitusRaha = false; private Timer aikaLaskuri; private double lopetusAika; - private EasyHighScore topLista = new ("toplistsave.txt", 10); + private EasyHighScore topLista = new ("toplistsave.txt", 10, "-"); private bool voitto; @@ -132,6 +181,43 @@ public class Financial_Freedom : PhysicsGame private Label bjVaihtoehdot; private Label pelaajanSummalab; + + public List<RouletteBet> CreateRouletteBets() +{ + var rulettitaskut = new List<RouletteBet>(); + + int[] pockets = + { + 6, 27, 13, 36, 11, 30, 8, 23, 10, 5, 00, 24, 16, 33, 1, 20, 14, 31, 9, 22, + 18, 29, 7, 28, 12, 35, 3, 26, 0, 32, 15, 19, 4, 21, 2, 25, 17, 34 + }; + + // Värit: Vihreät 0 ja 00, muut ovat virallisesti määrättyjä. + // Muut värit on asetettu siten, että annettu järjestys vastaa virallista ruletin väriä. + string[] colors = + { + "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Vihreä", + "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Vihreä", + "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen", "Musta", "Punainen" + }; + + double[] anglet = + { + 349.19, 343.59, 335.44, 328.59, 315.09, 305.46, 295.42, 286.78, 280.64, 273.02, 263.29, + 252.19, 236.73, 226.1, 211.09, 199.93, 188.91, 180.07, 173.39, 167.78, 154.57, 144.36, 133.26, 128.32, 120.23, 109.88, 99.42, 89.6, 84.32, + 78.91, 67.66, 57.39, 43.43, 33.12, 27.18, 20.23, 10.44, 0.0 + }; + + for (int i = 0; i < pockets.Length; i++) + { + int name = pockets[i]; + string color = colors[i]; + double angle = anglet[i]; + rulettitaskut.Add(new RouletteBet(name, color, angle)); + } + + return rulettitaskut; +} private string[] Suits = {"Hertta", "Ruutu", "Risti", "Pata" }; private string[] Ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" }; @@ -143,7 +229,11 @@ public class Financial_Freedom : PhysicsGame IsFullScreen = true; Level.Size = Screen.Size; Camera.ZoomToLevel(); + + tavoiteSaavutettu = false; + Valikko(); + } public void Valikko() // lore @@ -172,6 +262,7 @@ public class Financial_Freedom : PhysicsGame pistelaskuri.Value += 1000; AloitusRaha = true; + topLista.EnterText = "Onnittelut, olet päässyt kymmenen parhaimman uhkapelaajan joukkoon! Syötä nimesi niin jäät historian kirjoihin."; topLista.Text = "Parhaat uhkapelaajat"; topLista.HighScoreWindow.Size = new Vector(300,400); @@ -276,7 +367,7 @@ public class Financial_Freedom : PhysicsGame { lopetusAika = aikaLaskuri.SecondCounter.Value; Console.WriteLine("lopetusaika on "+aikaLaskuri.SecondCounter.Value); - finalscore = Math.Round((highScore-1000)/lopetusAika, 2); + finalscore = Math.Round((highScore-1000)/(lopetusAika/10), 0); Console.WriteLine(highScore+"-1000 on "+ (highScore-1000)+" ja se jaetaan "+lopetusAika+" tulee "+((highScore-1000)/lopetusAika)); Console.WriteLine("finalscore: "+finalscore); } @@ -287,6 +378,7 @@ public class Financial_Freedom : PhysicsGame Image taustakuvaBJ = LoadImage("taustakuvaBJ.jpg"); Image taustakuvaPlinko = LoadImage("plinkobg.jpg"); Image taustakuvaCF = LoadImage("Coinflipbg.png"); + Image taustakuvaRulet = LoadImage("RouletteBG.png"); Image Icon1 = LoadImage("Plinko.jpg"); Image Icon2 = LoadImage("Blackjack.png"); Image Icon3 = LoadImage("Ruletti.png"); @@ -320,6 +412,63 @@ public class Financial_Freedom : PhysicsGame Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); } + /// <summary> + /// luo suorakulmion annettun kokoon ja paikkaan + /// </summary> + /// <param name="peli"></param> + /// <param name="width">logon leveys</param> + /// <param name="height">logon korkeus</param> + /// <param name="x">logon paikka</param> + /// <param name="y">logon paikka</param> + public void MiniPeliLogo(Game peli, double width, double height, double x, double y, string kuva, int order) + { + PhysicsObject p = new PhysicsObject(width, height, Shape.Rectangle, x, y) + { + Position = new Vector(x, y), + Image = LoadImage(kuva), + Tag = order // Käytetään tagia tunnistamiseen + }; + p.Image = LoadImage(kuva); + Label iconLab = new Label(kuva+$" ({order})") + { + Color = Color.White, + Position = new Vector(x, y-90), // Asetetaan sijainti + }; + + // Klikkaustoiminto: Kun objektia klikataan, siirrytään peliin + Mouse.ListenOn(p, MouseButton.Left, ButtonState.Pressed, () => ValitsePeli(order), "Siirry peliin"); + + + peli.Add(p); + peli.Add(iconLab); + + } + + public async void ValitsePeli(int order) + { + switch (order) + { + case 1: + await Plinko(); + break; + case 2: + await BlackJack(); + break; + case 3: + await Ruletti(); + break; + case 4: + await Slots(); + break; + case 5: + await Coinflip(); + break; + default: + MessageDisplay.Add("Tuntematon peli!"); + break; + } + } + /// <summary> /// Blackjack peli, panosken asetus, peli ja tulosten lasku @@ -333,7 +482,7 @@ public class Financial_Freedom : PhysicsGame ClearControls(); Remove(pistenaytto); Add(pistenaytto); - await LisaaPanos(); // Odotetaan, kunnes panos on asetettu + await LisaaPanos(false); // Odotetaan, kunnes panos on asetettu panosAsetettu.TrySetResult(true); // Varmistetaan, että odotus päättyy TakaisinPV(); @@ -342,10 +491,11 @@ public class Financial_Freedom : PhysicsGame EnsimmäinenBJ(); } - public async Task LisaaPanos() + public async Task LisaaPanos(bool removeLabels) { + removePanosLabelAfterPanos = removeLabels; // Ylhäällä keskellä oleva teksti "Aseta panos" - Label titleLabel = new Label("Aseta panos") + titleLabel = new Label("Aseta panos") { Color = Color.White, Position = new Vector(0, 200), // Asetetaan sijainti @@ -364,10 +514,65 @@ public class Financial_Freedom : PhysicsGame kysymysIkkuna.TextEntered += ProcessInput; Add( kysymysIkkuna ); await panosAsetettu.Task; + if (removePanosLabelAfterPanos == true) {Remove(panosLabel); } Remove(titleLabel); + Console.WriteLine("lisaapanos = loppu"); } - + public async Task VaihdaPanos() // hmmmmmm voisiko ehkä vaihtaa panosta + { //esim plinkossa voi vaihtaa panosta lennosta + InputWindow kysymysIkkuna = new InputWindow("Aseta Panos" ); + kysymysIkkuna.TextEntered += ProcessInput; + Add( kysymysIkkuna ); + } + + void ProcessInput( InputWindow ikkuna ) // prosessoi inputin kun panos on asetettu + { + string vastaus = ikkuna.InputBox.Text; + if (double.TryParse(vastaus, out panos) && panos > 0 && panos <= pistelaskuri.Value) + { + panosLabel.Text = "Panos: " + Math.Round(panos, 2); // Update the display label + + MessageDisplay.Add("Panos hyväksytty: " + panos); + + panosAsetettu.TrySetResult(true); + // Lisää logiikka panoksen käyttämiseksi pelissä + } + else if (vastaus == "max" || vastaus == "m" || vastaus == "a" || vastaus == "allin" || vastaus == "all in" || vastaus == "all" || vastaus == "kaikki" || vastaus == "inshallah" || vastaus == "0" && panos > 0 && panos < pistelaskuri.Value) //AllIn + { + panos = pistelaskuri.Value; + + panosLabel.Text = "Panos: " + Math.Round(panos, 2); // Update the display label + + MessageDisplay.Add("Panos hyväksytty: " + panos); + + panosAsetettu.TrySetResult(true); + // Lisää logiikka panoksen käyttämiseksi pelissä + } + else if (vastaus == "half" || vastaus == "h" || vastaus == "puolet" || vastaus == "p" || vastaus == "1/2" || vastaus == "^" && panos > 0 && panos < pistelaskuri.Value) //puolet inee + { + panos = pistelaskuri.Value/2; + + panosLabel.Text = "Panos: " + Math.Round(panos, 2); // Update the display label + + MessageDisplay.Add("Panos hyväksytty: " + panos); + + panosAsetettu.TrySetResult(true); + // Lisää logiikka panoksen käyttämiseksi pelissä + } + else + { + MessageDisplay.Add("Virheellinen panos. Aseta panos johon sinulla on varaa ja joka on positiivinen luku."); + Remove(ikkuna); + Remove(titleLabel); + Remove(panosLabel); + Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await VaihdaPanos(), "vaihtaa panoksen"); + TakaisinPV(); + + } + } + + public async Task EnsimmäinenBJ() { ClearGameObjects(); @@ -493,6 +698,7 @@ public class Financial_Freedom : PhysicsGame }; Add(uusi); peliKesken -= 1; + Loppunapit(); Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); TakaisinPV(); @@ -530,6 +736,7 @@ public class Financial_Freedom : PhysicsGame }; Add(uusi); peliKesken -= 1; + Loppunapit(); Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); TakaisinPV(); @@ -568,6 +775,10 @@ public class Financial_Freedom : PhysicsGame //Keyboard.Listen(Key.H, ButtonState.Pressed, DoubleDown, "Ottaa vielä yhden kortin ja tuplaa panoksen"); //} + bool dd = false; + int nappiwidth = 280; + int nappiheight = 100; + if(pistelaskuri>= panos) //DoubleDown mahdollisuus { bjVaihtoehdot = new Label("Haluatko ottaa vielä kortin (h), tuplata panoksen ja ottaa viimeisen kortin (d) vai pysyä tässä (s)?") @@ -577,8 +788,9 @@ public class Financial_Freedom : PhysicsGame }; Add(bjVaihtoehdot); Keyboard.Listen(Key.D, ButtonState.Pressed, async () => await DoubleDown(bjVaihtoehdot, pelaajanSummalab), "Ottaa vielä yhden kortin ja tuplaa panoksen"); + dd = true; } - + else { bjVaihtoehdot = new Label("Haluatko ottaa vielä kortin (h) vai pysyä tässä (s)?") @@ -589,10 +801,10 @@ public class Financial_Freedom : PhysicsGame Add(bjVaihtoehdot); } + AddHitStayDDButtons(dd); Keyboard.Listen(Key.S, ButtonState.Pressed, async () => await PysyTassa(bjVaihtoehdot, pelaajanSummalab), "Pysyy tässä"); Keyboard.Listen(Key.H, ButtonState.Pressed, async () => await OtaKortti(bjVaihtoehdot, pelaajanSummalab), "Ottaa vielä kortin"); - } } @@ -601,9 +813,14 @@ public class Financial_Freedom : PhysicsGame ClearControls(); Remove(bjV); Remove(sum); + Remove(ddbutton); + Remove(staybutton); + Remove(hitbutton); TakaisinPV(); aCountP = 0; aCountD = 0; + + bool dd = false; int korttiLeveys = 150; // Oletetaan, että kortin leveys on 100 yksikköä int xOffset = 50; // Etäisyys korttien välillä @@ -688,12 +905,16 @@ public class Financial_Freedom : PhysicsGame else if (pelaajanSumma < 21 && pistelaskuri >= panos) { + dd = true; Label bjVaihtoehdot2 = new Label("Haluatko ottaa vielä kortin (h), tuplata panoksen ja ottaa viimeisen kortin (d) vai pysyä tässä (s)?") { Color = Color.White, Position = new Vector(0, -75), // Asetetaan sijainti }; Add(bjVaihtoehdot2); + + AddHitStayDDButtons(dd); + Keyboard.Listen(Key.S, ButtonState.Pressed, async () => await PysyTassa(bjVaihtoehdot2, pelaajanSummalab), "Pysyy tässä"); Keyboard.Listen(Key.H, ButtonState.Pressed, async () => await OtaKortti(bjVaihtoehdot2, pelaajanSummalab), "Ottaa vielä kortin"); Keyboard.Listen(Key.D, ButtonState.Pressed, async () => await DoubleDown(bjVaihtoehdot2, pelaajanSummalab), "Ottaa vielä yhden kortin ja tuplaa panoksen"); @@ -707,6 +928,9 @@ public class Financial_Freedom : PhysicsGame Position = new Vector(0, -75), // Asetetaan sijainti }; Add(bjVaihtoehdot3); + + AddHitStayDDButtons(dd); + Keyboard.Listen(Key.S, ButtonState.Pressed, async () => await PysyTassa(bjVaihtoehdot3, pelaajanSummalab), "Pysyy tässä"); Keyboard.Listen(Key.H, ButtonState.Pressed, async () => await OtaKortti(bjVaihtoehdot3, pelaajanSummalab), "Ottaa vielä kortin"); } @@ -721,6 +945,7 @@ public class Financial_Freedom : PhysicsGame }; Add(Bust); peliKesken -= 1; + Loppunapit(); Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); TakaisinPV(); @@ -733,6 +958,9 @@ public class Financial_Freedom : PhysicsGame { Remove(bjV); Remove(sum); + Remove(ddbutton); + Remove(staybutton); + Remove(hitbutton); ClearControls(); TakaisinPV(); Console.WriteLine("panos "+panos); @@ -824,6 +1052,7 @@ public class Financial_Freedom : PhysicsGame }; Add(Bust); peliKesken -= 1; + Loppunapit(); Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); TakaisinPV(); @@ -836,6 +1065,9 @@ public class Financial_Freedom : PhysicsGame { Remove(bjV); Remove(sum); + Remove(ddbutton); + Remove(staybutton); + Remove(hitbutton); ClearControls(); TakaisinPV(); @@ -891,9 +1123,42 @@ public class Financial_Freedom : PhysicsGame } + public void AddHitStayDDButtons(bool dd) + { + int nappiwidth = 350; + int nappiheight = 100; + + staybutton = new PushButton(nappiwidth, nappiheight, "Stay / Pysy Tässä"); + staybutton.Position = new Vector(Screen.Left+200, -Screen.Height / 6); // vasen + staybutton.Size = new Vector(350, 100); + staybutton.TextScale = new Vector(2,2); + staybutton.Clicked += delegate { _ = PysyTassa(bjVaihtoehdot, pelaajanSummalab); Remove(staybutton);};; + Add(staybutton); + + hitbutton = new PushButton( nappiwidth, nappiheight, "Hit / Ota kortti"); + hitbutton.Position = new Vector(Screen.Right-200, Screen.Height / 6); // Oikealle, + hitbutton.Size = new Vector(350, 100); + hitbutton.TextScale = new Vector(2,2); + hitbutton.Clicked += delegate { _ = OtaKortti(bjVaihtoehdot, pelaajanSummalab); Remove(hitbutton);};; + Add(hitbutton); + + if (dd) + { + ddbutton = new PushButton(nappiwidth, nappiheight, "Double down / Tuplaa panos"); + ddbutton.Position = new Vector(Screen.Right-325, -Screen.Height / 6); // Oikealle alas + ddbutton.Size = new Vector(600, 100); + ddbutton.TextScale = new Vector(2,2); + ddbutton.Clicked += delegate { _ = DoubleDown(bjVaihtoehdot, pelaajanSummalab); };; + Add(ddbutton); + } + } + public async Task DealerFinish(Label sum) // lopettaa pelin jakajan vuoroon { Remove(sum); + Remove(ddbutton); + Remove(staybutton); + Remove(hitbutton); Card kortti; Image kortinKuva; int korttiLeveys = 150; // Oletetaan, että kortin leveys on 100 yksikköä @@ -992,16 +1257,7 @@ public class Financial_Freedom : PhysicsGame bjDoubled = false; } - Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") - { - Color = Color.White, - Position = new Vector(0, -105), // Asetetaan sijainti - }; - Add(uusi); - peliKesken -= 1; - Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN - Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); - TakaisinPV(); + endScreenBJ(); } else if (pelaajanSumma > 21) @@ -1012,16 +1268,7 @@ public class Financial_Freedom : PhysicsGame Position = new Vector(0, -75), // Asetetaan sijainti }; Add(tulosLabel); - Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") - { - Color = Color.White, - Position = new Vector(0, -105), // Asetetaan sijainti - }; - Add(uusi); - peliKesken -= 1; - Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN - Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); - TakaisinPV(); + endScreenBJ(); } else if (jakajanSumma == pelaajanSumma) @@ -1038,16 +1285,7 @@ public class Financial_Freedom : PhysicsGame pistelaskuri.Value += panos * yTs; bjDoubled = false; } - Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") - { - Color = Color.White, - Position = new Vector(0, -105), // Asetetaan sijainti - }; - Add(uusi); - peliKesken -= 1; - Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN - Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); - TakaisinPV(); + endScreenBJ(); } else if (jakajanSumma < pelaajanSumma && pelaajanSumma <= 21) @@ -1064,17 +1302,7 @@ public class Financial_Freedom : PhysicsGame pistelaskuri.Value += 2 * panos * yTs; bjDoubled = false; } - - Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") - { - Color = Color.White, - Position = new Vector(0, -105), // Asetetaan sijainti - }; - Add(uusi); - peliKesken -= 1; - Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN - Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); - TakaisinPV(); + endScreenBJ(); } else if (pelaajanSumma < jakajanSumma && jakajanSumma <= 21) @@ -1085,16 +1313,7 @@ public class Financial_Freedom : PhysicsGame Position = new Vector(0, -75), // Asetetaan sijainti }; Add(tulosLabel); - Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") - { - Color = Color.White, - Position = new Vector(0, -105), // Asetetaan sijainti - }; - Add(uusi); - peliKesken -= 1; - Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN - Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); - TakaisinPV(); + endScreenBJ(); } else if (pelaajanSumma <= 21 && jakajanSumma > 21) { @@ -1110,21 +1329,55 @@ public class Financial_Freedom : PhysicsGame pistelaskuri.Value += 2 * panos * yTs; bjDoubled = false; } - - Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") - { - Color = Color.White, - Position = new Vector(0, -105), // Asetetaan sijainti - }; - Add(uusi); - peliKesken -= 1; - Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN - Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); - TakaisinPV(); + + endScreenBJ(); + } TakaisinPV(); } + + public void endScreenBJ() + { + Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") + { + Color = Color.White, + Position = new Vector(0, -105), // Asetetaan sijainti + }; + Add(uusi); + peliKesken -= 1; + Loppunapit(); + Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await BlackJack(), "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN + Keyboard.Listen(Key.N, ButtonState.Pressed, async () => await EnsimmäinenBJ(), "uus kiesi"); + TakaisinPV(); + } + + public void Loppunapit() + { + int nappiwidth = 350; + int nappiheight = 100; + + staybutton = new PushButton(nappiwidth, nappiheight, "Päävalikko"); + staybutton.Position = new Vector(Screen.Left+200, -Screen.Height / 6); // vasen + staybutton.Size = new Vector(350, 100); + staybutton.TextScale = new Vector(2,2); + staybutton.Clicked += delegate { _ = peliKesken = 0; ClearControls(); ClearGameObjects(); PelinValinta();}; + Add(staybutton); + + hitbutton = new PushButton( nappiwidth, nappiheight, "Vaihda panosta"); + hitbutton.Position = new Vector(Screen.Right-200, Screen.Height / 6); // Oikealle, + hitbutton.Size = new Vector(350, 100); + hitbutton.TextScale = new Vector(2,2); + hitbutton.Clicked += delegate { _ = BlackJack();}; + Add(hitbutton); + + ddbutton = new PushButton(nappiwidth, nappiheight, "Uusi kierros samalla panoksella"); + ddbutton.Position = new Vector(Screen.Right-350, -Screen.Height / 6); // Oikealle alas + ddbutton.Size = new Vector(650, 100); + ddbutton.TextScale = new Vector(2,2); + ddbutton.Clicked += delegate { _ = EnsimmäinenBJ();}; + Add(ddbutton); + } // Luo korttipakka public List<Card> LuoPakka() // luo korttipakan no shit sherlock @@ -1143,7 +1396,7 @@ public class Financial_Freedom : PhysicsGame //sekoittaa pakan - public static void SekoitaPakka(List<Card> pakka) // oisko vaikka että sekoittaa pakan + public void SekoitaPakka(List<Card> pakka) // oisko vaikka että sekoittaa pakan { Random rand = new Random(); int n = pakka.Count; @@ -1175,52 +1428,6 @@ public class Financial_Freedom : PhysicsGame return jaetutKortit; } - public async Task VaihdaPanos() // hmmmmmm voisiko ehkä vaihtaa panosta - { //esim plinkossa voi vaihtaa panosta lennosta - InputWindow kysymysIkkuna = new InputWindow("Aseta Panos" ); - kysymysIkkuna.TextEntered += ProcessInput; - Add( kysymysIkkuna ); - } - - void ProcessInput( InputWindow ikkuna ) // prosessoi inputin kun panos on asetettu - { - string vastaus = ikkuna.InputBox.Text; - if (double.TryParse(vastaus, out panos) && panos > 0 && panos <= pistelaskuri.Value) - { - panosLabel.Text = "Panos: " + Math.Round(panos, 2); // Update the display label - - MessageDisplay.Add("Panos hyväksytty: " + panos); - panosAsetettu.TrySetResult(true); - // Lisää logiikka panoksen käyttämiseksi pelissä - } - else if (vastaus == "max" || vastaus == "m" || vastaus == "a" || vastaus == "allin" || vastaus == "all in" || vastaus == "all" || vastaus == "kaikki" || vastaus == "inshallah" || vastaus == "0" && panos > 0 && panos < pistelaskuri.Value) //AllIn - { - panos = pistelaskuri.Value; - - panosLabel.Text = "Panos: " + Math.Round(panos, 2); // Update the display label - - MessageDisplay.Add("Panos hyväksytty: " + panos); - panosAsetettu.TrySetResult(true); - // Lisää logiikka panoksen käyttämiseksi pelissä - } - else if (vastaus == "half" || vastaus == "h" || vastaus == "puolet" || vastaus == "p" || vastaus == "1/2" || vastaus == "^" && panos > 0 && panos < pistelaskuri.Value) //puolet inee - { - panos = pistelaskuri.Value/2; - - panosLabel.Text = "Panos: " + Math.Round(panos, 2); // Update the display label - - MessageDisplay.Add("Panos hyväksytty: " + panos); - panosAsetettu.TrySetResult(true); - // Lisää logiikka panoksen käyttämiseksi pelissä - } - else - { - MessageDisplay.Add("Virheellinen panos. Aseta panos johon sinulla on varaa ja joka on positiivinen luku."); - Keyboard.Listen(Key.P, ButtonState.Pressed, async () => await VaihdaPanos(), "vaihtaa panoksen"); - TakaisinPV(); - - } - } /// <summary> @@ -1232,7 +1439,7 @@ public class Financial_Freedom : PhysicsGame ClearControls(); ClearGameObjects(); Add(pistenaytto); - await LisaaPanos(); // Odotetaan, kunnes panos on asetettu + await LisaaPanos(false); // Odotetaan, kunnes panos on asetettu panosAsetettu.TrySetResult(true); // Varmistetaan, että odotus päättyy panosLabel.Position = new Vector(0, Level.Top - 60); panosLabel.TextScale = new Vector(2,2); @@ -1240,6 +1447,7 @@ public class Financial_Freedom : PhysicsGame panosLabel.Color = Color.Transparent; + Level.Background.Image = taustakuvaPlinko; @@ -1373,7 +1581,7 @@ public class Financial_Freedom : PhysicsGame /// <param name="peli"></param> /// <param name="x">paikka x-akseliilla</param> /// <param name="y">paikka y-akselilla</param> - public static void EstePlinko(Game peli, double x,double y) + public void EstePlinko(Game peli, double x,double y) { PhysicsObject este = new PhysicsObject(10, 10, Shape.Circle, x, y ); este.Restitution = 0.5; @@ -1385,32 +1593,588 @@ public class Financial_Freedom : PhysicsGame public async Task Ruletti() { panosAsetettu = new TaskCompletionSource<bool>(false); + bets = new List<RBetAmounts>(); + ClearGameObjects(); ClearControls(); + Level.Background.Image = taustakuvaRulet; + Level.Background.Width = Screen.Width; + Level.Background.Height = Screen.Height; Add(pistenaytto); - await LisaaPanos(); - panosAsetettu.TrySetResult(true); - PhysicsObject p = new PhysicsObject(200, 300, Shape.Rectangle, 1, 200); - Add(p); + await LuoPanostusAlue(); TakaisinPV(); } - - public void RulettiPanos() + + public async Task LuoPanostusAlue() { + // Tyhjennetään välimuisti aina uuden alueen luomisen yhteydessä + if (clickLog.Count > 0) + { + clickLog.Clear(); + } + + // Nollataan valmis-nappi, jotta se luodaan uudelleen tarvittaessa + doneButton = null; + + ClearGameObjects(); + ClearControls(); + Add(pistenaytto); + + /*Label ohjeet = new Label(1100, 35, "Klikkaa mihin haluat asettaa panoksesi. Jos klikkaat montaa kohtaa niin panos jaetaan niiden välille tasan."); + ohjeet.Color = Color.SkyBlue; + ohjeet.TextColor = Color.Black; + ohjeet.Position = new Vector(Screen.Right-575, Screen.Top-25); + Add(ohjeet); + */ + + + // Tausta panostusalueelle + GameObject panostusAlue = new GameObject(Screen.Width / 4, Screen.Height / 2, Shape.Rectangle); + panostusAlue.Color = Color.DarkGreen; + panostusAlue.Position = new Vector(0,0); + Add(panostusAlue); + + // Grid-asetukset numeroiden nappeihin + int buttonSize = 50; + int padding = 5; + int buttonsPerRow = 6; // Nappeja per rivi + int totalButtons = 36; + + // Lasketaan gridin kokonaisleveys ja -korkeus + double gridWidth = buttonsPerRow * buttonSize + (buttonsPerRow - 1) * padding; + int totalRows = (totalButtons + buttonsPerRow - 1) / buttonsPerRow; // Pyöristys ylöspäin + double gridHeight = totalRows * buttonSize + (totalRows - 1) * padding; + + // Asetetaan gridin aloituskohta panostusalueen sisällä niin, että se on keskitetty + double startX = (panostusAlue.Position.X - gridWidth / 2 + buttonSize / 2); + double startY = (panostusAlue.Position.Y + panostusAlue.Height / 2 - gridHeight / 2 - buttonSize / 2); + + //Console.WriteLine($"start x ={startX} ja start y = {startY}"); + + for (int i = 0; i < totalButtons; i++) + { + int currentNumber = i+1; + int row = i / buttonsPerRow; + int col = i % buttonsPerRow; + + // Lasketaan napin sijainti gridissä + double x = startX + col * (buttonSize + padding); + double y = startY - row * (buttonSize + padding); + + GameObject numeroPanos = new GameObject(buttonSize, buttonSize); + // Vaihdetaan väri parillisen ja parittoman mukaan + if (currentNumber < 11) + { + numeroPanos.Color = (currentNumber % 2 == 0) ? Color.Black : Color.Red; + } + else if (10 < currentNumber) + { + if (currentNumber < 29) + { + if (currentNumber < 19) + { + numeroPanos.Color = (currentNumber % 2 == 0) ? Color.Red : Color.Black; + } + else + { + numeroPanos.Color = (currentNumber % 2 == 0) ? Color.Black : Color.Red; + } + } + else + { + numeroPanos.Color = (currentNumber % 2 == 0) ? Color.Red : Color.Black; + } + } + + numeroPanos.Position = new Vector(x, y); + numeroPanos.Tag = currentNumber; + Add(numeroPanos); + + Label numeroLabel = new Label(buttonSize, buttonSize); + numeroLabel.Text = currentNumber.ToString(); + numeroLabel.TextColor = Color.White; + numeroLabel.Position = new Vector(x, y); + numeroPanos.Add(numeroLabel); + + // Rekisteröidään napin hiiriklikkaus käyttäen paikallista muuttujaa + Mouse.Listen(MouseButton.Left, ButtonState.Pressed, async () => + { + if (numeroPanos.IsInside(Mouse.PositionOnScreen)) + { + panosAsetettu = new TaskCompletionSource<bool>(false); + // Tallennetaan vain numero välimuistiin + clickLog.Add(numeroPanos.Tag.ToString()); + await LisaaPanos(true); + panosAsetettu.TrySetResult(true); + double currentbet = panos; + peliKesken += 1; + pistelaskuri.Value -= currentbet; + AsetaPanos(numeroPanos.Tag.ToString(), currentbet); + if (doneButton == null) + { + CreateDoneButton(); + } + } + }, "Aseta panos numerolle " + currentNumber); + } + + GameObject gOPanos = new GameObject(150, 50); + gOPanos.Color = Color.LimeGreen; + // Asetetaan nappi hieman panostusalueen alapuolelle + gOPanos.Position = new Vector(startX+52, startY+60); + Add(gOPanos); + + Label gOLabel = new Label(150, 50); + gOLabel.Text = "0"; + gOLabel.TextColor = Color.White; + gOLabel.Position = new Vector(startX+52, startY+60); + gOPanos.Add(gOLabel); + + Mouse.Listen(MouseButton.Left, ButtonState.Pressed, async () => + { + if (gOPanos.IsInside(Mouse.PositionOnScreen)) + { + panosAsetettu = new TaskCompletionSource<bool>(false); + // Tallennetaan nolla välimuistiin + clickLog.Add("0"); + await LisaaPanos(true); + panosAsetettu.TrySetResult(true); + double currentbet = panos; + peliKesken += 1; + pistelaskuri.Value -= currentbet; + AsetaPanosNollat("0", currentbet); + if (doneButton == null) + { + CreateDoneButton(); + } + } + }, "Aseta panos nollalle"); + + GameObject gO0Panos = new GameObject(150, 50); + gO0Panos.Color = Color.LimeGreen; + // Asetetaan nappi hieman panostusalueen alapuolelle + gO0Panos.Position = new Vector(startX+220, startY+60); + Add(gO0Panos); + + Label gO0Label = new Label(150, 50); + gO0Label.Text = "00"; + gO0Label.TextColor = Color.White; + gO0Label.Position = new Vector(startX+220, startY+60); + gO0Panos.Add(gO0Label); + + Mouse.Listen(MouseButton.Left, ButtonState.Pressed, async () => + { + if (gO0Panos.IsInside(Mouse.PositionOnScreen)) + { + panosAsetettu = new TaskCompletionSource<bool>(false); + // Tallennetaan tuplanolla välimuistiin + clickLog.Add("00"); + await LisaaPanos(true); + panosAsetettu.TrySetResult(true); + double currentbet = panos; + peliKesken += 1; + pistelaskuri.Value -= currentbet; + AsetaPanosNollat("00", currentbet); + if (doneButton == null) + { + CreateDoneButton(); + } + } + }, "Aseta panos tuplanollalle"); + + GameObject punainenPanos = new GameObject(165, 60); + punainenPanos.Color = Color.Red; + // Asetetaan nappi hieman panostusalueen alapuolelle + punainenPanos.Position = new Vector(startX+52, startY+125); + Add(punainenPanos); + + Label punainenLabel = new Label(165, 60); + punainenLabel.Text = "Punainen"; + punainenLabel.TextColor = Color.White; + punainenLabel.Position = new Vector(startX+52, startY+125); + punainenPanos.Add(punainenLabel); + + Mouse.Listen(MouseButton.Left, ButtonState.Pressed, async () => + { + if (punainenPanos.IsInside(Mouse.PositionOnScreen)) + { + panosAsetettu = new TaskCompletionSource<bool>(false); + // Tallennetaan värin nimi välimuistiin + clickLog.Add("Punainen"); + await LisaaPanos(true); + panosAsetettu.TrySetResult(true); + double currentbet = panos; + peliKesken += 1; + pistelaskuri.Value -= currentbet; + await AsetaPanosVärille("Punainen", currentbet); + if (doneButton == null) + { + CreateDoneButton(); + } + } + }, "Aseta panos värille Punainen"); + + GameObject mustaPanos = new GameObject(165, 60); + mustaPanos.Color = Color.Black; + // Asetetaan nappi hieman panostusalueen alapuolelle + mustaPanos.Position = new Vector(startX+220, startY+125); + Add(mustaPanos); + + Label mustaLabel = new Label(165, 60); + mustaLabel.Text = "Musta"; + mustaLabel.TextColor = Color.White; + mustaLabel.Position = new Vector(startX+220, startY+125); + mustaPanos.Add(mustaLabel); + + Mouse.Listen(MouseButton.Left, ButtonState.Pressed, async () => + { + if (mustaPanos.IsInside(Mouse.PositionOnScreen)) + { + panosAsetettu = new TaskCompletionSource<bool>(false); + // Tallennetaan värin nimi välimuistiin + clickLog.Add("Musta"); + await LisaaPanos(true); + panosAsetettu.TrySetResult(true); + double currentbet = panos; + peliKesken += 1; + pistelaskuri.Value -= currentbet; + AsetaPanosVärille("Musta", currentbet); + if (doneButton == null) + { + CreateDoneButton(); + } + } + }, "Aseta panos värille Musta"); + + + } + + void CreateDoneButton() + { + GameObject Done = new GameObject(150, 75); + Done.Color = Color.Green; + // Asetetaan nappi hieman panostusalueen alapuolelle + Done.Position = new Vector(500,-200); + Add(Done); + + Label DoneLabel = new Label(150, 75); + DoneLabel.Text = "Valmis"; + DoneLabel.TextColor = Color.White; + DoneLabel.Position = new Vector(500,-200); + Done.Add(DoneLabel); + + Mouse.Listen(MouseButton.Left, ButtonState.Pressed, () => + { + if (Done.IsInside(Mouse.PositionOnScreen)) + { + //panosAsetettu.TrySetResult(true); + RulettiPyöritys(); + } + }, ""); + } + + async Task AsetaPanos(string numero, double bet) + { + if (bet <= 0.0) + { + return; + } + var existingBet = bets.FirstOrDefault(b => b.BetType == numero); + if (existingBet != null) + { + existingBet.Amount += bet; + } + else + { + bets.Add(new RBetAmounts(numero.ToString(), bet)); + } + + panosLabel.Clear(); + panos = 0; + MessageDisplay.Add($"{bet}€ panos on asetettu numeroon {numero}!"); } + async Task AsetaPanosVärille(string vari, double bet) + { + if (bet <= 0.0) + { + return; + } + var existingBet = bets.FirstOrDefault(b => b.BetType.Equals(vari, StringComparison.OrdinalIgnoreCase)); + if (existingBet != null) + { + // Lisätään panos olemassa olevaan määrään + existingBet.Amount += bet; + } + else + { + // Lisätään uusi panoslistaan + bets.Add(new RBetAmounts(vari, bet)); + } + + panosLabel.Clear(); + panos = 0; + MessageDisplay.Add($"{bet}€ panos on asetettu värille {vari}!"); + } + + async Task AsetaPanosNollat(string nolla, double bet) + { + if (bet <= 0.0) + { + return; + } + var existingBet = bets.FirstOrDefault(b => b.BetType == nolla); + if (existingBet != null) + { + existingBet.Amount += bet; + } + else + { + bets.Add(new RBetAmounts(nolla, bet)); + } + + panosLabel.Clear(); + panos = 0; + MessageDisplay.Add($"Panos {bet} asetettu numerolle {nolla}!"); + } + + void RulettiPyöritys() + { + ClearGameObjects(); + ClearControls(); + Add(pistenaytto); + + clickLog = new HashSet<string>(clickLog).ToList(); + MessageDisplay.Add($"Panokset on jaettu kohtiin:{string.Join(", ", clickLog)}"); + Console.WriteLine($"Panokset on jaettu kohtiin:{string.Join(", ", clickLog)}"); + Console.WriteLine($"Panos per kohde on {panos} jaettuna {clickLog.Count} on {panos/clickLog.Count}"); + + RulettiLauta(this, 850, 20, 30, 0, 0); + + TakaisinPV(); + } + + + /// <summary> + /// + /// </summary> + /// <param name="peli">peli johon "animaatio" luodaan</param> + /// <param name="ph">halkaisian pituus jolla pallo pyörii</param> + /// <param name="betpalloH">näkyvän pyörivän pallon koko</param> + /// <param name="pn">pyörimis nopeus</param> + public async Task RulettiLauta(Game peli, double ph,double betpalloH , double pn, double x, double y ) + { + bool pyorii = false; + + PhysicsObject pelilauta = new PhysicsObject(ph + 2 * betpalloH, ph + 2 * betpalloH, Shape.Circle, x, y); + pelilauta.AddCollisionIgnoreGroup(1); + pelilauta.Image = LoadImage("rulettipöytä.png"); + peli.Add(pelilauta); + + PhysicsObject transpallo = new PhysicsObject(ph, ph, Shape.Circle, x, y); + transpallo.Color = Color.Transparent; + transpallo.AddCollisionIgnoreGroup(1); + peli.Add(transpallo); + + + PhysicsObject betpallo = new PhysicsObject(betpalloH, betpalloH,Shape.Circle, ph/2 - ph/10 , y); + betpallo.Color = Color.Gold; + transpallo.Add(betpallo); + + + PhysicsObject pistePallo = new PhysicsObject(10,10,Shape.Circle, x-10, y+10); + pistePallo.AddCollisionIgnoreGroup(1); + pelilauta.Add(pistePallo); + + List<Angle> checkAngles = new List<Angle>(); + + + Keyboard.Listen(Key.Space, ButtonState.Pressed, async () => await pyorautalauta(transpallo, pelilauta, pn, pyorii, checkAngles),"pyöräyttää laudan ja pallon"); + } + + public async Task pyorautalauta(PhysicsObject transpallo, PhysicsObject pelilauta, double pn, bool pyorii, List<Angle> checkAngles) + { + ClearControls(); + transpallo.AngularDamping = RandomGen.NextDouble(0.7,2);// molemmat hidastuu eri nopeuksilla + pelilauta.AngularDamping = RandomGen.NextDouble(0.3,0.5); + transpallo.AngularVelocity = pn + RandomGen.NextDouble(4, 10); + pelilauta.AngularVelocity = -pn + RandomGen.NextDouble(-10, -5); + pyorii = true; + peliKesken += 1; + bool samaNopeus = false; + + while (pyorii) + { + if (transpallo.AngularVelocity <= 1 && !samaNopeus) + { + transpallo.AngularDamping += 2; + if (transpallo.AngularVelocity == 0) + { + transpallo.AngularVelocity = pelilauta.AngularVelocity; + transpallo.AngularDamping = pelilauta.AngularDamping; + samaNopeus = true; + } + + } + + if (pelilauta.AngularVelocity == 0) + { + pyorii = false; + rulepisteenlasku(transpallo, pelilauta, checkAngles); + } + await Task.Delay(100); + } + } + public async Task rulepisteenlasku(PhysicsObject transpallo, PhysicsObject pelilauta, List<Angle> checkAngles) + { + double payout = 0; + bool voitto = false; + var rulettitaskut = CreateRouletteBets(); + realangle = (transpallo.Angle.Degrees - pelilauta.Angle.Degrees) % 360; + Console.WriteLine(transpallo.Angle.GetPositiveDegrees()); + Console.WriteLine(pelilauta.Angle.GetPositiveDegrees()); + if (realangle < 0) { realangle += 360; } + Console.WriteLine(realangle); + Console.WriteLine("aloitetaan tarkistus"); + + string voittovari = ""; + int pallosijainti = (int)palloangle(realangle); + foreach (var rouletteBet in rulettitaskut) + { + if (rouletteBet.Pocket == pallosijainti) + { + voittovari = rouletteBet.Color; + break; + } + } + + + //ClearGameObjects(); + + // Erilliset listat numeroille ja sanoille + List<int> numbers = new List<int>(); + List<string> colors = new List<string>(); + + foreach (var bet in bets) + { + // Tarkastetaan, onko panos numeropanoksessa + if (int.TryParse(bet.BetType, out int betNumber)) + { + if (betNumber == pallosijainti) + { + // Oletetaan, että yksittäinen numeropanos maksaa 36-kertaisesti + payout = bet.Amount * 36; + pistelaskuri.Value += payout; + voitto = true; + MessageDisplay.Add($"Numeropanoksesta voitit: +{payout}"); + } + } + else // Muut panokset, esim. väri + { + // Vertaillaan värin nimiä (huomioi mahdolliset eri nimitykset) + if (bet.BetType.Equals(voittovari, StringComparison.OrdinalIgnoreCase)) /*|| + (bet.BetType.Equals("Punainen", StringComparison.OrdinalIgnoreCase) && voittovari.Equals("Red", StringComparison.OrdinalIgnoreCase)) || + (bet.BetType.Equals("Musta", StringComparison.OrdinalIgnoreCase) && voittovari.Equals("Black", StringComparison.OrdinalIgnoreCase)))*/ + { + // Esim. väri maksaa 2-kertaisesti + payout = bet.Amount * 2; + pistelaskuri.Value += payout; + voitto = true; + MessageDisplay.Add($"Väripanoksesta voitit: +{payout}"); + } + else if (bet.BetType == "0" || bet.BetType == "00") + { + // Esimerkiksi nollille voi olla oma kerroin (tarkista pelin säännöt) + payout = bet.Amount * 50; + // Jos voittava numero on 0 tai 00 + if (pallosijainti.ToString() == bet.BetType) + { + pistelaskuri.Value += payout; + voitto = true; + MessageDisplay.Add($"Nollapanoksesta voitit: +{payout}"); + } + } + } + } + bets = null; + peliKesken = 0; + + Label tulosTeksti = new Label(); + tulosTeksti.TextColor = Color.LimeGreen; + tulosTeksti.Color = Color.Black; + tulosTeksti.Position = new Vector(-Screen.Width / 3, Screen.Height / 4); // Vasemmalle ylös + if (voitto){tulosTeksti.Text = $"Numero: {pallosijainti}\nVäri: {voittovari}\nVoittosumma: {payout}€";} + else {tulosTeksti.Text = $"Numero: {pallosijainti}\nVäri: {voittovari}\nHävisit (luuseri) :DD";} + + tulosTeksti.TextScale = new Vector( 2, 2); + Add(tulosTeksti); + + double nappiwidth = 280; + double nappiheight = 100; + + PushButton uusiPeliNappi = new PushButton(nappiwidth, nappiheight, "Uusi peli"); + uusiPeliNappi.Position = new Vector(Screen.Right-200, Screen.Height / 6); // Oikealle + uusiPeliNappi.Size = new Vector(280, 100); + uusiPeliNappi.TextScale = new Vector(2,2); + uusiPeliNappi.Clicked += delegate { _ = Ruletti(); };; + Add(uusiPeliNappi); + + PushButton valikkoNappi = new PushButton( nappiwidth, nappiheight, "Päävalikko"); + valikkoNappi.Position = new Vector(Screen.Right-200, -Screen.Height / 6); // Oikealle, alemmaksi + valikkoNappi.Size = new Vector(280, 100); + valikkoNappi.TextScale = new Vector(2,2); + valikkoNappi.Clicked += RultoPV; + Add(valikkoNappi); + + TakaisinPV(); + } + + public void RultoPV() + { + ClearControls(); + ClearGameObjects(); + PelinValinta(); + } + + public double palloangle(double realangle) + { + var rulettitaskut = CreateRouletteBets(); + Console.WriteLine($"lista kohdista: {string.Join(", ", rulettitaskut)}"); + bool tarkastettu = false; + while (tarkastettu == false) + { + foreach (var rouletteBet in rulettitaskut) + { + if (realangle > rouletteBet.Angle) + { + Console.WriteLine(rouletteBet.Pocket); + tarkastettu = true; + int pocketdb = rouletteBet.Pocket; + return pocketdb; + } + } + } + return -1; + } public async Task Slots() { + Image tyhja = LoadImage("tyhjatausta.png"); + Level.Background.Image = tyhja; + Widget overlay = new Widget(Screen.Width, Screen.Height); // Kuvan koko (leveys, korkeus) + overlay.Image = LoadImage("slotBG.png"); + + Add(overlay); + panosAsetettu = new TaskCompletionSource<bool>(false); ClearGameObjects(); ClearControls(); Add(pistenaytto); - await LisaaPanos(); // Odotetaan, kunnes panos on asetettu + await LisaaPanos(false); // Odotetaan, kunnes panos on asetettu panosAsetettu.TrySetResult(true); AlustusSlots(); @@ -1655,7 +2419,7 @@ public class Financial_Freedom : PhysicsGame Level.Background.Image = taustakuvaCF; Level.Background.Width = Screen.Width; Level.Background.Height = Screen.Height; - await LisaaPanos(); // Odotetaan, kunnes panos on asetettu + await LisaaPanos(true); // Odotetaan, kunnes panos on asetettu panosAsetettu.TrySetResult(true); // Varmistetaan, että odotus päättyy TakaisinPV(); ClearControls(); @@ -1712,6 +2476,27 @@ public class Financial_Freedom : PhysicsGame TextScale = new Vector(2, 2) }; Add(veikkausLabel); + + double nappiwidth = 280; + double nappiheight = 100; + + PushButton kruuna = new PushButton(0,0,""); + PushButton klaava = new PushButton(0,0,""); + + kruuna = new PushButton(nappiwidth, nappiheight, "Kruuna"); + kruuna.Position = new Vector(Screen.Left+200, 0); // Oikealle + kruuna.Size = new Vector(280, 100); + kruuna.TextScale = new Vector(2,2); + kruuna.Clicked += delegate {Remove(veikkausLabel); Remove(kerroin); Remove(potti); HeitaKolikko(true, kruuna, klaava);};; + Add(kruuna); + + klaava = new PushButton( nappiwidth, nappiheight, "Klaava"); + klaava.Position = new Vector(Screen.Right-200, 0); // Oikealle, alemmaksi + klaava.Size = new Vector(280, 100); + klaava.TextScale = new Vector(2,2); + klaava.Clicked += delegate {Remove(veikkausLabel); Remove(kerroin); Remove(potti); HeitaKolikko(false, kruuna, klaava);}; + Add(klaava); + await Task.Delay(100); // Kuunnellaan näppäimistösyötteet, jolloin pelaaja voi valita kruunan ('K') tai klaavan ('C') Keyboard.Listen(Key.K, ButtonState.Pressed, () => @@ -1719,20 +2504,22 @@ public class Financial_Freedom : PhysicsGame Remove(veikkausLabel); Remove(kerroin); Remove(potti); - HeitaKolikko(true); + HeitaKolikko(true, kruuna, klaava); }, "Veikkaa kruuna"); Keyboard.Listen(Key.C, ButtonState.Pressed, () => { Remove(veikkausLabel); Remove(kerroin); Remove(potti); - HeitaKolikko(false); + HeitaKolikko(false, kruuna, klaava); }, "Veikkaa klaava"); } - private async Task HeitaKolikko(bool veikkausKruuna) + private async Task HeitaKolikko(bool veikkausKruuna, PushButton kruuna, PushButton klaava) { ClearControls(); + Remove(kruuna); + Remove(klaava); Random rand = new Random(); bool kolikkoKruuna = rand.Next(2) == 0; // Kruuna (true) vai Klaava (false) Console.WriteLine("kolikko kruuna "+kolikkoKruuna); @@ -1772,6 +2559,31 @@ public class Financial_Freedom : PhysicsGame TextScale = new Vector(1,1) }; Add(uusi); + + double nappiwidth = 280; + double nappiheight = 100; + + PushButton paavalikko = new PushButton(nappiwidth, nappiheight, "Päävalikko"); + paavalikko.Position = new Vector(Screen.Left+200, -Screen.Height / 6); // vasen + paavalikko.Size = new Vector(350, 100); + paavalikko.TextScale = new Vector(2,2); + paavalikko.Clicked += delegate { _ = peliKesken = 0; ClearControls(); ClearGameObjects(); PelinValinta();}; + Add(paavalikko); + + PushButton vaihdabet = new PushButton( nappiwidth, nappiheight, "Vaihda panosta"); + vaihdabet.Position = new Vector(Screen.Right-200, Screen.Height / 6); // Oikealle, + vaihdabet.Size = new Vector(350, 100); + vaihdabet.TextScale = new Vector(2,2); + vaihdabet.Clicked += delegate { _ = Coinflip();}; + Add(vaihdabet); + + PushButton samabet = new PushButton(nappiwidth, nappiheight, "Uusi kierros samalla panoksella"); + samabet.Position = new Vector(Screen.Right-350, -Screen.Height / 6); // Oikealle alas + samabet.Size = new Vector(650, 100); + samabet.TextScale = new Vector(2,2); + samabet.Clicked += delegate { Remove(uusi); Remove(paavalikko); Remove(vaihdabet); Remove(samabet); EnsimmäinenFlibidi(); }; + Add(samabet); + Keyboard.Listen(Key.P, ButtonState.Pressed, async () => { Remove(uusi); @@ -1865,6 +2677,30 @@ public class Financial_Freedom : PhysicsGame TextScale = new Vector(1,1) }; Add(JatkaCF); + + double nappiwidth = 280; + double nappiheight = 100; + + PushButton jatka = new PushButton(0,0,""); + PushButton lopeta = new PushButton(0,0,""); + + jatka = new PushButton(nappiwidth, nappiheight, "Jatka"); + jatka.Position = new Vector(Screen.Left+200, 0); // Oikealle + jatka.Size = new Vector(280, 100); + jatka.TextScale = new Vector(2,2); + jatka.Clicked += delegate {Remove(JatkaCF); Remove(kerroin); Remove(potti); Remove(jatka); Remove(lopeta); AsetaVeikkaus(); };; + Add(jatka); + + lopeta = new PushButton( nappiwidth, nappiheight, "Lopeta"); + lopeta.Position = new Vector(Screen.Right-200, 0); // Oikealle, alemmaksi + lopeta.Size = new Vector(280, 100); + lopeta.TextScale = new Vector(2,2); + lopeta.Clicked += delegate + { + Lopetaflip(JatkaCF, kerroin, potti, jatka, lopeta); + }; + Add(lopeta); + await Task.Delay(200); // Kuunnellaan pelaajan syöte - jos pelaaja haluaa jatkaa, peli jatkuu Keyboard.Listen(Key.J, ButtonState.Pressed, () => @@ -1872,6 +2708,7 @@ public class Financial_Freedom : PhysicsGame Remove(JatkaCF); Remove(kerroin); Remove(potti); + Remove(jatka); Remove(lopeta); // Pelaaja haluaa jatkaa, joten peli etenee AsetaVeikkaus(); // Asetetaan uusi veikkaus }, "Jatka peliä (J)"); @@ -1879,36 +2716,71 @@ public class Financial_Freedom : PhysicsGame // Jos pelaaja ei halua jatkaa, hän voi ottaa rahat Keyboard.Listen(Key.P, ButtonState.Pressed, () => { - ClearControls(); - peliKesken -= 1; - Remove(JatkaCF); - Remove(kerroin); - Remove(potti); - // Pelaaja ei halua jatkaa, ottaa kerätyt rahat - pistelaskuri.Value += Math.Round(keratytRahatCF * yTs, 2); // Lisää kerätyt rahat pelaajan saldolle - keratytRahatCF = 0; // Nollaa kerätyt rahat - MessageDisplay.Add($"Peli loppui. Rahasaldo: {pistelaskuri.Value}"); - Console.WriteLine($"Peli loppui. Rahasaldo: {pistelaskuri.Value}"); - Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") - { - Color = Color.White, - Position = new Vector(0, -275), // Asetetaan sijainti - }; - Add(uusi); - Keyboard.Listen(Key.P, ButtonState.Pressed, async () => - { - Remove(uusi); - await Coinflip(); - }, "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN - Keyboard.Listen(Key.N, ButtonState.Pressed, async () => - { - Remove(uusi); - await EnsimmäinenFlibidi(); - }, "uus kiesi"); - TakaisinPV(); // Siirtyy takaisin pelinvalintaan + Lopetaflip(JatkaCF, kerroin, potti, jatka, lopeta); }, "Ota rahat ja lopeta (P)"); } + + public void Lopetaflip(Label ljatkacf, Label lkerroin, Label lpotti, PushButton ljatka, PushButton llopeta) + { + ClearControls(); + peliKesken -= 1; + + Remove(ljatkacf); + Remove(lkerroin); + Remove(lpotti); + Remove(ljatka); + Remove(llopeta); + + // Pelaaja ei halua jatkaa, ottaa kerätyt rahat + pistelaskuri.Value += Math.Round(keratytRahatCF * yTs, 2); // Lisää kerätyt rahat pelaajan saldolle + keratytRahatCF = 0; // Nollaa kerätyt rahat + MessageDisplay.Add($"Peli loppui. Rahasaldo: {pistelaskuri.Value}"); + Console.WriteLine($"Peli loppui. Rahasaldo: {pistelaskuri.Value}"); + Label uusi = new Label("Haluatko aloittaa uuden kierroksen samalla panoksella (n), vaihtaa panosta (p) vai poistua pelistä (0)?") + { + Color = Color.White, + Position = new Vector(0, -275), // Asetetaan sijainti + }; + Add(uusi); + + int nappiwidth = 350; + int nappiheight = 100; + + PushButton paavalikko = new PushButton(nappiwidth, nappiheight, "Päävalikko"); + paavalikko.Position = new Vector(Screen.Left+200, -Screen.Height / 6); // vasen + paavalikko.Size = new Vector(350, 100); + paavalikko.TextScale = new Vector(2,2); + paavalikko.Clicked += delegate { _ = peliKesken = 0; ClearControls(); ClearGameObjects(); PelinValinta();}; + Add(paavalikko); + + PushButton vaihdabet = new PushButton( nappiwidth, nappiheight, "Vaihda panosta"); + vaihdabet.Position = new Vector(Screen.Right-200, Screen.Height / 6); // Oikealle, + vaihdabet.Size = new Vector(350, 100); + vaihdabet.TextScale = new Vector(2,2); + vaihdabet.Clicked += delegate { _ = Coinflip();}; + Add(vaihdabet); + + PushButton samabet = new PushButton(nappiwidth, nappiheight, "Uusi kierros samalla panoksella"); + samabet.Position = new Vector(Screen.Right-350, -Screen.Height / 6); // Oikealle alas + samabet.Size = new Vector(650, 100); + samabet.TextScale = new Vector(2,2); + samabet.Clicked += delegate { Remove(uusi); Remove(paavalikko); Remove(vaihdabet); Remove(samabet); EnsimmäinenFlibidi(); }; + Add(samabet); + + Keyboard.Listen(Key.P, ButtonState.Pressed, async () => + { + Remove(uusi); + await Coinflip(); + }, "uus kiesi uudella panoksella"); // MUUTA MYÖHEMMIN KOSKA UUSI KIESI LUO UUDEN PAKAN + Keyboard.Listen(Key.N, ButtonState.Pressed, async () => + { + Remove(uusi); + await EnsimmäinenFlibidi(); + }, "uus kiesi"); + TakaisinPV(); // Siirtyy takaisin pelinvalintaan + } + void AddRaha() { pistelaskuri.Value += 250000; @@ -1929,28 +2801,7 @@ public class Financial_Freedom : PhysicsGame } - /// <summary> - /// luo suorakulmion annettun kokoon ja paikkaan - /// </summary> - /// <param name="peli"></param> - /// <param name="width">logon leveys</param> - /// <param name="height">logon korkeus</param> - /// <param name="x">logon paikka</param> - /// <param name="y">logon paikka</param> - public static void MiniPeliLogo(Game peli, double width, double height, double x, double y, string kuva, int order) - { - PhysicsObject p = new PhysicsObject(width, height, Shape.Rectangle, x, y); - p.Image = LoadImage(kuva); - Label iconLab = new Label(kuva+$" ({order})") - { - - Color = Color.White, - Position = new Vector(x, y-90), // Asetetaan sijainti - }; - peli.Add(p); - peli.Add(iconLab); - - } + async Task Voitto() { Console.WriteLine(finalscore); @@ -2036,6 +2887,7 @@ public class Financial_Freedom : PhysicsGame peliKesken = 0; peliOhi = false; pistelaskuri = null; + highScore = 0; Begin(); }, "uus kiesi"); } diff --git a/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj b/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj index 0d07e79627de4d1beb7bcf52e3349b2b0d81bf68..2c9c5e3957c5f0a026afca4503afb7b3e0cd85ba 100644 --- a/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj +++ b/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj @@ -332,37 +332,16 @@ <None Update="Data\toplistsave.txt"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> - <None Update="Content\dia1.png"> + <None Update="Content\RouletteBG.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> - <None Update="Content\dia2.png"> + <None Update="Content\rulettipöytä.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> - <None Update="Content\dia 3.png"> + <None Update="Content\tyhjatausta.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> - <None Update="Content\dia 4.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> - <None Update="Content\dia 5.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> - <None Update="Content\dia 6.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> - <None Update="Content\dia 7.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> - <None Update="Content\dia 8.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> - <None Update="Content\dia 9.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> - <None Update="Content\dia 10.png"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> - <None Update="Content\dia 11.png"> + <None Update="Content\slotBG.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> </ItemGroup>