begin process at 2012 05 27 20:07:34
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > JEU D'AVENTURE EN DOS

JEU D'AVENTURE EN DOS


 Information sur la source

Note :
Aucune note
Catégorie :Jeux Classé sous :jeu, zelda, aventure, dos Niveau :Débutant Date de création :19/12/2010 Vu :2 520

Auteur : Fousse2

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Remake de : http://www.cppfrance.com/code.aspx?ID=22245

Cans le cadre d'un cours de correction de programme, j'ai choisi cette petite application en DOS et j'ai simplement...simplifié le code.

Source

  • /******************************************
  • * Programmed by Squallgamer
  • * Modified by Neterim 10-11-2010
  • * ZELDA
  • *
  • ******************************************/
  • #include <iostream>
  • #include <math.h>
  • #include <windows.h>
  • #include <ctime>
  • #include <conio.h>
  • using namespace std;
  • char tabl[20][20]; //Tableau de jeu
  • int vie=1;
  • int heroX;
  • int heroY;
  • int heroStartPositionX;
  • int heroStartPositionY;
  • int levelEndX;
  • int levelEndY;
  • char* levelMessage;
  • bool attacked = false; //Dit si le personnage a attaqué dans sa dernière action
  • void clearLevel(); //Vide le tableau de jeu
  • int niveauCourant = 1;
  • bool levelStarted = false;
  • int niveau1();
  • int niveau2();
  • int niveau3();
  • int keyHandler(); //Fonction gérant les commandes
  • int attackHandler(int x, int y); //Fonction gérant l'attaque
  • void showWeapon(int direction); //Fonction affichant l'arme : 0 - droite | 1 - bas | 2 - gauche | 3 - haut
  • int heroCollider(); // Fonction gérant le collision du héros avec les ennemies et les objets
  • int moveHero(int direction); //Fonction s'occupant de gérer le mouvement du hero
  • void moveEnemies(); //Gère les ennemies
  • ////////////////////////////////////////////////////////////////////
  • int main() //Fonction principale
  • {
  • while(niveauCourant != -1)
  • {
  • // Gestion des niveaux
  • clearLevel();
  • switch(niveauCourant)
  • {
  • case 1: niveau1();
  • break;
  • case 2: niveau2();
  • break;
  • case 3: niveau3();
  • break;
  • default: niveauCourant = -1;
  • break;
  • }
  • if(niveauCourant == -1)
  • {
  • break;
  • }
  • //Fin de la gestion des niveaux
  • //Gestion du jeu
  • for(;;)
  • {
  • if(heroX == levelEndX && heroY == levelEndY)
  • {
  • niveauCourant++;
  • break;
  • }
  • if(levelStarted)
  • {
  • system("cls");
  • }
  • else
  • {
  • cout << levelMessage;
  • levelStarted = true;
  • }
  • for(int y=0;y<20;y++) //Création du tableau (La carte du jeu)
  • {
  • for(int x=0;x<20;x++)
  • {
  • if((tabl[x][y] == '|' || tabl[x][y] == '-') && !attacked)
  • tabl[x][y] = ' ';
  • cout << tabl[x][y];
  • }
  • cout << endl;
  • }
  • cout << "\n\nNombre de vies : " << vie << endl;
  • attacked = false;
  • switch (keyHandler())
  • {
  • case 0 : break;
  • case 1 : vie--;
  • return main();
  • break;
  • case -1: niveauCourant = 1;
  • vie = 1;
  • return main();
  • break;
  • }
  • }
  • //Fin de la gestion du jeu
  • }
  • return 0; //Quitte le programme
  • }
  • ////////////////////////////////////////////////////////////////////
  • void clearLevel()
  • {
  • system("cls");
  • for(int x = 0; x < 20; x++)
  • {
  • for(int y = 0; y < 20; y++)
  • {
  • tabl[x][y] = ' ';
  • }
  • }
  • }
  • int niveau1()
  • {
  • int static r=0;
  • if(r==0)
  • {
  • levelMessage = "Bienvenue dans le jeu ZELDA niveau1!!!\nLe but est de tuer le petit nuckers qui a envahi la foret magique et emprisoner ton amie.\nPour cela bouger le \02 pour cela utiliser les touches 2,6,4,8.\n";r++;
  • }
  • heroY = 2;
  • heroX = 1;
  • heroStartPositionX = 1;
  • heroStartPositionY = 2;
  • levelEndX = 19;
  • levelEndY = 18;
  • tabl[18][18]='\01'; // \01 est un nuckers
  • tabl[17][16]='\03'; // \03 est une vie
  • tabl[heroX][heroY]='\02'; // \02 est le héros
  • for(int y=0;y<20;y++) //Création du tableau (La carte du jeu)
  • {
  • for(int x=0;x<20;x++)
  • {
  • if(x==0)
  • tabl[x][y]='\06'; //Création du décor (Les arbres qui ne ressemble pas à des arbres)
  • if(y==0)
  • tabl[x][y]='\06';
  • if(x==19&&y!=18)
  • tabl[x][y]='\06';
  • if(y==19)
  • tabl[x][y]='\06';
  • if(y==13&&x!=7&&x!=8&&x!=17)
  • tabl[x][y]='\06';
  • if(y==17&&x!=5)
  • tabl[x][y]='\06';
  • if(x==15&&y!=5&&y!=18)
  • tabl[x][y]='\06';
  • }
  • }
  • return 0;
  • }
  • ///////////////////////////////////////////////////////////////////////////////////////
  • int niveau2() //Pour le niveau 2 c'est le même principe
  • {
  • int static r=0;
  • if(r==0)
  • {
  • levelMessage = "Bienvenue dans le jeu ZELDA niveau2!!!\nVous arrivez plus profond dans la foret il faut sauver votre compagnon\01 et detruire les derniers petits \02\n";r++;
  • }
  • heroY=2;
  • heroX=1;
  • heroStartPositionY = 2;
  • heroStartPositionX = 1;
  • levelEndX = 18;
  • levelEndY = 18;
  • tabl[18][18]='\02';
  • tabl[17][16]='\01';
  • tabl[14][16]='\01';
  • tabl[6][16]='\01';
  • tabl[heroX][heroY]='\02';
  • for(int y=0;y<20;y++)
  • {
  • for(int x=0;x<20;x++)
  • {
  • if(x==0)
  • tabl[x][y]='\06';
  • if(y==0)
  • tabl[x][y]='\06';
  • if(x==19)
  • tabl[x][y]='\06';
  • if(y==19)
  • tabl[x][y]='\06';
  • if(y==15&&x!=7)
  • tabl[x][y]='\06';
  • if(y==17&&x!=15)
  • tabl[x][y]='\06';
  • if(x==10&&y!=4&&y!=18&&y!=16&&y!=12&&y!=9)
  • tabl[x][y]='\06';
  • if(x==3&&y!=2)
  • tabl[x][y]='\06';
  • if(y==10&&x!=16)
  • tabl[x][y]='\06';
  • if(x==1&&y!=2&&y!=1&&y!=3)
  • tabl[x][y]='\06';
  • if(x==2&&y!=2&&y!=1&&y!=3)
  • tabl[x][y]='\06';
  • if(y==5&&x!=17)
  • tabl[x][y]='\06';
  • }
  • }
  • return 0;
  • }
  • int niveau3()
  • {
  • int static r=0;
  • if(r==0)
  • {
  • levelMessage = "Bienvenue dans le jeu ZELDA niveau3!!!\n";
  • }
  • heroY=18;
  • heroX=1;
  • heroStartPositionY = 18;
  • heroStartPositionX = 1;
  • levelEndX = 18;
  • levelEndY = 1;
  • tabl[18][1]='O';
  • tabl[1][1]='\01';
  • tabl[1][4]='\01';
  • tabl[1][8]='\01';
  • tabl[2][13]='\01';
  • tabl[1][16]='\01';
  • tabl[2][9]='\01';
  • tabl[3][18]='\01';
  • tabl[3][1]='\01';
  • tabl[14][16]='\01';
  • tabl[6][16]='\01';
  • tabl[heroX][heroY]='\02';
  • for(int y=0;y<20;y++)
  • {
  • for(int x=0;x<20;x++)
  • {
  • if(x==0)
  • tabl[x][y]='\06';
  • if(y==0)
  • tabl[x][y]='\06';
  • if(x==19)
  • tabl[x][y]='\06';
  • if(y==19)
  • tabl[x][y]='\06';
  • if(y==4&&x!=0&&x!=1)
  • tabl[x][y]='\06';
  • if(y==12&&x!=18&&x!=17)
  • tabl[x][y]='\06';
  • }
  • }
  • return 0;
  • }
  • void moveEnemies()
  • {
  • for(int x = 0; x < 20; x++)
  • {
  • for(int y = 0; y < 20; y++)
  • {
  • if(tabl[x][y] == '\01')
  • {
  • int direction = (double)rand() / RAND_MAX *4;
  • switch(direction)
  • {
  • case 0: if(y+1 < 20 && tabl[x][y+1] != '\06' && tabl[x][y+1] != '\01' && tabl[x][y+1] != 'm')
  • {
  • tabl[x][y] = ' ';
  • tabl[x][y+1] = 'm';
  • }
  • break;
  • case 1: if(x+1 < 20 && tabl[x+1][y] != '\06' && tabl[x+1][y] != '\01' && tabl[x+1][y] != 'm')
  • {
  • tabl[x][y] = ' ';
  • tabl[x+1][y] = 'm';
  • }
  • break;
  • case 2: if(y-1 >= 0 && tabl[x][y-1] != '\06' && tabl[x][y-1] != '\01' && tabl[x][y-1] != 'm')
  • {
  • tabl[x][y] = ' ';
  • tabl[x][y-1] = 'm';
  • }
  • break;
  • case 3: if(x-1 >= 0 && tabl[x-1][y] != '\06' && tabl[x-1][y] != '\01' && tabl[x-1][y] != 'm')
  • {
  • tabl[x][y] = ' ';
  • tabl[x-1][y] = 'm';
  • }
  • break;
  • }
  • }
  • }
  • }
  • for(int x = 0; x < 20; x++)
  • {
  • for(int y = 0; y < 20; y++)
  • {
  • if(tabl[x][y] == 'm')
  • {
  • tabl[x][y] = '\01';
  • }
  • }
  • }
  • }
  • int attackHandler(int x, int y)
  • {
  • if(tabl[x][y] == '\01')
  • {
  • tabl[x][y] == NULL;
  • return 1;
  • }
  • return 0;
  • }
  • void showWeapon(int direction)
  • {
  • switch (direction)
  • {
  • case 0: if(tabl[heroX+1][heroY] != '\06')
  • tabl[heroX+1][heroY]='-';
  • if(tabl[heroX+1][heroY]=='-' && tabl[heroX+2][heroY] != '\06')
  • {
  • tabl[heroX+2][heroY]='-';
  • }
  • break;
  • case 1: if(tabl[heroX][heroY+1] != '\06')
  • tabl[heroX][heroY+1]='|';
  • if(tabl[heroX][heroY+1]=='|' && tabl[heroX][heroY+2] != '\06')
  • {
  • tabl[heroX][heroY+2]='|';
  • }
  • break;
  • case 2: if(tabl[heroX-1][heroY] != '\06')
  • tabl[heroX-1][heroY]='-';
  • if(tabl[heroX-1][heroY]=='-' && tabl[heroX-2][heroY] != '\06')
  • {
  • tabl[heroX-2][heroY]='-';
  • }
  • break;
  • case 3: if(tabl[heroX][heroY-1] != '\06')
  • tabl[heroX][heroY-1]='|';
  • if(tabl[heroX][heroY-1]=='|' && tabl[heroX][heroY-2] != '\06')
  • {
  • tabl[heroX][heroY-2]='|';
  • }
  • break;
  • }
  • attacked = true;
  • }
  • int heroCollider()
  • {
  • if(tabl[heroX][heroY] == '\01')
  • {
  • return 1;
  • }
  • else
  • {
  • if(tabl[heroX][heroY] == '\03')
  • {
  • return 2;
  • }
  • }
  • return 0;
  • }
  • int moveHero(int direction)
  • {
  • bool moved = false;
  • switch (direction)
  • {
  • case 0: if(tabl[heroX+1][heroY] != '\06')
  • {
  • tabl[heroX][heroY]=NULL;
  • heroX++;
  • moved = true;
  • }
  • break;
  • case 1: if(tabl[heroX][heroY+1] != '\06')
  • {
  • tabl[heroX][heroY]=NULL;
  • heroY++;
  • moved = true;
  • }
  • break;
  • case 2: if(tabl[heroX-1][heroY] != '\06')
  • {
  • tabl[heroX][heroY]=NULL;
  • heroX--;
  • moved = true;
  • }
  • break;
  • case 3: if(tabl[heroX][heroY-1] != '\06')
  • {
  • tabl[heroX][heroY]=NULL;
  • heroY--;
  • moved = true;
  • }
  • break;
  • }
  • return moved;
  • }
  • int keyHandler()
  • {
  • unsigned int g = getch(); //Getch() permet de taper sur une touche sans devoir appuyé sur Entrée
  • if(g==54) //Si on appuie sur 6 le héros sort son épée à droite
  • {
  • for(int t=0;t<1;t++)
  • {
  • showWeapon(0);
  • if(attackHandler(1+heroX, heroY) == 1 || attackHandler(2+heroX, heroY) == 1)
  • {
  • cout<<"Bien jouez!!!\n";Sleep(1000);
  • }
  • }
  • }
  • if(g==56) //Si on appuie sur 8 le héros sort son épée en haut
  • {
  • for(int t=0;t<1;t++)
  • {
  • showWeapon(3);
  • if(attackHandler(heroX, heroY-1) == 1 || attackHandler(heroX, heroY-2) == 1)
  • {
  • cout<<"Bien jouez!!!\n";Sleep(1000);
  • }
  • }
  • }
  • if(g==53) //Si on appuie sur 5 le héros sort son épée en bas
  • {
  • for(int t=0;t<1;t++)
  • {
  • showWeapon(1);
  • if(attackHandler(heroX, heroY+1) == 1 || attackHandler(heroX, heroY+2) == 1)
  • {
  • cout<<"Bien jouez!!!\n";Sleep(1000);
  • }
  • }
  • }
  • if(g==52) //Si on appuie sur 4 le héros sort son épée à gauche
  • {
  • for(int t=0;t<1;t++)
  • {
  • showWeapon(2);
  • if(attackHandler(heroX-1, heroY) == 1 || attackHandler(heroX-1, heroY) == 1)
  • {
  • cout<<"Bien jouez!!!\n";Sleep(1000);
  • }
  • }
  • }
  • moveEnemies();
  • //Si on appuie sur d le héros va à droite
  • if(g==100)
  • {
  • moveHero(0);
  • }
  • //Si on appuie sur w le héros va en haut
  • if(g==119)
  • {
  • moveHero(3);
  • }
  • //Si on appuie sur a le héros va à gauche
  • if(g==97)
  • {
  • moveHero(2);
  • }
  • //Si on appuie sur s le héros va en bas
  • if(g==115)
  • {
  • moveHero(1);
  • }
  • if(heroCollider() == 1)
  • {
  • vie--;
  • cout<<"tu a ete toucher il te reste "<<vie<<"\n";
  • if(vie<1){return -1;}
  • if(vie>=1)
  • {
  • tabl[heroX][heroY]=NULL;
  • heroY=heroStartPositionY;
  • heroX=heroStartPositionX;
  • return 1;
  • }
  • }
  • else
  • {
  • if(heroCollider() == 2)
  • {
  • cout << "Vous avez obtenu une vie!" << endl;
  • vie++;
  • tabl[heroX][heroY]='\02';
  • }
  • else
  • tabl[heroX][heroY]='\02';
  • }
  • return 0;
  • }
        /******************************************                                                                 
         *          Programmed by Squallgamer
         *	    Modified by Neterim 10-11-2010
         *          ZELDA                                      
         *                                                                      
         ******************************************/


