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

Added Visual Studio region to organize code, and comments

parent 8c6dd4af
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ namespace Controller
public class Game : Microsoft.Xna.Framework.Game
{
#region Variables
enum GameState //enumerated list for different possible Game States
{
MainMenu, //menu screen
......@@ -34,7 +35,6 @@ namespace Controller
AttackMenu, //attack menu
}
GameState CurrentGameState = GameState.MainMenu; //game starts in main menu screen
readonly GameFunction gameFunction = new GameFunction();
readonly MouseHandler mouseHandler = new MouseHandler();
......@@ -46,11 +46,11 @@ namespace Controller
dropDownMenu popUp;
Player[] allPlayers; // If at [0] , p1 turn, etc. Iterates through array in incremental fashion.
// If at end, go back to index 0
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D backGround, moveableNode, attackableNode;
private SpriteFont font; //custom font
#endregion
// constructor for game
public Game()
......@@ -65,9 +65,7 @@ namespace Controller
tut = new HowToPlay();
}
/// <summary>
/// Initialize game
/// </summary>
//initializes game
protected override void Initialize()
{
Form MyGameForm = (Form)Form.FromHandle(Window.Handle); // creates handle
......@@ -75,9 +73,7 @@ namespace Controller
base.Initialize();
}
/// <summary>
/// Load initial content (called once)
/// </summary>
//loads required textures and values for starting game
protected override void LoadContent()
{
// creates a new SpriteBatch, which can be used to draw textures
......@@ -91,7 +87,6 @@ namespace Controller
font = Content.Load<SpriteFont>("PixelFont"); //loads font PixelFont
graphics.PreferredBackBufferWidth = gameFunction.SCREEN_WIDTH; // width of screen
graphics.PreferredBackBufferHeight = gameFunction.SCREEN_HEIGHT; //height of screen
......@@ -99,14 +94,13 @@ namespace Controller
graphics.ApplyChanges(); // load images
}
//initializes players and units
private void initializeGame()
{
graph = new Graph(50,32);
player1 = new Player();
player2 = new Player();
allPlayers = new Player[2];
// current turn based on index of array, perhaps a randomizing func to determine who goes first.
// when turn over, move to next index of array. When at end of array, go to start
......@@ -116,25 +110,19 @@ namespace Controller
// this while loop should allow for all game functions during turn?
//while (allPlayers.ElementAt(turn).isTurnOver() == false) { }
// load character sprite and set position
Vector2 unit1Position = new Vector2(32.0f, 32.0f);
player1.addUnit(new Warrior(Content.Load<Texture2D>("charSprite"), Content.Load<Texture2D>("attack"), Content.Load<Texture2D>("move"),
Content.Load<Texture2D>("items"), Content.Load<Texture2D>("wait"), Content.Load<Texture2D>("warrior_stats"), unit1Position));
gameFunction.setPlayerCurrentlyMoving(player1); // set game state
}
/// <summary>
/// updates game in real time - called 60 times per second
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
// Updates game in real time - 60fps
protected override void Update(GameTime gameTime)
{
#region Exiting Game
// allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
this.Exit();
......@@ -144,7 +132,9 @@ namespace Controller
// call mouse handler if game window is active
mouseHandler.updateMouse(gameFunction, graph);
}
#endregion
#region Game States
MouseState mouse = Mouse.GetState();
//Lists possible game states
switch (CurrentGameState)
......@@ -189,41 +179,34 @@ namespace Controller
backGround = Content.Load<Texture2D>("Game_Map"); // load background
break;
}
#endregion
base.Update(gameTime); // repeatedly calls update
}
/// <summary>
/// Draws the game as it updates
/// </summary>
//draws the game as it updates
protected override void Draw(GameTime gameTime)
{
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null); // begin spriteBatch
//only draw objects relevent to current game state
switch (CurrentGameState)
{
case GameState.Playing: // while in game
#region Player 1 Units
// draws units for player 1
for (int i = 0; i < player1.getNumOfUnits(); i++)
{
Unit unit = player1.getUnits().ElementAt(i); //gets unit at i
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), Color.White);//draws sprite
//if unit is currently clicked on, draw char info screen
#region When Unit is selected
//if unit is currently clicked on
if (unit.getClickedOn())
{
#region Highlight nodes
//Highlight movable nodes in blue
LinkedList<Node> moveableNodes = gameFunction.getMovableNodes(graph, unit);
foreach(Node move in moveableNodes)
......@@ -240,9 +223,9 @@ namespace Controller
spriteBatch.Draw(attackableNode, attack.getPosition(), Color.White * 0.2f);
}
}
#endregion
#region Drop Down menu
if (unit.getMenuOpen()) //if dropDowMenu should be opened, draw dropDownMenu
{
Vector2 menuIncrement = new Vector2(0, 32); //increment downwards for successive button
......@@ -255,8 +238,10 @@ namespace Controller
currentButtonPosition = Vector2.Add(currentButtonPosition, menuIncrement); //increment location
}
}
Vector2 statLocation= new Vector2(60, 300); //starting location for first stat
#endregion
#region Character Info Screen
Vector2 statLocation = new Vector2(60, 300); //starting location for first stat
Vector2 increment = new Vector2(0, 30); //increment downwards for each stat
for(int k=0; k<6; k++) //for 6 stats - str, int, skill, speed, def, res
......@@ -264,16 +249,22 @@ namespace Controller
spriteBatch.DrawString(font, unit.getStats(k).ToString(), statLocation, Color.Black); //draws each stat
statLocation = statLocation + increment; //increment downwards
}
#endregion
spriteBatch.Draw(unit.getCharInfo(), Vector2.Zero, Color.White); //draw charInfoBackground texture
spriteBatch.Draw(unit.getCharInfo(), Vector2.Zero, Color.White*0.7f); //draw charInfoBackground texture
}
#endregion
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), Color.White); //redraws char sprite
}
#endregion
#region Player 2 Units
// draws units for player 2
for (int i = 0; i < player2.getNumOfUnits(); i++)
{
......@@ -281,9 +272,9 @@ namespace Controller
spriteBatch.Draw(unit.getSpriteImage(), unit.getPixelCoordinates(), Color.White);
}
#endregion
spriteBatch.Draw(backGround, Vector2.Zero, Color.White); // draws background
break;
......
......@@ -40,6 +40,7 @@ namespace Controller
// TODO: determine if player has clicked on a menu button
#region Check if a unit is clicked
// if player clicks after unit is already selected ...
if (gameFunction.isPlayableUnitSelected())
{
......@@ -51,11 +52,7 @@ namespace Controller
updateUnitPosition(position, gameFunction);
}
setSelectedUnit(gameFunction, null, false);
}
// if player clicks when no unit is selected ...
else
{
} else{
// if there is a playable, player-owned unit on position clicked, set selected unit status
Unit unit = getPlayableUnitOnNodeClicked(graph.getNode(position), position, gameFunction.playerCurrentlyMoving());
if (unit != null)
......@@ -63,6 +60,7 @@ namespace Controller
setSelectedUnit(gameFunction, unit, true);
}
}
#endregion
}
}
......
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