Skip to content

Commit

Permalink
Debug attack
Browse files Browse the repository at this point in the history
  • Loading branch information
amm266 committed Mar 11, 2021
1 parent 9941ced commit cdfb7e8
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Assets/Scenes/MapScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ Camera:
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.8679245, g: 0.79126555, b: 0.118725546, a: 0}
m_BackGroundColor: {r: 0.5943396, g: 0.5443024, b: 0.43454075, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
Expand Down Expand Up @@ -781,6 +781,7 @@ MonoBehaviour:
y0: 0
width: 2
haight: 2
playAnime: 0
--- !u!4 &1778195491
Transform:
m_ObjectHideFlags: 0
Expand Down
8 changes: 4 additions & 4 deletions Assets/Scripts/LogScripts/GameLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void MakeLog(string jsonStr)
this.GameLog = new GameLog(map, turns);
}

private void Awake()
private void Start()
{
try
{
Expand All @@ -102,8 +102,8 @@ private void Awake()
else // desktop app
{
string jsonStr = File.ReadAllText("./test1.json");
MakeLog(jsonStr); //TODO: must be called from UI, this is for test. ALSO don't need to inherit MonoBehaviour
GameObject.FindWithTag("GameManager").GetComponent<GameManager>().StartGameManager(GameLog);
MakeLog(jsonStr);
GameManager.Instance.StartGameManager(GameLog);
}
}
catch (Exception x)
Expand All @@ -115,6 +115,6 @@ private void Awake()
public void WebGLSetJson(string json)
{
MakeLog(json);
GameObject.FindWithTag("GameManager").GetComponent<GameManager>().StartGameManager(GameLog);
GameManager.Instance.StartGameManager(GameLog);
}
}
35 changes: 27 additions & 8 deletions Assets/Scripts/Map/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ public class GameManager : MonoBehaviour
private Hashtable AntsTable = new Hashtable();
public int MaxTurns { get; private set; }
private float baseTime;
public bool playAnime;
[HideInInspector]
private bool playAnime;

public static GameManager Instance { get; private set; }

private void Awake()
{
Instance = this;
}

public void StartGameManager(GameLog gameLog)
{
Expand Down Expand Up @@ -58,7 +65,7 @@ private void ApplyTurnUnAnim(Turn turn)
{
ChatManager.Instance.SetLeftChatMessages(turn.ChatBox0.Split(','));
ChatManager.Instance.SetRightChatMessages(turn.ChatBox1.Split(','));
Debug.Log("unAnim move "+currTurn);
Debug.Log("unAnim move " + currTurn);
foreach (GameObject temp in Temps)
{
Destroy(temp);
Expand Down Expand Up @@ -115,18 +122,15 @@ private IEnumerator ApplyTurnAnim(Turn turn)
{
//new ants
NewAnts.Add(ant.Id, ant);

// antObject = Instantiate(antPrefab);
// antObject.GetComponent<AntScript>().Set(ant.Row, ant.Col, ant.Team, ant.Type, ant.Health, ant.Resource);
}
}

foreach (DictionaryEntry antDE in cloneAntTable)
if (playAnime)
{
//dead ants
AntScript antScript = (AntScript) (antDE.Value);
StartCoroutine(antScript.die(baseTime / 2));
}

Debug.Log("start phase1");
foreach (DictionaryEntry antDE in NewAnts)
{
//new ants
Expand All @@ -138,6 +142,21 @@ private IEnumerator ApplyTurnAnim(Turn turn)
AntsTable.Add(antObject.Id, ant);
}

foreach (Attack attack in turn.Attacks)
{
GameObject attacker = (GameObject) AntsTable[attack.AttackerId];
attacker.GetComponent<AntScript>().Attack(attack.DstRow, attack.DstCol, baseTime / 2);
}

foreach (DictionaryEntry antDE in cloneAntTable)
{
//dead ants
GameObject antScript = (GameObject) (antDE.Value);
AntsTable.Remove(antDE.Key);
StartCoroutine(antScript.GetComponent<AntScript>().die(baseTime / 4, baseTime / 4));
}


Debug.Log("end phase1");
yield return new WaitForSeconds(baseTime / 2);
if (playAnime)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/PrefabScripts/AntScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public IEnumerator Go(int x, int y, int health, int recource, float time)
SetResource(recource);
SetHealth(health);
yield return new WaitForSeconds(baseTime / 2);
temp = gameManager.ConvertPosition(x, y);
temp = GameManager.Instance.ConvertPosition(x, y);
mainAnimator.Play("Walk");
readTemp = true;
reachTime = time+Time.time;
Expand Down Expand Up @@ -117,7 +117,7 @@ public IEnumerator die(float time)

private void SetPosition(int x, int y)
{
transform.position = gameManager.ConvertPosition(x, y);
transform.position = GameManager.Instance.ConvertPosition(x, y);
Debug.Log(transform.position);
}

Expand Down
73 changes: 72 additions & 1 deletion Assets/Scripts/PrefabScripts/BaseScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,75 @@ void Start()
void Update()
{
}
}
}
//
// <!DOCTYPE html>
// <html lang="en-us">
// <head>
// <meta charset="utf-8">
// <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
// <title>Unity WebGL Player | AIC21-Graphic</title>
// <link rel="shortcut icon" href="TemplateData/favicon.ico">
// <link rel="stylesheet" href="TemplateData/style.css">
// </head>
// <body>
// <div id="unity-container" class="unity-desktop">
// <canvas id="unity-canvas"></canvas>
// <div id="unity-loading-bar">
// <div id="unity-logo"></div>
// <div id="unity-progress-bar-empty">
// <div id="unity-progress-bar-full"></div>
// </div>
// </div>
// <div id="unity-footer">
// <div id="unity-webgl-logo"></div>
// <div id="unity-fullscreen-button"></div>
// <div id="unity-build-title">AIC21-Graphic</div>
// </div>
// </div>
// <script>
// var buildUrl = "Build";
// var loaderUrl = buildUrl + "/WebGLBuild.loader.js";
// var config = {
// dataUrl: buildUrl + "/WebGLBuild.data",
// frameworkUrl: buildUrl + "/WebGLBuild.framework.js",
// codeUrl: buildUrl + "/WebGLBuild.wasm",
// streamingAssetsUrl: "StreamingAssets",
// companyName: "DefaultCompany",
// productName: "AIC21-Graphic",
// productVersion: "1.0",
// };
// var container = document.querySelector("#unity-container");
// var canvas = document.querySelector("#unity-canvas");
// var loadingBar = document.querySelector("#unity-loading-bar");
// var progressBarFull = document.querySelector("#unity-progress-bar-full");
// var fullscreenButton = document.querySelector("#unity-fullscreen-button");
// if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
// container.className = "unity-mobile";
// config.devicePixelRatio = 1;
// } else {
// canvas.style.width = "1440px";
// canvas.style.height = "720px";
// }
// loadingBar.style.display = "block";
// var script = document.createElement("script");
// script.src = loaderUrl;
// script.onload = () => {
// createUnityInstance(canvas, config, (progress) => {
// progressBarFull.style.width = 100 * progress + "%";
// }).then((unityInstance) => {
// loadingBar.style.display = "none";
// fullscreenButton.onclick = () => {
// unityInstance.SetFullscreen(1);
// };
// fetch('test1.json')
// .then(response => response.text())
// .then(text => unityInstance.SendMessage('GameLogReader', 'WebGLSetJson', text));
// }).catch((message) => {
// alert(message);
// });
// };
// document.body.appendChild(script);
// </script>
// </body>
// </html>

0 comments on commit cdfb7e8

Please sign in to comment.