#include <iostream>
#include <math.h>
#include <windows.h>
#include <ctime>
#include <conio.h>
using namespace std;

char tabl[20][20]; //Tableau de jeu

int vie=1;
int heroX;
int heroY;
int heroStartPositionX;
int heroStartPositionY;
int levelEndX;
int levelEndY;

char* levelMessage;

bool attacked = false; //Dit si le personnage a attaqué dans sa dernière action

void clearLevel(); //Vide le tableau de jeu
int niveauCourant = 1;
bool levelStarted = false;
int niveau1();
int niveau2();
int niveau3();

int keyHandler(); //Fonction gérant les commandes
int attackHandler(int x, int y); //Fonction gérant l'attaque
void showWeapon(int direction); //Fonction affichant l'arme : 0 - droite | 1 - bas | 2 - gauche | 3 - haut
int heroCollider(); // Fonction gérant le collision du héros avec les ennemies et les objets
int moveHero(int direction); //Fonction s'occupant de gérer le mouvement du hero 
void moveEnemies(); //Gère les ennemies

////////////////////////////////////////////////////////////////////
int main() //Fonction principale
{
    
    while(niveauCourant != -1)
	{
		// Gestion des niveaux
		clearLevel();

		switch(niveauCourant)
		{
			case 1:	niveau1();
					break;

			case 2:	niveau2();
					break;

			case 3:	niveau3();
					break;

			default: niveauCourant = -1;
					break;

		}		

		if(niveauCourant == -1)
		{
			break;
		}

		//Fin de la gestion des niveaux

		//Gestion du jeu
		for(;;)
		{		

			if(heroX == levelEndX && heroY == levelEndY)
			{
				niveauCourant++;
				break;
			}

			if(levelStarted)
			{
				system("cls");
			}
			else
			{
				cout << levelMessage;
				levelStarted = true;
			}

			for(int y=0;y<20;y++)   //Création du tableau (La carte du jeu)
			{
				for(int x=0;x<20;x++)
				{
					if((tabl[x][y] == '|' || tabl[x][y] == '-') && !attacked)
						tabl[x][y] = ' ';

					cout << tabl[x][y];
				}   

				cout << endl;			
			}

			cout << "\n\nNombre de vies : " << vie << endl;	
			attacked = false;

			switch (keyHandler())
			{
				case 0 : break;
				case 1 : vie--;
						 return main();
						 break;
				case -1: niveauCourant = 1;
						 vie = 1;
						 return main();
						 break;
			}
		}
		//Fin de la gestion du jeu
	}

    return 0;   //Quitte le programme
    
}
////////////////////////////////////////////////////////////////////

void clearLevel()
{
	system("cls");
	for(int x = 0; x < 20; x++)
	{
		for(int y = 0; y < 20; y++)
		{
			tabl[x][y] = ' ';
		}
	}
}

int niveau1()
{
	int static r=0;

	if(r==0) 
	{
		levelMessage = "Bienvenue dans le jeu ZELDA niveau1!!!\nLe but est de tuer le petit nuckers qui a envahi la foret magique et emprisoner ton amie.\nPour cela bouger le \02 pour cela utiliser les touches 2,6,4,8.\n";r++;
	}

	heroY = 2;
	heroX = 1;

	heroStartPositionX = 1;
	heroStartPositionY = 2;

	levelEndX = 19;
	levelEndY = 18;

	tabl[18][18]='\01'; // \01 est un nuckers 
	tabl[17][16]='\03'; // \03 est une vie

	tabl[heroX][heroY]='\02'; // \02 est le héros   

	for(int y=0;y<20;y++)   //Création du tableau (La carte du jeu)
	{
		for(int x=0;x<20;x++)
		{

			if(x==0)
				tabl[x][y]='\06'; //Création du décor (Les arbres qui ne ressemble pas à des arbres)

			if(y==0)
				tabl[x][y]='\06';

			if(x==19&&y!=18)
				tabl[x][y]='\06';

			if(y==19)
				tabl[x][y]='\06';

			if(y==13&&x!=7&&x!=8&&x!=17)
				tabl[x][y]='\06';

			if(y==17&&x!=5)
				tabl[x][y]='\06';

			if(x==15&&y!=5&&y!=18)
				tabl[x][y]='\06';

		}   			
	}
	return 0;
}

