Michele13

Giochino in C++

Apr 4th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. //#define PLAYER_ATK 20
  4. #define ATK 10
  5.  
  6. //un gioco a turni basato su un gioco di megaman che ho trovato online
  7. //a turn based game based on a megaman online game
  8.  
  9. class Game {
  10.     public:
  11.     //mostra menu
  12.     //display menu
  13.     void menu();
  14.     //ripristina la salute del giocatore
  15.     // restore player's health
  16.     void heal();
  17.     //danneggia il nemico
  18.     // damages the enemy
  19.     void attack();
  20.     //controllo dei turni di gioco
  21.     //turn game control
  22.     int turn();
  23.     //danneggia il giocatore
  24.     // damages the player
  25.     void enemy_attack();
  26.     //il limite deve essere una combo di 5 attacchi
  27.     // limit is a combo of 5 attacks
  28.     void limit_attack();
  29.     //construttore
  30.     //constructor
  31.     Game(int a){
  32.         level=a;
  33.         //salute del giocatore: 100 per ogni livello
  34.         health=100*level;
  35.         limit=0;
  36.         enemy_limit=0;
  37.         potions=3;
  38.         //salute del nemico: 300 per ogni livello
  39.         enemy_health=300*level;
  40.         your_turn=true;
  41.         };
  42.    
  43.     private:
  44.     int level;
  45.     int health;
  46.     //percentuale del limite (se il limite è 100 permetti l'esecuzione del comando.
  47.     //limit percentage (if 100 allow execution of the limit)
  48.     int limit;
  49.     //le pozioni devono essere tre
  50.     // potions must be 3
  51.     int potions;
  52.     int enemy_limit;
  53.     int enemy_health;
  54.     bool your_turn;
  55.     };
  56.  
  57. int Game::turn(){
  58.     //controlla se il giocatore è ancora vivo
  59.     //check if the player is still alive
  60.     while(health>0){
  61.         //controlla che il nemico sia ancora vivo
  62.         //check if the enemy is still alive
  63.         if (enemy_health>0) {
  64.             //controlla se è il tuo turno o quello del giocatore
  65.             //check if it's your turn or your enemy's
  66.     if (your_turn==true) menu();
  67.     else enemy_attack();
  68. }
  69. //HAI VINTO!
  70. else {cout << "YOU WIN!" << endl;
  71.     return 0;
  72.     }
  73. //SEI MORTO!
  74. if (health<1) {cout << "YOU DIED" << endl;
  75.     return 1;
  76. }
  77. }
  78. //C'è un errore nel sistema del controllo dei turni di gioco! (Non dovresti arrivare a questo punto)
  79. cout << "There was an error with the turn system of the game!";
  80. return 2;}
  81.  
  82. void Game::menu(){
  83. cout << "HP: " << health << "   " << "Enemy: " << enemy_health << endl;
  84. cout << endl;
  85. cout << "1) Attack" << endl;
  86. cout << "2) Potion (" << potions << ")"<< endl;
  87. cout << "3) Limit (" << limit << "%)" << endl;
  88. cout << "Choice: ";
  89. int x;
  90. cin >> x;
  91. switch(x){
  92.     case 1: attack();
  93.     case 2: heal();
  94.     case 3: limit_attack();
  95.     default: menu();
  96.         }
  97.        
  98. }
  99.  
  100.  
  101. void Game::enemy_attack(){
  102.     int damage=ATK*level;
  103. //Il terzo attacco è più forte degli altri due (3 volte più forte, giusto per rendere il gioco più divertente e meno monotono
  104.         if(enemy_limit==3) {health=health-damage*enemy_limit;
  105.             enemy_limit=0;}
  106.             else {enemy_limit++;
  107.             health=health-damage;}
  108.             your_turn=true;
  109. //aumenta il limite di 25
  110.             limit=limit+25;
  111. }
  112. //BUG  incasina i valori
  113. // BUG screws up values        
  114. void Game::heal(){
  115.     if (potions>0) {health=100*level;
  116.     potions--;
  117.     your_turn=false;
  118.       }
  119.     }
  120.  
  121. void Game::attack(){
  122.     int damage=ATK*level;
  123.     enemy_health=enemy_health-damage;
  124.     your_turn=false;
  125.     }
  126.  
  127. // il Limite è una combo di 5 attacchi
  128. // limit is a combo of 5 attacks
  129. void Game::limit_attack(){
  130.     if(limit<100) menu();
  131.     else {enemy_health=enemy_health-(ATK*level*5);
  132.         limit=limit-100;}
  133.         }
  134.  
  135. int main() {
  136.     Game game();
  137.     //Chiede un numero positivo maggiore di zero per saltare a un determinato livello
  138.     //Asks for a level number that must be positive and major of zero
  139.     int level=0;
  140.     do {
  141.     cout << "Insert Level (Positive Number): ";
  142.     cin >> level;
  143. }while(level<=0);
  144. //avvia il gioco
  145. //initialize game
  146.     int result;
  147.     do{
  148.     Game game(level);
  149.     result=game.turn();
  150.     if (result==0) level++;
  151.     } while(result==0);
  152.     return 0;}
Advertisement
Add Comment
Please, Sign In to add comment