1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include <iostream>
#include <iomanip>
#include <ctime>
#include <windows.h>
using namespace std;
void dis_tab (int coordX[], int coordY[]);
int estrai_num ();
void dis_num (int coordX[], int coordY[], int num);
int main ()
{
INPUT_RECORD Input;
DWORD num_eventi;
int X[90] , Y[90];
int num;
SetConsoleTitleA("Tombola");
dis_tab (X, Y);
cout << "Premi INVIO per estrarre un numero." << endl;
while (true) {
ReadConsoleInput(GetStdHandle (STD_INPUT_HANDLE),
&Input,
1,
&num_eventi);
if (Input.EventType == KEY_EVENT) {
if (Input.Event.KeyEvent.bKeyDown &&
Input.Event.KeyEvent.wVirtualKeyCode == 0x0D) {
num = estrai_num ();
dis_num (X, Y, num);
}
}
}
return 0;
}
void dis_tab (int coordX[], int coordY[])
{
cout << (char)218;
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 2; j++)
cout << (char)196;
cout << (char)194;
}
for (int i = 0; i < 2; i++)
cout << (char)196;
cout << (char)191 << endl;
int k = 1;
for (int i = 0; i < 8; i++) {
cout << (char)179;
for (int j = 0; j < 10; j++) {
coordX[k-1] = (j * 3) + 1;
coordY[k-1] = (i * 2) + 1;
cout << setw (2) << k++;
cout << (char)179;
}
cout << endl;
cout << (char)195;
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 2; j++)
cout << (char)196;
cout << (char)197;
}
for (int i = 0; i < 2; i++)
cout << (char)196;
cout << (char)180 << endl;
}
cout << (char)179;
for (int i = 0; i < 10; i++) {
coordX[k-1] = (i * 3) + 1;
coordY[k-1] = 17;
cout << setw (2) << k++;
cout << (char)179;
}
cout << endl << (char)192;
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 2; j++)
cout << (char)196;
cout << (char)193;
}
for (int i = 0; i < 2; i++)
cout << (char)196;
cout << (char)217 << endl;
}
int estrai_num ()
{
static bool ext[90], prim_call = true;
int num;
if(prim_call == true) {
srand (time (NULL));
prim_call = false;
}
do {
num = rand () % 90 + 1;
} while (ext[num-1] == true);
ext[num-1] = true;
return num;
}
void dis_num (int coordX[], int coordY[], int num)
{
CONSOLE_SCREEN_BUFFER_INFO schermo;
WORD col_orig;
COORD punti, punti_orig;
HANDLE outhandle = GetStdHandle (STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo (outhandle, &schermo);
col_orig = schermo.wAttributes;
punti_orig = schermo.dwCursorPosition;
punti.X = coordX[num-1];
punti.Y = coordY[num-1];
SetConsoleCursorPosition (outhandle, punti);
SetConsoleTextAttribute (outhandle, FOREGROUND_BLUE |
FOREGROUND_INTENSITY |
BACKGROUND_GREEN |
BACKGROUND_INTENSITY);
cout << setw (2) << num;
SetConsoleCursorPosition (outhandle, punti_orig);
SetConsoleTextAttribute (outhandle, col_orig);
}
|