rosoladm Temat założony przez niniejszego użytkownika |
Projekt Wieloplikowy, Obiekty Globalne, Błędy Konsolidacji » 2013-11-01 10:30:07 Witam, Tworze gre wieloplikową, to jest dopiero początek platformy, dlateog zależy mi żeby napisać ją w kilku plikach ( będzie dużo edycji ) Podczas konsolidacji pojawia się problem ( załączony niżej log ), jak widzę jest to problem zmiennych, a raczej obiektów globalnych, poniżej zamieszczam kod wszystkich plików. Z góry dziękuję za pomoc, Pozdrawiam, Krystian g++ -c fun/main.cpp -o appo/main.o g++ -c fun/fun1.cpp -o appo/fun1.o g++ -c fun/maszt.cpp -o appo/maszt.o g++ -c fun/plansza.cpp -o appo/plansza.o g++ -c fun/statek.cpp -o appo/statek.o g++ appo/main.o appo/fun1.o appo/maszt.o appo/plansza.o appo/statek.o -o gra appo/fun1.o:(.bss+0x0): multiple definition of `Orzel' appo/main.o:(.bss+0x0): first defined here appo/fun1.o:(.bss+0x20): multiple definition of `Jastrzab' appo/main.o:(.bss+0x20): first defined here appo/fun1.o:(.bss+0x40): multiple definition of `Hawk' appo/main.o:(.bss+0x40): first defined here appo/fun1.o:(.bss+0x5c): multiple definition of `Eagle' appo/main.o:(.bss+0x5c): first defined here appo/maszt.o:(.bss+0x0): multiple definition of `Orzel' appo/main.o:(.bss+0x0): first defined here appo/maszt.o:(.bss+0x20): multiple definition of `Jastrzab' appo/main.o:(.bss+0x20): first defined here appo/maszt.o:(.bss+0x40): multiple definition of `Hawk' appo/main.o:(.bss+0x40): first defined here appo/maszt.o:(.bss+0x5c): multiple definition of `Eagle' appo/main.o:(.bss+0x5c): first defined here appo/plansza.o:(.bss+0x0): multiple definition of `Orzel' appo/main.o:(.bss+0x0): first defined here appo/plansza.o:(.bss+0x20): multiple definition of `Jastrzab' appo/main.o:(.bss+0x20): first defined here appo/plansza.o:(.bss+0x40): multiple definition of `Hawk' appo/main.o:(.bss+0x40): first defined here appo/plansza.o:(.bss+0x5c): multiple definition of `Eagle' appo/main.o:(.bss+0x5c): first defined here appo/statek.o:(.bss+0x0): multiple definition of `Orzel' appo/main.o:(.bss+0x0): first defined here appo/statek.o:(.bss+0x20): multiple definition of `Jastrzab' appo/main.o:(.bss+0x20): first defined here appo/statek.o:(.bss+0x40): multiple definition of `Hawk' appo/main.o:(.bss+0x40): first defined here appo/statek.o:(.bss+0x5c): multiple definition of `Eagle' appo/main.o:(.bss+0x5c): first defined here collect2: ld returned 1 exit status make: *** [gra] Błąd 1
funkcje.h #ifndef _FUNKCJE_H #define _FUNKCJE_H
#include <iostream> #include <iomanip> #include <cstdlib> #include <ctime>
using namespace std;
class plansza; class maszt; class statek; class pancernik; class torpedowiec;
class plansza { public: maszt *** wsk; plansza(); ~plansza(); void wyswietl(); };
class maszt { public: char stan; int typ; maszt() : stan( '.' ) , typ( 3 ) { } void wyswietl(); };
class statek { public: virtual bool CzyPlywam() { return true; }; virtual void buduj( int x, int y, plansza & NazwaPlanszy, bool pion ) { }; };
class pancernik : public statek { public: int iks, igrek; bool pionowy; maszt * tablica[ 4 ]; void buduj( int x, int y, plansza & NazwaPlanszy, bool pion ); bool CzyPlywam(); };
class torpedowiec : public statek { public: int iks, igrek; bool pionowy; maszt * tablica[ 3 ]; void buduj( int x, int y, plansza & NazwaPlanszy, bool pion ); bool CzyPlywam(); };
void Ruch( plansza & NazwaPlanszy, pancernik & okret, torpedowiec & torpeda ); int IlePlywa( int wyswietl ); #endif
zmienne.h #ifndef _ZMIENNE_H #define _ZMIENNE_H #include "funkcje.h"
pancernik Orzel, Jastrzab; torpedowiec Hawk, Eagle; const bool Linux = true; const bool Testowanie = false; #endif
main.cpp: #include "../lib/funkcje.h" #include "../lib/zmienne.h"
int main() { extern pancernik Orzel, Jastrzab; extern torpedowiec Hawk, Eagle; srand( time( NULL ) ); plansza statki; bool pion = rand() % 2; statek * wsk =& Orzel; ( * wsk ).buduj(( pion ) ?( rand() % 15 ) + 1 :( rand() % 12 ) + 1 ,( pion ) ?( rand() % 12 ) + 1 :( rand() % 15 ) + 1 , statki , pion ); pion = rand() % 2; int iks_, igrek_; do { iks_ =( pion ) ?( rand() % 15 ) + 1 :( rand() % 12 ) + 1; igrek_ =( pion ) ?( rand() % 12 ) + 1 :( rand() % 15 ) + 1; } while(( abs( iks_ - Orzel.iks ) < 4 ) ||( abs( igrek_ - Orzel.igrek ) < 4 ) ); wsk =& Jastrzab; ( * wsk ).buduj( iks_, igrek_, statki, pion ); pion = rand() % 2; do { iks_ =( pion ) ?( rand() % 15 ) + 1 :( rand() % 12 ) + 1; igrek_ =( pion ) ?( rand() % 12 ) + 1 :( rand() % 15 ) + 1; } while(( abs( iks_ - Orzel.iks ) < 3 || abs( iks_ - Jastrzab.iks ) < 3 ) ||( abs( igrek_ - Orzel.igrek ) < 3 || abs( igrek_ - Jastrzab.igrek ) < 3 ) ); wsk =& Hawk; ( * wsk ).buduj( iks_, igrek_, statki, pion ); pion = rand() % 2; do { iks_ =( pion ) ?( rand() % 15 ) + 1 :( rand() % 12 ) + 1; igrek_ =( pion ) ?( rand() % 12 ) + 1 :( rand() % 15 ) + 1; } while(( abs( iks_ - Orzel.iks ) < 3 &&( abs( igrek_ - Orzel.igrek ) < 3 ) ||( abs( iks_ - Jastrzab.iks ) < 3 && abs( igrek_ - Jastrzab.igrek ) < 3 ) ||( abs( iks_ - Hawk.iks ) < 2 ) && abs( igrek_ - Hawk.igrek ) < 3 ) ); wsk =& Eagle; ( * wsk ).buduj( iks_, igrek_, statki, pion ); statki.wyswietl(); int ile = 4; int IloscRuchow = 0; while( IlePlywa( 0 ) ) { IlePlywa( 1 ); Ruch( statki, Orzel, Hawk ); ++IloscRuchow; IlePlywa( 1 ); if( IlePlywa( 0 ) ) { Ruch( statki, Jastrzab, Eagle ); ++IloscRuchow; } } statki.wyswietl(); cout << "Brawo! Wszystkie zatopione!\n" << "Ilosc ruchow: " << IloscRuchow << "\n"; return 0; }
fun1.cpp #include "../lib/funkcje.h" #include "../lib/zmienne.h"
extern pancernik Orzel, Jastrzab; extern torpedowiec Hawk, Eagle;
int IlePlywa( int wyswietl ) { int ile = 0; statek * wsk[ 4 ] = { & Orzel, & Jastrzab, & Hawk, & Eagle }; for( int i = 0; i < 4; ++i ) if(( *( wsk[ i ] ) ).CzyPlywam() ) ile++; if( wyswietl ) cout << "Plywa jeszcze statkow: " << ile << endl; return ile; }
void Ruch( plansza & NazwaPlanszy, pancernik & okret, torpedowiec & torpeda ) { bool CzyZatopiony = false; int x, y; do { cout << "Podaj x: "; cin >> x; cout << "Podaj y: "; cin >> y; if( x > 16 || y > 16 || x < 0 || y < 0 ) { if( !x || !y ) exit( 0 ); NazwaPlanszy.wyswietl(); IlePlywa( 1 ); cout << "Zle wspolrzedne, podaj jeszcze raz!\n"; if( x == 1337 ) { Testowanie == true; NazwaPlanszy.wyswietl(); } } } while( x > 16 || y > 16 || x < 0 || y < 0 ); if( x == 0 || y == 0 ) exit( 0 ); char temp = NazwaPlanszy.wsk[ y - 1 ][ x - 1 ]->stan; switch( temp ) { case '.': NazwaPlanszy.wsk[ y - 1 ][ x - 1 ]->stan = char( 219 ); NazwaPlanszy.wsk[ y - 1 ][ x - 1 ]->typ = 4; break; case 'X': case 'o': NazwaPlanszy.wsk[ y - 1 ][ x - 1 ]->stan = 'o'; NazwaPlanszy.wsk[ y - 1 ][ x - 1 ]->typ = 1; break; } statek * wsk; wsk =& okret; if( okret.CzyPlywam() == false ) { for( int i = 1; i <= 4; i++ ) { ( okret.pionowy ) ? NazwaPlanszy.wsk[ okret.igrek + 4 - i ][ okret.iks ]->stan = '\\' : NazwaPlanszy.wsk[ okret.igrek ][ okret.iks + 4 - i ]->stan = '\\'; ( okret.pionowy ) ? NazwaPlanszy.wsk[ okret.igrek + 4 - i ][ okret.iks ]->typ = 2 : NazwaPlanszy.wsk[ okret.igrek ][ okret.iks + 4 - i ]->typ = 2; } } if( torpeda.CzyPlywam() == false ) { for( int i = 1; i <= 3; i++ ) { ( torpeda.pionowy ) ? NazwaPlanszy.wsk[ torpeda.igrek + 3 - i ][ torpeda.iks ]->stan = '\\' : NazwaPlanszy.wsk[ torpeda.igrek ][ torpeda.iks + 3 - i ]->stan = '\\'; ( torpeda.pionowy ) ? NazwaPlanszy.wsk[ torpeda.igrek + 3 - i ][ torpeda.iks ]->typ = 2 : NazwaPlanszy.wsk[ torpeda.igrek ][ torpeda.iks + 3 - i ]->typ = 2; } } NazwaPlanszy.wyswietl(); }
maszt.cpp #include "../lib/funkcje.h" #include "../lib/zmienne.h"
extern pancernik Orzel, Jastrzab; extern torpedowiec Hawk, Eagle;
void maszt::wyswietl() { if( Testowanie ) cout << stan << " "; else ( stan == 'X' ) ? cout << ". " : cout << stan << " "; }
plansza.cpp #include "../lib/funkcje.h" #include "../lib/zmienne.h"
extern pancernik Orzel, Jastrzab; extern torpedowiec Hawk, Eagle;
plansza::plansza() { wsk = new maszt **[ 18 ]; for( int i = 0; i < 18; i++ ) { wsk[ i ] = new maszt *[ 18 ]; for( int j = 0; j < 18; j++ ) { wsk[ i ][ j ] = new maszt(); } } }
plansza::~plansza() { cout << "Plansza kaput!\n"; for( int i = 0; i < 18; i++ ) { for( int j = 0; j < 18; j++ ) { delete wsk[ i ][ j ]; } delete wsk[ i ]; } delete wsk; if( !Linux ) system( "pause" ); }
void plansza::wyswietl() { if( Linux ) system( "clear" ); else system( "cls" ); for( int i = 1; i <= 16; i++ ) { cout << setw( 2 ) << i << " "; for( int j = 1; j <= 16; j++ ) wsk[ i - 1 ][ j - 1 ]->wyswietl(); switch( i ) { case 1: cout << "Legenda: "; break; case 2: cout << " . Pole puste nieostrzelane"; break; case 3: cout << " / Maszt zatopiony"; break; case 4: cout << " o Maszt ostrzelany"; break; case 5: cout << " " << char( 219 ) << " Pudlo"; break; case 6: cout << " x=1337 - cheat ;-)"; break; case 8: cout << " 0 - wyjscie z programu"; break; } cout << endl; } cout << " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n\n"; }
statek.cpp #include "../lib/funkcje.h" #include "../lib/zmienne.h"
extern pancernik Orzel, Jastrzab; extern torpedowiec Hawk, Eagle;
void pancernik::buduj( int x, int y, plansza & NazwaPlanszy, bool pion ) { iks = x; igrek = y; pionowy = pion; for( int i = 0; i < 4; i++ ) { ( pion ) ? tablica[ i ] = NazwaPlanszy.wsk[ y + i ][ x ] : tablica[ i ] = NazwaPlanszy.wsk[ y ][ x + i ]; ( pion ) ? NazwaPlanszy.wsk[ y + i ][ x ]->stan = 'X' : NazwaPlanszy.wsk[ y ][ x + i ]->stan = 'X'; ( pion ) ? NazwaPlanszy.wsk[ y + i ][ x ]->typ = 0 : NazwaPlanszy.wsk[ y ][ x + i ]->typ = 0; } }
bool pancernik::CzyPlywam() { int Good = 4; for( int i = 0; i < 4; i++ ) { if( tablica[ i ]->typ == 1 || tablica[ i ]->typ == 2 ) Good--; } if( Good > 0 ) return true; return false; }
void torpedowiec::buduj( int x, int y, plansza & NazwaPlanszy, bool pion ) { iks = x; igrek = y; pionowy = pion; for( int i = 0; i < 3; i++ ) { ( pion ) ? tablica[ i ] = NazwaPlanszy.wsk[ y + i ][ x ] : tablica[ i ] = NazwaPlanszy.wsk[ y ][ x + i ]; ( pion ) ? NazwaPlanszy.wsk[ y + i ][ x ]->typ = 0 : NazwaPlanszy.wsk[ y ][ x + i ]->typ = 0; ( pion ) ? NazwaPlanszy.wsk[ y + i ][ x ]->stan = 'X' : NazwaPlanszy.wsk[ y ][ x + i ]->stan = 'X'; } }
bool torpedowiec::CzyPlywam() { int Good = 3; for( int i = 0; i < 3; i++ ) { if( tablica[ i ]->typ == 1 || tablica[ i ]->typ == 2 ) Good--; } if( Good > 0 ) return true; return false; }
|