Sign in to follow this  

My C++ with SDL code doesn't working well

This topic is 3779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. I making a game on C++ with SDL library, and at yesterday its working ok. But today I change some things and aren't showing the images...
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
const int GAME_FLAG = 1;
const int WIDTH = 1000,HEIGHT = 700,BPP = 32;
const int TW = 51,TH = 75;
const int FH[4] = {34,48,35,48};
const int FW[4] = {48,35,48,34};
int csn=0;
SDL_Event event;
SDL_Surface *background,*screen,*cromos,*deck;
SDL_Rect decks(int n){
	SDL_Rect offset;
	offset.x = 95*n;
	offset.y = 0;
	offset.w = 95;
	offset.h = 95;
	return offset;
}
void apply(int x,int y,SDL_Surface *source,SDL_Surface *des,SDL_Rect clip){
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;
	if(SDL_BlitSurface(source,&clip,des,&offset) == 0){
		printf("--\n");
	}
}
void apply(int x,int y,SDL_Surface *source,SDL_Surface *des){
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;
	SDL_BlitSurface(source,NULL,des,&offset);
}
SDL_Surface *load_image(char *filename){
	SDL_Surface *image,*op,*des;
	image = IMG_Load(filename);
	if(image != NULL){
		op = SDL_DisplayFormat(image);
		SDL_FreeSurface(image);
		Uint32 colorkey = SDL_MapRGB( op->format, 0xCC, 0xCC, 0xCC );
		SDL_SetColorKey( op, SDL_SRCCOLORKEY, colorkey );
	}
	return op;
}
SDL_Surface *load_image(char *filename,Uint8 r,Uint8 g,Uint8 b){
	SDL_Surface *image,*op,*des;
	image = IMG_Load(filename);
	if(image != NULL){
		op = SDL_DisplayFormat(image);
		SDL_FreeSurface(image);
		Uint32 colorkey = SDL_MapRGB( op->format, r, g, b );
		SDL_SetColorKey( op, SDL_SRCCOLORKEY, colorkey );
	}
	return op;
}
SDL_Rect get_cromo(int color,int colors,int face){
	SDL_Rect rect;
	switch(color){
		case 0:
			switch(colors){
				case 0:
					switch(face){
						case 0:
							rect.x = 0;
							rect.y = 2*TH+2;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = 0;
							rect.y = 3*TH+3;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 1:
					switch(face){
						case 0:
							rect.x = 0;
							rect.y = 0;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = 0;
							rect.y = TH+1;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 2:
					switch(face){
						case 0:
							rect.x = 0;
							rect.y = (4*TH+4);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = 0;
							rect.y = (4*TH+4)+(FH[0]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = 0;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = 0;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
				case 3:
					switch(face){
						case 0:
							rect.x = 0;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = 0;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = 0;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = 0;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(2*FH[2]+2)+(FH[3]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
			}
			break;
		case 1:
			switch(colors){
				case 0:
					switch(face){
						case 0:
							rect.x = 3*TW+3;
							rect.y = 2*TH+2;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = 3*TW+3;
							rect.y = 3*TH+3;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 1:
					switch(face){
						case 0:
							rect.x = 3*TW+3;
							rect.y = 0;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = 3*TW+3;
							rect.y = TH+1;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 2:
					switch(face){
						case 0:
							rect.x = 3*TW+3;
							rect.y = (4*TH+4);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = 3*TW+3;
							rect.y = (4*TH+4)+(FH[0]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = 3*TW+3;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = 3*TW+3;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
				case 3:
					switch(face){
						case 0:
							rect.x = 3*TW+3;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = 3*TW+3;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = 3*TW+3;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = 3*TW+3;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(2*FH[2]+2)+(FH[3]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
			}
			break;
		case 2:
			switch(colors){
				case 0:
					switch(face){
						case 0:
							rect.x = 2*TW+2;
							rect.y = 2*TH+2;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = 2*TW+2;
							rect.y = 3*TH+3;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 1:
					switch(face){
						case 0:
							rect.x = 2*TW+2;
							rect.y = 0;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = 2*TW+2;
							rect.y = TH+1;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 2:
					switch(face){
						case 0:
							rect.x = 2*TW+2;
							rect.y = (4*TH+4);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = 2*TW+2;
							rect.y = (4*TH+4)+(FH[0]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = 2*TW+2;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = 2*TW+2;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
				case 3:
					switch(face){
						case 0:
							rect.x = 2*TW+2;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = 2*TW+2;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = 2*TW+2;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = 2*TW+2;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(2*FH[2]+2)+(FH[3]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
			}
			break;
		case 3:
			switch(colors){
				case 0:
					switch(face){
						case 0:
							rect.x = TW+1;
							rect.y = 2*TH+2;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = TW+1;
							rect.y = 3*TH+3;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 1:
					switch(face){
						case 0:
							rect.x = TW+1;
							rect.y = 0;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = TW+1;
							rect.y = TH+1;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 2:
					switch(face){
						case 0:
							rect.x = TW+1;
							rect.y = (4*TH+4);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = TW+1;
							rect.y = (4*TH+4)+(FH[0]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = TW+1;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = TW+1;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
				case 3:
					switch(face){
						case 0:
							rect.x = TW+1;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = TW+1;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = TW+1;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = TW+1;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(2*FH[2]+2)+(FH[3]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
			}
			break;
		case 4:
			switch(colors){
				case 0:
					switch(face){
						case 0:
							rect.x = 4*TW+4;
							rect.y = 2*TH+2;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = 4*TW+4;
							rect.y = 3*TH+3;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 1:
					switch(face){
						case 0:
							rect.x = 4*TW+4;
							rect.y = 0;
							rect.w = TW;
							rect.h = TH;
							break;
						case 1:
							rect.x = 4*TW+4;
							rect.y = TH+1;
							rect.w = TW;
							rect.h = TH;
							break;
					}
					break;
				case 2:
					switch(face){
						case 0:
							rect.x = 4*TW+4;
							rect.y = (4*TH+4);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = 4*TW+4;
							rect.y = (4*TH+4)+(FH[0]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = 4*TW+4;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = 4*TW+4;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
				case 3:
					switch(face){
						case 0:
							rect.x = 4*TW+4;
							rect.y = (4*TH+4)+(FH[0]+1)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[0];
							rect.h = FH[0];
							break;
						case 1:
							rect.x = 4*TW+4;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(FH[1]+1)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[1];
							rect.h = FH[1];
							break;
						case 2:
							rect.x = 4*TW+4;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(FH[2]+1)+(FH[3]+1);
							rect.w = FW[2];
							rect.h = FH[2];
							break;
						case 3:
							rect.x = 4*TW+4;
							rect.y = (4*TH+4)+(2*FH[0]+2)+(2*FH[1]+2)+(2*FH[2]+2)+(FH[3]+1);
							rect.w = FW[3];
							rect.h = FH[3];
							break;
					}
					break;
			}
			break;
	}
	return rect;
}
void cromofull(int colors,int colora,int colorb,int deckn){
	apply(120+(csn*105),590,deck,screen,decks(deckn));
	switch(colors){
		case 0:
			apply(130+(csn*105),600,cromos,screen,get_cromo(colora,0,0));
			apply(154+(csn*105),600,cromos,screen,get_cromo(colorb,0,1));
			printf("%d,%d,%d,%d,%d,%d\n",csn,colors,colora,colorb,deckn,get_cromo(colora,0,0).x);
			break;
		case 1:
			apply(130+(csn*105),600,cromos,screen,get_cromo(colora,1,1));
			apply(154+(csn*105),600,cromos,screen,get_cromo(colorb,1,0));
			printf("SIM\n");
			break;
	}
	if(csn < 4){
		csn++;
	}
	else{
		csn=0;
	}
}
void cromofull(int colors,int colora,int colorb,int colorc,int colord,int deckn){
	apply(120+(csn*105),590,deck,screen,decks(deckn));
	switch(colors){
		case 2:
			apply(133+(csn*105),602,cromos,screen,get_cromo(colora,2,0));
			apply(132+(csn*105),625,cromos,screen,get_cromo(colorb,2,1));
			apply(155+(csn*105),639,cromos,screen,get_cromo(colorc,2,2));
			apply(171+(csn*105),603,cromos,screen,get_cromo(colord,2,3));
			printf("SIM\n");
			break;
		case 3:
			apply(155+(csn*105),602,cromos,screen,get_cromo(colora,3,0));
			apply(132+(csn*105),603,cromos,screen,get_cromo(colorb,3,1));
			apply(134+(csn*105),639,cromos,screen,get_cromo(colorc,3,2));
			apply(170+(csn*105),625,cromos,screen,get_cromo(colord,3,3));
			printf("SIM\n");
			break;
	}
	if(csn < 4){
		csn++;
	}
	else{
		csn=0;
	}
}
int ra(){
	int temp;
	temp = rand();
	return temp;
}

void direction(int a, int b){
	switch(b){
		case 1:
			printf("Toda:");
			break;
		case 2:
			switch(a){
				case 0:
					printf("Topo e Esquerda:");
					break;
				case 1:
					printf("Base e Direita:");
					break;
			}
			break;
		case 4:
			switch(a){
				case 0:
					printf("Topo:");
					break;
				case 1:
					printf("Esquerda:");
					break;
				case 2:
					printf("Base:");
					break;
				case 3:
					printf("Direita:");
					break;
			}
			break;
	}
}
class Cromo{
	public:
		int colors;
		int *color;
		int pts;
		bool hand;
		bool field;
		Cromo(){}
		void set(int a,int b,int c){
			printf("REE\n");
			colors = c;
			hand = 0;
			field = 0;
			color = (int*)malloc(sizeof(int)*2);
			color[0] = a;
			color[1] = b;
			if(color[0] == 4){
				pts += 5;
			}
			else{
				pts += 50;
			}
			if(color[1] == 4){
				pts += 5;
			}
			else{
				pts += 50;
			}
		}
		void set(int a,int b,int c, int d,int e){
			colors = e;
			hand = 0;
			field = 0;
			color = (int*)malloc(sizeof(int)*4);
			color[0] = a;
			color[1] = b;
			color[2] = c;
			color[3] = d;
			if(color[0] == 4){
				pts += 5;
			}
			else{
				pts += 25;
			}
			if(color[1] == 4){
				pts += 5;
			}
			else{
				pts += 25;
			}
			if(color[2] == 4){
				pts += 5;
			}
			else{
				pts += 25;
			}
			if(color[3] == 4){
				pts += 5;
			}
			else{
				pts += 25;
			}
			printf("\npts:%d\n",pts);
		}
		void random(){
			int i=0;
			int temp;
			temp = (ra()%4);
			switch(temp){
				case 0:
					set(ra()%5,ra()%5,0);
					break;
				case 1:
					set(ra()%5,ra()%5,1);
					break;
				case 2:
					set(ra()%5,ra()%5,ra()%5,ra()%5,2);
					break;
				case 3:
					set(ra()%5,ra()%5,ra()%5,ra()%5,3);
					break;
			}
		};
/* 												Parei Aqui*/
		void status(int j){
			int i = 0;
			switch(colors){
				case 0:
					cromofull(0,color[0],color[1],0);
					printf("OK\n");
					break;
				case 1:
					cromofull(1,color[0],color[1],0);
					printf("OK\n");
					break;
				case 2:
					cromofull(2,color[0],color[1],color[2],color[3],0);
					printf("OK\n");
					break;
				case 3:
					cromofull(3,color[0],color[1],color[2],color[3],0);
					printf("OK\n");
					break;
			}
		}
};
bool cbd(int,int,Cromo*);
class Table{
	public:
		Cromo table[6][3];
		Table(){
			int i=0;
			int j=0;
			while(i<6){
				while(j<3){
					table[i][j].field = 0;
					j++;
				}
				i++;
				j=0;
			}
		}
		void show(){
			int i=0;
			int j=0;
			while(i<3){
				printf("+----+----+----+----+----+----+\n|");
				while(j<6){
					if(table[j][i].colors == 0){
						printf("    ");
					}
					if(table[j][i].colors == 1){
						switch((int)table[j][i].color[0]){
							case 0:
								printf("RRRR");
								break;
							case 1:
								printf("YYYY");
								break;
							case 2:
								printf("GGGG");
								break;
							case 3:
								printf("BBBB");
								break;
							case 4:
								printf("WWWW");
								break;
						}
					}
					if((int)table[j][i].colors == 2){
						switch((int)table[j][i].color[0]){
							case 0:
								printf("RR");
								break;
							case 1:
								printf("YY");
								break;
							case 2:
								printf("GG");
								break;
							case 3:
								printf("BB");
								break;
							case 4:
								printf("WW");
								break;
						}
						switch((int)table[j][i].color[1]){
							case 0:
								printf("RR");
								break;
							case 1:
								printf("YY");
								break;
							case 2:
								printf("GG");
								break;
							case 3:
								printf("BB");
								break;
							case 4:
								printf("WW");
								break;
						}
					}
					if((int)table[j][i].colors == 4){
						switch((int)table[j][i].color[0]){
							case 0:
								printf("R");
								break;
							case 1:
								printf("Y");
								break;
							case 2:
								printf("G");
								break;
							case 3:
								printf("B");
								break;
							case 4:
								printf("W");
								break;
						}
						switch((int)table[j][i].color[1]){
							case 0:
								printf("R");
								break;
							case 1:
								printf("Y");
								break;
							case 2:
								printf("G");
								break;
							case 3:
								printf("B");
								break;
							case 4:
								printf("W");
								break;
						}
						switch((int)table[j][i].color[2]){
							case 0:
								printf("R");
								break;
							case 1:
								printf("Y");
								break;
							case 2:
								printf("G");
								break;
							case 3:
								printf("B");
								break;
							case 4:
								printf("W");
								break;
						}
						switch((int)table[j][i].color[3]){
							case 0:
								printf("R");
								break;
							case 1:
								printf("Y");
								break;
							case 2:
								printf("G");
								break;
							case 3:
								printf("B");
								break;
							case 4:
								printf("W");
								break;
						}
					}
					printf("|");
					j++;
				}
				i++;
				j=0;
				printf("\n");
			}
		}
		bool complete(){
			int i=0;
			int j=0;
			int k=0;
			while(i<6){
				while(j<3){
					j++;
					if(table[i][j].field != 0){
						k++;
					}
				}
				i++;
				j=0;
			}
			printf("\n%d\n",k);
			if(k == 17){
				return 1;
			}
			else{
				return 0;
			}
		}
}tab;

class Book{
	private:
		int cards;
		int top_card;
	public:
		Cromo *card;
		Book(){

		}
		void set( int a ){
			int i;
			top_card = 0;
			cards = a;
			card = (Cromo *)malloc(sizeof(Cromo)*a);
			for(i=0;i<a;i++){
				if(GAME_FLAG == 1){
					card[i].random();
				}
				else{
					card[i].set(4,4,0);
				}
			}
			buy();
			buy();
			buy();
			buy();
			buy();
		}
		void buy(){
			card[top_card++].hand = 1;
		}
		void show_hand(){
			int i=0;
			while(i<cards){
				if(card[i].hand == 1){
					card[i].status(i);
				}
				i++;
			}
		}
		int drop(Cromo *a,int x, int y){
			bool i=0;
			if(!(x<6 && x>-1)){
				return 1;
			}
			if(!(y<3 && y>-1)){
				return 1;
			}
			if(tab.table[x][y].field == 0){
				switch((int)a->colors){
					case 1:
						if(cbd(x,y,a)){
							printf("\n*%d*\n",cbd(x,y,a));
							i=1;
						}
						break;
					case 2:
						if(cbd(x,y,a)){
							printf("\n*%d*\n",cbd(x,y,a));
							i=1;
						}
						break;
					case 4:
						if(cbd(x,y,a)){
							printf("\n*%d*\n",cbd(x,y,a));
							i=1;
						}
						break;
				}
				if(i==1){
					tab.table[x][y].colors = a->colors;
					tab.table[x][y].field = 1;
					switch(a->colors){
						case 1:
							tab.table[x][y].color = (int*)malloc(sizeof(int));
							tab.table[x][y].color[0] = (int)a->color[0];
							break;
						case 2:
							tab.table[x][y].color = (int*)malloc(sizeof(int)*2);
							tab.table[x][y].color[0] = (int)a->color[0];
							tab.table[x][y].color[1] = (int)a->color[1];
							break;
						case 4:
							tab.table[x][y].color = (int*)malloc(sizeof(int)*4);
							tab.table[x][y].color[0] = (int)a->color[0];
							tab.table[x][y].color[1] = (int)a->color[1];
							tab.table[x][y].color[2] = (int)a->color[2];
							tab.table[x][y].color[3] = (int)a->color[3];
							break;
					}
					a->hand = 0;
					return 0;
				}
			}
			else{
				return 2;
			}
		}
};

class Player{
	private:
		Book book;
	public:
		int pts;
		Player(){
			book.set(9);
			pts = 0;
		}
		void turn(){
			int i;
			int x;
			int y;
			printf("Pontos:%d - Mao:\n\n",pts);
			book.show_hand();
			printf("\n\nQue cromo baixar?\n");
			scanf("%d",&i);
			tab.show();
			printf("\n\n Em que coluna?\n");
			scanf("%d",&x);
			printf("\n\n Em que linha?\n");
			scanf("%d",&y);
			book.drop(&book.card[i],x,y);
			pts += book.card[i].pts;
			book.buy();
		}
};

int main(){
	srand(time(NULL));
	Player p1,p2;
	bool turn = 0;
	bool quit = 0;
	if(SDL_Init( SDL_INIT_EVERYTHING ) == -1){
		return 1;
	}
	SDL_WM_SetCaption("Cromos em ACAO",NULL);
	printf("+%d+",get_cromo(0,0,0));
	screen = SDL_SetVideoMode( WIDTH, HEIGHT, BPP, SDL_SWSURFACE );
	background = load_image("bigfundo.jpg");
	cromos = load_image("ocromos.png",0xCC,0xCC,0xCC);
	deck = load_image("fundocromos_.png",0xFF,0x00,0x00);
	apply(0,0,background,screen);
	if( SDL_Flip( screen ) == -1 ){
		return 1;
	}
	tab.show();
	while(quit == 0){
		while(SDL_PollEvent(&event)){
			switch(event.type){
				case SDL_QUIT:
					printf("Bye!");
					quit = 1;
					SDL_FreeSurface( screen );
					SDL_FreeSurface( background );
					SDL_Quit();
			}
		}
		switch(turn){
			case 0:
				p1.turn();
				turn = 1;
				break;
			case 1:
				p2.turn();
				turn = 0;
				break;
		}
		tab.show();
		getchar();
		if(tab.complete() == 1){
			printf("\n\n***Fim de jogo***\n\nJogador 1:%d\nJogador 2:%d\n\n",p1.pts,p2.pts);
			break;
		}
	}
};
bool cbd(int x, int y, Cromo *cro){
	int i=0;
	int col;
	if(x > 0){
		if(tab.table[x-1][y].field != 0){
			if((int)cro->colors == 1){
				col = (int)cro->color[0];
			}
			if((int)cro->colors == 2){
				col = (int)cro->color[0];
			}
			if((int)cro->colors == 4){
				col = (int)cro->color[1];
			}
			if(col == 4){
				i++;
				printf("0-ok\n");
			}
			else{
				switch(tab.table[x-1][y].colors){
					case 1:
						if(((int)tab.table[x-1][y].color[0] == col) || ((int)tab.table[x-1][y].color[0] == 4) ){
							i++;
							printf("0-ok\n");
						}
						break;
					case 2:
						if(((int)tab.table[x-1][y].color[1] == col) || ((int)tab.table[x-1][y].color[1] == 4) ){
							i++;
							printf("0-ok\n");
						}
						break;
					case 4:
						if(((int)tab.table[x-1][y].color[3] == col) || ((int)tab.table[x-1][y].color[3] == 4) ){
							i++;
							printf("0-ok\n");
						}
						break;
				}
			}
		}
		else{
			i++;
			printf("0-ok\n");
		}
	}
	else{
		i++;
		printf("0-ok\n");
	}
	if(y > 0){
		if(tab.table[x][y-1].field != 0){
			if((int)cro->colors == 1){
				col = (int)cro->color[0];
			}
			if((int)cro->colors == 2){
				col = (int)cro->color[0];
			}
			if((int)cro->colors == 4){
				col = (int)cro->color[0];
			}
			if(col == 4){
				i++;
				printf("1-ok\n");
			}
			else{
				switch(tab.table[x][y-1].colors){
					case 1:
						if(((int)tab.table[x][y-1].color[0] == col) || ((int)tab.table[x][y-1].color[0] == 4) ){
							i++;
							printf("1-ok\n");
						}
						break;
					case 2:
						if(((int)tab.table[x][y-1].color[1] == col) || ((int)tab.table[x][y-1].color[1] == 4) ){
							i++;
							printf("1-ok\n");
						}
						break;
					case 4:
						if(((int)tab.table[x][y-1].color[2] == col) || ((int)tab.table[x][y-1].color[2] == 4) ){
							i++;
							printf("1-ok\n");
						}
						break;
				}
			}
		}
		else{
			i++;
			printf("1-ok\n");
		}
	}
	else{
		i++;
		printf("1-ok\n");
	}
	if(x < 5){
		if(tab.table[x+1][y].field != 0){
			if((int)cro->colors == 1){
				col = (int)cro->color[0];
			}
			if((int)cro->colors == 2){
				col = (int)cro->color[1];
			}
			if((int)cro->colors == 4){
				col = (int)cro->color[3];
			}
			if(col == 4){
				i++;
				printf("2-ok\n");
			}
			else{
				switch(tab.table[x+1][y].colors){
					case 1:
						if(((int)tab.table[x+1][y].color[0] == col) || ((int)tab.table[x+1][y].color[0] == 4) ){
							i++;
							printf("2-ok\n");
						}
						break;
					case 2:
						if(((int)tab.table[x+1][y].color[0] == col) || ((int)tab.table[x+1][y].color[0] == 4) ){
							i++;
							printf("2-ok\n");
						}
						break;
					case 4:
						if(((int)tab.table[x+1][y].color[1] == col) || ((int)tab.table[x+1][y].color[1] == 4) ){
							i++;
							printf("2-ok\n");
						}
						break;
				}
			}
		}
		else{
			i++;
			printf("2-ok\n");
		}
	}
	else{
		i++;
		printf("2-ok\n");
	}
	if(y < 2){
		if(tab.table[x][y+1].field != 0){
			if((int)cro->colors == 1){
				col = (int)cro->color[0];
			}
			if((int)cro->colors == 2){
				col = (int)cro->color[1];
			}
			if((int)cro->colors == 4){
				col = (int)cro->color[2];
			}
			if(col == 4){
				i++;
				printf("3-ok\n");
			}
			else{
				switch(tab.table[x][y+1].colors){
					case 1:
						if(((int)tab.table[x][y+1].color[0] == col) || ((int)tab.table[x][y+1].color[0] == 4) ){
							i++;
							printf("3-ok\n");
						}
						break;
					case 2:
						if(((int)tab.table[x][y+1].color[0] == col) || ((int)tab.table[x][y+1].color[0] == 4) ){
							i++;
							printf("3-ok\n");
						}
						break;
					case 4:
						if(((int)tab.table[x][y+1].color[0] == col) || ((int)tab.table[x][y+1].color[0] == 4) ){
							i++;
							printf("3-ok\n");
						}
						break;
				}
			}
		}
		else{
			i++;
			printf("3-ok\n");
		}
	}
	else{
		i++;
		printf("3-ok\n");
	}
	printf("\n%d\n\n",i);
	if(i == 4){
		return 1;
	}
	else{
		return 0;
	}
}
Help me please! Thanks

Share this post


Link to post
Share on other sites
Two things:

1) Use source tags. They make stuff easier to read. Learn how to use them here.
2) Don't just dump all your code on use and expect us to fix it for you. Only post the relevant code IE rendering code and the code you changed since it stopped working.

Share this post


Link to post
Share on other sites

This topic is 3779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this