Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone, im using Dragonfire sdk to develop 15 puzzle Game.
i'm storing the images of the puzzle boxes in an integer array, but when i try to display the images of boxes, red box appears on the screen instead of the the original image which means the image is not loaded (or indirectly the image doesn't exist).. the background is loaded properly..
heres the code please help
C++
//===============================================
#include "DragonFireSDK.h"
//===============================================

#define MAXROWS 4
#define MAXCOLS 4

//===============================================

int boxes[15] = {	 ImageAdd("Assets/1.png"),
					ImageAdd("Assets/1.png"),
					ImageAdd("Assets/3.png"),
					ImageAdd("Assets/4.png"),
					ImageAdd("Assets/5.png"),
					ImageAdd("Assets/6.png"),
					ImageAdd("Assets/7.png"),
					ImageAdd("Assets/8.png"),
					ImageAdd("Assets/9.png"),
					ImageAdd("Assets/10.png"),
					ImageAdd("Assets/11.png"),
					ImageAdd("Assets/12.png"),
					ImageAdd("Assets/13.png"),
					ImageAdd("Assets/14.png"),
					ImageAdd("Assets/15.png")
					};

//===============================================

struct board {
	int grid[MAXROWS][MAXCOLS];
	int posx;
	int posy;
	int image;
	int view;
} base;

//===============================================

struct box {
	int posx;
	int posy;
	int image;
	int view;
	int id;
	box *up;
	box *down;
	box *left;
	box *right;
} *head , *temp , *p ;

//===============================================

void InitializeBoard(){
	base.image = ImageAdd("Assets/BG+F.png");
	base.posx = 0;
	base.posy = 0;
	base.view = ViewAdd(base.image, base.posx, base.posy);


	head = 0;
}

void InitializeBoxes(){
	for (int count = 0; count<15 ; count++)
	
	{
		if (head == 0 && count == 0)
		{
			temp = new box;
			temp->posx = 22 ;
			temp->posy = 132 ;
			temp->image = boxes[count] ;
			temp->view = ViewAdd(temp->image, temp->posx, temp->posy) ;
			temp->id = count ;
			temp->up = 0 ;
			temp->left = 0 ;
			temp->right = 0 ;
			temp->down = 0 ;
		}


	}

}

void AppMain()
{
	InitializeBoard();
	InitializeBoxes();
}


//===============================================

void OnTimer()
{

}

//===============================================
Posted
Updated 21-Dec-11 10:21am
v5
Comments
Albert Holguin 21-Dec-11 10:03am    
First off, this is very bad C++, you use C-like coding practices by polluting the global namespace when you don't really have to.
LanFanNinja 21-Dec-11 10:20am    
Why you change your question from what it was to what it is now I will truly never know ??!?!?!?
[no name] 21-Dec-11 10:45am    
Changed question completly.
Richard MacCutchan 21-Dec-11 17:05pm    
Rolled back to original question so some of the responses will make more sense.

From looking at this:
http://dragonfiresdk.wikispaces.com/ImageAdd%28char+*filename%29[^]

I can see what you're trying to accomplish, and you're doing it all wrong. I'm thinking you don't know C++? You can't declare and load an array dynamically like that, it doesn't work that way. You have to declare it then load it at run-time in a function.
 
Share this answer
 
Comments
LanFanNinja 21-Dec-11 10:16am    
+5
yes OP needs to read the DragonFireSDK documentation
http://www.dragonfiresdk.net/help/DragonFireSDKHelp.html
And practice, practice, practice!

OP wrote "P.S if i initialize the boxes within the InitializeBoxes() function it works :P"

Your problem is due to a misunderstanding.
Albert Holguin 21-Dec-11 10:27am    
Thanks...and it is a weird question change he just did.
LanFanNinja 21-Dec-11 10:33am    
Indeed! Oo
Problem here is, you have not initialized value of i.

Here is your updated code.

C#
int array1 [5] = {1,2,3,4,5};

initialize()
{
int x;
for(int i=0; i<5;i++)
x=array1[i];
}
 
Share this answer
 
v2
Comments
Albert Holguin 21-Dec-11 10:26am    
He completely changed his question, look at the previous versions.
[no name] 21-Dec-11 10:44am    
Oh yes! This type of Question Answer mismatch gives really bad impression.
@all who replied
thanks guys but i found none of you encouraging rather i felt rudeness of tone in your answers..
im just a 16 years old guy trying to learn coding.. but may be i should just quit :/
 
Share this answer
 
Comments
Albert Holguin 21-Dec-11 12:15pm    
Just learn and keep moving... Don't quit because of what strangers have to say... :)
JackDingler 21-Dec-11 15:03pm    
The answers don't seem rude to me.
They are giving it to you straight, and assuming you're an adult.

I doubt that you'd want us to be condescending to you.
So, let me get this straight - you're trying to store an image into an array of integers...

Well, there's your problem...

One final observation, you're putting 16 values into a 15-element array.
 
Share this answer
 
v2
Comments
Albert Holguin 21-Dec-11 10:08am    
They're image handles, looked up the "DragonFireSDK"... although his code is still all wrong even conceptually.
#realJSOP 21-Dec-11 10:41am    
He completely changed his original question.
Albert Holguin 21-Dec-11 10:44am    
Yeah, I just noticed... ::headscratch::

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900