le même principe que morpion que j'ai déjà posé couleur/curseur la méme interface mais pas de menu pas de truc inutile code facile a comprendre bon c pas grand chose en gros
Source / Exemple :
/****************main.c**************************************/
#include "CTE.h"
/*Realiser par KHALID MAJDOUB*/
int main()
{
char choix=0;
while(1) {
jeu();
system("cls");
}
}
int jeu()
{
char map[15][17]={NULL},objet[2]={3,4},event=0;
int x=2,y=12,i=0,donne=1;
parcourirMap(map,1);
while(donne)
{
color(4,15);printf("JOUEUR %ld\n\n\n\n\n\n",i%2 +1);
AFFICHAGE;
event=getch();
system("cls");
switch(event)
{
case HAUT : BOUGE-UP ; break;
case BAS : BOUGE-DOWN ; break;
case GAUCHE : BOUGE-LEFT ; break;
case DROIT : BOUGE-RIGHT; break;
case OK : DRAW break;
}
if(gagner(map)) {
AFFICHAGE;donne=0;
printf("\n LE JOUEUR %ld A GAGNE\n\n\n",((i%2)+1)*-1 + 3); system("pause");}
}
system("cls");
return 0;
}
void parcourirMap(char map[][17],int s)
{
FILE* file=fopen("map.txt","r");
int L=0,l=0;
while(L!=15)
{
color(7,0);if(s==2)printf("\t\t\t");
while(l!=17)
{
if(s==1)map[L][l]=fgetc(file)-48;
else if(s==2){
switch(map[L][l]){
case 0: color(BLANC,BLANC); printf(" "); break;
case 1: color(BLEUG,BLEUG); printf(" "); break;
case 2: color(GRIS,GRIS); printf(" "); break;
case 3: color(VERT,BLANC); printf("X"); break;
case 4: color(RED,BLANC); printf("O"); break;
case 5: color(VERT,GRIS); printf("X"); break;
case 6: color(RED,GRIS); printf("O"); break;
}}l++;
}
if(s==2) printf("\n");
l=0;L++;
}
}
void color(int T,int F)
{
HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(H,F*16+T);
}
void bouger(char map[][17],int *x,int *y,int X,int Y)
{
if(map[*y+Y][*x+X]!=1) {
map[*y][*x]-=2; *y+=Y; *x+=X; map[*y][*x]+=2;
}
}
int gagner(char map[][17])
{
int sxh=0,sxv=0,soh=0,sov=0,L=2,l=2,E=0;
while(L!=14)
{
while(l!=16 )
{
if(map[L][l]==3||map[L][l]==5){sxh+=1; soh=0;}
if(map[l][L]==3||map[l][L]==5){sxv+=1; sov=0;}
if(map[L][l]==4||map[L][l]==6){soh+=1; sxh=0;}
if(map[l][L]==4||map[l][L]==6){sov+=1; sxv=0;}
l+=2;
if(sxv==4||sxh==4||soh==4||sov==4) E=1;
}
sxv=0;sxh=0;soh=0;sov=0;
l=2;L+=2;
}
return E;
}
/*******************************CTE.H***********************************/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define BLANC 15
#define BLACK 0
#define BLEUG 3
#define RED 4
#define VERT 2
#define GRIS 8
#define UP 0,-2)
#define DOWN 0,2)
#define LEFT 2,0)
#define RIGHT -2,0)
#define BOUGE bouger(map,&x,&y,
#define DRAW if(map[y][x]==2 && map[y+2][x]!=0){map[y][x]+=objet[i%2];i++;}
#define AFFICHAGE parcourirMap(map,2);color(7,0)
#define HAUT 72
#define BAS 80
#define GAUCHE 75
#define DROIT 77
#define OK 13
void parcourirMap(char map[][17],int s);
void color(int ,int );
void bouger(char map[][17],int *x,int *y,int X,int Y);
int gagner(char map[][17]);
- fin*******************************
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.