Pelaaja valitsee kruunan tai klaavan ja jompikumpi tulee randomina. Rahat tuplaantuvat jos menee oikein ja nollaantuvat jos menee väärin.
Exe löytyy
http://koti.mbnet.fi/linkku-/koodit/Tuplaus/Tuplaus.exe
#include <windows.h>
#include <time.h> //time()
#include <stdlib.h> // rand(), srand()
#define TIMER 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
HINSTANCE hInstance;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static char szAppName[] = "Tuplaus" ;
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; // iconi
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; // cursori
wndclass.hbrBackground = (HBRUSH) COLOR_WINDOW ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;
RegisterClassEx (&wndclass) ; // ikkunan luokan rekisteröinti
hwnd = CreateWindow (szAppName, "Tuplaus",
WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION,
200, 200, 220, 200,
NULL, NULL, hInstance, NULL) ;
srand(time(0)); // randomlukugeneraattori
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0)){
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hwndYla, hwndAla, hwndOK, hwndKlaava, hwndKruuna, hwndSumma, hwndRaha;
char bufferi[10];
switch (iMsg)
{
case WM_CREATE:
hwndKruuna=CreateWindow("button", "Kruuna", WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,
10, 20, 100, 20, hwnd, (HMENU) 0, hInstance, NULL);
SendMessage(hwndKruuna, BM_SETCHECK, 1, 0); // Valitaan ensimmäinen nappi
hwndKlaava=CreateWindow("button", "Klaava", WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,
10, 40, 100, 20, hwnd, (HMENU) 1, hInstance, NULL);
hwndOK=CreateWindow("button", "OK", WS_CHILD|WS_VISIBLE,
10, 60, 100, 30, hwnd, (HMENU) 2, hInstance, NULL); // OK-nappi
hwndYla=CreateWindowEx(WS_EX_STATICEDGE, "static", "", WS_CHILD|WS_VISIBLE,
10, 100, 190, 20, hwnd, (HMENU) 3, hInstance, NULL); // tekstinlaatikko
hwndAla=CreateWindowEx(WS_EX_STATICEDGE, "static", "", WS_CHILD|WS_VISIBLE,
10, 130, 190, 20, hwnd, (HMENU) 3, hInstance, NULL); // tekstinlaatikko
hwndSumma=CreateWindowEx(WS_EX_CLIENTEDGE, "static", "2", WS_CHILD|WS_VISIBLE,
130, 63, 60, 20, hwnd, (HMENU) 5, hInstance, NULL); // tekstinlaatikko
hwndRaha=CreateWindowEx(WS_EX_WINDOWEDGE, "static", "Rahat", WS_CHILD|WS_VISIBLE,
130, 40, 60, 20, hwnd, (HMENU) 6, hInstance, NULL); // tekstinlaatikko
return 0 ;
case WM_COMMAND:
switch HIWORD(wParam)
{
case BN_CLICKED: // nappia on painettu
if ( LOWORD(wParam)==2) // Pitää painaa OK-nappia
{
int random = rand() % 2; // randomluku väliltä 0-1
SetTimer(hwnd, TIMER, 2000, NULL); // Käynnistetään ajastin, 2 sekuntia aikaa
// 0 = Kruuna
// 1 = Klaava
if(random==0 && SendMessage(hwndKruuna, BM_GETCHECK, 0,0) == TRUE)
{
// Tuplaus
GetWindowText ( hwndSumma, bufferi, 10 );
int buffer = atoi( bufferi ); // muunnetaan char intiksi
itoa( buffer * 2, bufferi, 10 ); // muunnetaan int chariksi
SetWindowText(hwndSumma, bufferi);
SetWindowText(hwndYla, "Kruuna"); // Kirjoitetaan teksti laatikoihin
SetWindowText(hwndAla, "Oikein!!!!");
return 0;
}
if(random==1 && SendMessage(hwndKlaava, BM_GETCHECK, 0,0) == TRUE)
{
// Tuplaus
GetWindowText ( hwndSumma, bufferi, 10 );
int buffer = atoi( bufferi ); // muunnetaan char intiksi
itoa( buffer * 2, bufferi, 10 ); // muunnetaan int chariksi
SetWindowText(hwndSumma, bufferi);
SetWindowText(hwndYla, "Klaava");
SetWindowText(hwndAla, "Oikein!!!!");
return 0;
}
//SendMessage(hwndKruuna, BM_GETCHECK, 0,0) hakee tiedon, onko hwndKruuna valittu
if(random==0 && SendMessage(hwndKruuna, BM_GETCHECK, 0,0) == FALSE)
{
SetWindowText(hwndYla, "Kruuna");
SetWindowText(hwndAla, "Väärin =(");
SetWindowText(hwndSumma, "0");
return 0;
}
if(random==1 && SendMessage(hwndKlaava, BM_GETCHECK, 0,0) == FALSE)
{
SetWindowText(hwndYla, "Klaava");
SetWindowText(hwndAla, "Väärin =(");
SetWindowText(hwndSumma, "0");
return 0;
}
else // Jos mikään ehto ei täyty
{
MessageBox(hwnd,"Nyt joku bugaa!","Errori", MB_OK | MB_ICONSTOP);
return 0;
}
}
}
return 0;
case WM_TIMER : // Ajastimen aika on kulunut ja se lähettää WM_TIMER messun
switch(wParam)
{
case TIMER: // Miltä ajastimelta viesti tuli
SetWindowText(hwndYla, ""); // tyhjennetään textboxit
SetWindowText(hwndAla, "");
KillTimer(hwnd, TIMER); // Tapetaan ajastin
return 0;
}
case WM_DESTROY :
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}Aihe on jo aika vanha, joten et voi enää vastata siihen.