밑이 소스인데 가위바위보 게임이야
근데 가위바위보 각자 승리횟수랑 비긴횟수를 써넣었는데
그 값이 증가를 안해 계속 0인채로야
어떻게 해야하나;;;
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "resource.h"
void DrawBitmap(HDC hdc,int x, int y, HBITMAP hBit);
int userwin=0;
int comwin=0;
int draw=0;
int GetRand(int low, int max)
{
return (rand()%(max+1-low))+low;
}
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hlnst;
LPCTSTR lpszClass=TEXT("가위! 바위! 보!");
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hlnst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while (GetMessage(&Message,NULL,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
int b;
RECT rt, at;
HDC hdc,MemDC;
PAINTSTRUCT ps;
HBITMAP MyBitmap, OldBitmap;
TCHAR Message[256];
SetRect(&rt,200,500,500,500);
SetRect(&at,400,500,500,500);
switch (iMessage) {
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP5));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,0,0,1400,900,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)){
case ID_MENU_40001:
MessageBox(hWnd,TEXT("가위! 바위! 보! 게임을 시작합니다."),TEXT("시작알림"),MB_OK);
InvalidateRect(hWnd,NULL,TRUE);
hdc=BeginPaint(hWnd,&ps);
CreateWindow(TEXT("button"),TEXT("가위를 냅니다"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,20,20,100,25,hWnd,(HMENU)1,g_hlnst,NULL);
CreateWindow(TEXT("button"),TEXT("바위를 냅니다"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,20,50,100,25,hWnd,(HMENU)2,g_hlnst,NULL);
CreateWindow(TEXT("button"),TEXT("보를 냅니다"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,20,80,100,25,hWnd,(HMENU)3,g_hlnst,NULL);
wsprintf(Message,TEXT("플레이어 승리 : %d"),userwin); //여기있는 값들이
TextOut(hdc,600,10,Message,lstrlen(Message));
wsprintf(Message,TEXT("구하라 승리 : %d"),comwin); //증가를 안해
TextOut(hdc,600,30,Message,lstrlen(Message));
wsprintf(Message,TEXT("비긴 횟수 : %d"),draw); //
TextOut(hdc,600,50,Message,lstrlen(Message));
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP1));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,800,0,600,800,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
break;
case 1:
b=GetRand(1,3);
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP2));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,200,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
if (b==1)
{
draw++; //여기서 증가시키려고 하는데
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP6));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
if (b==2)
{
comwin++; //증가를 안해 ㅠㅠ
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP7));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
if (b==3)
{
userwin++;
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP8));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
break;
case 2:
b=GetRand(1,3);
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP3));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,200,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
if (b==1)
{
draw++;
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP6));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
if (b==2)
{
comwin++;
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP7));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
if (b==3)
{
userwin++;
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP8));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
break;
case 3:
b=GetRand(1,3);
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP4));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,200,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
if (b==1)
{
draw++;
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP6));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
if (b==2)
{
comwin++;
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP7));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
if (b==3)
{
userwin++;
InvalidateRect(hWnd,NULL,FALSE);
hdc=BeginPaint(hWnd,&ps);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hlnst,MAKEINTRESOURCE(IDB_BITMAP8));
OldBitmap=(HBITMAP)SelectObject(MemDC,MyBitmap);
BitBlt(hdc,400,500,125,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);
EndPaint(hWnd,&ps);
}
break;
case ID_MENU_40002:
DestroyWindow(hWnd);
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.