Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
igem-quantifly
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
igem-quantifly
Commits
74e79f6e
Commit
74e79f6e
authored
Oct 25, 2016
by
Naliwe GS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Score
parent
ec218a89
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
63 additions
and
25 deletions
+63
-25
BG.png.meta
Assets/Images/BG.png.meta
+5
-0
Menu.unity
Assets/Scenes/Menu.unity
+0
-0
Score.cs
Assets/Scripts/API/Score.cs
+12
-1
Server.cs
Assets/Scripts/API/Server.cs
+29
-19
Player.cs
Assets/Scripts/Player.cs
+3
-0
SimpleEnnemy.cs
Assets/Scripts/SimpleEnnemy.cs
+1
-1
Spawner.cs
Assets/Scripts/Spawner.cs
+2
-2
UIController.cs
Assets/Scripts/UIController.cs
+11
-2
EditorSettings.asset
ProjectSettings/EditorSettings.asset
+0
-0
GraphicsSettings.asset
ProjectSettings/GraphicsSettings.asset
+0
-0
ProjectSettings.asset
ProjectSettings/ProjectSettings.asset
+0
-0
No files found.
Assets/Images/BG.png.meta
View file @
74e79f6e
...
...
@@ -54,6 +54,11 @@ TextureImporter:
textureFormat: -3
compressionQuality: 50
allowsAlphaSplitting: 0
- buildTarget: Android
maxTextureSize: 8192
textureFormat: -2
compressionQuality: 50
allowsAlphaSplitting: 0
spriteSheet:
serializedVersion: 2
sprites: []
...
...
Assets/Scenes/Menu.unity
View file @
74e79f6e
No preview for this file type
Assets/Scripts/API/Score.cs
View file @
74e79f6e
using
System
;
using
UnityEngine
;
namespace
Assets.Scripts.API
{
[
Serializable
]
[
S
ystem
.
S
erializable
]
public
class
Score
{
public
string
playerName
;
public
string
team
;
public
int
score
;
public
DateTime
date
;
public
string
_id
;
public
static
Score
CreateFromJson
(
string
json
)
{
return
JsonUtility
.
FromJson
<
Score
>(
json
);
}
public
override
string
ToString
()
{
return
string
.
Format
(
"PlayerName: {0}, Team: {1}, Score: {2}, Date: {3}, Id: {4}"
,
playerName
,
team
,
score
,
date
,
_id
);
}
}
}
Assets/Scripts/API/Server.cs
View file @
74e79f6e
...
...
@@ -2,6 +2,7 @@
using
UnityEngine
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Linq
;
using
UnityEngine.Networking
;
namespace
Assets.Scripts.API
...
...
@@ -23,32 +24,41 @@ namespace Assets.Scripts.API
Debug
.
LogError
(
"Error:"
+
www
.
error
);
return
null
;
}
else
{
Debug
.
Log
(
"Got response: "
+
www
.
downloadHandler
.
text
);
ScoresRes
res
=
JsonUtility
.
FromJson
<
ScoresRes
>(
www
.
downloadHandler
.
text
);
Debug
.
Log
(
"Got scores: "
+
res
.
scores
);
string
mockText
=
"{\"status\":\"ok\",\"scores\":["
+
"{\"playerName\":\"John Smith\",\"team\":null,\"score\":10,\"date\":\"2016-10-23T12:42:54.810Z\",\"_id\":\"d21b623e9b394993be3224de89099194\"},"
+
"{\"playerName\":\"Randy\",\"team\":\"iGEM Headquarters\",\"score\":42,\"date\":\"2016-10-23T12:45:45.774Z\",\"_id\":\"a3a66de22b30450492f8f6b1bf178123\"}"
+
"]}"
;
ScoresRes
mock
=
JsonUtility
.
FromJson
<
ScoresRes
>(
mockText
);
//TODO: Why does JsonUtility fail to deserialize? /o\
Debug
.
Log
(
"Mock scores: "
+
mock
);
return
res
.
scores
;
}
Debug
.
Log
(
"Got response: "
+
www
.
downloadHandler
.
text
);
ScoresRes
res
=
JsonUtility
.
FromJson
<
ScoresRes
>(
www
.
downloadHandler
.
text
);
//Debug.Log("Got scores: " + res.scores);
string
status
=
"{\"status\":\"ok\"}"
;
string
mockText
=
"{\"scores\":[{\"playerName\":\"John Smith\",\"team\":null,\"score\":10,\"date\":\"2016-10-23T12:42:54.810Z\",\"_id\":\"d21b623e9b394993be3224de89099194\"},"
+
"{\"playerName\":\"Randy\",\"team\":\"iGEM Headquarters\",\"score\":42,\"date\":\"2016-10-23T12:45:45.774Z\",\"_id\":\"a3a66de22b30450492f8f6b1bf178123\"}"
+
"]}"
;
ScoresRes
mock
=
ScoresRes
.
CreateFromJson
(
status
,
mockText
);
//TODO: Why does JsonUtility fail to deserialize? /o\
Debug
.
Log
(
"Mock scores: "
+
mock
);
return
res
.
scores
;
}
[
Serializable
]
p
rivate
class
ScoresRes
{
[
S
ystem
.
S
erializable
]
p
ublic
class
ScoresRes
{
public
string
status
{
get
;
set
;}
public
List
<
Score
>
scores
{
get
;
set
;}
public
ScoresRes
()
{}
public
ScoresRes
(
string
status
,
List
<
Score
>
scores
)
{
this
.
scores
=
scores
;
this
.
status
=
status
;
}
public
static
ScoresRes
CreateFromJson
(
string
status
,
string
scores
)
{
return
new
ScoresRes
{
status
=
status
,
scores
=
JsonUtility
.
FromJson
<
List
<
Score
>>(
scores
)
};
}
public
override
string
ToString
()
{
var
s
=
(
from
e
in
scores
where
e
!=
null
select
e
.
ToString
()).
ToArray
();
return
"Status: "
+
status
+
"Scores:\n"
+
string
.
Join
(
","
,
s
);
}
}
}
}
...
...
Assets/Scripts/Player.cs
View file @
74e79f6e
...
...
@@ -30,7 +30,10 @@ namespace Assets.Scripts
Blink
();
if
(
Battery
<
12
)
{
PlayerPrefs
.
SetInt
(
"highscore"
,
Score
);
SceneManager
.
LoadScene
(
"GameOver"
);
}
if
(
Progression
==
25
)
SceneManager
.
LoadScene
(
"Win"
);
}
...
...
Assets/Scripts/SimpleEnnemy.cs
View file @
74e79f6e
...
...
@@ -33,7 +33,7 @@ public class SimpleEnnemy : MonoBehaviour
_player
.
GetComponent
<
Player
>().
Battery
-=
8
;
_player
.
GetComponent
<
Player
>().
SetBlinking
();
//GetScores();
TODO: Successfully get scores from API
GetScores
();
//
TODO: Successfully get scores from API
}
void
GetScores
()
{
...
...
Assets/Scripts/Spawner.cs
View file @
74e79f6e
...
...
@@ -34,10 +34,10 @@ public class Spawner : MonoBehaviour
var
r
=
_rand
.
Next
(
100
);
if
(
r
<
20
)
Instantiate
(
Toluen
,
new
Vector3
(
_rightBorder
,
_rand
.
Next
(
1
,
9
),
0
),
Quaternion
.
identity
);
Instantiate
(
StaticEnemy
,
new
Vector3
(
_rightBorder
,
_rand
.
Next
(
1
,
9
),
0
),
Quaternion
.
identity
);
else
if
(
r
<
50
)
Instantiate
(
BasicEnemy
,
new
Vector3
(
_rightBorder
,
_rand
.
Next
(
1
,
9
),
0
),
Quaternion
.
identity
);
else
Instantiate
(
StaticEnemy
,
new
Vector3
(
_rightBorder
,
_rand
.
Next
(
1
,
9
),
0
),
Quaternion
.
identity
);
Instantiate
(
Toluen
,
new
Vector3
(
_rightBorder
,
_rand
.
Next
(
1
,
9
),
0
),
Quaternion
.
identity
);
}
}
Assets/Scripts/UIController.cs
View file @
74e79f6e
...
...
@@ -20,6 +20,7 @@ public class UIController : MonoBehaviour
public
List
<
Sprite
>
BatteryImages
;
private
Player
_player
;
private
int
_oldHs
;
void
Start
()
{
...
...
@@ -28,20 +29,28 @@ public class UIController : MonoBehaviour
Vial1
.
enabled
=
false
;
Vial2
.
enabled
=
false
;
Vial3
.
enabled
=
false
;
_oldHs
=
PlayerPrefs
.
GetInt
(
"highscore"
);
}
void
Update
()
{
Distance
.
text
=
(
int
.
Parse
(
Distance
.
text
)
+
1
).
ToString
();
int
score
=
_player
.
Score
+
int
.
Parse
(
Distance
.
text
)
/
5
;
Score
.
text
=
(
_player
.
Score
+
score
).
ToString
();
_player
.
Score
+=
1
;
Score
.
text
=
_player
.
Score
.
ToString
();
NbVials
.
text
=
_player
.
NbVials
.
ToString
();
DisplayBattery
();
HandlePowerUps
();
HandleScore
();
}
private
void
HandleScore
()
{
if
(
_oldHs
<
_player
.
Score
)
HighScore
.
enabled
=
true
;
}
private
void
HandlePowerUps
()
{
if
(
_player
.
NbVials
>=
5
)
...
...
ProjectSettings/EditorSettings.asset
View file @
74e79f6e
No preview for this file type
ProjectSettings/GraphicsSettings.asset
View file @
74e79f6e
No preview for this file type
ProjectSettings/ProjectSettings.asset
View file @
74e79f6e
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment