Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,128 @@ | |||
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 (); | |||
} | |||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
m_EditorVersion: 5.4.0f3 | |||
m_StandardAssetsVersion: 0 |