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

Added Unit classes + refined comments

parent d489e61d
No related branches found
No related tags found
No related merge requests found
......@@ -8,26 +8,26 @@ using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Model;
namespace Controller
{
/// <summary>
/// This is the main type for your game
/// Main Controller for game
/// </summary>
public class Game : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D backGround, unit1;
Texture2D backGround;
Warrior unit1;
int screenHeight = 320;
int screenWidth = 320;
// Set the coordinates to draw the sprite at.
Vector2 spritePosition = new Vector2(32.0f, 32.0f);
// Store some information about the sprite's motion.
// Vector2 spriteSpeed = new Vector2(50.0f, 50.0f);
//constructor for game
public Game()
{
graphics = new GraphicsDeviceManager(this);
......@@ -37,10 +37,7 @@ namespace Controller
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// Initialize game
/// </summary>
protected override void Initialize()
{
......@@ -50,37 +47,28 @@ namespace Controller
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// Load initial content (called once)
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
unit1 = new Warrior(Content.Load<Texture2D>("charSprite"), spritePosition);//load character sprite
unit1 = Content.Load<Texture2D>("charSprite");
backGround = Content.Load<Texture2D>("Game Map");
graphics.PreferredBackBufferWidth = screenWidth; // width of screen..
graphics.PreferredBackBufferHeight = screenHeight; //height of screen..
IsMouseVisible = true; //sets mouse visibility to true
graphics.ApplyChanges(); // load images...
backGround = Content.Load<Texture2D>("Game Map"); //load background
// TODO: use this.Content to load your game content here
}
graphics.PreferredBackBufferWidth = screenWidth; // width of screen
graphics.PreferredBackBufferHeight = screenHeight; //height of screen
IsMouseVisible = true; //sets mouse visibility to true
graphics.ApplyChanges(); // load images
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// updates game in real time - called 60 times per second
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
......@@ -89,31 +77,28 @@ namespace Controller
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
unit1 = Content.Load<Texture2D>("charSprite");
backGround = Content.Load<Texture2D>("Game Map");
MouseState mouse = Mouse.GetState();
MouseState mouse = Mouse.GetState(); //create mouse
base.Update(gameTime);
base.Update(gameTime); //repeatedly calls update
}
/// <summary>
/// This is called when the game should draw itself.
/// Draws the game as it updates
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null);
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null); //being spriteBatch
// TODO: Add your drawing code here
spriteBatch.Draw(unit1, spritePosition, Color.White);
unit1.updateSprite(spriteBatch); //draws characte
spriteBatch.Draw(backGround, Vector2.Zero, Color.White); //draws background
spriteBatch.End();
base.Draw(gameTime);
spriteBatch.End(); //end spriteBatch
base.Draw(gameTime); //repeatedly calls draw
}
}
}
......@@ -13,7 +13,7 @@ namespace Controller
public bool isAnEnemyUnitInRange(Unit unit) { return false; }
// returns all enemy units in range of the specified unit
public LinkedList<Unit> enemyUnitsInRange(Unit unit) { return [0]; }
public LinkedList<Unit> enemyUnitsInRange(Unit unit) { return null; }
// checks if current turn is over yet (no more possible moves)
public bool isTurnOver(Player player) { return false; }
......
......@@ -9,20 +9,21 @@ 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
Weapon[] getEquipableWeapons(); // returns array of equipable weapons
int getLevel(); // returns unit's level
UnitType getClass(); // returns unit's class (warrior, mage, archer)
Texture2D getSpriteImage(); // returns the sprite image of the unit
Vector2 getCurrentPosition(); // returns the current position (pixel coordinates) of the sprite
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
Weapon[] getEquipableWeapons(); // returns array of equipable weapons
int getLevel(); // returns unit's level
UnitType getClass(); // returns unit's class (warrior, mage, archer)
Texture2D getSpriteImage(); // returns the sprite image of the unit
Vector2 getCurrentPosition(); // returns the current position (pixel coordinates) of the sprite
void updateSprite(SpriteBatch spriteBatch); // update sprite location
}
enum UnitType { Warrior, Archer, Mage }; //defines the possible classes of a unit
......
......@@ -99,5 +99,10 @@ namespace Model
{
return position;
}
public void updateSprite(SpriteBatch spriteBatch)
{
spriteBatch.Draw(spriteImage, position, Color.White);
}
}
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
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