From 976a649468d46b68477e526a6fef9f16b3989ccf Mon Sep 17 00:00:00 2001
From: Rajahalme Tomi Tapani <tomi.rajahalme.tr@gmail.com>
Date: Fri, 14 Mar 2025 05:33:03 +0200
Subject: [PATCH] =?UTF-8?q?Harjoitusty=C3=B6n=20ensimm=C3=A4inen=20versio?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../.idea/.idea.Cat Rescue/.idea/.gitignore   |  13 ++
 .../.idea.Cat Rescue/.idea/indexLayout.xml    |   8 +
 .../.idea/.idea.Cat Rescue/.idea/vcs.xml      |   6 +
 Cat Rescue/Cat Rescue.sln                     |  16 ++
 Cat Rescue/Cat Rescue/Cat Rescue.cs           | 211 ++++++++++++++++++
 Cat Rescue/Cat Rescue/Cat Rescue.csproj       |  12 +
 Cat Rescue/Cat Rescue/Images/floortile32.png  | Bin 0 -> 340 bytes
 Cat Rescue/Cat Rescue/Ohjelma.cs              |  26 +++
 8 files changed, 292 insertions(+)
 create mode 100644 Cat Rescue/.idea/.idea.Cat Rescue/.idea/.gitignore
 create mode 100644 Cat Rescue/.idea/.idea.Cat Rescue/.idea/indexLayout.xml
 create mode 100644 Cat Rescue/.idea/.idea.Cat Rescue/.idea/vcs.xml
 create mode 100644 Cat Rescue/Cat Rescue.sln
 create mode 100644 Cat Rescue/Cat Rescue/Cat Rescue.cs
 create mode 100644 Cat Rescue/Cat Rescue/Cat Rescue.csproj
 create mode 100644 Cat Rescue/Cat Rescue/Images/floortile32.png
 create mode 100644 Cat Rescue/Cat Rescue/Ohjelma.cs

diff --git a/Cat Rescue/.idea/.idea.Cat Rescue/.idea/.gitignore b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/.gitignore
new file mode 100644
index 0000000..bf5beaa
--- /dev/null
+++ b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/.gitignore	
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/.idea.Cat Rescue.iml
+/modules.xml
+/contentModel.xml
+/projectSettingsUpdater.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/Cat Rescue/.idea/.idea.Cat Rescue/.idea/indexLayout.xml b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/indexLayout.xml	
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="UserContentModel">
+    <attachedFolders />
+    <explicitIncludes />
+    <explicitExcludes />
+  </component>
+</project>
\ No newline at end of file
diff --git a/Cat Rescue/.idea/.idea.Cat Rescue/.idea/vcs.xml b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/Cat Rescue/.idea/.idea.Cat Rescue/.idea/vcs.xml	
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/Cat Rescue/Cat Rescue.sln b/Cat Rescue/Cat Rescue.sln
new file mode 100644
index 0000000..dcb20c9
--- /dev/null
+++ b/Cat Rescue/Cat Rescue.sln	
@@ -0,0 +1,16 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cat Rescue", "Cat Rescue\Cat Rescue.csproj", "{FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{FF737DC5-AA74-4B0E-9A50-28E9DEF03A8A}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+EndGlobal
diff --git a/Cat Rescue/Cat Rescue/Cat Rescue.cs b/Cat Rescue/Cat Rescue/Cat Rescue.cs
new file mode 100644
index 0000000..25c38b4
--- /dev/null
+++ b/Cat Rescue/Cat Rescue/Cat Rescue.cs	
@@ -0,0 +1,211 @@
+using System;
+using System.Collections.Generic;
+using Jypeli;
+using Jypeli.Assets;
+using Jypeli.Controls;
+using Jypeli.Widgets;
+
+namespace Cat_Rescue;
+
+/// @author Tomi
+/// @version 14.03.2025
+/// <summary>
+/// 
+/// </summary>
+public class Cat_Rescue : Game
+{
+    private static readonly String[] lines1 = {
+        "  YYYYYYYYYYYYYYYYYYYYYYYY ",  
+        "  Y       X              Y ",  
+        "  Y     # X            = Y ",  
+        "  Y *     X              Y ",  
+        "  Y       X   XXX  XXX   Y ",  
+        "  Y       X   X      X   Y ",
+        "  YXX  XXXX   X      X   Y ",
+        "  Y           X      X   Y ",
+        "  Y =         X      X   Y ",
+        "  Y           X      X   Y ",
+        "  YXX  XXXXXXXX      X   Y ",
+        "  Y       X          X   Y ",
+        "  Y       X          X   Y ",
+        "  Y     # X #        X   Y ",  
+        "  Y       X          X C Y ",  
+        "  Y       X          X   Y ",  
+        "  YYYYYYYYYYYYYYYYYYYYYYYY ",  
+    };
+    private static readonly String[] level1 = {
+        " YYYYYYYYYYYYYYYYYYYYYYYY ",  
+        " Y       X              Y ",  
+        " Y     0 X            = Y ",  
+        " Y       X              Y ",  
+        " Y       X   XXX  XXX   Y ",  
+        " Y       X   X      X   Y ",
+        " YXX  XXXX   X      X   Y ",
+        " Y           X      X   Y ",
+        " Y =         X      X   Y ",
+        " Y           X      X   Y ",
+        " YXX  XXXXXXXX      X   Y ",
+        " Y       X          X   Y ",
+        " Y       X          X   Y ",
+        " Y     1 X 2        X   Y ",  
+        " Y       X          X   Y ",  
+        " YC  *   X          X   Y ",  
+        " YYYYYYYYYYYYYYYYYYYYYYYY ",  
+    };
+    
+    private int[] playerPos = new int[2];
+    private bool playerMoveCooldown = true;
+    
+    private int[,] map_entities = new int[24,24];
+    
+    //private Image planksImage = LoadImage("");
+    //private Image oWallImage = LoadImage("");
+    //private Image iWallImage = LoadImage("");
+    //private Image keyImage = LoadImage("");
+    //private Image cageImage = LoadImage("");
+    
+    private GameObject player;
+    private GameObject key;
+    private GameObject[] cage = new GameObject[3];
+    
+    private bool keyHeld = false;
+    
+    public override void Begin()
+    {
+        CreateMap();
+        
+        CreateKeys();
+        
+        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
+        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
+    }
+    
+    private void CreateMap()
+    {
+        Level.Background.CreateGradient(Color.SlateGray, Color.ForestGreen);
+        
+        CreateFloor(750, 500, Color.LightGray);
+        
+        
+        
+        TileMap tiles = TileMap.FromStringArray(level1);
+        tiles.SetTileMethod('X', CreateWall, Color.Gray);
+        tiles.SetTileMethod('Y', CreateWall, Color.DarkGray);
+        tiles.SetTileMethod('*', CreateKey, Color.LightYellow);
+        tiles.SetTileMethod('=', CreateGuard, Color.Salmon);
+        tiles.SetTileMethod('C', CreatePlayer, Color.White);
+        for (int i = 0; i < 3; i++)
+        {
+            tiles.SetTileMethod(Convert.ToChar((char)(i+48)), CreateCage, Color.LightBlue, i);
+        }
+        
+        tiles.Execute(32, 32);
+        Camera.ZoomToLevel();
+    }
+    
+    
+    
+    private void CreateWall(Vector location, double width, double height, Color color)
+    {
+        GameObject wall = new GameObject(width, height);
+        wall.Position = location;
+        wall.Color = color;
+        map_entities[Convert.ToInt16(wall.X/32+11.5), Convert.ToInt16(wall.Y/32+8)] = 1;
+        Add(wall);
+    }
+    
+    private void CreateFloor(double width, double height, Color color)
+    {
+        GameObject floor = new GameObject(width, height);
+        floor.Color = color;
+        Add(floor);
+    }
+    
+    private void CreateCage(Vector location, double width, double height, Color color, int id)
+    {
+        cage[id] = new GameObject(width, height);
+        cage[id].Position = location;
+        cage[id].Color = color;
+        map_entities[Convert.ToInt16(cage[id].X/32+11.5), Convert.ToInt16(cage[id].Y/32+8)] = (id + 3);
+        Add(cage[id]);
+    }
+    
+    private void CreateKey(Vector location, double width, double height, Color color)
+    {
+        key = new GameObject(width, height);
+        key.Position = location;
+        key.Color = color;
+        map_entities[Convert.ToInt16(key.X/32+11.5), Convert.ToInt16(key.Y/32+8)] = 2;
+        Add(key);
+    }
+
+    private void CreateGuard(Vector location, double width, double height, Color color)
+    {
+        GameObject guard = new GameObject(width, height);
+        guard.Position = location;
+        guard.Color = color;
+        Add(guard);
+    }
+    
+    private void CreatePlayer(Vector location, double width, double height, Color color)
+    {
+        player = new GameObject(width, height);
+        player.Position = location;
+        player.Color = color;
+        player.Tag = "Player";
+        playerPos[0] = 1;
+        playerPos[1] = 1;
+        
+        Add(player);
+    }
+    
+    private void CreateKeys()
+    {
+        Keyboard.Listen(Key.W, ButtonState.Pressed, MovePlayer, "Liikkuu vasemmalle", player, 0, 1);
+        Keyboard.Listen(Key.A, ButtonState.Pressed, MovePlayer, "Liikkuu vasemmalle", player, -1, 0);
+        Keyboard.Listen(Key.S, ButtonState.Pressed, MovePlayer, "Liikkuu vasemmalle", player, 0, -1);
+        Keyboard.Listen(Key.D, ButtonState.Pressed, MovePlayer, "Liikkuu vasemmalle", player, 1, 0);
+    }
+
+    private void MovePlayer(GameObject entity, int x, int y)
+    {
+        if (playerMoveCooldown)
+        {
+            if (map_entities[playerPos[0] + x, playerPos[1] + y] != 1)
+            {
+                playerMoveCooldown = false;
+                if (map_entities[playerPos[0] + x, playerPos[1] + y] == 2)
+                {
+                    key.Destroy();
+                    keyHeld = true;
+                    Console.WriteLine("Key Found!");
+                }
+                if (map_entities[playerPos[0] + x, playerPos[1] + y] > 2 && keyHeld == true)
+                {
+                    for (int i = 0; i < 3; i++)
+                    {
+                        if (map_entities[playerPos[0] + x, playerPos[1] + y] == (i + 3))
+                        {
+                            cage[i].Destroy();
+                        }
+                    }
+                    Console.WriteLine("Cat Freed!");
+                }
+                player.MoveTo(new Vector((playerPos[0]-11.5+ x)*32, (playerPos[1]-8+y)*32), 50, playerPosSet(x, y));
+            }
+        }
+    }
+    
+    private System.Action playerPosSet(int x, int y)
+    {
+        playerPos[0] += x;
+        playerPos[1] += y;
+        playerMoveCooldown = true;
+        return null;
+    }
+
+    private void KillMe()
+    {
+        Console.WriteLine("Fuck!");
+    }
+}
\ No newline at end of file
diff --git a/Cat Rescue/Cat Rescue/Cat Rescue.csproj b/Cat Rescue/Cat Rescue/Cat Rescue.csproj
new file mode 100644
index 0000000..6617984
--- /dev/null
+++ b/Cat Rescue/Cat Rescue/Cat Rescue.csproj	
@@ -0,0 +1,12 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+    <PropertyGroup>
+        <OutputType>WinExe</OutputType>
+        <TargetFramework>net8.0</TargetFramework>
+    </PropertyGroup>
+
+    <ItemGroup>
+        <PackageReference Include="Jypeli.NET" Version="11.*"/>
+    </ItemGroup>
+
+</Project>
diff --git a/Cat Rescue/Cat Rescue/Images/floortile32.png b/Cat Rescue/Cat Rescue/Images/floortile32.png
new file mode 100644
index 0000000000000000000000000000000000000000..b1e4207843bebc91c186b622eb1a47346cd88630
GIT binary patch
literal 340
zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN
z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!;7d;z$B+p3w^KF>9x~u@H4bSz!M4R@3(o<j
zGY2%@9PoQK$GW&r>2&-g+2AD=zIy4lwchjIotAMk+ABXj;o;{!o9+v*zrCsPxB4dG
z6|!p_wdTE=A)LXga=}QHOS|FDT(*^sy$*3RCjCF2=$rXRsz|>7N&U71MeQ$YJPvRM
z9ISE37WyETp~0CkS%fvKeX5GUrJL^*mk32o{49GTwoznx*#UtYk`KD7HBYW*vbAz9
z%y&F;sUeHETJ4GoBVWj`8uneWj!N~xJFdRd6Igik^G^ZR3yz<1PAYPG{9!SPt*}~F
i;>|EsW=~u352lGSHN5Vz4)Q=xGkCiCxvX<aXaWEcOM$om

literal 0
HcmV?d00001

diff --git a/Cat Rescue/Cat Rescue/Ohjelma.cs b/Cat Rescue/Cat Rescue/Ohjelma.cs
new file mode 100644
index 0000000..4f52c6e
--- /dev/null
+++ b/Cat Rescue/Cat Rescue/Ohjelma.cs	
@@ -0,0 +1,26 @@
+#region Using Statements
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+#endregion
+
+namespace Cat_Rescue
+{
+    /// <summary>
+    /// The main class.
+    /// </summary>
+    public static class Program
+    {
+        /// <summary>
+        /// The main entry point for the application.
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            using var game = new Cat_Rescue();
+            game.Run();
+        }
+    }
+}
\ No newline at end of file
-- 
GitLab