begin process at 2010 02 09 23:59:47
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > JEU DU TAQUIN

JEU DU TAQUIN


 Information sur la source

Note :
Aucune note
Catégorie :Jeux Classé sous :taquin Niveau :Débutant Date de création :24/01/2006 Date de mise à jour :16/06/2008 19:03:34 Vu / téléchargé :6 816 / 991

Auteur : pasty

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

 Description

Ce code est une version windows du jeu du taquin. J'ai utilisé DEV c++.
Le jeu est constitué de 15 pièces. On ne peut bouger une piéce que si dans sa colonne ou sa rangée se trouve la case libre. Le bouton mélange, permute les piéces aléatoirement. Le but du jeu est de replacer les piéces de 1 à 15 dans l'ordre.

Source

  • //jeu du taquin
  • //auteur: Philippe Pasty
  • //date: 26 janvier 2006
  • #include <windows.h>
  • #include <stdio.h>
  • #include <stdlib.h>
  • #include <time.h>
  • #include <math.h>
  • int nHeight,nWidth;
  • HWND GlobalHwnd;
  • int random(int n)
  • {return rand()%n;}
  • void randomize() {
  • srand(time(0));
  • }
  • LONG APIENTRY WndProc( HWND, UINT , WPARAM, LONG);
  • const int xpiece=4,ypiece=4;
  • char piece[16];
  • int TaillePiece=50;
  • int TailleBouton=24;
  • int TailleFenetreX()
  • {return xpiece*TaillePiece+GetSystemMetrics(SM_CXBORDER)*2;}
  • int TailleFenetreY()
  • {return GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CXBORDER)*2+TailleBouton+ypiece*TaillePiece;}
  • #pragma argsused
  • int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  • LPSTR lpszCmd, int nCmdShow)
  • {
  • static char szAppName[] = "Taquin" ;
  • HWND hwnd ;
  • MSG msg ;
  • WNDCLASS wndclass ;
  • wndclass.lpfnWndProc = (WNDPROC)WndProc ;
  • wndclass.lpszClassName = szAppName ;
  • wndclass.hInstance = hInstance ;
  • wndclass.lpszMenuName = NULL ;
  • wndclass.style = CS_HREDRAW | CS_VREDRAW ;
  • wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  • wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
  • wndclass.hbrBackground =(HBRUSH)GetStockObject(LTGRAY_BRUSH);
  • wndclass.cbClsExtra = 0 ;
  • wndclass.cbWndExtra = 0 ;
  • RegisterClass (&wndclass) ;
  • hwnd = CreateWindow (szAppName,
  • szAppName,
  • WS_OVERLAPPEDWINDOW&(~WS_THICKFRAME)&(~WS_MAXIMIZEBOX),
  • CW_USEDEFAULT, //coord x de la fenetre
  • CW_USEDEFAULT, //coord y de la fenetre
  • TailleFenetreX(),
  • TailleFenetreY(),
  • NULL,
  • NULL,
  • hInstance,
  • NULL) ;
  • ShowWindow (hwnd, nCmdShow) ;
  • UpdateWindow (hwnd) ;
  • while (GetMessage (&msg, NULL, 0, 0))
  • {
  • {
  • TranslateMessage (&msg) ;
  • DispatchMessage (&msg) ;
  • }
  • }
  • return msg.wParam ;
  • }
  • LONG APIENTRY WndProc(HWND hwnd, UINT message , WPARAM wparam,LONG lparam)
  • {
  • char chiffre[4],strGagne[80];
  • int x,y,n,index1,index2,temp,x0,y0,yy;
  • static HINSTANCE hInstance;
  • static HPEN hPen1,hPen2;
  • static char Melange=0;
  • static int Temps0;
  • RECT rectPiece;
  • HDC hdc;
  • PAINTSTRUCT ps;
  • switch (message)
  • {case WM_CREATE:
  • GlobalHwnd = hwnd;
  • randomize();
  • for(x=0;x<xpiece*ypiece;x++)piece[x]=x;
  • hInstance=((LPCREATESTRUCT)lparam)->hInstance;
  • CreateWindow("button","Mélange",WS_CHILD|WS_VISIBLE,0,0,100,TailleBouton,hwnd,(HMENU)1,hInstance,0);
  • hPen1= CreatePen(PS_SOLID,2,RGB(255,255,255));
  • hPen2= CreatePen(PS_SOLID,2,RGB(0,0,0));
  • return 0;
  • case WM_COMMAND:
  • switch(LOWORD(wparam))
  • {
  • //mélange des piéces
  • case 1:
  • Melange=1;
  • Temps0=GetTickCount();
  • for(x=0;x<xpiece*ypiece;x++)piece[x]=x;
  • for(n=0;n<20;n++)
  • {
  • index1=random(xpiece*ypiece-2)+2;
  • index2=random(index1-1)+1;
  • temp=piece[index1];
  • piece[index1]=piece[index2];
  • piece[index2]=temp;
  • }
  • InvalidateRect(hwnd,0,TRUE);
  • break;
  • }
  • return 0;
  • case WM_PAINT:
  • hdc = BeginPaint(hwnd,&ps);
  • SetWindowExtEx(hdc,TailleFenetreX(),TailleFenetreY(),NULL);
  • SetBkColor(hdc,RGB(192,192,192));
  • for(x=0;x<xpiece;x++)
  • {for(y=0;y<ypiece;y++)
  • {
  • n=piece[x+y*xpiece];
  • if(n)
  • { wsprintf(chiffre,"%d",n);
  • rectPiece.left=x*TaillePiece;rectPiece.right=(x+1)*TaillePiece;
  • rectPiece.top=y*TaillePiece+TailleBouton;
  • rectPiece.bottom=(y+1)*TaillePiece+TailleBouton;
  • DrawText(hdc,chiffre,-1,&rectPiece,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
  • //dessin bordure
  • SelectObject(hdc,hPen1);
  • MoveToEx(hdc,x*TaillePiece,(y+1)*TaillePiece+TailleBouton-2,0);
  • LineTo(hdc,x*TaillePiece,y*TaillePiece+TailleBouton+1);
  • LineTo(hdc,(x+1)*TaillePiece-1,TailleBouton+TaillePiece*y+1);
  • SelectObject(hdc,hPen2);
  • LineTo(hdc,(x+1)*TaillePiece-1,(y+1)*TaillePiece-2+TailleBouton);
  • LineTo(hdc,x*TaillePiece,(y+1)*TaillePiece+TailleBouton-2);
  • }
  • }
  • }
  • if(Melange)
  • {
  • for(x=xpiece*ypiece-1;(piece[x]==x)&&x;x--);
  • if(!x)
  • {wsprintf(strGagne,"Gagné en %d secondes",(GetTickCount()-Temps0)/1000);
  • MessageBox(hwnd,strGagne,"",MB_OK);
  • Melange=0;
  • }
  • }
  • EndPaint(hwnd,&ps);
  • return 0;
  • case WM_LBUTTONUP:
  • x=LOWORD(lparam)/TaillePiece; y=(HIWORD(lparam)-TailleBouton)/TaillePiece;
  • if((x>=xpiece)||(y>=ypiece)) return 0;
  • yy=y*xpiece;
  • for(x0=0;x0<xpiece;x0++)
  • {if(!piece[x0+yy])
  • {
  • if(x<x0)
  • for(;x0>x;x0--)
  • piece[x0+yy]=piece[x0-1+yy];
  • else
  • for(;x0<x;x0++)
  • piece[x0+yy]=piece[x0+1+yy];
  • piece[x+yy]=0;
  • InvalidateRect(hwnd,0,TRUE);
  • return 0;
  • } //if
  • } //for
  • for(y0=0;y0<ypiece;y0++)
  • {
  • if(!piece[x+y0*xpiece])
  • {
  • if(y<y0)
  • for(;y0>y;y0--)
  • {n=x+y0*xpiece;
  • piece[n]=piece[n-xpiece];
  • }
  • else
  • for(;y0<y;y0++)
  • {n=x+y0*xpiece;
  • piece[n]=piece[n+xpiece];
  • }
  • piece[x+yy]=0;
  • InvalidateRect(hwnd,0,TRUE);
  • return 0;
  • }
  • }
  • return 0;
  • case WM_DESTROY:
  • PostQuitMessage(0); // this is the end...
  • DeleteObject(hPen1);
  • DeleteObject(hPen2);
  • return(0L);
  • case WM_CLOSE:
  • DestroyWindow(hwnd);
  • return(0L);
  • }
  • return(DefWindowProc(hwnd, message, wparam, lparam));
  • }
//jeu du taquin
//auteur: Philippe Pasty
//date: 26 janvier 2006
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

int nHeight,nWidth;
HWND GlobalHwnd;

int random(int n)
{return rand()%n;}

void randomize() {
 srand(time(0));
}

LONG APIENTRY WndProc( HWND, UINT , WPARAM, LONG);

const int xpiece=4,ypiece=4;
char piece[16];
int TaillePiece=50;
int TailleBouton=24;


int TailleFenetreX()
 {return xpiece*TaillePiece+GetSystemMetrics(SM_CXBORDER)*2;}
int TailleFenetreY()
 {return GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CXBORDER)*2+TailleBouton+ypiece*TaillePiece;}
