Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cstdio>
- #include <unistd.h>
- using namespace std;
- class Machine{
- private:
- int production;
- int amount;
- int base_price;
- char buying_button;
- double price;
- string name;
- public:
- int getBaseProduction(){
- return production;
- }
- int getProduction(){
- return amount*production;
- }
- int getAmount(){
- return amount;
- }
- int getPrice(){
- return base_price;
- }
- char getBuyingChar(){
- return buying_button;
- }
- string getName(){
- return name;
- }
- bool canBuy(int money){
- return money>price;
- }
- void addNewMachine(){
- amount += 1;
- price = price * 1.1;
- //cout << " i kupilem!\n";
- }
- Machine(int a, char b, int c, string d){
- production = a;
- buying_button = b;
- base_price = c;
- amount = 0;
- price = base_price;
- name = d;
- //cout << "New machine object o nazwie " << name << endl;
- }
- };
- class Player{
- private:
- int money;
- vector < Machine > owned_machines;
- public:
- int getMoney(){
- return money;
- }
- void addMoney(int a){
- money += a;
- }
- int getProductionFromMachines(){
- int machines_production = 0;
- for(int i = 0; i < getMachineAmount();i++){
- machines_production += getMachineNr(i).getProduction();
- }
- return machines_production;
- }
- Player(int a){
- money = a;
- }
- void addMachine(int production, char buying_button, int base_price, string name){
- owned_machines.push_back(Machine(production,buying_button,base_price,name));
- }
- Machine getMachineNr(int a){
- return owned_machines[a];
- }
- int getMachineAmount(){
- return owned_machines.size();
- }
- void buyMachine(int nr_of_machine){
- //cout << "Kupuje";
- owned_machines[nr_of_machine].addNewMachine();
- //cout << "MAM " << owned_machines[nr_of_machine].getAmount();
- money -= owned_machines[nr_of_machine].getPrice();
- }
- };
- int main(){
- //deklaracja obiektów i zmiennych
- Player game_player(4);
- bool game_is_running = true;
- int pressed_keycode = 0;
- char pressed_key = 0;
- int number_of_while = 0;
- string font_normal = "\033[0m";
- string font_green = "\033[92m";
- string font_red = "\033[91m";
- string font_yellow = "\033[33m";
- string font_magenta = "\033[35m";
- string font_cyan = "\033[36m";
- //wstępna konfiguracja gry
- game_player.addMachine(1,'z',10,"Zielonka");
- game_player.addMachine(10,'x',200,"Stulejarz");
- game_player.addMachine(55,'c',1000,"Mirek");
- game_player.addMachine(120,'v',2137,"Różowy pasek");
- game_player.addMachine(1200,'b',15000,"Bordo");
- cout << "Mirko, theGame!\nKliknij, aby zacząć!"<< endl;
- //pętla gry
- while(game_is_running == true){
- pressed_keycode = getchar();
- pressed_key = pressed_keycode;
- cout << endl << font_red << "Czekaj!\n" << font_normal;
- sleep(1);
- game_player.addMoney(game_player.getProductionFromMachines());
- game_player.addMoney(1);
- // lets clear the entire screen
- cout << "\033[2J\033[1;1H";
- cout << "Posiadam " << font_green << game_player.getMoney() << font_normal << " plusów\n";
- //cout << pressed_key << endl << number_of_while << endl;
- for(int i = 0; i < game_player.getMachineAmount();i++){
- cout << font_magenta << "-----------------------------------------------\n" << font_normal;
- cout << game_player.getMachineNr(i).getName() << " kosztuje " << game_player.getMachineNr(i).getPrice() << "(" << game_player.getMachineNr(i).getBaseProduction() << " +/s)" << endl;
- cout << "Mam " << game_player.getMachineNr(i).getAmount() << " mirków produkujących " << game_player.getMachineNr(i).getProduction() << " na sekundę\n";
- cout << "Naduś " << font_yellow << game_player.getMachineNr(i).getBuyingChar() << font_normal << " aby zarejestrować nowe multikonto" << endl;
- if(pressed_key == game_player.getMachineNr(i).getBuyingChar()){
- if(game_player.getMachineNr(i).canBuy(game_player.getMoney()) == true){
- game_player.buyMachine(i);
- }
- }
- }
- cout << font_magenta << "-----------------------------------------------\n" << font_normal;
- cout << "Produkcja wynosi " << game_player.getProductionFromMachines() + 1 << endl;
- 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;
- number_of_while++;
- if(pressed_key == 'q')
- game_is_running = false;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment