using System;
namespace game
{
class MainClass
{
private static DateTime dt = DateTime.Now;
private static DateTime elapsedTime = DateTime.Now;
private static int i = 0;
private static int drawCount = 0;
private static double dps = 0.0;
// How many ticks to iterate through before you draw
// Lower = Faster FPS
private static int ticksPerDraw = 30000;
///
/// Puts the cursor at the top so the screen may be overwritten
///
private static void Clear()
{
Console.SetCursorPosition(0,0);
}
///
/// Returns a long with the number of ticks since last reset
///
///
/// A
///
private static long GetTickCount()
{
DateTime now = DateTime.Now;
long ticks = now.Ticks - dt.Ticks;
return ticks;
}
///
/// Resets ticks
///
private static void ResetTicks()
{
dt = DateTime.Now;
i = 0;
}
///
/// Returns the number of Milliseconds since the game started
///
///
/// A
///
private static double GetMilliseconds()
{
DateTime check = DateTime.Now;
TimeSpan ts = check - elapsedTime;
return ts.TotalMilliseconds;
}
///
/// Returns the Framerate of the game
///
///
/// A
///
private static double CalculateFPS()
{
double seconds = GetMilliseconds();
if(seconds > 0)
{
dps = drawCount / seconds;
}
return dps * 1000;
}
///
/// Draws.
///
private static void Draw()
{
long ticks = GetTickCount();
if(ticks > ticksPerDraw)
{
double fps = CalculateFPS();
drawCount++;
string draw = "\nGame Updates " + i + "\n" +
"Draw Count " + drawCount + "\n" +
"Frames per second " + fps;
Console.Write(draw);
ResetTicks();
}
}
///
/// Updates the game info
///
private static void UpdateGame()
{
i++;
}
///
/// Checks for keyboard input
///
private static void CheckInput()
{
}
///
/// Here be dragons
///
///
/// A
///
public static void Main()
{
Console.Clear();
/**
* Game Loop
*/
bool running = true;
while(running)
{
// Checks for keyboard input
CheckInput();
// Updates the game data
UpdateGame();
// Draws the game data
Draw();
// Resets the screen
Clear();
}
}
}
}