using System;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms;
namespace PacMan
{
///
/// The form provides the user interface handles user-triggered events. It also handles the timer and creates the gameEngine object.
///
public partial class Form1 : Form
{
private const int SCORE_SIZE_AREA = 50;
private Random rand;
private Grid dataGrid;
private GameEngine gameEngine;
private PictureBox[] lifeCounter;
private System.Windows.Media.MediaPlayer sound;
public Form1()
{
InitializeComponent();
rand = new Random();
dataGrid = new Grid("TileMap.csv");
Controls.Add(dataGrid);
sound = new System.Windows.Media.MediaPlayer();
sound.Open(new Uri("pacmanDubHeavy.mp3", UriKind.Relative));
sound.Play();
gameEngine = new GameEngine(dataGrid, rand, timer1.Interval);
//pacman font
PrivateFontCollection fontCollection = new PrivateFontCollection();
fontCollection.AddFontFile("crackman.ttf");
FontFamily ff = fontCollection.Families[0];
int fontsize = 12;
Font pacmanFont = new Font(ff, fontsize, FontStyle.Bold);
label2.Font = pacmanFont;
label3.Font = pacmanFont;
label4.Font = pacmanFont;
lifeCounter = new PictureBox[3];
lifeCounter[0] = pictureBox1;
lifeCounter[1] = pictureBox2;
lifeCounter[2] = pictureBox3;
}
///
/// If the user clicks this menustrip item the application closes.
///
///
///
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
///
/// Listens for user keystrokes
///
///
///
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
gameEngine.GetUserDirection(e.KeyCode);
}
///
/// Prompts the game to progress at each timer-tick. Also prompts Score, Lives left, and Game Over visuals to display
///
///
///
private void timer1_Tick(object sender, EventArgs e)
{
label3.Text = gameEngine.CalculateScore().ToString();
gameEngine.RunGame();
for (int i = gameEngine.N_Lives; i < lifeCounter.Length; i++)
{
lifeCounter[i].Visible = false;
}
if (gameEngine.GameOver == true)
{
label4.Text = ("GAME OVER \n\nFINAL SCORE: " + gameEngine.CalculateScore().ToString());
label4.Visible = true;
timer1.Enabled = false;
}
}
}
}