1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Good resources for C# programming

Discussion in 'Programming' started by Emperor, Feb 17, 2007.

  1. #1
    I have quite a problem on my hands and require some tutorials for programming c#. My main goal is to create the popular sokoban game using C#, no graphics required, for a school project. Where can I find useful tutorials that cold help me out?
     
    Emperor, Feb 17, 2007 IP
  2. MarkusJ_NZ

    MarkusJ_NZ Well-Known Member

    Messages:
    240
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi, I always use the codeproject.com, great site and great community. Here's a link to a sokoban game in C# and there are others there too

    codeproject.com/csharp/sokobanpro.asp
     
    MarkusJ_NZ, Feb 22, 2007 IP
    Emperor likes this.
  3. Emperor

    Emperor Guest

    Messages:
    4,821
    Likes Received:
    180
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the link but I’m trying to create something much simpler :D

    This is what I’ve been able to do :D
    #include <stdio.h>
    
    void moverEsquerda(int areaJogo[19][19], int coluna, int linha);
    void moverDireita(int areaJogo[19][19], int coluna, int linha);
    void moverCima(int areaJogo[19][19], int coluna, int linha);
    void moverBaixo(int areaJogo[19][19], int coluna, int linha);
    void apresentarAreaJogo(int areaJogo[19][19]);
    int obterNumeroCaixas(int areaJogo[19][19]);
    
    int obterNumeroCaixas(int areaJogo[19][19])
    {
    	int numeroCaixas = 0;
    	int i,j; 
    	for(i=0; i < 19; i=i++)
    	{
    		for(j=0; j<19; j++)
    		{
    			if(areaJogo[j][i] == 2)numeroCaixas++;
    		}
    	}
    	return(numeroCaixas);
    }
    
    void apresentarAreaJogo(int areaJogo[19][19])
    {
    	int i,j; 
    	for(i=0; i < 19; i=i++)
    	{
    		for(j=0; j<19; j++)
    		{
    			printf("%d", areaJogo[j][i]);
    		}
    		printf("%\n");
    	}
    }
    
    void moverEsquerda(int areaJogo[19][19], int coluna, int linha)
    {
    	if(areaJogo[coluna-1][linha] == 0)
    	{
    		areaJogo[coluna-1][linha] = 1;
    		areaJogo[coluna][linha] = 0;
    	}
    }
    
    void moverDireita(int areaJogo[19][19], int coluna, int linha)
    {
    	if(areaJogo[coluna+1][linha] == 0)
    	{
    		areaJogo[coluna+1][linha] = 1;
    		areaJogo[coluna][linha] = 0;
    	}
    }
    
    void moverCima(int areaJogo[19][19], int coluna, int linha)
    {
    	if(areaJogo[coluna][linha-1] == 0)
    	{
    		areaJogo[coluna][linha-1] = 1;
    		areaJogo[coluna][linha] = 0;
    	}
    }
    
    void moverBaixo(int areaJogo[19][19], int coluna, int linha)
    {
    	if(areaJogo[coluna][linha+1] == 0)
    	{
    		areaJogo[coluna][linha+1] = 1;
    		areaJogo[coluna][linha] = 0;
    	}
    }
    
    int main(int argc, char *argv[])
    {
    	int areaJogo[19][19] = {
    	{9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,},
    	{9,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9},
    	{9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9},
    	};
    	
    	int coluna = 1;
    	int linha = 1;
    
    	int caixas = obterNumeroCaixas(areaJogo);
    	
    	int opcao = -1;
    	
    	do
    	{
    		if(opcao == 0)
    		{
    			return;
    		}
    		else if(opcao == 1)
    		{
    			moverEsquerda(areaJogo, coluna, linha);
    			coluna = coluna-1;
    		}
    		else if(opcao == 2)
    		{
    			moverDireita(areaJogo, coluna, linha);
    			coluna = coluna+1;
    		}
    		else if(opcao == 3)
    		{
    			moverCima(areaJogo, coluna, linha);
    			linha = linha-1;
    		}
    		else if(opcao == 4)
    		{
    			moverBaixo(areaJogo, coluna, linha);
    			linha = linha+1;
    		}
    		
    		apresentarAreaJogo(areaJogo);
    
    		printf("1 - Mover Esquerda\n");
    		printf("2 - Mover Direita\n");
    		printf("3 - Mover Cima\n");
    		printf("4 - Mover Baixo\n");
    		printf("0 - Sair\n");
    		
    		fflush(stdin);
    		scanf("%d", &opcao);
    
    	}while(caixas > 0);
    }
    Code (markup):
     
    Emperor, Feb 24, 2007 IP