im trying to make a simple tic tac toe application but i cant seem to stop it from puting in a o or x when there is already one there i know all the if statments are terribly messy but im still intrigued as to why it wont work any way here the code
CODE
#include <windows.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void drawFigure (int, int, HWND);
int boardArray [3][3] = {{0,0,0}, {0,0,0}};
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
//mouse positions
int mouseX;
int mouseY;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = L"WinApp";
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
L"WinApp", /* Classname */
L"Tic Tac Toe", /* Title Text */
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
307, /* The programs width */
327, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
HDC hdc;
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
MoveToEx(hdc,100,0,NULL);
LineTo(hdc,100,300);
MoveToEx(hdc,200,0,NULL);
LineTo(hdc,200,300);
MoveToEx(hdc,0,100,NULL);
LineTo(hdc,300,100);
MoveToEx(hdc,0,200,NULL);
LineTo(hdc,300,200);
EndPaint(hwnd, &ps);
break;
case WM_LBUTTONDOWN:
mouseX = LOWORD(lParam);
mouseY = HIWORD(lParam);
drawFigure(mouseX,mouseY,hwnd);
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
int xOrO=1;
void drawFigure(int xPosition, int yPosition, HWND hwnd) {
int xStart,yStart,xFinish,yFinish;
if (xPosition <= 100) {
xStart = 0;
xFinish = 100;
}
else if (xPosition <= 200) {
xStart = 100;
xFinish = 200;
}
else if (xPosition <=300) {
xStart = 200;
xFinish = 300;
}
if (yPosition <= 100) {
yStart = 0;
yFinish = 100;
}
else if (yPosition <= 200) {
yStart = 100;
yFinish = 200;
}
else if (xPosition <=300) {
yStart = 200;
yFinish = 300;
}
if (xStart == 0 && yStart == 0) {
if (boardArray[0][0] = 0)
boardArray[0][0] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
else if (xStart == 100 && yStart == 0) {
if (boardArray[1][0] = 0)
boardArray[1][0] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
else if (xStart == 200 && yStart == 0) {
if (boardArray[2][0] = 0)
boardArray[2][0] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
else if (xStart == 0 && yStart == 100) {
if (boardArray[0][1] = 0)
boardArray[0][1] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
else if (xStart == 100 && yStart == 100) {
if (boardArray[1][1] = 0)
boardArray[1][1] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
else if (xStart == 200 && yStart == 100) {
if (boardArray[2][1] = 0)
boardArray[2][1] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
else if (xStart == 0 && yStart == 200) {
if (boardArray[0][2] = 0)
boardArray[0][2] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
else if (xStart == 100 && yStart == 200) {
if (boardArray[1][2] = 0)
boardArray[1][2] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
else if (xStart == 200 && yStart == 200) {
if (boardArray[2][2] = 0)
boardArray[2][2] = xOrO;
else if (boardArray[0][0] != 0)
return;
}
hdc = GetDC(hwnd);
if(xOrO == 1) {
MoveToEx(hdc,xStart,yStart,NULL);
LineTo(hdc,xFinish,yFinish);
MoveToEx(hdc,xStart+100,yStart,NULL);
LineTo(hdc,xFinish-100,yFinish);
xOrO = 2;
}
else if (xOrO == 2) {
HBRUSH hBrush = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
SelectObject(hdc,hBrush);
Ellipse(hdc,xStart,yStart,xFinish,yFinish);
xOrO = 1;
}
ReleaseDC(hwnd,hdc);
}