Tutaj chodzi mi o 3 linie które zaznaczyłem w komentarzach dużymi literami. **Cout ** nie wyświetla napisu który zainicjalizowałem globalnie poprzez string, jednak kiedy używam char nie ma problemu z wyświetleniem. Tak z ciekawości zastanawiam się jaka może być tego przyczyna.
// ConsoleApplication45.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <locale>
#include <conio.h>
#include <cstdlib>
#include <time.h>
#include <windows.h>
using namespace std;
struct warior {string name; float attack; float hp;}; // DEKLARACJA
warior enemy[10]{ enemy[0] = { "Pucybut", 5.5, 113 } };
warior champion[10]{ champion[0] = { "aaa", 4, 125 } }; // INICJALIZACJA
int i, R_number;
float C_hp = 100, E_hp = 100, gold;
void battle();
int N_random(int& x);
void Crit_chance(int x, float& z );
int main()
{
setlocale(LC_ALL, "");
cout << champion[0].name << endl; // COUT NIE wyświetla "aaa"
cout << "Witaj w świecie łamanych kości i czaszek!\n";
cout << "Witaj na aranie!\n";
cout << "----------------------------------------------------\n";
wcout << L"Wpisz imię swojego wojownika(bez pl znaków): ";
cout << "\nTwój pierwszy przeciwnik to: " << enemy[0].name << endl;
battle();
Sleep(3000);
system("cls");
cout << C_hp << " i: " << E_hp;
cin.get();
cin.get();
return 0; // zrobić, a następnie zapętlić menu główne
}
void battle()
{
int choice;
while (C_hp >= 0 && E_hp >= 0)
{
cout << "\n1. Atakuj!\n";
cout << "2. Opuśc arenę\n\n";
cin >> choice;
switch (choice)
{
case 1:
N_random(R_number);
Crit_chance(R_number, E_hp);
C_hp = C_hp - enemy[0].attack;
break;
case 2:
cout << "Wyszedłeś z pola bitwy\n";
exit(0);
break;
}
cout << "Pozostałe życie " << champion[0].name << " to: " << C_hp << endl;
cout << "Pozostałe życie " << enemy[0].name << " to: " << E_hp << endl;
Sleep(1000);
if (E_hp <= 0)
{
cout << "Pokonałeś " << enemy[0].name << "!"<< endl;
}
if (C_hp <= 0)
{
cout << "Przegrałeś z: " << enemy[0].name;
cout << ". Wróć ponownie silniejszy." << endl;
}
// system("cls");
}
}
int N_random(int& x) // funkcja odpowiadająca za liczbę losową
{
srand(time(NULL));
x = rand() % 100 + 1; x = rand() % 100 + 1;
x = rand() % 100 + 1; x = rand() % 100 + 1;
x = rand() % 100 + 1; x = rand() % 100 + 1;
x = rand() % 100 + 1; x = rand() % 100 + 1;
x = rand() % 100 + 1; x = rand() % 100 + 1;
x = rand() % 100 + 1; x = rand() % 100 + 1;
x = rand() % 100 + 1; x = rand() % 100 + 1;
x = rand() % 100 + 1; x = rand() % 100 + 1;
x = rand() % 100 + 1; x = rand() % 100 + 1;
return x = rand() % 100 + 1;
}
void Crit_chance(int x, float& z )
{
if (x <= 20)
{
E_hp = E_hp - 5 * champion[0].attack;
cout << "Zadajesz obrażenia krytyczne!" << endl;
}
else
{
E_hp = E_hp - champion[0].attack;
}
cout << endl << x << endl;
}