Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DMD2542/First Project/Assets/Scripts/DNDFight.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
128 lines (104 sloc)
3.16 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
public class DNDFight : MonoBehaviour { | |
public Text log; | |
public Text pName; | |
public Text pHitPoints; | |
public Text pDMG; | |
public Text pAcc; | |
public Text eName; | |
public Text eHitPoints; | |
public Text eDMG; | |
public Text eAcc; | |
public string pNameStr; | |
public int pHitPointsInt; | |
public int pDMGLow; | |
public int pDMGHigh; | |
public int pAccf; | |
public string eNameStr; | |
public int eHitPointsInt; | |
public int eDMGLow; | |
public int eDMGHigh; | |
public int eAccf; | |
// Use this for initializations | |
void Start () { | |
Debug.Log ("HI"); | |
pName = pName.GetComponent<Text> (); | |
pHitPoints = pHitPoints.GetComponent<Text> (); | |
pDMG = pDMG.GetComponent<Text> (); | |
pAcc = pAcc.GetComponent<Text> (); | |
eName = eName.GetComponent<Text> (); | |
eHitPoints = eHitPoints.GetComponent<Text> (); | |
eDMG = eDMG.GetComponent<Text> (); | |
eAcc = eAcc.GetComponent<Text> (); | |
log = log.GetComponent<Text> (); | |
} | |
void set () { | |
pName.text = pNameStr; | |
pHitPoints.text = "HP: " + pHitPointsInt.ToString (); | |
pDMG.text = pDMGLow.ToString () + " - " + pDMGHigh.ToString (); | |
pAcc.text = "Accuracy: " + pAccf.ToString () + " %"; | |
eName.text = eNameStr; | |
eHitPoints.text = "HP: " + eHitPointsInt.ToString (); | |
eDMG.text = eDMGLow.ToString () + " - " + eDMGHigh.ToString (); | |
eAcc.text = "Accuracy: " + eAccf.ToString () + " %"; | |
} | |
public void Roll () { | |
pNameStr = "PLAYER 1"; | |
pHitPointsInt = getRandomInt (4.0f, 24.0f); | |
int pdmg1 = getRandomInt (4.0f, 24.0f); | |
int pdmg2 = getRandomInt (4.0f, 24.0f); | |
pDMGHigh = Mathf.Max (pdmg1, pdmg2); | |
pDMGLow = Mathf.Min (pdmg1, pdmg2); | |
pAccf = getRandomInt(0.0f, 100.0f); | |
eNameStr = "Enemy 1"; | |
eHitPointsInt = getRandomInt (4.0f, 24.0f); | |
int edmg1 = getRandomInt (4.0f, 24.0f); | |
int edmg2 = getRandomInt (4.0f, 24.0f); | |
eDMGHigh = Mathf.Max (edmg1, edmg2); | |
eDMGLow = Mathf.Min (edmg1, edmg2); | |
eAccf = getRandomInt(0.0f, 100.0f); | |
} | |
public void Fight () { | |
string final = playerAttackEnemy () + enemyAttackPlayer (); | |
log.text = final; | |
} | |
string playerAttackEnemy () { | |
string result = ""; | |
if (getRandomInt (0.0f, 100.0f) < pAccf) { | |
result += "Hit! " + pNameStr + " hit " + eNameStr + " for "; | |
int dmg = getRandomInt ((float)pDMGLow, (float)pDMGHigh); | |
eHitPointsInt = eHitPointsInt - dmg; | |
result += dmg.ToString () + " damage. \n"; | |
if (eHitPointsInt <= 0) { | |
result += "Dead! " + eNameStr + " has died! \n"; | |
} | |
} else { | |
result += "Miss! " + pNameStr + " missed " + eNameStr + "! \n"; | |
} | |
return result; | |
} | |
string enemyAttackPlayer () { | |
string result = ""; | |
if (getRandomInt (0.0f, 100.0f) < pAccf) { | |
result += "Hit! " + eNameStr + " hit " + pNameStr + " for "; | |
int dmg = getRandomInt ((float)eDMGLow, (float)eDMGHigh); | |
pHitPointsInt = pHitPointsInt - dmg; | |
result += dmg.ToString () + " damage. \n"; | |
if (pHitPointsInt <= 0) { | |
result += "Dead! " + pNameStr + " has died! \n"; | |
} | |
} else { | |
result += "Miss! " + eNameStr + " missed " + pNameStr + "! \n"; | |
} | |
return result; | |
} | |
int getRandomInt(float i, float j) { | |
return Mathf.RoundToInt(Random.Range (i, j)); | |
} | |
// Update is called once per frame | |
void Update () { | |
set (); | |
} | |
} |