///////////////////////////////////////////////////////////////////////////////////////
int niveau2() //Pour le niveau 2 c'est le même principe
{
	int static r=0;

	if(r==0)
	{
		levelMessage = "Bienvenue dans le jeu ZELDA niveau2!!!\nVous arrivez plus profond dans la foret il faut sauver votre compagnon\01 et detruire les derniers petits \02\n";r++;
	}
	    
	heroY=2;
	heroX=1;

	heroStartPositionY = 2;
	heroStartPositionX = 1;

	levelEndX = 18;
	levelEndY = 18;

	tabl[18][18]='\02';
	tabl[17][16]='\01';
	tabl[14][16]='\01';
	tabl[6][16]='\01';

	tabl[heroX][heroY]='\02';  

	for(int y=0;y<20;y++)
	{
		for(int x=0;x<20;x++)
		{
			if(x==0)
				tabl[x][y]='\06';

			if(y==0)
				tabl[x][y]='\06';

			if(x==19)
				tabl[x][y]='\06';

			if(y==19)
				tabl[x][y]='\06';

			if(y==15&&x!=7)
				tabl[x][y]='\06';

			if(y==17&&x!=15)
				tabl[x][y]='\06';

			if(x==10&&y!=4&&y!=18&&y!=16&&y!=12&&y!=9)
				tabl[x][y]='\06';

			if(x==3&&y!=2)
				tabl[x][y]='\06';

			if(y==10&&x!=16)
				tabl[x][y]='\06';

			if(x==1&&y!=2&&y!=1&&y!=3)
				tabl[x][y]='\06';

			if(x==2&&y!=2&&y!=1&&y!=3)
				tabl[x][y]='\06';

			if(y==5&&x!=17)
				tabl[x][y]='\06';
		} 
	}

	return 0;
}

int niveau3() 
{
	int static r=0;

	if(r==0)
	{
		levelMessage = "Bienvenue dans le jeu ZELDA niveau3!!!\n";
	}
	    
	heroY=18;
	heroX=1;

	heroStartPositionY = 18;
	heroStartPositionX = 1;

	levelEndX = 18;
	levelEndY = 1;

	tabl[18][1]='O';

	tabl[1][1]='\01';
	tabl[1][4]='\01';
	tabl[1][8]='\01';
	tabl[2][13]='\01';
	tabl[1][16]='\01';
	tabl[2][9]='\01';
	tabl[3][18]='\01';
	tabl[3][1]='\01';
	tabl[14][16]='\01';
	tabl[6][16]='\01';

	tabl[heroX][heroY]='\02';  

	for(int y=0;y<20;y++)
	{
		for(int x=0;x<20;x++)
		{
			if(x==0)
				tabl[x][y]='\06';

			if(y==0)
				tabl[x][y]='\06';

			if(x==19)
				tabl[x][y]='\06';

			if(y==19)
				tabl[x][y]='\06';

			if(y==4&&x!=0&&x!=1)
				tabl[x][y]='\06';

			if(y==12&&x!=18&&x!=17)
				tabl[x][y]='\06';
		} 
	}

	return 0;
}

void moveEnemies()
{
	for(int x = 0; x < 20; x++)
	{
		for(int y = 0; y < 20; y++)
		{
			if(tabl[x][y] == '\01')
			{
				int direction = (double)rand() / RAND_MAX *4;

				switch(direction)
				{
					case 0:	if(y+1 < 20 && tabl[x][y+1] != '\06' && tabl[x][y+1] != '\01' && tabl[x][y+1] != 'm')
							{
								tabl[x][y] = ' ';
								tabl[x][y+1] = 'm';
							}
							break;

					case 1:	if(x+1 < 20 && tabl[x+1][y] != '\06' && tabl[x+1][y] != '\01' && tabl[x+1][y] != 'm')
							{
								tabl[x][y] = ' ';
								tabl[x+1][y] = 'm';
							}
							break;

					case 2:	if(y-1 >= 0 && tabl[x][y-1] != '\06' && tabl[x][y-1] != '\01' && tabl[x][y-1] != 'm')
							{
								tabl[x][y] = ' ';
								tabl[x][y-1] = 'm';
							}
							break;

					case 3:	if(x-1 >= 0 && tabl[x-1][y] != '\06' && tabl[x-1][y] != '\01' && tabl[x-1][y] != 'm')
							{
								tabl[x][y] = ' ';
								tabl[x-1][y] = 'm';
							}
							break;
				}
			}
		}
	}

	for(int x = 0; x < 20; x++)
	{
		for(int y = 0; y < 20; y++)
		{
			if(tabl[x][y] == 'm')
			{
				tabl[x][y] = '\01';
			}
		}
	}
}

int attackHandler(int x, int y)
{
	if(tabl[x][y] == '\01')
	{
		tabl[x][y] == NULL;
		return 1;
	}

	return 0;
}

void showWeapon(int direction)
{
	switch (direction)
	{
		case 0: if(tabl[heroX+1][heroY] != '\06')
					tabl[heroX+1][heroY]='-';

				if(tabl[heroX+1][heroY]=='-' && tabl[heroX+2][heroY] != '\06')
				{
					tabl[heroX+2][heroY]='-';
				}

				break;

		case 1: if(tabl[heroX][heroY+1] != '\06')
					tabl[heroX][heroY+1]='|';

				if(tabl[heroX][heroY+1]=='|' && tabl[heroX][heroY+2] != '\06')
				{
					tabl[heroX][heroY+2]='|';
				}

				break;

		case 2: if(tabl[heroX-1][heroY] != '\06')
					tabl[heroX-1][heroY]='-';

				if(tabl[heroX-1][heroY]=='-' && tabl[heroX-2][heroY] != '\06')
				{
					tabl[heroX-2][heroY]='-';
				}

				break;

		case 3: if(tabl[heroX][heroY-1] != '\06')
					tabl[heroX][heroY-1]='|';

				if(tabl[heroX][heroY-1]=='|' && tabl[heroX][heroY-2] != '\06')
				{
					tabl[heroX][heroY-2]='|';
				}

				break;
	}

	attacked = true;
}

int heroCollider()
{
	if(tabl[heroX][heroY] == '\01')
	{
		return 1;
	}
	else
	{
		if(tabl[heroX][heroY] == '\03')
		{
			return 2;
		}
	}
		
	return 0;
}

int moveHero(int direction)
{
	bool moved = false;

	switch (direction)
	{
		case 0:	if(tabl[heroX+1][heroY] != '\06')
				{
					tabl[heroX][heroY]=NULL;
					heroX++;
					moved = true;
				}

				break;

		case 1:	if(tabl[heroX][heroY+1] != '\06')
				{
					tabl[heroX][heroY]=NULL;
					heroY++;
					moved = true;
				}

				break;

		case 2:	if(tabl[heroX-1][heroY] != '\06')
				{
					tabl[heroX][heroY]=NULL;
					heroX--;
					moved = true;
				}

				break;

		case 3:	if(tabl[heroX][heroY-1] != '\06')
				{
					tabl[heroX][heroY]=NULL;
					heroY--;
					moved = true;
				}

				break;
	}

	return moved;
}

int keyHandler()
{
	unsigned int g = getch(); //Getch() permet de taper sur une touche sans devoir appuyé sur Entrée

	if(g==54) //Si on appuie sur 6 le héros sort son épée à droite 
	{
		for(int t=0;t<1;t++)
		{
			showWeapon(0);

			if(attackHandler(1+heroX, heroY) == 1 || attackHandler(2+heroX, heroY) == 1)
			{
				cout<<"Bien jouez!!!\n";Sleep(1000);
			}
		}
	}

	if(g==56) //Si on appuie sur 8 le héros sort son épée en haut 
	{
		for(int t=0;t<1;t++)
		{
			showWeapon(3);

			if(attackHandler(heroX, heroY-1) == 1 || attackHandler(heroX, heroY-2) == 1)
			{
				cout<<"Bien jouez!!!\n";Sleep(1000);
			}
		}
	}

	if(g==53) //Si on appuie sur 5 le héros sort son épée en bas 
	{
		for(int t=0;t<1;t++)
		{
			 showWeapon(1);

			if(attackHandler(heroX, heroY+1) == 1 || attackHandler(heroX, heroY+2) == 1)
			{
				cout<<"Bien jouez!!!\n";Sleep(1000);
			}
		}
	}

	if(g==52) //Si on appuie sur 4 le héros sort son épée à gauche 
	{
		for(int t=0;t<1;t++)
		{
			 showWeapon(2);

			if(attackHandler(heroX-1, heroY) == 1 || attackHandler(heroX-1, heroY) == 1)
			{
				cout<<"Bien jouez!!!\n";Sleep(1000);
			}
		}
	}

	moveEnemies();

	//Si on appuie sur d le héros va à droite
	if(g==100)
	{
		moveHero(0);
	} 
		
	//Si on appuie sur w le héros va en haut 
	if(g==119)
	{
		moveHero(3);
	}

	//Si on appuie sur a le héros va à gauche 
	if(g==97)
	{
		moveHero(2);
	}

	//Si on appuie sur s le héros va en bas
	if(g==115)
	{
		moveHero(1);
	}   

	if(heroCollider() == 1)
	{
		vie--;
		cout<<"tu a ete toucher il te reste "<<vie<<"\n";

		if(vie<1){return -1;}

		if(vie>=1)
		{
			tabl[heroX][heroY]=NULL;
			heroY=heroStartPositionY;
			heroX=heroStartPositionX;
			return 1;
		}
	}
	else
	{
		if(heroCollider() == 2)
		{
			cout << "Vous avez obtenu une vie!" << endl;
			vie++;
			tabl[heroX][heroY]='\02';
		}
		else
			tabl[heroX][heroY]='\02';
	}

	return 0;
}

 Conclusion

Je ne demande pas vraiment de feedback, c'était dans l'énoncé du travail de le reposter.


 Sources de la même categorie

Source avec Zip Source avec une capture JEU DES CARTES par eapaceinfo
PROGRAMME DE JEU DE MPT par KerizGarmm
Source avec Zip Source avec une capture JEUX SERPENT par antho974
Source avec Zip Source avec une capture PENDU EN SDL par Damsou91
Source avec Zip STATE MACHINE MODIFICATION MATH BUCKHAM par billybones79

 Sources en rapport avec celle ci

Source avec Zip Source .NET (Dotnet) JEU DE ZELDA EN DIRECTX MODIFIÉ par kidling
Source avec Zip Source avec une capture ZELDA (PETIT JEU MODE CONSOLE EN C++) par Squallgamer
Source avec Zip Source avec une capture TETRIS EN MODE TEXTE (FENETRE DOS SOUS VISUAL C++) par Mindce
Source avec Zip Source avec une capture JEU DE ZELDA EN DIRECTX par BumpMANN
Source avec Zip PUR JEU DE ROLE par chocobo

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Dev d'un jeu à la Age of Empires [ par jaylin ] Si vous êtes intéressez par le développement d'un jeu à la Age of Empires mais en plus réaliste contactez moi sur ICQ: 108283779 ou mailez moi: jaylin Empire Warriors [ par jaylin ] Je pourrais savoir pourquoi la partie du forum consacré au jeu a été supprimé??Le site du jeu www.empire-warriors.fr.st URGENT!!! appli dos lancer par interface visual c++ avec param [ par olivier ] Comment puis je lancer une appli dos qui prend une ou trois chaines de caracteres comme parametre grace a une interface graphique en visual c++.Merci BMP sous DOS [ par GoldenEye ] Comment afficher un fichier.bmp sous DOS avec Visual C++ ?Merci de votre aide.GoldenEye Caractères ASCII sous Dos [ par Lorenzo ] Salut,Je n'arrive pas sous Dos à afficher des accents (é,è,à etc...) avec la fonction printf, celle-ci remplace ces caractères par d'autres.D'où cela Comment faire un prog qui s'ouvre dans une fenetre Windows et pas Dos [ par fucker ] Vous connaisez mon probleme.Merci de m'aider. Création d'un jeu de stratégie en CPP et DIRECTX ! [ par DunËsPIdËr ] SalUt à tOuS! Nous sommes actuellement 4 programmeurs et 1 infographiste. Nous voulons créer un jeu de stratégie en temps réel sous Win utilisant di un ptit jeu [ par BLaFarD ] euh, je viens de me pondre un petit moteur 3d de merde en opengldonc, si qlqun veut me filer des model 3d k'il a fait (sous 3dsmax si possible), bah, DIRECTX et interface [ par ELKI ] je suis en train de concevoir un jeu d'echec et j'aurai voulu savoir comment je pouurai faire pour associer des pièce d'un jeu d'echec avec mon interf effacer l'ecran de la console dos en C [ par gollum ] Comment effecer l'ecran de la console DOS en C ?


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,452 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales