Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- namespace Rings
- {
- class Ring
- {
- public bool Visible { get; set; } //a boolean property that dictates whether or not the ring is visible
- public int WedgeSpan { get; set; } //An integer property that dictates the arclength of each wedge
- private int rotation = 0; //The current degree of rotation for the ring
- private float radius = 0f; //The radius of the ring
- private static float degree = (float)(Math.PI/180); //This float represents 1 degree, in radians
- private Position[] positions; //An array of position data for all 360 degrees, based upon the radius of the ring
- private Factory myFactory; //A factory which will be responsible for making wedges
- List<Wedge> wedges; //A list of wedges
- /// <summary>
- /// This is a list of all the wedges in the ring
- /// </summary>
- public List<Wedge> Wedges
- {
- get
- {
- return this.wedges;
- }
- }
- /// <summary>
- /// This gets or sets the current rotation for the ring.
- /// If the rotation is set, all wedges will have their rotation updated
- /// </summary>
- public int Rotation
- {
- get
- {
- return this.rotation;
- }
- set
- {
- //Bound the rotation between 0 and 360 degrees
- //value = value < 0 ? 360 + value : value;
- if (value < 0) { value = 360 + value; }
- value=value%360;
- this.rotation = value;
- updateWedgePositions();
- }
- }
- /// <summary>
- /// Initializes a ring with a specified radius, degree of rotation, and arclength of each wedge
- /// </summary>
- /// <param name="radius">The radius of the ring, with the size of its wedges factored in</param>
- /// <param name="rotation">A positive integer between 0 and 359 that represents the degrees of rotation for this ring</param>
- /// <param name="wedgeSpan">The arclength of each wedge</param>
- public Ring(float radius, int rotation, int wedgeSpan,bool visible, Factory myFactory)
- {
- this.radius = radius; //Sets the ring's radius
- this.rotation = rotation; //Sets the ring's rotation
- this.WedgeSpan = wedgeSpan; //Sets the ring's wedgespan
- this.myFactory = myFactory; //Sets the ring's factory
- this.Visible = visible; //Sets whether or not the ring is visible
- initializeWedges(visible); //Initializes all of the wedges in the ring
- setPositions(); //Sets up the position array
- }
- /// <summary>
- /// This function sets up the position array for the ring
- /// </summary>
- private void setPositions()
- {
- positions = new Position[360];
- //Loops through each position, and sets its corresponding values.
- //Note: Each index is also the the degree for the position
- for (int i = 0; i < positions.Length; i++)
- {
- positions[i].Degrees = Game1.basePositions[i].Degrees;
- positions[i].Radians = Game1.basePositions[i].Radians;
- positions[i].X = Game1.basePositions[i].X * this.radius;
- positions[i].Y = Game1.basePositions[i].Y * this.radius;
- positions[i].LocationVector=new Vector2(positions[i].X,positions[i].Y);
- }
- }
- /// <summary>
- /// Gets the Position information at a specific index
- /// </summary>
- /// <param name="index">The index to return</param>
- /// <returns></returns>
- public Position getWedgePosition(int index)
- {
- return positions[wedges[index].Rotation];
- }
- /// <summary>
- /// Creates and initializes the wedges contained within the ring
- /// </summary>
- /// <param name="visible">Whether or not the wedges are visible</param>
- private void initializeWedges(bool visible)
- {
- int numWedges;
- numWedges = 360 / wedgeSpan;
- wedges = new List<Wedge>(numWedges);
- //Fills the ring with random wedges
- for (int i = 0; i < numWedges; i++)
- {
- //Wedge newWedge = GameScreen.wedgeFactory.CreateWedge();
- Wedge newWedge = myFactory.CreateWedge(visible);
- newWedge.Rotation = i * rotation;
- wedges.Add(newWedge);
- //wedges.Add( new Wedge(i*rotation) );
- }
- }
- /// <summary>
- /// Updates the position of each wedge
- /// </summary>
- private void updateWedgePositions()
- {
- //Iterates through each wedge and updates its rotation
- for (int i = 0; i < wedges.Count; i++)
- {
- wedges[i].Rotation = ((i * WedgeSpan) + rotation) % 360;
- }
- }
- /// <summary>
- /// Makes a currently-hidden wedge visible and changes its type to the proper WedgeType
- /// </summary>
- /// <param name="index">The index of the wedge that will become visible</param>
- /// <param name="type">The WedgeType to set the wedge to when it is visible</param>
- public void showWedge(int index, WedgeType type)
- {
- wedges[index].Type = type; //Sets the new type for the wedge
- wedges[index].Visible = true; //Makes the wedge visible
- this.Visible = true; //Ensures that the ring is visible
- }
- /// <summary>
- /// Hides a currently-visible wedge.
- /// After the wedge is hidden, it may hide the entire ring.
- /// </summary>
- /// <param name="index">The index of the wedge to be hidden</param>
- public void hideWedge(int index)
- {
- bool showRing = false; //Set up a bool that will potentially hide the ring
- wedges[index].Visible = false; //hide the wedge
- //checks if any of the wedges in the ring are visible. If they are, then the ring should be visible
- for (int i = 0; i < wedges.Count; i++)
- {
- if (wedges[i].Visible == true)
- {
- showRing = true;
- break;
- }
- }
- this.Visible = showRing;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment