home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aztec Masterblend
/
aztecmasterblendazteknewmediaj
/
wcdbrk2
/
wcdbrk2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-07
|
17KB
|
677 lines
/*********************************************************************
PROGRAM: WCDBRK2.C
PURPOSE: Code Break game
AUTHOR: Ken Fogel
Omnibus Systems
8108 Norfolk Road
Cote St-Luc, Québec
Canada H4X 1A3
(514) 487-1565
CompuServe: 74646,2157
REVISION: June 1, 1991 - Version 2
Full Colour/Bitmaps
April 22, 1991 - Version 1.01
April 15, 1991 - Version 1
*********************************************************************/
#include <windows.h> /* required for all Windows applications */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "wcdbrk2.h" /* specific to this program */
HANDLE hInst; /* current instance */
HWND hGameGrid[10][4]; /* array of buttons */
int board[10][4]; /* array of guesses */
int code[4]; /* secret code */
char clues[10][4]; /* array of clues */
int cur_round; /* current row */
int cur_column; /* current column */
char str[80]; /* general purpose string */
HWND DidIGetItRight;
BOOL Setup;
BITMAP Bitmap;
HBITMAP hOldBitmap;
HBITMAP hBoardmap;
HBITMAP hBlclpegmap;
HBITMAP hWhclpegmap;
HBITMAP hPegBoardmap;
LPSTR lpPegs[8] = {"Bluepeg","Dkpupeg","Grenpeg","Ltblpeg",
"Oranpeg","Purppeg","Redpeg","Yellpeg"};
HBITMAP hPegs[8];
int iXpos,iYpos;
int curcolour = 0;
int prevcolour = -1;
int winstate;
/*********************************************************************/
int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance; /* current instance */
HANDLE hPrevInstance; /* previous instance */
LPSTR lpCmdLine; /* command line */
int nCmdShow; /* show-window type (open/icon) */
{
MSG msg; /* message */
Setup = FALSE;
if (!hPrevInstance) /* Other instances of app running? */
if (!InitApplication(hInstance)) /* Initialize shared things */
return (FALSE); /* Exits if unable to initialize */
/* Perform initializations that apply to a specific instance */
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
/* Aquire and dispatch messages until a WM_QUIT message is recieved */
while (GetMessage(&msg, /* message structure */
NULL, /* handle of window recieving the message */
NULL, /* lowest message to examine */
NULL)) /* highest message to examine */
{
TranslateMessage(&msg); /* Translates virtual key codes */
DispatchMessage(&msg); /* Dispatches message to window */
}
return(msg.wParam); /* Returns the value from PostQuitMessage */
}
/*********************************************************************/
BOOL InitApplication(hInstance)
HANDLE hInstance; /* current instance */
{
WNDCLASS wc;
/* Fill in window class structure with parameters that describe the */
/* main window. */
wc.style = CS_DBLCLKS; /* Class style(s). */
wc.lpfnWndProc = MainWndProc; /* Function to retrieve messages for */
/* windows of this class */
wc.cbClsExtra = 0; /* No per-class extra data */
wc.cbWndExtra = 0; /* No per-window extra data */
wc.hInstance = hInstance; /* Application that owns the class. */
wc.hIcon = LoadIcon(hInstance, "Wcdbrk2");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "WndCdBrkMenu"; /* Name of menu resource in .RC file */
wc.lpszClassName = "WndCdBrkWClass";/* Name used in call to CreateWindow */
/* Register the window class and return success/failure code */
return (RegisterClass(&wc));
}
/*********************************************************************/
BOOL InitInstance(hInstance, nCmdShow)
HANDLE hInstance; /* Current instance identifier */
int nCmdShow; /* Param for first ShowWindow() call */
{
HWND hWnd; /* Main window handle */
hInst = hInstance;
/* Create a main window for this application instance */
hWnd = CreateWindow(
"WndCdBrkWClass", /* See RegisterClass() call */
"Code Breaker II", /* Text for window title bar */
/* The following line creates a window which can be */
/* minimized to an icon and moved but not re-sized */
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
120, /* Initial column */
30, /* Initial row */
230, /* Width */
435, /* Height */
NULL, /* Overlapped windows have no parent */
NULL, /* Use the window class menu */
hInstance, /* This instance owns this window */
NULL /* Pointer not needed */
);
/* If window could not be created, return "failure" */
if (!hWnd)
return (FALSE);
/* Make the window visible; update its client area; and return "success" */
ShowWindow(hWnd, nCmdShow); /* Show the window */
UpdateWindow(hWnd); /* Sends WM_PAINT message */
return (TRUE); /* Returns the value from POSTQUITMESSAGE */
}
/*********************************************************************/
long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
HWND hWnd; /* window handle */
unsigned message; /* type of message */
WORD wParam; /* additional information */
LONG lParam; /* additional information */
{
FARPROC lpProcAbout; /* pointer to the "About" function */
int x,y;
switch (message)
{
case WM_CREATE:
if (!Setup) /* Do this only once */
{
hBoardmap = LoadBitmap(hInst,"Board");
hPegBoardmap = LoadBitmap(hInst,"Pegboard");
hBlclpegmap = LoadBitmap(hInst,"Blclpeg");
hWhclpegmap = LoadBitmap(hInst,"Whclpeg");
for (x=0;x<8;x++)
hPegs[x] = LoadBitmap(hInst,lpPegs[x]);
if(!bMakeGameButtons(hWnd))
{
MessageBox(hWnd,"Failure to create buttons!",NULL,
MB_OK | MB_ICONHAND);
}
Setup = TRUE;
}
vInitialize();
vMakecode();
break;
case WM_LBUTTONUP: /* Mouse button was pressed */
iXpos = LOWORD(lParam);
iYpos = HIWORD(lParam);
if (bCheckPosition(hWnd))
{
board[cur_round][cur_column] = curcolour;
vPutPeg(hWnd,curcolour,cur_round,cur_column);
}
break;
case WM_PAINT: /* Time to repaint */
vBasicScreen(hWnd);
vMarkColour(hWnd);
for (x=0;x<=cur_round;x++)
{
for (y=0;y<4;y++)
vPutPeg(hWnd,board[x][y],x,y);
vDoClues(hWnd,x);
}
if (winstate == 1)
vDoWin(hWnd);
else
if (winstate == 2)
vDoLoose(hWnd);
break;
case WM_COMMAND: /* message: command from application menu */
switch(wParam)
{
case DIDIGETITRIGHT:
if (!winstate) /* If won or lost ignore commands */
{
if (!bCheckfill()) break;
if (bCheckguess(cur_round))
{
vDoWin(hWnd);
break;
}
else
{
vDoClues(hWnd,cur_round);
cur_round++;
if (cur_round == 10) /* You loose */
vDoLoose(hWnd);
}
}
break;
case IDM_ABOUT:
lpProcAbout = MakeProcInstance(About, hInst);
DialogBox(hInst, /* current instance */
"AboutBox", /* resource to use */
hWnd, /* parent handle */
lpProcAbout); /* About() instance address */
FreeProcInstance(lpProcAbout);
break;
case IDM_NEW: /* Let's play again */
InvalidateRect(hWnd, NULL, TRUE);
SendMessage(hWnd,WM_CREATE,NULL,NULL);
break;
case IDM_GIVEUP:
vDoLoose(hWnd);
break;
case IDM_HELP:
lpProcAbout = MakeProcInstance(About, hInst);
DialogBox(hInst, /* current instance */
"HelpBox", /* resource to use */
hWnd, /* parent handle */
lpProcAbout); /* About() instance address */
FreeProcInstance(lpProcAbout);
break;
default: /* Lets Windows pro