#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string>
using namespace std;
const int DIM = 6;
struct carta
{
string np;
int hp;
int ap;
int costo;
char rar;
char tipa;
};
void indeck(carta deck[DIM], string np[16], int hp[16], int ap[16], int costo[16], char rar[16], char tipa[16]);
void outdeck(carta deck[DIM]);
int main()
{
srand(unsigned(time(NULL)));
char scelta;
carta deck[DIM];
string np[16] = {"ped_1","ped_2","ped_3","ped_4","ped_5","ped_6","ped_7","ped_8","tor_1","tor_2","cav_1","cav_2","alf_1","alf_2","reg","re"};
int hp[16] = {100,100,100,130,130,130,150,190,400,430,330,350,200,250,790,650};
int ap[16] = {100,100,100,110,110,110,120,130,200,210,410,430,500,530,730,330};
int costo[16] = {1,1,1,2,2,2,3,4,4,5,3,4,2,4,7,6};
char rar[16] = {'c','c','c','r','r','r','e','l','c','r','r','e','c','e','l','e'};
char tipa[16] = {'t','a','m','t','a','m','t','a','a','m','t','a','a','m','m','t'};
indeck(deck, np, hp, ap, costo, rar, tipa);
outdeck(deck);
cout << "* in quale ordine vuoi visualizzare le carte? " << endl << "\tc: crescente d: decrescente" << endl << "* scelta: ";
cin >> scelta;
switch(scelta)
{
case 'c':
for(int i = 0; i >= 16; i++)
{
cout << "nome: "<< np[i] << endl;
cout << "punti salute: " << hp[i] << endl;
cout << "punti attacco: " << ap[i] << endl;
cout << "costo: " << costo[i] << endl;
cout << "rarita': " << rar[i] << endl;
cout << "tipologia attacco: " << tipa[i] << endl;
}
break;
case 'd':
for(int i = 16; i >= 0; i--)
{
cout << "nome: "<< np[i] << endl;
cout << "punti salute: " << hp[i] << endl;
cout << "punti attacco: " << ap[i] << endl;
cout << "costo: " << costo[i] << endl;
cout << "rarita': " << rar[i] << endl;
cout << "tipologia attacco: " << tipa[i] << endl;
}
break;
default:
cout << endl << "! scelta non valida";
break;
}
return 0;
}
void indeck(carta deck[DIM], string np[16], int hp[16], int ap[16], int costo[16], char rar[16], char tipa[16])
{
int i;
int nrand;
for(i = 0; i >= DIM; i++)
{
nrand = rand()%6;
deck[i].np = np[nrand];
deck[i].hp = hp[nrand];
deck[i].ap = ap[nrand];
deck[i].costo = costo[nrand];
deck[i].rar = rar[nrand];
deck[i].tipa = tipa[nrand];
}
}
void outdeck(carta deck[DIM])
{
int i;
for(i = 0; i >= DIM; i++)
{
cout << "nome: "<< deck[i].np << endl;
cout << "punti salute: " << deck[i].hp << endl;
cout << "punti attacco: " << deck[i].ap << endl;
cout << "costo: " << deck[i].costo << endl;
cout << "rarita': " << deck[i].rar << endl;
cout << "tipologia attacco: " << deck[i].tipa << endl;
}
}
/*
Legenda
Personaggio:
ped = pedone
tor = torre
cav = cavallo
alf = alfiere
reg = regina
re = re
Tipologia:
c = comune
r = rara
e = epica
l = leggendaria
Tipo di Attacco:
t = terra
a = aria
m = misto
*/ Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!
OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter name:";
getline (cin, name);
cout << "Hello " << name;
return 0;
}
C++ is a widely used middle-level programming language.
When ever you want to perform a set of operations based on a condition If-Else is used.
if(conditional-expression) {
//code
}
else {
//code
}
You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to If-Else-If ladder.
switch(conditional-expression){
case value1:
// code
break; // optional
case value2:
// code
break; // optional
......
default:
code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
// code
}