Jacahehe Temat założony przez niniejszego użytkownika |
[SFML] Niepasujace stringi » 2015-07-24 12:18:26 Witam! Mam taki mały kłopot, mianowicie szaleją mi strasznie napisy, w ogole nie pokazują zmiennych które mają tylko jakies losowe liczby. Probowalem na milion sposobow, ale jeszcze nie znalazlem tego wlasciwego. Chodzi o zmienna sdonemoney i sdonedepositmoney. deposit.cpp: #include "main_menu.hpp" #include "button_class.hpp" #include "char_card.hpp" #include "game_menu.hpp" #include <SFML/Graphics.hpp> #include <SFML/System.hpp> #include <string> #include "hero.hpp" #include "deposit.hpp" #include <sstream> #include <iostream>
using namespace std;
void fdeposit( sf::Font font, sf::RenderWindow & window, bool & DepositOpenB, bool & MainMenuOpenB, bool & GameMenuOpenB, sf::Texture & TexButtonOn, sf::Texture & TexButtonOff, int & VM_x, int & VM_y ) { sf::Texture TexBackground; TexBackground.loadFromFile( "data/graphics/Background.png" ); sf::Texture TexDeposit; TexDeposit.loadFromFile( "data/graphics/deposit.png" ); sf::Sprite BackgroundSpr; BackgroundSpr.setTexture( TexBackground ); sf::Sprite DepositSpr; DepositSpr.setTexture( TexDeposit ); DepositSpr.setPosition( 0.21 * VM_x, 0.05 * VM_y ); button dp10; button dp100; button dp1000; button dp10000; button dp100000; button dp1000000; button wt10; button wt100; button wt1000; button wt10000; button wt100000; button wt1000000; button wtall; button exit_to_menu; long long newherodepositmoney = herodepositmoney; long long newheromoney = heromoney; sf::Text tmoney; tmoney.setFont( font ); stringstream ssmoney; string smoney; string sdonemoney; ssmoney << newheromoney; ssmoney >> smoney; sdonemoney = "Twoje pieniadze: " + smoney; tmoney.setColor( sf::Color::Black ); tmoney.setCharacterSize( 50 ); tmoney.setStyle( sf::Text::Bold ); tmoney.setPosition( 0.1 * VM_x, 0.75 * VM_y ); sf::Text tdepositmoney; tdepositmoney.setFont( font ); stringstream ssdepositmoney; string sdepositmoney; string sdonedepositmoney; ssdepositmoney << newherodepositmoney; ssdepositmoney >> sdepositmoney; sdonedepositmoney = "Pieniadze w depozycie: " + sdepositmoney; tdepositmoney.setString( sdonedepositmoney ); tdepositmoney.setColor( sf::Color::Black ); tdepositmoney.setCharacterSize( 50 ); tdepositmoney.setStyle( sf::Text::Bold ); tdepositmoney.setPosition( 0.1 * VM_x, 0.81 * VM_y ); sf::Text tdepositinfo; tdepositinfo.setFont( font ); tdepositinfo.setString( L"Każdego dnia naliczane jest 0,05% premii. (Min. 1000 monet)" ); tdepositinfo.setColor( sf::Color::Black ); tdepositinfo.setCharacterSize( 29 ); tdepositinfo.setStyle( sf::Text::Bold ); tdepositinfo.setPosition( 0.048 * VM_x, 0.7 * VM_y ); sf::Text tnomoney; tnomoney.setFont( font ); tnomoney.setString( L"Nie masz tyle pieniedzy!" ); tnomoney.setColor( sf::Color::Black ); tnomoney.setCharacterSize( 29 ); tnomoney.setStyle( sf::Text::Bold ); tnomoney.setPosition( 0.355 * VM_x, 0.04 * VM_y ); sf::Text tdepnomoney; tdepnomoney.setFont( font ); tdepnomoney.setString( L"Nie masz tyle pieniedzy!" ); tdepnomoney.setColor( sf::Color::Black ); tdepnomoney.setCharacterSize( 29 ); tdepnomoney.setStyle( sf::Text::Bold ); tdepnomoney.setPosition( 0.21 * VM_x, 0.005 * VM_y ); bool bnomoney = false; bool bnodepmoney = false; int mouse_x; int mouse_y; do { mouse_x = sf::Mouse::getPosition( window ).x; mouse_y = sf::Mouse::getPosition( window ).y; window.clear(); window.draw( BackgroundSpr ); window.draw( DepositSpr ); window.draw( tdepositinfo ); dp10.place_button( L"Wpłać 10", 0.15, 0.1, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); dp100.place_button( L"Wpłać 100", 0.15, 0.2, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); dp1000.place_button( L"Wpłać 1000", 0.15, 0.3, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); dp10000.place_button( L"Wpłać 10000", 0.15, 0.4, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); dp100000.place_button( L"Wpłać 100000", 0.15, 0.5, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); dp1000000.place_button( L"Wpłać 1000000", 0.15, 0.6, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); wt10.place_button( L"Wypłać 10", 0.86, 0.1, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); wt100.place_button( L"Wypłać 100", 0.86, 0.2, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); wt1000.place_button( L"Wypłać 1000", 0.86, 0.3, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); wt10000.place_button( L"Wypłać 10000", 0.86, 0.4, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); wt100000.place_button( L"Wypłać 100000", 0.86, 0.5, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); wt1000000.place_button( L"Wypłać 1000000", 0.86, 0.6, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); wtall.place_button( L"Wypłać wszystko", 0.86, 0.7, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); exit_to_menu.place_button( L"Powrót do miasta", 0.5, 0.92, VM_x, VM_y, TexButtonOn, TexButtonOff, window, font ); if( dp10.BoolButtonOnOff == true && sf::Mouse::isButtonPressed( sf::Mouse::Left ) ) { if( newheromoney < 10 ) bnomoney = true; if( newheromoney >= 10 ) { newherodepositmoney = newherodepositmoney + 10; newheromoney = newheromoney - 10; bnomoney = false; bnodepmoney = false; smoney.erase(); ssmoney << newheromoney; ssmoney >> smoney; sdonemoney.erase(); sdonemoney = "Twoje pieniadze: " + smoney; ssdepositmoney << newherodepositmoney; ssdepositmoney >> sdepositmoney; sdonedepositmoney.erase(); sdonedepositmoney = "Pieniadze w depozycie: " + sdepositmoney; tdepositmoney.setString( sdonedepositmoney ); } } if( bnomoney == true ) window.draw( tnomoney ); if( bnodepmoney == true ) window.draw( tdepnomoney ); if( exit_to_menu.BoolButtonOnOff == true && sf::Mouse::isButtonPressed( sf::Mouse::Left ) ) { DepositOpenB = false; GameMenuOpenB = true; heromoney = newheromoney; herodepositmoney = newherodepositmoney; game_menu( font, window, MainMenuOpenB, GameMenuOpenB, TexButtonOn, TexButtonOff, VM_x, VM_y ); } tmoney.setString( sdonemoney ); window.draw( tdepositmoney ); window.draw( tmoney ); window.display(); } while( DepositOpenB == true ); }
hero.hpp: #ifndef hero_hpp #define hero_hpp #include <SFML/Graphics.hpp> #include <string>
extern long long heromoney; extern long long heroexp; extern short heromovepoint; extern short heromovepointMAX; extern short heroHP; extern short herolvl; extern short herolvlpoints; extern short heroMaxHP; extern short heroHP; extern short heroatt; extern short herodamin; extern short herodamax; extern short herodef; extern short heroagi; extern short heroluc;
extern long long herodepositmoney;
#endif
PS. Wiem ze zmienne globalne to zlo, ale je tez chce umiec poprawnie uzywac, stad wlasnie pomysl na nie :) |