Четверг, 28.11.2024, 06:56 | Приветствую Вас Гость

...

Код

Главная » Статьи » C++

gleq - card

#include <windows.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
typedef void (WINAPI *pfcdtInit)(int *, int *);
typedef void (WINAPI *pfcdtDraw)(HDC, int x, int y, int card, int type, DWORD color);
typedef void (WINAPI *pfcdtDrawEx)(HDC, int x, int y, int dx, int dy, int card, int type, DWORD color);
typedef void (WINAPI *pfcdtAnimate)(HDC hdc, int cardback, int x, int y, int state);
typedef void (WINAPI *pfcdtTerm) (void);
pfcdtInit cdtInit;
pfcdtDraw cdtDraw;
pfcdtDrawEx cdtDrawEx;
pfcdtTerm cdtTerm;
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HDC hdc;
HWND hwnd;
HWND button_1;
HWND button_2;
HWND button_3;
int IndexCard = 0;
int OverLap= 0;
int arraycard[52];
int getrank(int cardnumber);
int generate_card();
void sortcards();
void RenderCards();

 

int getrank(int cardnumber)
{
if (cardnumber > 51 || cardnumber < 0 ) return -1;

for (int iteration = 4;iteration <=51; iteration+=4 )
{
if (cardnumber >= iteration && cardnumber <= iteration + 3)
{
return iteration/4;
}
}
return 13;
}

int generate_card()
{
srand(time(0));
int i,a;
for(i=0;i<=51;i++){
arraycard[i]=rand()%52;
for(a=0;a<i;a++){
if(arraycard[a]==arraycard[i]) {
i--;
break;
}
}
}

}

void RenderCards()
{

RECT rc;
rc.left = 0;
rc.top = 0;
rc.right = 500;
rc.bottom = 300;

if (IndexCard == 51)
{
IndexCard = 0;
OverLap = 0;
FillRect(hdc,&rc, (HBRUSH)(COLOR_BACKGROUND));
}


HBITMAP memBM = CreateCompatibleBitmap(hdc,200,200);
HDC memDC = CreateCompatibleDC(hdc);

SelectObject(memDC,memBM);
FillRect(memDC,&rc, (HBRUSH)(COLOR_BACKGROUND));

char buffer[20];
itoa(OverLap,buffer,10);
char *text_1 = "Количество совпадений";
TextOut(hdc,300,0,text_1,strlen(text_1));
TextOut(hdc,300,50,buffer,strlen(buffer));
itoa(IndexCard,buffer,10);


char *text_2 = "Взято карт из колоды";
TextOut(hdc,300,150,text_2,strlen(text_2));
TextOut(hdc,300,250,buffer,strlen(buffer));

cdtDrawEx(memDC,100,0,90,90,arraycard[IndexCard],0,0);

 


BitBlt(hdc,0,0,200,200, memDC, 0, 0, SRCCOPY);

}

 

char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{

MSG messages;
WNDCLASSEX wincl;


wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);


wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

if (!RegisterClassEx (&wincl))
        return 0;


hwnd = CreateWindowEx (
           0,
           szClassName,
           "Windows App",
           WS_OVERLAPPEDWINDOW,
           CW_USEDEFAULT,
           CW_USEDEFAULT,
           500,
           400,
           HWND_DESKTOP,
           NULL,
           hThisInstance,
           NULL
           );


ShowWindow (hwnd, nFunsterStil);

HMODULE hCardDll;
hCardDll = LoadLibrary("cards.dll");
cdtInit   = (pfcdtInit)   GetProcAddress(hCardDll, "cdtInit");
cdtDraw   = (pfcdtDraw)   GetProcAddress(hCardDll, "cdtDraw");
cdtDrawEx = (pfcdtDrawEx) GetProcAddress(hCardDll, "cdtDrawExt");
cdtTerm   = (pfcdtTerm)   GetProcAddress(hCardDll, "cdtTerm");


int w;
int h;
cdtInit(&w,&h);
hdc = GetDC(hwnd);
generate_card();
button_1=CreateWindow("button","Больше",WS_VISIBLE|WS_CHILD,0,300,75,35,hwnd,NULL,NULL,NULL);

button_2=CreateWindow("button","Меньше",WS_VISIBLE|WS_CHILD,100,300,75/**<  */,35,hwnd,NULL,NULL,NULL);

button_3=CreateWindow("button","Равно",WS_VISIBLE|WS_CHILD,200,300,75,35,hwnd,NULL,NULL,NULL);


RenderCards();

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

 


LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{

case WM_COMMAND:
if ((HWND)lParam == button_1)
{
int currentcard = getrank(arraycard[IndexCard]);
int nextcard = getrank(arraycard[IndexCard+1]);


if (nextcard   >  currentcard ) OverLap++;

IndexCard++;
RenderCards();

 

}

if ((HWND)lParam == button_2)
{
int currentcard = getrank(arraycard[IndexCard]);
int nextcard = getrank(arraycard[IndexCard+1]);


if (nextcard   <  currentcard ) OverLap++;
IndexCard++;
RenderCards();

 

}
if ((HWND)lParam == button_3)
{
int currentcard = getrank(arraycard[IndexCard]);
int nextcard = getrank(arraycard[IndexCard+1]);


if (nextcard   ==  currentcard ) OverLap++;

IndexCard++;
RenderCards();

}

break;

case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

 

Категория: C++ | Добавил: moskov (14.06.2018)
Просмотров: 316 | Рейтинг: 0.0/0
Добавлять комментарии могут только зарегистрированные пользователи.
[ Регистрация | Вход ]

Меню сайта

Категории раздела

PHP [41]
C++ [71]
Autoit [108]
Processing [105]
Basic4GL [7]
Fasm [2]
PABC [7]
Js [236]
Gentee [1]
Python [204]
Java android [3]
Small Basic [9]

Мини-чат

Статистика


Онлайн всего: 13
Гостей: 13
Пользователей: 0

Форма входа

Друзья сайта

  • ЗОВ КОСМОСА

  • Хулиган Вселенной

  • Тюремная поэзия

  • Религиозная поэзия

  • Сайт клана ЛеГиоН
  • Поиск