#pragma comment (lib, "fmodvc.lib") 

#include <windows.h>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <sstream>
#include <apmatrix.h>
#include "resource.h"//for menu system #defines
#include "CFmod.h"
#include "bitmap.h"

#define SONG_NAME "music.mod"
CFmod mySong;

// Globals
HDC hdc; //global device context (used for drawing)
BUFFER gBuffer;//global buffer for drawing bitmaps

//global position info
int bmpWIDTH		= 48;
int bmpHEIGHT		= 48;
int buttonWIDTH		= 78;
int buttonHEIGHT	= 38;
int BRD_VERTSHIFT	= 0;
int WIN_WIDTH		= bmpWIDTH * 18 + 9;
int WIN_HEIGHT		= bmpHEIGHT * 12 + 120;

// global bitmaps
HBITMAP red_bmp				= NULL;
HBITMAP blue_bmp			= NULL;
HBITMAP green_bmp			= NULL;
HBITMAP yellow_bmp			= NULL;
HBITMAP silver_bmp			= NULL;
HBITMAP purple_bmp			= NULL;
HBITMAP soundon_bmp			= NULL;
HBITMAP soundoff_bmp		= NULL;
HBITMAP newgameon_bmp		= NULL;
HBITMAP newspdgameon_bmp	= NULL;
HBITMAP newgameoff_bmp		= NULL;
HBITMAP newspdgameoff_bmp	= NULL;

// global clix stuff
apmatrix <char> board;
char score[8] = {'0','0','0','0','0','0','0',0};//last character is the null escape (aka 0)
char levelstr[2] = {0};
int mode = 0;//0 for normal game mode, 1 for speed game mode
bool sound = true;//true = on, false = off 

LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
bool InitilizeStuff (MSG &msg, WNDCLASS &wndclass, HINSTANCE &hinstance, char class_name[], HWND &hwnd, int &ishow);
void InitBitmap (HBITMAP &bitmap, LPSTR filename);

void LoadImageSet(int imageset);
void UnloadBitmaps();

int mover (int row, int col);
void recursivemove (apmatrix <char> &board, const int &row, const int &col, const char &target, const char &dontmove, int &numremoved);
bool isvalidmove (const int &row, const int &col);
void removezeros ();
void removecol (int col);
int nummoves ();
void rInputMatrix (int level, int numrow, int numcol);
void fInputMatrix (const string &filename);
void sOutputMatrix ();
void clearscreen ();
void OutputBoardAndInfo ();
void addtoscore (int n);