Guest User

Untitled

a guest
Apr 22nd, 2016
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cstdio>
  5. #include <unistd.h>
  6.  
  7. using namespace std;
  8.  
  9. class Machine{
  10.     private:
  11.         int production;
  12.         int amount;
  13.         int base_price;
  14.         char buying_button;
  15.         double price;
  16.         string name;
  17.     public:
  18.         int getBaseProduction(){
  19.             return production;
  20.         }
  21.         int getProduction(){
  22.             return amount*production;
  23.         }
  24.         int getAmount(){
  25.             return amount;
  26.         }
  27.         int getPrice(){
  28.             return base_price;
  29.         }
  30.         char getBuyingChar(){
  31.             return buying_button;
  32.         }
  33.         string getName(){
  34.             return name;
  35.         }
  36.         bool canBuy(int money){
  37.             return money>price;
  38.         }
  39.         void addNewMachine(){
  40.             amount += 1;
  41.             price = price * 1.1;
  42.             //cout << " i kupilem!\n";
  43.         }
  44.         Machine(int a, char b, int c, string d){
  45.             production = a;
  46.             buying_button = b;
  47.             base_price = c;
  48.             amount = 0;
  49.             price = base_price;
  50.             name = d;
  51.             //cout << "New machine object o nazwie " << name << endl;
  52.         }
  53.  
  54. };
  55.  
  56. class Player{
  57.     private:
  58.         int money;
  59.         vector < Machine > owned_machines;
  60.     public:
  61.         int getMoney(){
  62.             return money;
  63.         }
  64.         void addMoney(int a){
  65.             money += a;
  66.         }
  67.  
  68.         int getProductionFromMachines(){
  69.             int machines_production = 0;
  70.             for(int i = 0; i < getMachineAmount();i++){
  71.                 machines_production += getMachineNr(i).getProduction();
  72.             }
  73.             return machines_production;
  74.         }
  75.         Player(int a){
  76.             money = a;
  77.         }
  78.  
  79.         void addMachine(int production, char buying_button, int base_price, string name){
  80.  
  81.             owned_machines.push_back(Machine(production,buying_button,base_price,name));
  82.         }
  83.         Machine getMachineNr(int a){
  84.             return owned_machines[a];
  85.         }
  86.         int getMachineAmount(){
  87.                 return owned_machines.size();
  88.         }
  89.         void buyMachine(int nr_of_machine){
  90.             //cout << "Kupuje";
  91.             owned_machines[nr_of_machine].addNewMachine();
  92.             //cout << "MAM " << owned_machines[nr_of_machine].getAmount();
  93.             money -= owned_machines[nr_of_machine].getPrice();
  94.         }
  95. };
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. int main(){
  104.     //deklaracja obiektów i zmiennych
  105.     Player game_player(4);
  106.     bool game_is_running = true;
  107.     int pressed_keycode = 0;
  108.     char pressed_key = 0;
  109.     int number_of_while = 0;
  110.     string font_normal = "\033[0m";
  111.     string font_green = "\033[92m";
  112.     string font_red = "\033[91m";
  113.     string font_yellow = "\033[33m";
  114.     string font_magenta = "\033[35m";
  115.     string font_cyan = "\033[36m";
  116.  
  117.     //wstępna konfiguracja gry
  118.     game_player.addMachine(1,'z',10,"Zielonka");
  119.     game_player.addMachine(10,'x',200,"Stulejarz");
  120.     game_player.addMachine(55,'c',1000,"Mirek");
  121.     game_player.addMachine(120,'v',2137,"Różowy pasek");
  122.     game_player.addMachine(1200,'b',15000,"Bordo");
  123.  
  124.  
  125.     cout << "Mirko, theGame!\nKliknij, aby zacząć!"<< endl;
  126.  
  127.     //pętla gry
  128.     while(game_is_running == true){
  129.         pressed_keycode = getchar();
  130.         pressed_key = pressed_keycode;
  131.         cout << endl << font_red << "Czekaj!\n" << font_normal;
  132.         sleep(1);
  133.         game_player.addMoney(game_player.getProductionFromMachines());
  134.         game_player.addMoney(1);
  135.         // lets clear the entire screen
  136.         cout << "\033[2J\033[1;1H";
  137.  
  138.         cout << "Posiadam " << font_green << game_player.getMoney() << font_normal << " plusów\n";
  139.         //cout << pressed_key << endl << number_of_while << endl;
  140.  
  141.         for(int i = 0; i < game_player.getMachineAmount();i++){
  142.             cout << font_magenta << "-----------------------------------------------\n" << font_normal;
  143.             cout << game_player.getMachineNr(i).getName() << " kosztuje " << game_player.getMachineNr(i).getPrice() << "(" << game_player.getMachineNr(i).getBaseProduction() << " +/s)" << endl;
  144.             cout << "Mam " << game_player.getMachineNr(i).getAmount() << " mirków produkujących " << game_player.getMachineNr(i).getProduction() << " na sekundę\n";
  145.             cout << "Naduś " << font_yellow << game_player.getMachineNr(i).getBuyingChar() << font_normal << " aby zarejestrować nowe multikonto" << endl;
  146.             if(pressed_key == game_player.getMachineNr(i).getBuyingChar()){
  147.                 if(game_player.getMachineNr(i).canBuy(game_player.getMoney()) == true){
  148.                     game_player.buyMachine(i);
  149.                 }
  150.             }
  151.         }
  152.         cout << font_magenta << "-----------------------------------------------\n" << font_normal;
  153.         cout << "Produkcja wynosi " << game_player.getProductionFromMachines() + 1 << endl;
  154.         cout << font_cyan << "Aby wyjść z gry kliknij \033[33mq\033[36m\nJeśli chcesz czekać kliknij jakikolwiek klawisz poza q i klawiszami kupowania" << font_normal << endl;
  155.         number_of_while++;
  156.         if(pressed_key == 'q')
  157.             game_is_running = false;
  158.  
  159.     }
  160.     return 0;
  161. }
Add Comment
Please, Sign In to add comment