Skip to content
Snippets Groups Projects
Commit 5ee0f413 authored by bwalie's avatar bwalie
Browse files

documentation

parents f7a7f470 bab67188
No related branches found
No related tags found
No related merge requests found
<<<<<<< HEAD
# Pohja Ohjelmointi 1 -kurssin harjoitustöiden GIT-repoille.
Tämä on pohja Ohjelmointi 1 -kurssin harjoitustöiden Git-repoille.
......@@ -9,3 +10,7 @@ ja projektin kuvausta kohdasta Settings.
Lue Git-versiohallinnan tarkemmat käyttöohjeet TIMistä: <https://tim.jyu.fi/view/kurssit/tie/ohj1/harjoitustyo/git>
=======
# fshy-fsh
Catch the fsh xd
>>>>>>> bab671887382e691dc5701e4c2a90d35ea88e589
......@@ -18,7 +18,7 @@ namespace stupidanimale
[STAThread]
static void Main()
{
using var game = new stupidanimale();
using var game = new StupidAnimale();
game.Run();
}
}
......
using System;
using System.Collections.Generic;
using Jypeli;
using Jypeli.Assets;
using Jypeli.Controls;
using Jypeli.Widgets;
namespace stupidanimale
namespace StupidAnimale
{
public class stupidanimale : PhysicsGame
/// <summary>
/// @version @author
/// StupidAnimle class represents the game name.
/// In the game the player controls a character called "kat" which is basically cat to collected fishes while avoiding sharks.
/// The game includes features like movement by keyboard controls, collision detection, conditions for win/lose.
/// </summary>
public class StupidAnimale : PhysicsGame
{
static string[] line =
/// <summary>
/// Static array represents the layout of the game map.
/// Each characters describes specific types of object in the game.
/// X as a galaxy object, S as fish and X as shark.
/// </summary>
private static readonly string[] LINE =
{
" X * S ",
" S ",
......@@ -38,16 +50,20 @@ namespace stupidanimale
" S X X",
};
int tileWidth;
int tileHeight;
IntMeter collectedFishC;
IntMeter sharkhitC;
Label fishCounterlabel;
Label sharkhitlabel;
int remainingfsh;
int remainingShark;
int lives;
private int tileWidth;
private int tileHeight;
private IntMeter collectedFishC;
private IntMeter sharkhitC;
private Label fishCounterlabel;
private Label sharkhitlabel;
private int remainingfsh;
private int remainingShark;
private int lives;
/// <summary>
/// Starts by setting window size, Background music, Loading game objects, start message display and Counter creation.
/// </summary>
public override void Begin()
{
SetWindowSize(2030, 780);
......@@ -57,11 +73,11 @@ namespace stupidanimale
ShowStartMessage();
CreateCounters();
}
void LoadGame()
/// <summary>
/// Loading the game by setting up background, creating game objects, keyboard controls, tile map, creating borders.
/// </summary>
private void LoadGame()
{
ClearAll();
......@@ -73,24 +89,24 @@ namespace stupidanimale
remainingfsh = 10;
remainingShark = 4;
tileWidth = (int)(Screen.Width / line[0].Length);
tileHeight = (int)(Screen.Height / line.Length);
tileWidth = (int)(Screen.Width / LINE[0].Length);
tileHeight = (int)(Screen.Height / LINE.Length);
PhysicsObject kat = new PhysicsObject(90.0, 90.0, Shape.Circle);
Add(kat);
kat.Image = LoadImage("kat");
Keyboard.Listen(Key.W, ButtonState.Down, movekat, "Move Up", kat, new Vector(0, 400));
Keyboard.Listen(Key.A, ButtonState.Down, movekat, "Move Left", kat, new Vector(-400, 0));
Keyboard.Listen(Key.S, ButtonState.Down, movekat, "Move Down", kat, new Vector(0, -400));
Keyboard.Listen(Key.D, ButtonState.Down, movekat, "Move Right", kat, new Vector(200, 0));
Keyboard.Listen(Key.W, ButtonState.Down, MoveKat, "Move Up", kat, new Vector(0, 400));
Keyboard.Listen(Key.A, ButtonState.Down, MoveKat, "Move Left", kat, new Vector(-400, 0));
Keyboard.Listen(Key.S, ButtonState.Down, MoveKat, "Move Down", kat, new Vector(0, -400));
Keyboard.Listen(Key.D, ButtonState.Down, MoveKat, "Move Right", kat, new Vector(200, 0));
Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, null);
TileMap tiles = TileMap.FromStringArray(line);
TileMap tiles = TileMap.FromStringArray(LINE);
tiles.SetTileMethod('X', CreateGalaxy);
tiles.SetTileMethod('S', Createfsh);
tiles.SetTileMethod('*', Createshark);
tiles.SetTileMethod('S', CreateFsh);
tiles.SetTileMethod('*', CreateShark);
tiles.Execute(tileWidth, tileHeight);
Level.CreateBorders();
......@@ -98,7 +114,11 @@ namespace stupidanimale
Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Exit Game");
}
void CreateCounters()
/// <summary>
/// Counters to keep track of collected objects and remaining lives
/// </summary>
private void CreateCounters()
{
collectedFishC = new IntMeter(0);
sharkhitC = new IntMeter(0);
......@@ -125,7 +145,10 @@ namespace stupidanimale
Add(sharkhitlabel);
}
void ShowStartMessage()
/// <summary>
/// displays the start message when the game begins.
/// </summary>
private void ShowStartMessage()
{
string message = "MOI!!!! HUOM! = you have 4 lives, dont touch the sharks, get the fishes!!! ";
Label messageLabel = new Label(message);
......@@ -135,21 +158,30 @@ namespace stupidanimale
Timer.SingleShot(5.0, () => messageLabel.Destroy());
}
void CreateGalaxy(Vector location, double width, double height)
/// <summary>
/// Create and Position a galaxy object at demanded location.
/// </summary>
/// <param name="location"></param>
/// <param name="width"></param>
/// <param name="height"></param>
private void CreateGalaxy(Vector location, double width, double height)
{
PhysicsObject galaxy = PhysicsObject.CreateStaticObject(tileWidth, tileHeight);
galaxy.Position = location;
int randomIndex = RandomGen.NextInt(1, 4);
galaxy.Image = LoadImage("stone");
galaxy.Width = 40;
galaxy.Height = 80;
Add(galaxy);
}
void Createfsh(Vector location, double width, double height)
/// <summary>
/// Create and Position a galaxy object at demanded location.
/// </summary>
/// <param name="location"></param>
/// <param name="width"></param>
/// <param name="height"></param>
private void CreateFsh(Vector location, double width, double height)
{
int randomIndex = RandomGen.NextInt(0, 3);
PhysicsObject fsh = PhysicsObject.CreateStaticObject(tileWidth, tileHeight);
......@@ -174,23 +206,32 @@ namespace stupidanimale
fsh.Width = 100;
fsh.Height = 100;
Add(fsh);
AddCollisionHandler(fsh, CollisionWithfsh);
AddCollisionHandler(fsh, CollisionWithFsh);
}
void CollisionWithfsh(PhysicsObject fsh, PhysicsObject target)
/// <summary>
/// collision between the fish and other objects
/// Increases fish count when collected and destroy fish object
/// sound effect for win condition
/// </summary>
/// <param name="fsh"></param>
/// <param name="target"></param>
private void CollisionWithFsh(PhysicsObject fsh, PhysicsObject target)
{
collectedFishC.Value++;
remainingfsh--;
fsh.Destroy();
PlaySound("pop");
if (remainingfsh == 0)
{
WinGame();
}
if (remainingfsh == 0) WinGame();
}
void Createshark(Vector location, double width, double height)
/// <summary>
/// Create and Position a shark object at demanded location.
/// </summary>
/// <param name="location"></param>
/// <param name="width"></param>
/// <param name="height"></param>
private void CreateShark(Vector location, double width, double height)
{
PhysicsObject shark = PhysicsObject.CreateStaticObject(tileWidth, tileHeight);
shark.Position = location;
......@@ -201,20 +242,26 @@ namespace stupidanimale
AddCollisionHandler(shark, CollisionWithShark);
}
void CollisionWithShark(PhysicsObject shark, PhysicsObject target)
/// <summary>
/// collision between the shark and other objects
/// Increases shark count when hit.
/// sound effect for lose condition
/// </summary>
/// <param name="shark"></param>
/// <param name="target"></param>
private void CollisionWithShark(PhysicsObject shark, PhysicsObject target)
{
sharkhitC.Value++;
remainingShark--;
PlaySound("meow");
if (remainingShark == 0 && remainingfsh > 0)
{
LoseGame();
}
if (remainingShark == 0 && remainingfsh > 0) LoseGame();
}
void WinGame()
/// <summary>
/// Displays win message, stops background music
/// a delay to restart the game
/// </summary>
private void WinGame()
{
MediaPlayer.Stop();
PlaySound("fishyonme");
......@@ -222,31 +269,37 @@ namespace stupidanimale
Timer.SingleShot(3.0, () => LoadGame());
}
void LoseGame()
/// <summary>
/// Displays lose message, stop background music
/// a delay to restart the game
/// </summary>
private void LoseGame()
{
PlaySound("shark");
ShowMessage("NOOOO SHARKKK");
Timer.SingleShot(3.0, () => LoadGame());
}
void ShowMessage(string message)
/// <summary>
/// display message for a demanded time length
/// </summary>
/// <param name="message"></param>
private void ShowMessage(string message)
{
Label messageLabel = new Label(message);
messageLabel.Position = new Vector(0, 0);
Add(messageLabel);
Timer.SingleShot(3.0, () => messageLabel.Destroy());
}
void movekat(PhysicsObject kat, Vector force)
/// <summary>
/// 'kat' object in the demanded location.
/// </summary>
/// <param name="kat"></param>
/// <param name="force"></param>
private void MoveKat(PhysicsObject kat, Vector force)
{
kat.Hit(force);
}
}
}
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