diff --git a/Financial_Freedom/Financial_Freedom/Content/CasinoEntrance.png b/Financial_Freedom/Financial_Freedom/Content/CasinoEntrance.png new file mode 100644 index 0000000000000000000000000000000000000000..343807be1fe881ea602fc9b5973913ccd153659e Binary files /dev/null and b/Financial_Freedom/Financial_Freedom/Content/CasinoEntrance.png differ diff --git a/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs b/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs index 945ee9b4647b5c9c4a84c9a04834f20a4ad03b53..8c8c177e9cb9d8804d608b243680d833d5c40222 100644 --- a/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs +++ b/Financial_Freedom/Financial_Freedom/Financial_Freedom.cs @@ -185,6 +185,7 @@ public class Financial_Freedom : PhysicsGame private Label pelaajanSummalab; private PhysicsObject tero; + private PhysicsObject door; private List<GameObject> ovet; private int selectedDoor = -1; private Label doorPopupLabel; @@ -341,7 +342,7 @@ public class Financial_Freedom : PhysicsGame LuoAikaLaskuri(); LuoPistelaskuri(); - PelinValinta(); + Casinoentry(); } private void LuoAikaLaskuri() @@ -439,6 +440,47 @@ public class Financial_Freedom : PhysicsGame Console.WriteLine(highScore+"-1000 on "+ (highScore-1000)+" ja se jaetaan "+lopetusAika+" tulee "+((highScore-1000)/lopetusAika)); Console.WriteLine("finalscore: "+finalscore); } + + private void Casinoentry() + { + Level.Background.Image = LoadImage("Casinoentrance.png"); + Level.Background.FitToLevel(); + + ovet = new List<GameObject>(); + + tero = null; + // Pelaaja + tero = new PlatformCharacter(Screen.Width/9, Screen.Height/4.5){ + Shape = Shape.Rectangle, + Position = new Vector(Screen.Left+150, Screen.Bottom+0.6*(Screen.Height/3)), + IgnoresCollisionResponse = true, + Image = LoadImage("tero.png") , + }; + Add(tero); + + PhysicsObject door = new PhysicsObject(Screen.Width/11, Screen.Height/6); + door.Shape = Shape.Rectangle; + door.Color = Color.Transparent; + door.Position = new Vector(Screen.Width/3.6, Screen.Bottom+0.55*(Screen.Height/3)); + door.Tag = "Door " + (7) + ": " + GetDoorDescription(7); + door.MakeStatic(); + ovet.Add(door); + Add(door); + + doorPopupLabel = new Label(""){ + Position = new Vector(0, 200), + TextColor = Color.White, + TextScale = new Vector(2, 2), + Color = Color.Black, + Size = new Vector(300, 50) + }; + + // controllit + Keyboard.Listen(Key.A, ButtonState.Down, () => tero.X -= 12, "Move left"); + Keyboard.Listen(Key.D, ButtonState.Down, () => tero.X += 12, "Move right"); + Keyboard.Listen(Key.Space, ButtonState.Pressed, SelectDoor, "Select a door"); + Keyboard.Listen(Key.Enter, ButtonState.Pressed, SelectDoor, "Select a door"); + } //kuvien lataus @@ -475,29 +517,21 @@ public class Financial_Freedom : PhysicsGame Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); } - public void PelinValinta() + public async Task PelinValinta() { ClearControls(); ClearGameObjects(); - // Define layers - Layer miniPeliLogotLayer = new Layer(); - Layer teroLayer = new Layer(); - - // Add layers to the game in the desired rendering order - Layers.Add(miniPeliLogotLayer); - Layers.Add(teroLayer); - string[] alkulogot = {"Plinko", "Blackjack", "Ruletti", "Slots", "Coinflip", "exit"}; Gravity = new Vector(0, 0); Level.Background.Image = taustakuvaPV; Level.Background.FitToLevel(); + LuoPistelaskuri(); var pakka = LuoPakka(); SekoitaPakka(pakka); - int ovicount = 6; // Tekee viis ovea @@ -506,18 +540,19 @@ public class Financial_Freedom : PhysicsGame double startX = -Screen.Width/3; for (int i = 0; i < ovicount; i++) { - GameObject door = new GameObject(Screen.Width/10, Screen.Height/3); + PhysicsObject door = new PhysicsObject(Screen.Width/10, Screen.Height/3); door.Shape = Shape.Rectangle; door.Color = Color.Brown; door.Image = LoadImage("door.png"); door.Position = new Vector(startX + i * doorSpacing, Screen.Bottom+0.75*(Screen.Height/3)); + door.MakeStatic(); //door.Image = LoadImage(alkulogot[i]); - MiniPeliLogo(this,door.Width, door.Height/2, door.X, door.Y+(0.8*door.Height), alkulogot[i], i, miniPeliLogotLayer); + MiniPeliLogo(this,door.Width, door.Height/2, door.X, door.Y+(0.8*door.Height), alkulogot[i], i); door.Tag = "Door " + (i + 1) + ": " + GetDoorDescription(i + 1); - door.Layer = miniPeliLogotLayer; + Console.WriteLine($"door {door.Tag} added"); Add(door); ovet.Add(door); } @@ -529,26 +564,28 @@ public class Financial_Freedom : PhysicsGame TextScale = new Vector(2, 2), Color = Color.Black, Size = new Vector(300, 50) - }; - - //Add(doorPopupLabel); - - Keyboard.Listen(Key.Space, ButtonState.Pressed, SelectDoor, "Select a door"); - Keyboard.Listen(Key.Enter, ButtonState.Pressed, SelectDoor, "Select a door"); + }; + await Task.Delay(10); // Pelaaja tero = new PhysicsObject(Screen.Width/6, Screen.Height/3){ Shape = Shape.Rectangle, Position = new Vector(Screen.Left+150, Screen.Bottom+0.6*(Screen.Height/3)), IgnoresCollisionResponse = true, Image = LoadImage("tero.png") , - Layer = teroLayer }; Add(tero); - + Console.WriteLine("tero added"); + + Remove(tero); + Add(tero); + + Keyboard.Listen(Key.Space, ButtonState.Pressed, SelectDoor, "Select a door"); + Keyboard.Listen(Key.Enter, ButtonState.Pressed, SelectDoor, "Select a door"); + // controllit - Keyboard.Listen(Key.A, ButtonState.Down, () => tero.X -= 10, "Move left"); - Keyboard.Listen(Key.D, ButtonState.Down, () => tero.X += 10, "Move right"); + Keyboard.Listen(Key.A, ButtonState.Down, () => tero.X -= 12, "Move left"); + Keyboard.Listen(Key.D, ButtonState.Down, () => tero.X += 12, "Move right"); } @@ -563,6 +600,7 @@ public class Financial_Freedom : PhysicsGame case 4: return "Slots"; case 5: return "Coinflip"; case 6: return "Ulos"; + case 7: return "Mene kasinoon sisälle"; default: return "Unknown"; } } @@ -571,6 +609,7 @@ public class Financial_Freedom : PhysicsGame private void UpdateDoorPopup() { if (doorPopupLabel == null) { return; } + if (tero == null) { return; } if (tero.IsAddedToGame == false) { return; } if (ovet == null) { return; } @@ -628,6 +667,11 @@ public class Financial_Freedom : PhysicsGame MessageDisplay.Add("You selected " + door.Tag); Remove(tero); Remove(doorPopupLabel); + ovet = null; + doorPopupLabel = null; + tero = null; + ClearGameObjects(); + ClearControls(); ValitsePeli(doorNumber); return; } @@ -645,14 +689,13 @@ public class Financial_Freedom : PhysicsGame /// <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, Layer layer) + 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 - Layer = layer }; p.Image = LoadImage(kuva); Label iconLab = new Label(kuva+$" ({order})") @@ -692,6 +735,9 @@ public class Financial_Freedom : PhysicsGame case 6: CasinoExit(); break; + case 7: + PelinValinta(); + break; default: MessageDisplay.Add("Tuntematon peli!"); break; diff --git a/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj b/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj index c3256e827824aa8c4ff05684789967851af177db..b63c1dee1da79a7cce5d71027d3a69dbc1265ece 100644 --- a/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj +++ b/Financial_Freedom/Financial_Freedom/Financial_Freedom.csproj @@ -389,6 +389,9 @@ <None Update="Content\door.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Update="Content\CasinoEntrance.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup>