Skip to content
Snippets Groups Projects
Commit 976a6494 authored by Rajahalme Tomi Tapani's avatar Rajahalme Tomi Tapani
Browse files

Harjoitustyön ensimmäinen versio

parent 5137ff9c
No related branches found
No related tags found
No related merge requests found
# 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
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?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

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
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
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jypeli.NET" Version="11.*"/>
</ItemGroup>
</Project>
Cat Rescue/Cat Rescue/Images/floortile32.png

340 B

#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
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