Commit 74e79f6e by Naliwe GS

Score

parent ec218a89
...@@ -54,6 +54,11 @@ TextureImporter: ...@@ -54,6 +54,11 @@ TextureImporter:
textureFormat: -3 textureFormat: -3
compressionQuality: 50 compressionQuality: 50
allowsAlphaSplitting: 0 allowsAlphaSplitting: 0
- buildTarget: Android
maxTextureSize: 8192
textureFormat: -2
compressionQuality: 50
allowsAlphaSplitting: 0
spriteSheet: spriteSheet:
serializedVersion: 2 serializedVersion: 2
sprites: [] sprites: []
......
No preview for this file type
using System; using System;
using UnityEngine;
namespace Assets.Scripts.API namespace Assets.Scripts.API
{ {
[Serializable] [System.Serializable]
public class Score public class Score
{ {
public string playerName; public string playerName;
public string team; public string team;
public int score; public int score;
public DateTime date; 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);
}
} }
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine.Networking; using UnityEngine.Networking;
namespace Assets.Scripts.API namespace Assets.Scripts.API
...@@ -23,32 +24,41 @@ namespace Assets.Scripts.API ...@@ -23,32 +24,41 @@ namespace Assets.Scripts.API
Debug.LogError("Error:" + www.error); Debug.LogError("Error:" + www.error);
return null; return null;
} }
else { Debug.Log("Got response: " + www.downloadHandler.text);
Debug.Log("Got response: " + www.downloadHandler.text); ScoresRes res = JsonUtility.FromJson<ScoresRes>(www.downloadHandler.text);
ScoresRes res = JsonUtility.FromJson<ScoresRes>(www.downloadHandler.text); //Debug.Log("Got scores: " + res.scores);
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;
}
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] [System.Serializable]
private class ScoresRes { public class ScoresRes {
public string status { get; set;} public string status { get; set;}
public List<Score> scores { get; set;} public List<Score> scores { get; set;}
public ScoresRes() {} public ScoresRes() {}
public ScoresRes(string status, List<Score> scores) { public static ScoresRes CreateFromJson(string status, string scores)
this.scores = scores; {
this.status = status; 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);
}
} }
} }
} }
......
...@@ -30,7 +30,10 @@ namespace Assets.Scripts ...@@ -30,7 +30,10 @@ namespace Assets.Scripts
Blink(); Blink();
if (Battery < 12) if (Battery < 12)
{
PlayerPrefs.SetInt("highscore", Score);
SceneManager.LoadScene("GameOver"); SceneManager.LoadScene("GameOver");
}
if (Progression == 25) if (Progression == 25)
SceneManager.LoadScene("Win"); SceneManager.LoadScene("Win");
} }
......
...@@ -33,7 +33,7 @@ public class SimpleEnnemy : MonoBehaviour ...@@ -33,7 +33,7 @@ public class SimpleEnnemy : MonoBehaviour
_player.GetComponent<Player>().Battery -= 8; _player.GetComponent<Player>().Battery -= 8;
_player.GetComponent<Player>().SetBlinking(); _player.GetComponent<Player>().SetBlinking();
//GetScores(); TODO: Successfully get scores from API GetScores(); // TODO: Successfully get scores from API
} }
void GetScores() { void GetScores() {
......
...@@ -34,10 +34,10 @@ public class Spawner : MonoBehaviour ...@@ -34,10 +34,10 @@ public class Spawner : MonoBehaviour
var r = _rand.Next(100); var r = _rand.Next(100);
if (r < 20) 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) else if (r < 50)
Instantiate(BasicEnemy, new Vector3(_rightBorder, _rand.Next(1, 9), 0), Quaternion.identity); Instantiate(BasicEnemy, new Vector3(_rightBorder, _rand.Next(1, 9), 0), Quaternion.identity);
else 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);
} }
} }
...@@ -20,6 +20,7 @@ public class UIController : MonoBehaviour ...@@ -20,6 +20,7 @@ public class UIController : MonoBehaviour
public List<Sprite> BatteryImages; public List<Sprite> BatteryImages;
private Player _player; private Player _player;
private int _oldHs;
void Start () void Start ()
{ {
...@@ -28,20 +29,28 @@ public class UIController : MonoBehaviour ...@@ -28,20 +29,28 @@ public class UIController : MonoBehaviour
Vial1.enabled = false; Vial1.enabled = false;
Vial2.enabled = false; Vial2.enabled = false;
Vial3.enabled = false; Vial3.enabled = false;
_oldHs = PlayerPrefs.GetInt("highscore");
} }
void Update () void Update ()
{ {
Distance.text = (int.Parse(Distance.text) + 1).ToString(); 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(); NbVials.text = _player.NbVials.ToString();
DisplayBattery(); DisplayBattery();
HandlePowerUps(); HandlePowerUps();
HandleScore();
} }
private void HandleScore()
{
if (_oldHs < _player.Score)
HighScore.enabled = true;
}
private void HandlePowerUps() private void HandlePowerUps()
{ {
if (_player.NbVials >= 5) if (_player.NbVials >= 5)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment