Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HTohj1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
myahsumy
HTohj1
Commits
5ee0f413
Commit
5ee0f413
authored
10 months ago
by
bwalie
Browse files
Options
Downloads
Plain Diff
documentation
parents
f7a7f470
bab67188
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+5
-0
5 additions, 0 deletions
README.md
stupidanimale/stupidanimale/Ohjelma.cs
+1
-1
1 addition, 1 deletion
stupidanimale/stupidanimale/Ohjelma.cs
stupidanimale/stupidanimale/stupidanimale.cs
+112
-59
112 additions, 59 deletions
stupidanimale/stupidanimale/stupidanimale.cs
with
118 additions
and
60 deletions
README.md
+
5
−
0
View file @
5ee0f413
<<<<<<< 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
This diff is collapsed.
Click to expand it.
stupidanimale/stupidanimale/Ohjelma.cs
+
1
−
1
View file @
5ee0f413
...
...
@@ -18,7 +18,7 @@ namespace stupidanimale
[
STAThread
]
static
void
Main
()
{
using
var
game
=
new
s
tupid
a
nimale
();
using
var
game
=
new
S
tupid
A
nimale
();
game
.
Run
();
}
}
...
...
This diff is collapsed.
Click to expand it.
stupidanimale/stupidanimale/stupidanimale.cs
+
112
−
59
View file @
5ee0f413
using
System
;
using
System.Collections.Generic
;
using
Jypeli
;
using
Jypeli.Assets
;
using
Jypeli.Controls
;
using
Jypeli.Widgets
;
namespace
s
tupid
a
nimale
namespace
S
tupid
A
nimale
{
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
,
m
ove
k
at
,
"Move Up"
,
kat
,
new
Vector
(
0
,
400
));
Keyboard
.
Listen
(
Key
.
A
,
ButtonState
.
Down
,
m
ove
k
at
,
"Move Left"
,
kat
,
new
Vector
(-
400
,
0
));
Keyboard
.
Listen
(
Key
.
S
,
ButtonState
.
Down
,
m
ove
k
at
,
"Move Down"
,
kat
,
new
Vector
(
0
,
-
400
));
Keyboard
.
Listen
(
Key
.
D
,
ButtonState
.
Down
,
m
ove
k
at
,
"Move Right"
,
kat
,
new
Vector
(
200
,
0
));
Keyboard
.
Listen
(
Key
.
W
,
ButtonState
.
Down
,
M
ove
K
at
,
"Move Up"
,
kat
,
new
Vector
(
0
,
400
));
Keyboard
.
Listen
(
Key
.
A
,
ButtonState
.
Down
,
M
ove
K
at
,
"Move Left"
,
kat
,
new
Vector
(-
400
,
0
));
Keyboard
.
Listen
(
Key
.
S
,
ButtonState
.
Down
,
M
ove
K
at
,
"Move Down"
,
kat
,
new
Vector
(
0
,
-
400
));
Keyboard
.
Listen
(
Key
.
D
,
ButtonState
.
Down
,
M
ove
K
at
,
"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'
,
Create
f
sh
);
tiles
.
SetTileMethod
(
'*'
,
Create
s
hark
);
tiles
.
SetTileMethod
(
'S'
,
Create
F
sh
);
tiles
.
SetTileMethod
(
'*'
,
Create
S
hark
);
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
,
CollisionWith
f
sh
);
AddCollisionHandler
(
fsh
,
CollisionWith
F
sh
);
}
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
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment