Accueil > > > JEU D'AVENTURE EN DOS
JEU D'AVENTURE EN DOS
Information sur la source
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
Commentaires et avis
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 ?
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|