Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include "character.h"
- #include "enemy.h"
- #include "game.h"
- using namespace std;
- // Change Color
- int *switchColor(int choice, int *array) {
- switch (choice) {
- case 1:
- array[0] = RED;
- array[1] = GREEN;
- array[2] = GREEN;
- array[3] = GREEN;
- array[4] = GREEN;
- break;
- case 2:
- array[0] = GREEN;
- array[1] = RED;
- array[2] = GREEN;
- array[3] = GREEN;
- array[4] = GREEN;
- break;
- case 3:
- array[0] = GREEN;
- array[1] = GREEN;
- array[2] = RED;
- array[3] = GREEN;
- array[4] = GREEN;
- break;
- case 4:
- array[0] = GREEN;
- array[1] = GREEN;
- array[2] = GREEN;
- array[3] = RED;
- array[4] = GREEN;
- break;
- case 5:
- array[0] = GREEN;
- array[1] = GREEN;
- array[2] = GREEN;
- array[3] = GREEN;
- array[4] = RED;
- break;
- }
- return array;
- }
- // Hide Cursor
- void ShowConsoleCursor(bool showFlag)
- {
- HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_CURSOR_INFO cursorInfo;
- GetConsoleCursorInfo(out, &cursorInfo);
- cursorInfo.bVisible = showFlag; // set the cursor visibility
- SetConsoleCursorInfo(out, &cursorInfo);
- }
- // Duel
- int Duel(Character *mainCharacter, Character *mob, HANDLE *hConsole) {
- SetConsoleTextAttribute(*hConsole, GREEN);
- cout << "Napotykasz ";
- SetConsoleTextAttribute(*hConsole, RED);
- cout << mob->name;
- SetConsoleTextAttribute(*hConsole, GREEN);
- cout << "poziomu: ";
- SetConsoleTextAttribute(*hConsole, RED);
- cout << mob->level;
- SetConsoleTextAttribute(*hConsole, GREEN);
- cout << "!" << endl;
- while (mainCharacter->alive == true && mob->alive == true) {
- if (mainCharacter->level >= mob->level) {
- mainCharacter->attack(mob);
- }
- mob->attack(mainCharacter);
- }
- if (mainCharacter->alive == false) {
- mainCharacter->~Character;
- cout << "Niestety przegrywasz ten pojedynek!" << endl;
- SetConsoleTextAttribute(*hConsole, RED);
- cout << "Koniec Gry!" << endl;
- return 1;
- }
- else if (mob->alive == false) {
- SetConsoleTextAttribute(*hConsole, GREEN);
- cout << "Pokonujesz " << mob->name << "!" << endl;
- if (mob->equipment.size > 1) {
- cout << "Otrzymujesz: ";
- cout << mob->equipment[1]->name;
- mainCharacter->stash(mob->equipment[1]);
- }
- //mob->~Character;
- }
- return 0;
- }
- // Game
- int Game(bool *loop, int *choice, int *col, HANDLE *hConsole, string *name, Character *mainCharacter) {
- char c;
- Item *current;
- int amount;
- bool choosed = false;
- unsigned floor = 1;
- *loop = true;
- *choice = 1;
- while (*loop == true) {
- system("CLS");
- switchColor(*choice, col);
- SetConsoleTextAttribute(*hConsole, GREEN);
- cout << "===============" << endl;
- SetConsoleTextAttribute(*hConsole, RED);
- cout << "Pietro: " << floor << endl;
- SetConsoleTextAttribute(*hConsole, GREEN);
- cout << "===============" << endl;
- SetConsoleTextAttribute(*hConsole, col[0]);
- cout << "Idz na przod" << endl;
- SetConsoleTextAttribute(*hConsole, col[1]);
- cout << "Ekwipunek" << endl;
- SetConsoleTextAttribute(*hConsole, col[2]);
- cout << "Techniki" << endl;
- SetConsoleTextAttribute(*hConsole, col[3]);
- cout << "Sklep" << endl;
- SetConsoleTextAttribute(*hConsole, col[4]);
- cout << "Zapisz i wyjdz z gry" << endl;
- SetConsoleTextAttribute(*hConsole, GREEN);
- switch ((c = _getch())) {
- case KEY_DOWN:
- if (*choice != 5) {
- *choice += 1;
- }
- break;
- case KEY_UP:
- if (*choice != 1) {
- *choice -= 1;
- }
- break;
- case KEY_ENTER:
- choosed = true;
- break;
- }
- if (choosed == true) {
- switch (*choice) {
- case 1:
- // Wygeneruj moba, sekwencja walki, zwolnij miejsce po ubiciu moba lub wyswietl koniec gry przy dedzie
- if (floor < 5) {
- Zombie mob;
- if (Duel(mainCharacter, &mob, hConsole) == 1) {
- *loop = false;
- }
- }
- break;
- case 2:
- // Wyswietl ekwipunek
- system("CLS");
- amount = mainCharacter->equipment.size();
- cout << "Liczba przedmiotow w ekwipunku: " << amount << endl;
- for (int i = 1; i <= amount; i++) {
- current = mainCharacter->equipment[i-1];
- cout << "================" << endl;
- if (current->legendary == true) {
- SetConsoleTextAttribute(*hConsole, GOLD);
- }
- else {
- SetConsoleTextAttribute(*hConsole, RED);
- }
- cout << current->name << endl;
- SetConsoleTextAttribute(*hConsole, GREEN);
- cout << current->desc << endl;
- SetConsoleTextAttribute(*hConsole, AQUA);
- cout << "Atak: " << current->attc << endl;
- cout << "Zdrowie: " << current->health << endl;
- cout << "Mana: " << current->mana << endl;
- cout << "Szczescie: " << current->luck << endl;
- cout << "Obureczny: ";
- if (current->twoHanded == true) {
- cout << "tak" << endl;
- }
- else {
- cout << "nie" << endl;
- }
- SetConsoleTextAttribute(*hConsole, GREEN);
- cout << "================" << endl;
- }
- cout << "Wcisnij ENTER aby wrocic" << endl;
- while (1) {
- if ((c = _getch()) == KEY_ENTER) {
- choosed = false;
- break;
- }
- }
- break;
- case 3:
- // Techniki
- break;
- case 4:
- // SKlep
- break;
- case 5:
- // Zapisz i wyjdz
- *loop = false;
- exit(1);
- break;
- }
- }
- }
- return 0;
- }
- // New Game
- int newGame() {
- string name;
- HANDLE hConsole;
- int choice = 1, col[5];
- char c;
- bool loop = true;
- ShowConsoleCursor(false);
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- // Class choice menu loop
- while(loop == true) {
- system("CLS");
- switchColor(choice,col);
- SetConsoleTextAttribute(hConsole, GREEN);
- cout << ":::::Wybierz swoja klase:::::" << endl;
- cout << "=============================" << endl;
- SetConsoleTextAttribute(hConsole, col[0]);
- cout << "Barbarzynca ";
- SetConsoleTextAttribute(hConsole, col[1]);
- cout << " Mag" << endl;
- SetConsoleTextAttribute(hConsole, GREEN);
- switch((c = _getch())) {
- case KEY_RIGHT:
- if (choice != 2) {
- choice++;
- }
- break;
- case KEY_LEFT:
- if (choice != 1) {
- choice--;
- }
- break;
- case KEY_ENTER:
- loop = false;
- break;
- }
- }
- // Character name
- system("CLS");
- cout << "===========================" << endl;
- cout << "Nadaj nazwe swojej postaci!" << endl;
- cout << "===========================" << endl;
- ShowConsoleCursor(true);
- SetConsoleTextAttribute(hConsole, RED);
- cin >> name;
- SetConsoleTextAttribute(hConsole, GREEN);
- system("CLS");
- cout << "Startuje..." << endl;
- // Barbarian
- if (choice == 1) {
- Barbarian mainCharacter;
- mainCharacter.name = name;
- Game(&loop, &choice, col, &hConsole, &name, &mainCharacter);
- }
- // Mage
- if (choice == 2) {
- Mage mainCharacter;
- mainCharacter.name = name;
- Game(&loop, &choice, col, &hConsole, &name, &mainCharacter);
- }
- return 0;
- }
- // Main Menu
- int main_menu() {
- HANDLE hConsole;
- int col[3];
- int choice = 1;
- int input;
- ShowConsoleCursor(false);
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- while (1) {
- switchColor(choice,col);
- SetConsoleTextAttribute(hConsole, GREEN);
- system("CLS");
- cout << ".....:::::<Insert_title> The Game:::::....." << endl;
- cout << "===========================================" << endl;
- SetConsoleTextAttribute(hConsole, col[0]);
- cout << "Nowa Gra" << endl;
- SetConsoleTextAttribute(hConsole, col[1]);
- cout << "Wczytaj ostatni zapis" << endl;
- SetConsoleTextAttribute(hConsole, col[2]);
- cout << "Wyjdz z gry" << endl;
- SetConsoleTextAttribute(hConsole, GREEN);
- switch((input = _getch())) {
- case KEY_DOWN:
- //cout << "KEY_DOWN" << endl;
- if (choice != 3) {
- choice++;
- }
- break;
- case KEY_UP:
- //cout << "KEY_UP" << endl;
- if (choice != 1) {
- choice--;
- }
- break;
- case KEY_ENTER:
- switch (choice) {
- case 1:
- newGame();
- break;
- case 2:
- //loadGame();
- break;
- case 3:
- exit(1);
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement