Skip to content
Snippets Groups Projects
Commit a9e54eff authored by Trandinh Thien's avatar Trandinh Thien
Browse files

Added initial warrior stats. Replaced all getters and setters in unit...

Added initial warrior stats. Replaced all getters and setters in unit interface with C# properties which acts as both in 1 method. Made changes to multiple classes to account for change
parent 2fd83e4c
No related branches found
No related tags found
No related merge requests found
......@@ -13,11 +13,11 @@ namespace Model
public int getDamageDealt(Unit attacker, Unit defender, bool physOrMagic){
if(physOrMagic== false)
{
return attacker.getStr() - defender.getDefense(); //return physical damage dealt
return attacker.Str - defender.Def; //return physical damage dealt
}
else
{
return attacker.getInt() - defender.getResistance(); //else return magical damage dealt
return attacker.Int - defender.Res; //else return magical damage dealt
}
}
......@@ -25,19 +25,19 @@ namespace Model
//passes in the 2 units, and returns the hit rate as a percentage out of 100 by taking into account both unit's skill
public int getHitRate(Unit attacker, Unit defender)
{
return (int) Math.Round( ( ( (attacker.getSkill() / 10.0) - (defender.getSkill() / 10.0) + 1.0) * 0.8)*100.0);
return (int) Math.Round( ( ( (attacker.Skill / 10.0) - (defender.Skill / 10.0) + 1.0) * 0.8)*100.0);
}
//passes in the 2 units, and returns the crit rate as a percentage out of 100 by taking into account both unit's skill
public int getCritRate(Unit attacker, Unit defender)
{
return (int)Math.Round( ( ( (attacker.getSkill() / 3.0) - (defender.getSkill() / 3.0) + 1.0) * 0.8) * 100.0);
return (int)Math.Round( ( ( (attacker.Skill / 3.0) - (defender.Skill / 3.0) + 1.0) * 0.8) * 100.0);
}
//passes in then 2 units, and determines how many attacks the attacker makes by factoring in both unit's relative speed
public int getHitCount(Unit attacker, Unit defender)
{
if (attacker.getSpeed() > (defender.getSpeed() + 4))
if (attacker.Speed > (defender.Speed + 4))
{
return 2; //return 2 attack if speed of attacker if 4 higher
}
......
......@@ -236,7 +236,7 @@ namespace Controller
for (int i = 0; i < player1.getNumOfUnits(); i++)
{
Unit unit = player1.getUnits().ElementAt(i); //gets unit at i
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(),
spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates,
unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
}
#endregion
......@@ -281,7 +281,7 @@ namespace Controller
#region Drop Down menu
if (GameState.getMenuOpen()) // if dropDowMenu should be opened, draw dropDownMenu
{
unit.setMenuButtonCoordinates(unit.getPixelCoordinates());
unit.setMenuButtonCoordinates(unit.PixelCoordinates);
foreach (MenuButton button in unit.getMenuButtons())
{
if (button.getActive())
......@@ -307,7 +307,7 @@ namespace Controller
spriteBatch.DrawString(font, unit.getStats(k).ToString(), statLocation, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws each stat
statLocation = statLocation + increment; //increment downwards
}
spriteBatch.DrawString(largeFont, unit.getHp().ToString(), new Vector2(255, 515), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws each stat
spriteBatch.DrawString(largeFont, unit.Hp.ToString(), new Vector2(250, 515), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws each stat
spriteBatch.Draw(unit.getCharInfo(), infoLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charInfoBackground texture
}
......@@ -322,8 +322,7 @@ namespace Controller
spriteBatch.DrawString(font, unit.getStats(k).ToString(), statLocation, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws each stat
statLocation = statLocation + increment; //increment downwards
}
spriteBatch.DrawString(largeFont, unit.getHp().ToString(), new Vector2(255, 515), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws each stat
spriteBatch.DrawString(largeFont, unit.Hp.ToString(), new Vector2(250, 515), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws each stat
spriteBatch.Draw(unit.getCharInfo(), infoLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charInfoBackground texture
}
#endregion
......@@ -336,7 +335,7 @@ namespace Controller
for (int i = 0; i < player2.getNumOfUnits(); i++)
{
Unit unit = player2.getUnits().ElementAt(i);
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(),
spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates,
unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
}
#endregion
......
......@@ -111,7 +111,7 @@ namespace Controller
public static LinkedList<Node> getMovableNodes(Graph graph, Unit unit)
{
LinkedList<Node> moveableNodes = new LinkedList<Node>();
Node currentNode = graph.getNode(unit.getPosition());
Node currentNode = graph.getNode(unit.Position);
// iterate through all nodes in the graph
for (int x=0; x<graph.getWidth(); x++)
......@@ -156,7 +156,7 @@ namespace Controller
public static LinkedList<Node> getAttackRangeAfterMoving(Graph graph, Unit unit)
{
LinkedList<Node> attackableNodes = new LinkedList<Node>();
Tuple<int, int> currentPosition = unit.getPosition();
Tuple<int, int> currentPosition = unit.Position;
for (int x = 0; x < graph.getWidth(); x++)
{
for (int y = 0; y < graph.getHeight(); y++)
......
......@@ -69,7 +69,7 @@ namespace Controller
Game.Instance.Tick();
// set variables for path finding
Node startNode = graph.getNode(GameState.getSelectedUnit().getPosition());
Node startNode = graph.getNode(GameState.getSelectedUnit().Position);
Node endNode = graph.getNode(mouseClickCoordinates);
LinkedList<Node> path = GameFunction.pathFinder(graph, GameState.getSelectedUnit(), startNode, endNode);
......@@ -113,8 +113,8 @@ namespace Controller
for (int i = 0; i < currentPlayer.getNumOfUnits(); i++)
{
Unit unit = currentPlayer.getUnits().ElementAt(i);
int unitX = unit.getPosition().Item1;
int unitY = unit.getPosition().Item2;
int unitX = unit.Position.Item1;
int unitY = unit.Position.Item2;
int clickedX = (int)Math.Floor(positionClicked.X / 32);
int clickedY = (int)Math.Floor(positionClicked.Y / 32);
if (unitX == clickedX && unitY == clickedY)
......@@ -148,39 +148,40 @@ namespace Controller
int nodePixelX = node.getPositionX() * 32;
int nodePixelY = node.getPositionY() * 32;
graph.getNode(unit.getPosition()).setUnitOnNode(null);
graph.getNode(unit.Position).setUnitOnNode(null);
while (unit.getPixelCoordinates().X != nodePixelX)
while (unit.PixelCoordinates.X != nodePixelX)
{
if (unit.getPixelCoordinates().X < nodePixelX)
if (unit.PixelCoordinates.X < nodePixelX)
{
unit.animate(2);
unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X + 4, unit.getPixelCoordinates().Y));
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X + 4, unit.PixelCoordinates.Y);
Game.Instance.Tick();
Thread.Sleep(40);
}
else
{
unit.animate(1);
unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X - 4, unit.getPixelCoordinates().Y));
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X - 4, unit.PixelCoordinates.Y);
Game.Instance.Tick();
Thread.Sleep(40);
}
}
while (unit.getPixelCoordinates().Y != nodePixelY)
while (unit.PixelCoordinates.Y != nodePixelY)
{
if (unit.getPixelCoordinates().Y < nodePixelY)
if (unit.PixelCoordinates.Y < nodePixelY)
{
unit.animate(0);
unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X, unit.getPixelCoordinates().Y + 4));
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X, unit.PixelCoordinates.Y + 4);
Game.Instance.Tick();
Thread.Sleep(40);
}
else
{
unit.animate(3);
unit.setPixelCoordinates(new Vector2(unit.getPixelCoordinates().X, unit.getPixelCoordinates().Y - 4));
unit.PixelCoordinates = new Vector2(unit.PixelCoordinates.X, unit.PixelCoordinates.Y - 4);
Game.Instance.Tick();
Thread.Sleep(40);
}
......
......@@ -11,34 +11,32 @@ namespace Model
{
interface Unit
{
bool isAlive(); // whether unit is dead or alive
int getHp(); // returns unit's HP
int getStr(); // returns unit's strength
int getInt(); // returns unit's intelligence
int getSkill(); // returns unit's skill
int getSpeed(); // returns unit's speed
int getDefense(); // returns unit's defense
int getResistance(); // returns unit's resistance
int getCriticalRate(); // returns unit's critical rate
bool Alive { get; set; } // whether unit is dead or alive
int Hp { get; set; } // returns unit's HP
int Str { get; set; } // returns unit's strength
int Int { get; set; } // returns unit's intelligence
int Skill { get; set; } // returns unit's skill
int Speed { get; set; } // returns unit's speed
int Def { get; set; } // returns unit's defense
int Res { get; set; } // returns unit's resistance
int Level { get; set; }
int getMovability(); // returns the unit's movability (number of spaces the unit can move in one turn)
int getStats(int i); // returns stat located at i (in order from 0-6: lvl, str, mag, skill, spd, def, res)
Tuple<int, int> Position { get; set;} // gets and sets unit's position by tile
Vector2 PixelCoordinates { get; set; }
Weapon[] getEquipableWeapons(); // returns array of equipable weapons
Weapon getEquippedWeapon(); // returns weapon the unit is currently equipping
int getLevel(); // returns unit's level
UnitType getClass(); // returns unit's class (warrior, mage, archer)
Texture2D getSpriteImage(); // returns the sprite image of the unit
Texture2D getButtonImage(MenuButtonType buttonType); // returns the button texture at index i
bool isButtonActive(MenuButtonType buttonType); // indicates whether a button has already been previously selected or not
Texture2D getCharInfo(); // returns the char info screen texture
Tuple<int, int> getPosition(); // returns the current position (by node) of the unit
Vector2 getPixelCoordinates(); // returns the pixel coordinates of the sprite
void setPixelCoordinates(Vector2 p); // sets the pixel coordinates of the sprite
void setPosition(int x, int y); // sets the current position (by node) of the unit
void setEquippedWeapon(Weapon w); // sets the unit's currently equipped weapon
MenuButton[] getMenuButtons(); // returns the dropdown menu buttons of the unit
void setMenuButtonCoordinates(Vector2 pixelCoordinates); // sets the coordinates of menu buttons
Rectangle getCurrentFrame(); // returns the current sprite frame in animation sequence
void animate(int direction);
void animate(int direction); // animate sprite walking the direction specified
void setInitialStats(); // sets initial unit stats upon creation
}
enum UnitType { Warrior, Archer, Mage }; //defines the possible classes of a unit
......
......@@ -12,16 +12,16 @@ namespace Model
{
class Warrior : Unit
{
private bool alive;
private int hp;
private int str;
private int intelligence;
private int skill;
private int speed;
private int defense;
private int resistance;
private int criticalRate;
private int level;
public bool Alive { get; set; }
public int Hp { get; set; }
public int Str { get; set; }
public int Int { get; set; }
public int Skill { get; set; }
public int Speed { get; set; }
public int Def { get; set; }
public int Res { get; set; }
public int Level { get; set; }
private readonly int movability = 4; // all warriors will have 5 movability
private Weapon[] equipableWeapons;
private Weapon equippedWeapon;
......@@ -35,7 +35,6 @@ namespace Model
public Warrior(Texture2D spriteImage, MenuButton attackButton, MenuButton moveButton,
MenuButton itemButton, MenuButton waitButton, Texture2D charInfo, Vector2 coordinates)
{
// TODO: setup pre-determined stats for warrior
this.spriteImage = spriteImage;
menuButtons[0] = attackButton;
menuButtons[1] = moveButton;
......@@ -48,52 +47,23 @@ namespace Model
position = new Tuple<int, int>(positionX, positionY);
currentFrame = 1;
setMenuButtonCoordinates(pixelCoordinates);
setInitialStats(); //sets initial warrior stats
}
public bool isAlive()
{
return alive;
}
public int getHp()
{
return hp;
}
public int getStr()
//sets initial unit stats
public void setInitialStats()
{
return str;
}
public int getInt()
{
return intelligence;
}
Alive = true;
Hp = 10;
Str = 9;
Int = 1;
Skill = 6;
Speed = 8;
Def = 8;
Res = 4;
public int getSkill()
{
return skill;
}
public int getSpeed()
{
return speed;
}
public int getDefense()
{
return defense;
}
public int getResistance()
{
return resistance;
}
public int getCriticalRate()
{
return criticalRate;
}
public int getMovability()
......@@ -101,22 +71,17 @@ namespace Model
return movability;
}
public int getLevel()
{
return level;
}
//returns each stat as an index for incrementing purposes
public int getStats(int i)
{
int[] allStats = new int[7];
allStats[0] = getLevel();
allStats[1] = getStr();
allStats[2] = getInt();
allStats[3] = getSkill();
allStats[4] = getSpeed();
allStats[5] = getDefense();
allStats[6] = getResistance();
allStats[0] = Level;
allStats[1] = Str;
allStats[2] = Int;
allStats[3] = Skill;
allStats[4] = Speed;
allStats[5] = Def;
allStats[6] = Res;
return allStats[i];
}
......@@ -182,28 +147,32 @@ namespace Model
return charInfo;
}
public Tuple<int, int> getPosition()
{
return position;
}
public Vector2 getPixelCoordinates()
{
return pixelCoordinates;
}
public void setPosition(int x, int y)
{
position = new Tuple<int, int>(x, y);
pixelCoordinates = new Vector2(x * 32, y * 32);
}
public Tuple<int, int> Position
{
get
{
return position;
}
set
{
position = value;
pixelCoordinates = new Vector2(value.Item1 * 32, value.Item2 * 32);
}
}
public void setPixelCoordinates(Vector2 p)
public Vector2 PixelCoordinates
{
pixelCoordinates = p;
int positionX = (int)Math.Round(pixelCoordinates.X / 32);
int positionY = (int)Math.Round(pixelCoordinates.Y / 32);
position = new Tuple<int, int>(positionX, positionY);
get
{
return pixelCoordinates;
}
set
{
pixelCoordinates = value;
int positionX = (int)Math.Round(PixelCoordinates.X / 32);
int positionY = (int)Math.Round(PixelCoordinates.Y / 32);
position = new Tuple<int, int>(positionX, positionY);
}
}
public void setEquippedWeapon(Weapon w)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment