#include<iostream>
#include<ctime>
#define num_pacchi 20
using namespace std;
int Gioca(string nome, int pacco);
int offerta(string nome, int pacco);
int Apertura_Pacco();
int Fine();
char nome[20];
int pacco,fare_offerta= 0;
int pacchi_rimanenti[20]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
struct pa
{
int tipo;
int contenuto_pacco; //{Pacchi}
string premio;
}p[num_pacchi];
int cambio_finito=0;
int main () {
system("color 34");
srand(time(NULL));
int scelta;
p[0].tipo=2;
p[0].contenuto_pacco=-1;
p[0].premio="aaaaaa";
p[1].tipo=2;
p[1].contenuto_pacco=-1;
p[1].premio="bbbbb";
p[2].tipo=2;
p[2].contenuto_pacco=-1;
p[2].premio="ccccc";
p[3].tipo=2;
p[3].contenuto_pacco=-1;
p[3].premio="ddddd";
p[4].tipo=2;
p[4].contenuto_pacco=-1;
p[4].premio="eeeee";
p[5].tipo=1;
p[5].contenuto_pacco=1;
p[5].premio="1 euro";
p[6].tipo=1;
p[6].contenuto_pacco=5;
p[6].premio="5 euro";
p[7].tipo=1;
p[7].contenuto_pacco=10;
p[7].premio="10 euro";
p[8].tipo=1;
p[8].contenuto_pacco=20;
p[8].premio="20 euro";
p[9].tipo=1;
p[9].contenuto_pacco=100;
p[9].premio="100 euro";
p[10].tipo=1;
p[10].contenuto_pacco=500;
p[10].premio="500 euro";
p[11].tipo=1;
p[11].contenuto_pacco=1000;
p[11].premio="1000 euro";
p[12].tipo=1;
p[12].contenuto_pacco=5000;
p[12].premio="5000 euro";
p[13].tipo=1;
p[13].contenuto_pacco=10000;
p[13].premio="10000 euro";
p[14].tipo=1;
p[14].contenuto_pacco=20000;
p[14].premio="20000 euro";
p[15].tipo=1;
p[15].contenuto_pacco=50000;
p[15].premio="50000 euro";
p[16].tipo=1;
p[16].contenuto_pacco=75000;
p[16].premio="75000 euro";
p[17].tipo=1;
p[17].contenuto_pacco=100000;
p[17].premio="100000 euro";
p[18].tipo=1;
p[18].contenuto_pacco=250000;
p[18].premio="250000 euro";
p[19].tipo=1;
p[19].contenuto_pacco=500000;
p[19].premio="500000 euro";
do {
system("cls");
cout << "\t\t****************************************************\n";
cout << "\t\t* *\n";
cout << "\t\t* Benvenuti ad AFFARI TUOI *\n";
cout << "\t\t* *\n";
cout << "\t\t****************************************************\n\n";
cout << "1 - Gioca\n\n2 - Esci\n\n";
cin >> scelta;
}while(scelta < 1 || scelta > 2);
switch (scelta) {
case 1:
system("cls");
cout << "\n\nInserisci il tuo nome: ";
cin >> nome;
while (pacco < 1 || pacco > 20)
{
cout << "\n\nInserisci il numero del pacco che vuoi(1-20): ";
cin >> pacco;
}
Gioca(nome,pacco);
break;
case 2:
exit (1);
}
}
int Gioca(string nome, int pacco) {//fare_offerta++;
Fine();
if (fare_offerta > 0 && fare_offerta == 3)
offerta(nome, pacco);
int chiama = 0; //Chiamata Pacco
do {
system("cls");
cout << "Pacchi rimasti: ";
for (int x = 0; x < 20; x++) { //Mostra Pacchi Rimasti
if (pacchi_rimanenti[x]!=pacchi_rimanenti[pacco-1] && pacchi_rimanenti[x]!=0)
cout << pacchi_rimanenti[x] << " ";
else
cout << " ";
}
for (int y = 0; y < num_pacchi; y++) { //Mostra Valori Rimasti
if(p[y].contenuto_pacco!=0)
cout << endl << p[y].premio;
else
cout << endl;
}
cout << endl << endl << endl;
cout << "Quale pacco vuoi chiamare? ";
cin >> chiama;
}while(pacco == chiama || pacchi_rimanenti[chiama-1]==0);
Apertura_Pacco();
pacchi_rimanenti[chiama-1]=0;
fare_offerta++;
getchar();
Gioca(nome, pacco);
}
int offerta(string nome, int pacco) {
int tipo_offerta = rand()%2;;
int scelta = 0;
if (tipo_offerta==0) {
int tot_pacchi_rimasti = 0; //TOTale PaCchi
int valore_pacchi_rimasti = 0; //TOTale RiManente
int off = 0;
for (int x=0; x < 20; x++) {
if ((p[x].contenuto_pacco!=0) && (p[x].contenuto_pacco==-1))
tot_pacchi_rimasti++;
else if (p[x].contenuto_pacco!=0) {
valore_pacchi_rimasti += p[x].contenuto_pacco;
tot_pacchi_rimasti++;
}
}
system("cls");
off = ((valore_pacchi_rimasti / tot_pacchi_rimasti)) * 0.1;
do {
cout << nome << ", per te l'offerta e': " << off;
cout << endl << "Accetti l'offerta? (1)-(SI) - (0)-(NO)" << endl;
cin >> scelta;
}while(scelta < 0 || scelta > 1);
if (scelta==1) {
system("cls");
cout << "Hai vinto: " << off << endl;
system("pause");
exit(1);
}
} else {
do {
system("cls");
cout << "Vuoi cambiare pacco? 1-Si 0-No" << endl;
cin >> scelta;
}while (scelta> 1 || scelta< 0);
if (scelta==1) {
cout << endl << "Con quale pacco vuoi cambiare il tuo?" << endl << "Nuovo pacco: ";
cin >> pacco;
}
}
fare_offerta = 0;
Gioca(nome,pacco);
}
int Apertura_Pacco() {
int PcVal;
system("cls");
cout << "Il valore del pacco e': ";
PcVal = rand() % 20;
while (p[PcVal].contenuto_pacco==0)
PcVal = rand() % 20;
cout << p[PcVal].premio;
p[PcVal].contenuto_pacco=0;
getchar();
}
int Fine() {
string TotWin;
int temp,flag=1;
//Totale Vincita
if (fare_offerta==19) {
system("cls");
for (int y = 0; y < 20; y++) { //Trova Valore che hai vinto
if (p[y].contenuto_pacco!=0) {
if (p[y].contenuto_pacco!=-1)
TotWin =p[y].premio;
else {
flag=0;
temp=y;
}
}
}
if(flag)
cout << "Hai vinto: " << TotWin << "!!!\n\n";
else
cout << "Hai vinto: " << p[temp].premio << "\n\n";
system("pause");
exit (1);
}
}