Skip to content
Snippets Groups Projects
Commit 968ce302 authored by Susan Yuen's avatar Susan Yuen
Browse files

Fixed buggy mouse click

parent 3cbd15a9
No related branches found
No related tags found
No related merge requests found
Showing
with 84 additions and 74 deletions
......@@ -7,5 +7,6 @@ namespace Model
{
class Archer
{
// TODO
}
}
......@@ -26,15 +26,13 @@ namespace Controller
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D backGround;
int screenHeight = 320;
int screenWidth = 320;
//constructor for game
// constructor for game
public Game()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = screenHeight;
graphics.PreferredBackBufferHeight = screenWidth;
graphics.PreferredBackBufferWidth = gameFunction.SCREEN_HEIGHT;
graphics.PreferredBackBufferHeight = gameFunction.SCREEN_WIDTH;
Content.RootDirectory = "Content";
}
......@@ -43,8 +41,6 @@ namespace Controller
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
......@@ -53,17 +49,17 @@ namespace Controller
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
// creates a new SpriteBatch, which can be used to draw textures
spriteBatch = new SpriteBatch(GraphicsDevice);
initializeGame();
backGround = Content.Load<Texture2D>("Game Map"); //load background
backGround = Content.Load<Texture2D>("Game Map"); // load background
graphics.PreferredBackBufferWidth = screenWidth; // width of screen
graphics.PreferredBackBufferHeight = screenHeight; //height of screen
graphics.PreferredBackBufferWidth = gameFunction.SCREEN_WIDTH; // width of screen
graphics.PreferredBackBufferHeight = gameFunction.SCREEN_HEIGHT; //height of screen
IsMouseVisible = true; //sets mouse visibility to true
IsMouseVisible = true; // sets mouse visibility to true
graphics.ApplyChanges(); // load images
}
......@@ -73,13 +69,17 @@ namespace Controller
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
// allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
mouseHandler.updateMouse(gameFunction, graph);
if (this.IsActive)
{
// call mouse handler if game window is active
mouseHandler.updateMouse(gameFunction, graph);
}
base.Update(gameTime); //repeatedly calls update
base.Update(gameTime); // repeatedly calls update
}
/// <summary>
......@@ -87,8 +87,7 @@ namespace Controller
/// </summary>
protected override void Draw(GameTime gameTime)
{
// begin spriteBatch
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null);
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null); // begin spriteBatch
// draws units for player 1
for (int i = 0; i < player1.getNumOfUnits(); i++)
......@@ -104,14 +103,11 @@ namespace Controller
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), Color.White);
}
// draws background
spriteBatch.Draw(backGround, Vector2.Zero, Color.White);
// end spriteBatch
spriteBatch.End();
// repeatedly calls draw
base.Draw(gameTime);
spriteBatch.Draw(backGround, Vector2.Zero, Color.White); // draws background
spriteBatch.End(); // end spriteBatch
base.Draw(gameTime); // repeatedly calls draw
}
private void initializeGame()
......@@ -123,9 +119,8 @@ namespace Controller
// load character sprite and set position
Vector2 unit1Position = new Vector2(32.0f, 32.0f);
player1.addUnit(new Warrior(Content.Load<Texture2D>("charSprite"), unit1Position));
// set game state
gameFunction.setPlayerCurrentlyMoving(player1);
gameFunction.setPlayerCurrentlyMoving(player1); // set game state
}
}
}
......@@ -9,6 +9,9 @@ namespace Controller
{
class GameFunction
{
public readonly int SCREEN_HEIGHT = 320;
public readonly int SCREEN_WIDTH = 320;
private bool playableUnitSelected;
private Unit selectedUnit;
private Player currentPlayer;
......@@ -16,18 +19,21 @@ namespace Controller
// might not need; check if enemyUnitsInRange returns an empty list
public bool isAnEnemyUnitInRange(Unit unit)
{
// TODO
return false;
}
// returns all enemy units in range of the specified unit
public LinkedList<Unit> enemyUnitsInRange(Unit unit)
{
// TODO
return null;
}
// checks if current turn is over yet (no more possible moves)
public bool isTurnOver(Player player)
{
// TODO
return false;
}
......@@ -56,12 +62,14 @@ namespace Controller
// checks if specified unit can perform actions
public bool hasUnitFinishedActions(Unit unit)
{
// TODO
return false;
}
// checks lose/win conditions to determine if game is over
public bool isGameOver()
{
// TODO
return false;
}
......
......@@ -8,10 +8,10 @@ namespace Model
{
class Graph
{
private int numberOfNodes; // total number of nodes in the graph
private int width; // width of the graph (by number of nodes)
private int height; // height of the graph (by number of nodes)
private Node[,] nodes; // list of nodes in the graph
private int numberOfNodes; // total number of nodes in the graph
private int width; // width of the graph (by number of nodes)
private int height; // height of the graph (by number of nodes)
private Node[,] nodes; // list of nodes in the graph
public Graph(int x, int y)
{
......
......@@ -7,5 +7,6 @@ namespace Model
{
class Mage
{
// TODO
}
}
......@@ -7,11 +7,12 @@ namespace Model
{
class MapFunction
{
// returns list of nodes representing the path from start node to end node
public LinkedList<Node> pathFinder(Graph graph, Node start, Node end)
{
LinkedList<Node> path = new LinkedList<Node>();
path.AddFirst(start);
//TODO: finds path to highlight for unit movement; returns list of nodes representing the path from start node to end node
// TODO: finds path to highlight for unit movement
path.AddLast(end);
return path;
}
......
......@@ -11,13 +11,23 @@ namespace Controller
{
class MouseHandler
{
MouseState lastMouseState;
MouseState currentMouseState;
public void updateMouse(GameFunction gameFunction, Graph graph)
{
MouseState ms = Mouse.GetState();
lastMouseState = currentMouseState;
currentMouseState = Mouse.GetState();
bool validX = currentMouseState.X < gameFunction.SCREEN_WIDTH && currentMouseState.X > 0;
bool validY = currentMouseState.Y < gameFunction.SCREEN_HEIGHT && currentMouseState.Y > 0;
if (ms.LeftButton == ButtonState.Pressed)
// checks for single mouse click inside the window
if (lastMouseState.LeftButton == ButtonState.Released
&& currentMouseState.LeftButton == ButtonState.Pressed
&& validX && validY)
{
Vector2 position = new Vector2(ms.X, ms.Y);
Vector2 position = new Vector2(currentMouseState.X, currentMouseState.Y);
// TODO: determine if player has clicked on a menu button
......@@ -29,11 +39,15 @@ namespace Controller
if (!endNode.getIsObstacle())
{
// update the unit's position to the clicked position
int positionX = (int) Math.Floor(position.X / 32);
int positionX = (int)Math.Floor(position.X / 32);
int positionY = (int)Math.Floor(position.Y / 32);
gameFunction.getSelectedUnit().setPosition(positionX, positionY);
gameFunction.setPlayableUnitSelected(false);
gameFunction.setSelectedUnit(null);
if (!(gameFunction.getSelectedUnit().getPosition() == new Tuple<int, int>(positionX, positionY)))
{
// if new position is different from old position, set unit to new position
gameFunction.getSelectedUnit().setPosition(positionX, positionY);
gameFunction.setPlayableUnitSelected(false);
gameFunction.setSelectedUnit(null);
}
}
}
else
......@@ -46,8 +60,6 @@ namespace Controller
gameFunction.setSelectedUnit(unit);
}
}
// TODO: need to check if user clicked on menu button
}
}
......@@ -68,7 +80,5 @@ namespace Controller
}
return null;
}
//public Vector2
}
}
......@@ -12,8 +12,8 @@ namespace Model
public Node()
{
movability = 0;
isObstacle = false;
movability = 0; // defaults to no hindrence in unit movement
isObstacle = false; // default to non-obstacle tile
}
public void setMovability(int m)
......
......@@ -8,12 +8,10 @@ namespace Model
class Player
{
private LinkedList<Unit> ownedUnits; // units that the player owns
private bool moving; // indicates if it is currently the player's turn
public Player()
{
ownedUnits = new LinkedList<Unit>();
moving = false;
}
public LinkedList<Unit> getUnits()
......@@ -25,12 +23,6 @@ namespace Model
{
return ownedUnits.Count;
}
public bool isMoving()
{
return moving;
}
// Tells whether a specified unit is owned by the player
public bool ownsUnit(Unit unit)
{
......
......@@ -9,25 +9,25 @@ 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
Weapon getEquippedWeapon();
int getLevel(); // returns unit's level
UnitType getClass(); // returns unit's class (warrior, mage, archer)
Texture2D getSpriteImage(); // returns the sprite image of the unit
Tuple<int, int> getPosition(); // returns the current position (by node) of the sprite
Vector2 getPixelCoordinates(); // returns the current position (pixel coordinates) of the sprite
void setPixelCoordinates(Vector2 p);
void setPosition(int x, int y);
void setEquippedWeapon(Weapon w);
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
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
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
}
enum UnitType { Warrior, Archer, Mage }; //defines the possible classes of a unit
......
......@@ -9,7 +9,7 @@ namespace Model
{
class Warrior : Unit
{
private bool alive; // whether unit is alive or dead
private bool alive;
private int hp;
private int str;
private int intelligence;
......
No preview for this file type
No preview for this file type
......@@ -57,3 +57,4 @@ C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\ob
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\obj\x86\Debug\Blaze_Brigade.pdb
C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Content\charSprite.xnb
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\bin\x86\Debug\Content\charSprite.xnb
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_Brigade\obj\x86\Debug\Blaze_Brigade.csprojResolveAssemblyReference.cache
No preview for this file type
No preview for this file type
No preview for this file type
C:\Users\chaos\Documents\Git\Blaze-Brigade\src\Blaze-Brigade\Blaze_BrigadeContent\obj\x86\Debug\Blaze_BrigadeContent.contentprojResolveAssemblyReference.cache
C:\Users\Susan\Documents\GitHub\Blaze-Brigade\src\Blaze-Brigade\Blaze_BrigadeContent\obj\x86\Debug\Blaze_BrigadeContent.contentprojResolveAssemblyReference.cache
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