On board.cpp I load an image that is 15x15 pixels and on the generate_board method I resize the screen so that the images can just barely fit on the screen. However, when I do this the tiles get sized down from 15x15 to some ridiculously small size. Any idea why? Thanks for any help in advance.
Main.cpp-
#include "DarkGDK.h"
#include "Board.cpp"
enum KEYBOARD
{
KEY_NONE,KEY_ESC,KEY_ONE,KEY_TWO,KEY_THREE,KEY_FOUR,KEY_FIVE,KEY_SIX,
KEY_SEVEN,KEY_EIGHT,KEY_NINE,KEY_ZERO,KEY_DASH,KEY_EQUAL,KEY_BACK_SPACE,KEY_TAB,KEY_Q,KEY_W,
KEY_E,KEY_R,KEY_T,KEY_Y,KEY_U,KEY_I,KEY_O,KEY_P,KEY_LEFT_BRACKET,KEY_RIGHT_BRACKET,KEY_ENTER,
KEY_LEFT_CTRL,KEY_A,KEY_S,KEY_D,KEY_F,KEY_G,KEY_H,KEY_J,KEY_K,KEY_L,KEY_SEMI_COLON,KEY_APOSTROPHE,
KEY_TILDA,KEY_LEFT_SHIFT,KEY_BACK_SLASH,KEY_Z,KEY_X,KEY_C,KEY_V,KEY_B,KEY_N,KEY_M,KEY_COMMA,KEY_PERIOD,
KEY_FORWARD_SLASH,KEY_PRINT_SCREEN,KEY_ALT,KEY_SPACE,KEY_CAPS,KEY_F1,KEY_F2,KEY_F3,KEY_F4,
KEY_F5,KEY_F6,KEY_F7,KEY_F8,KEY_F9,KEY_F10,KEY_NUM_LOCK,KEY_SCROLL,KEY_NUM_7,KEY_NUM_8,KEY_NUM_9,
KEY_NUM_DASH,KEY_NUM_4,KEY_NUM_5,KEY_NUM_6,KEY_NUM_PLUS,KEY_NUM_1,KEY_NUM_2,KEY_NUM_3,
KEY_NUM_0,KEY_NUM_DEL,KEY_EMPTY_1,KEY_EMPTY_2,KEY_EMPTY_3,KEY_F11,KEY_F12,KEY_EMPTY_89,
KEY_EMPTY_90,KEY_EMPTY_91,KEY_EMPTY_92,KEY_EMPTY_93,KEY_EMPTY_94,KEY_EMPTY_95,
KEY_EMPTY_96,KEY_EMPTY_97,KEY_EMPTY_98,KEY_EMPTY_99,KEY_EMPTY_100,KEY_EMPTY_101,
KEY_EMPTY_102,KEY_HOME,KEY_UP,KEY_PAGE_UP,KEY_EMPTY_106,KEY_LEFT,KEY_EMPTY_108,KEY_RIGHT,
KEY_EMPTY_110,KEY_END,KEY_DOWN,KEY_PAGE_DOWN,KEY_INSERT,KEY_DELETE
};
enum DIFFICULTY{EASY,MEDIUM,HARD};
enum GAME_STATE{WAITING,GENERATING,PLAYING};
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
// a call is made to this function so we can stop the GDK from
// responding to the escape key, we can then add in some code in our
// main loop so we can control what happens when the escape key is pressed
dbDisableEscapeKey ( );
// now we will set the random seed value to the timer, this will
// help us to get more random values each time we run the program
dbRandomize ( dbTimer ( ) );
// next we will load in some animated sprites, before doing this
// we need to adjust the image color key, by using this function we
// can make a specific color be transparent, in our case we want this
// to be bright pink
dbSetImageColorKey ( 255, 0, 255 );
DIFFICULTY difficulty=EASY;
GAME_STATE game_state=WAITING;
int keyPress=0;
game_board current_board;
while ( LoopGDK ( ) )
{
dbCLS();
if(dbScanCode()!=0 && game_state==WAITING)
{
keyPress=dbScanCode();
game_state=GENERATING;
}
if(game_state==GENERATING)
{
switch(keyPress)
{
case 2:
difficulty=EASY;
break;
case 3:
difficulty=MEDIUM;
break;
case 4:
difficulty=HARD;
break;
default:
difficulty=EASY;
break;
}
current_board.generate_game_board(difficulty);
game_state=PLAYING;
}
int currentKey=dbScanCode();
if(currentKey==KEY_TAB)
{
current_board.generate_game_board(difficulty);
}
if(game_state==PLAYING)
{
current_board.draw_board();
}
if (currentKey==KEY_ESC )
break;
dbSync ( );
}
// and now everything is ready to return back to Windows
return;
}
Board.cpp-
#include "DarkGDK.h"
#include "Matrix.cpp"
class game_board : public Matrix<int>
{
private:
int width,height,num_mines,tile_width,tile_height;
Matrix *mine_array,*tile_array;
public:
game_board()
{
this->tile_width=15;
this->tile_height=15;
char image[]="c:\\Users\\Charles\\Pictures\\sweeper_blank.jpg";
dbLoadImage(image,1,1);
}
void generate_game_board(int difficulty)
{
switch(difficulty)
{
case 0:
width=5;
height=5;
num_mines=5;
break;
case 1:
width=10;
height=10;
num_mines=25;
break;
case 2:
width=20;
height=20;
num_mines=100;
break;
}
mine_array=new Matrix(height,width);
tile_array=new Matrix(height,width);
int placed_mines=0;
int total_tiles=width*height;
for(int y=0;y<height;y++)
{
for(int x=0;x<width;x++)
{
int mine=dbRND(100);
int number=x*width+y;
int tolerance=75;
if(placed_mines<num_mines)
{
int percent=number/total_tiles*100;
if(percent>99)
{
tolerance=0;
}
else if(percent>95)
{
tolerance=5;
}
else if(percent>90)
{
tolerance=10;
}
else if(percent>85)
{
tolerance=15;
}
else if(percent>80)
{
tolerance=20;
}
}
if(mine>tolerance && (placed_mines<num_mines))
{
mine_array->Set(y,x,1);
placed_mines++;
}
else
{
mine_array->Set(y,x,0);
}
}
}
for(int y=0;y<height;y++)
{
for(int x=0;x<width;x++)
{
tile_array->Set(y,x,0);
}
}
dbSetWindowSize
(
this->width*this->tile_width*1.5,
this->height*this->tile_height*1.5
);
}
void draw_board()
{
int x_space=15,x_pos=0;
char temp[3];
for(int a=0;a<this->width;a++)
{
for(int b=0;b<this->height;b++)
{
if(b==0)
{
x_pos=0;
}
x_pos+=x_space;
int y_pos=(a*15);
dbPasteImage(1,x_pos,y_pos,0);
}
}
}
~game_board()
{
dbDeleteImage(1);
}
};
Matrix.cpp-
/**
* 2D Matrix with non-contiguous 2D storage internally.
*/
template <typename TValue>
class Matrix
{
public:
/**
* the value type.
*/
typedef TValue ValueType;
/**
* the value type.
*/
typedef Matrix<ValueType> Self;
/**
* the pointer type.
*/
typedef ValueType* PointerType;
/**
* the storage type.
*/
typedef ValueType** StorageType;
/**
* the size type.
*/
typedef int SizeType;
/**
* contructor.
*/
Matrix( SizeType nrow, SizeType ncol )
: m_nrow( nrow )
, m_ncol( ncol )
, m_data( Create( nrow, ncol ) )
{
}
Matrix()
{
}
/**
* destructor.
*/
virtual ~Matrix()
{
/*for ( int row = 0; row < Rows(); ++row )
{
delete[] m_data[ row ];
}*/
delete[] m_data;
}
/**
* the i-th row;
* this allows you to write matrix[y][x] to access an element.
*/
PointerType operator[]( int i )
{
return m_data[ i ];
}
/**
* alias for Get(y,x) (const);
* this allows you to write int x = matrix(y,x) to access an element.
*/
ValueType operator()( SizeType y, SizeType x ) const
{
return Get( y, x );
}
/**
* alias for Get(y,x) (non-const);
* this allows you to write matrix(y,x) = x; to access an element.
*/
ValueType& operator()( SizeType y, SizeType x )
{
return Get( y, x );
}
/**
* the number of rows.
*/
SizeType Rows() const
{
return m_nrow;
}
/**
* the number of columns.
*/
SizeType Columns() const
{
return m_ncol;
}
/**
* the value of the given location (const).
*/
ValueType Get( SizeType y, SizeType x ) const
{
return m_data[ y ][ x ];
}
/**
* the value of the given location (non-const).
*/
ValueType& Get( SizeType y, SizeType x )
{
return m_data[ y ][ x ];
}
/**
* set the value of the given location.
*/
void Set( SizeType y, SizeType x, const ValueType& value )
{
m_data[ y ][ x ] = value;
}
/**
* the internal representation.
*/
friend StorageType GetImpl( Self& matrix )
{
return matrix.m_data;
}
protected:
/**
* convenience function to create the internal representation inside the
* member initialization list (MIL).
*/
StorageType Create( SizeType nrow, SizeType ncol )
{
StorageType m = new PointerType[ nrow ];
for ( int row = 0; row < nrow; ++row )
{
m[ row ] = new ValueType[ ncol ];
}
return m;
}
private:
/**
* the number of columns.
*/
SizeType m_ncol;
/**
* the number of rows.
*/
SizeType m_nrow;
/**
* the internal representation.
*/
StorageType m_data;
private:
/**
* prevent asignement.
*/
Self& operator= ( const Self& );
/**
* prevent copy-asignement.
*/
Matrix( const Self& );
};
Charles Thompson