#pragma argsused
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
			 LPSTR lpszCmd, int nCmdShow)
{
	static char szAppName[] = "Taquin" ;
	HWND        hwnd ;
	MSG         msg ;
	WNDCLASS    wndclass ;

        wndclass.lpfnWndProc   = (WNDPROC)WndProc ;
	wndclass.lpszClassName = szAppName ;
	wndclass.hInstance     = hInstance ;
	wndclass.lpszMenuName  = NULL ;
	wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
	wndclass.hIcon         = LoadIcon( NULL, IDI_APPLICATION );
	wndclass.hbrBackground =(HBRUSH)GetStockObject(LTGRAY_BRUSH);
	wndclass.cbClsExtra    = 0 ;
	wndclass.cbWndExtra    = 0 ;

	RegisterClass (&wndclass) ;


  hwnd = CreateWindow (szAppName,
	 szAppName,
         WS_OVERLAPPEDWINDOW&(~WS_THICKFRAME)&(~WS_MAXIMIZEBOX),
	 CW_USEDEFAULT, //coord x de la fenetre
	 CW_USEDEFAULT, //coord y de la fenetre
	 TailleFenetreX(),
	 TailleFenetreY(),
	 NULL,
	 NULL,
	 hInstance,
	 NULL) ;

	ShowWindow (hwnd, nCmdShow) ;
	UpdateWindow (hwnd) ;


	while (GetMessage (&msg, NULL, 0, 0))
	{
	 {
		 TranslateMessage (&msg) ;
		 DispatchMessage (&msg) ;
	 }
	}
	return msg.wParam ;
}

