Accueil > > > JEU DU TAQUIN
JEU DU TAQUIN
Information sur la source
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));
}
Historique
- 16 juin 2008 19:03:35 :
- ajout fichier projet DEV C++
Sources du même auteur
Sources de la même categorie
Commentaires et avis
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 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
|
Derniers Blogs
TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
WIN APIWIN API par omarino_007
Cliquez pour lire la suite par omarino_007
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|