LONG APIENTRY WndProc(HWND hwnd, UINT message , WPARAM wparam,LONG lparam)
{
 char chiffre[4],strGagne[80];
 int x,y,n,index1,index2,temp,x0,y0,yy;
 static HINSTANCE hInstance;
 static HPEN hPen1,hPen2;
 static char Melange=0;
 static int Temps0;
 RECT rectPiece;
 HDC hdc;
 PAINTSTRUCT ps;

 switch (message)
  {case WM_CREATE:
    GlobalHwnd = hwnd;
    randomize();
    for(x=0;x<xpiece*ypiece;x++)piece[x]=x;
    hInstance=((LPCREATESTRUCT)lparam)->hInstance;
    CreateWindow("button","Mélange",WS_CHILD|WS_VISIBLE,0,0,100,TailleBouton,hwnd,(HMENU)1,hInstance,0);
    hPen1= CreatePen(PS_SOLID,2,RGB(255,255,255));
    hPen2= CreatePen(PS_SOLID,2,RGB(0,0,0));
 	 return 0;
   case WM_COMMAND:
    switch(LOWORD(wparam))
    {
     //mélange des piéces
     case 1:
      Melange=1;
      Temps0=GetTickCount();
      for(x=0;x<xpiece*ypiece;x++)piece[x]=x;
      for(n=0;n<20;n++)
      {
       index1=random(xpiece*ypiece-2)+2;
       index2=random(index1-1)+1;

       temp=piece[index1];
       piece[index1]=piece[index2];
       piece[index2]=temp;
      }
       InvalidateRect(hwnd,0,TRUE);
       break;
    }
    return 0;
	case WM_PAINT:
		hdc = BeginPaint(hwnd,&ps);
      SetWindowExtEx(hdc,TailleFenetreX(),TailleFenetreY(),NULL);
      SetBkColor(hdc,RGB(192,192,192));
      for(x=0;x<xpiece;x++)
       {for(y=0;y<ypiece;y++)
        {
         n=piece[x+y*xpiece];
         if(n)
         { wsprintf(chiffre,"%d",n);
           rectPiece.left=x*TaillePiece;rectPiece.right=(x+1)*TaillePiece;
           rectPiece.top=y*TaillePiece+TailleBouton;
           rectPiece.bottom=(y+1)*TaillePiece+TailleBouton;
           DrawText(hdc,chiffre,-1,&rectPiece,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
           //dessin bordure
           SelectObject(hdc,hPen1);
           MoveToEx(hdc,x*TaillePiece,(y+1)*TaillePiece+TailleBouton-2,0);
           LineTo(hdc,x*TaillePiece,y*TaillePiece+TailleBouton+1);
           LineTo(hdc,(x+1)*TaillePiece-1,TailleBouton+TaillePiece*y+1);
           SelectObject(hdc,hPen2);
           LineTo(hdc,(x+1)*TaillePiece-1,(y+1)*TaillePiece-2+TailleBouton);
           LineTo(hdc,x*TaillePiece,(y+1)*TaillePiece+TailleBouton-2);

         }
        }
       }
      if(Melange)
      {
       for(x=xpiece*ypiece-1;(piece[x]==x)&&x;x--);
       if(!x)
        {wsprintf(strGagne,"Gagné en %d secondes",(GetTickCount()-Temps0)/1000);
         MessageBox(hwnd,strGagne,"",MB_OK);
         Melange=0;
        }
      }
		EndPaint(hwnd,&ps);
   	return 0;
    case WM_LBUTTONUP:
      x=LOWORD(lparam)/TaillePiece; y=(HIWORD(lparam)-TailleBouton)/TaillePiece;
      if((x>=xpiece)||(y>=ypiece)) return 0;
      yy=y*xpiece;
      for(x0=0;x0<xpiece;x0++)
       {if(!piece[x0+yy])
        {
        if(x<x0)
          for(;x0>x;x0--)
           piece[x0+yy]=piece[x0-1+yy];
         else
          for(;x0<x;x0++)
           piece[x0+yy]=piece[x0+1+yy];
        piece[x+yy]=0;
        InvalidateRect(hwnd,0,TRUE);
        return 0;
        } //if
       }  //for
       for(y0=0;y0<ypiece;y0++)
       {
        if(!piece[x+y0*xpiece])
        {
         if(y<y0)
           for(;y0>y;y0--)
           {n=x+y0*xpiece;
            piece[n]=piece[n-xpiece];
           }
          else
           for(;y0<y;y0++)
           {n=x+y0*xpiece;
            piece[n]=piece[n+xpiece];
           }
         piece[x+yy]=0;
         InvalidateRect(hwnd,0,TRUE);
         return 0;
        }
       }
       return 0;
	 case WM_DESTROY:
		PostQuitMessage(0);   // this is the end...
      DeleteObject(hPen1);
      DeleteObject(hPen2);
		return(0L);
	 case WM_CLOSE:
	  DestroyWindow(hwnd);
	  return(0L);
	}
	return(DefWindowProc(hwnd, message, wparam, lparam));
}


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  • taquin.devTélécharger ce fichier [Réservé aux membres club]294 octets
  • taquin.ex_Télécharger ce fichier [Réservé aux membres club]8 192 octets
  • taquinwin.cTélécharger ce fichier [Réservé aux membres club]Voir ce fichier5 700 octets

Télécharger le zip


 Historique

16 juin 2008 19:03:35 :
ajout fichier projet DEV C++

 Sources du même auteur

Source avec Zip GENERATEUR DE BITS ALÉATOIRES

 Sources de la même categorie

Source avec Zip Source avec une capture PLUS OU MOINS par antho974
Source avec Zip Source avec une capture TETRIS EN C++ AVEC SDL par Marmalus
Source avec une capture DÉMINEUR SOUS TERMINAL par aom333
Source avec Zip JEU: MARIO SOKOBAN par astro53
Source avec Zip JEU PUISSANCE IV par ElendilAranwe

 Sources en rapport avec celle ci

JEU TAQUIN AVEC MATRICE par snoopi_19ans

Commentaires et avis

Commentaire de BruNews le 24/01/2006 16:12:03 administrateur CS

hPrevInstance est inutile et toujours NULL depuis Win95, ne plus en tenir compte.

Commentaire de bobkiller le 27/11/2006 18:25:50

yo !
Est-ce que tu testes bien la possibilité de réalisation de ton taquin ? Car je suis tombé sur une configuration impossible à réaliser...
1  2  3  4
5  6  7  8
9  10 11 12
13 15 14 0

pour plus d'explications :
http://villemin.gerard.free.fr/Puzzle/Taquin.htm

Commentaire de imenhd le 12/06/2008 14:31:57

salut
svp j'ai à programmer le jeux taquin(3*3) avec dev-c++-4.9.9.2 alors j'ai essayé de télécharger vos fichiers taquin.c mais ca ne se compile pas et je ne trouve pas d'exécutable taquin.exe et pouvez vous m'expliquer c'est quoi le fichier makefile
une dernière chose svp si vous avez un exécutable taquin(3*3)construit avec dev-c++-4.9.9.2 veuillez me l'envoyer svp vers ma boite imen_hd@hotmail.fr ou imenhd@live.fr et veuillez joindre le code source svp
et merci d'avance
c'est très urgent

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

le programme du jeux taquin en c [ par mbodj ] Merci de me faire part un bout de programme taquin en c taquin en c [ par kloug42 ] Bonjours a tous j ai un petit j aimerai bien recevoir le programme en c du jeux du taquin ca serai&nbsp;tro cool merci d avance.merci de me l envoyer Aide, résolution d'un taquin [ par Micha1177 ] Bonjour, Dans le cadre d'un projet, je doit élaborer une grille de taquin résoluble, et pouvoir effectuer le déplacement des cases, et ensuite concev


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
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,577 sec (4)

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