1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
| #include "Partie.hpp"
#include <stdexcept>
#include "Bonus.hpp"
Partie::Partie()
{}
void Partie::initialisation()
{
for(int y = 0; y < 25; y++)
{
for(int x = 0; x < 25; x++)
{
TabBateauxJ1[x][y]=0 ;
TabBateauxJ2[x][y]=0;
TabTirJ2[x][y]='-';
TabTirJ1[x][y]='-';
}
}
}
void Partie::PlacementBateaux(int Tab [][25])
{
int Bateaux=2;
while(Bateaux>=2 && Bateaux<=5)
{
std::cout<<"Entrez une position pour le ";
switch(Bateaux)
{
case 2: std::cout<<"Torpilleur"<<std::endl;break;
case 3: std::cout<<"Destroyer"<<std::endl;break;
case 4: std::cout<<"Croiseur"<<std::endl;break;
case 5: std::cout<<"Porte-Avion"<<std::endl;break;
default: std::cout<<"erreur"<<std::endl;
}
//try
//{
std::cin>>SonX>>SonY;
// if(SonX<=0 || SonX>25 || SonY<=0 || SonY>25)
// throw(true);
//}
//catch(bool & e)
//{
// std::cout<<"Erreur veuillez entrer un chiffre entre 1 et 25"<<std::endl;
// std::cin>>SonX>>SonY;
//}
std::cout<<"Placement Horizontal(h) ou vertical(v) ?"<<std::endl;
std::cin>>SaDirection;
SaLongueur=0;
if (SaDirection=='h' || SaDirection=='H')
{
while(SaLongueur<Bateaux)
{
int Taille=Bateaux;
std::cout<<SonX<<";"<<SonY<<std::endl;
(Tab[SonX-1][SonY-1])=Taille; // probleme si le tableau vaut Tableau; [SonX-1][SonY-1]car un tableau commence �0
SonY++;
SaLongueur++;
}
}
if (SaDirection=='v' || SaDirection=='V')
{
while(SaLongueur<Bateaux)
{
int Taille=Bateaux;
std::cout<<SonX<<";"<<SonY<<std::endl;
(Tab[SonX-1][SonY-1])=Taille; // probleme si le tableau vaut Tableau; [SonX-1][SonY-1]car un tableau commence �0
SonX++;
SaLongueur++;
}
}
Bateaux++;
std::cout<<std::endl;
}
}
void Partie::affiche(std::string Joueur)
{
if(Joueur=="J1")
{
std::cout<<"Maps Joueurs 1"<<std::endl<<std::endl;
for(int i = 0; i < 25; i++)
{
for(int j = 0; j < 25; j++)
std::cout << TabBateauxJ1[i][j];
std::cout<<" ";
for(int j = 0; j < 25; j++)
std::cout << TabTirJ1[i][j];
std::cout << std::endl;
}
}
if(Joueur=="J2")
{
std::cout<<"Maps Joueurs 2"<<std::endl<<std::endl;
for(int i = 0; i < 25; i++)
{
for(int j = 0; j < 25; j++)
std::cout << TabBateauxJ2[i][j];
std::cout<<" ";
for(int j = 0; j < 25; j++)
std::cout<<TabTirJ2[i][j];
std::cout << std::endl;
}
}
}
void Partie::Tir(int TabJr [][25],char TabTir[][25], Joueurs J)
{
if(TabJr==TabBateauxJ2)
{
std::cout<<"Joueur 1 ";
}
else
{
std::cout<<"Joueur 2 ";
}
std::cout<<"Entrez la position ou vous souhaitez tirer"<<std::endl;
std::cin>>SonTirX>>SonTirY;
NumeroBateau=TabJr[SonTirX-1][SonTirY-1];
if(TabJr[SonTirX-1][SonTirY-1]<=5 && TabJr[SonTirX-1][SonTirY-1]>0)
{
std::cout<<"toucher"<<std::endl;
TabTir[SonTirX-1][SonTirY-1]='T';
std::cout<<"NumeroBateau";
std::cout<<NumeroBateau<<std::endl;
J.VerifCouler(NumeroBateau,J);
}
else
{
std::cout<<"a l'eau"<<std::endl;
TabTir[SonTirX-1][SonTirY-1]='E';
//Tir();
}
}
void Partie::execute()
{
initialisation();
std::cout<<"Joueur1 place bateau"<<std::endl;
PlacementBateaux(TabBateauxJ1);
affiche("J1");
PauseEfface();
std::cout<<"Joueur 2 place bateau"<<std::endl;
PlacementBateaux(TabBateauxJ2);
affiche("J2");
PauseEfface();
TourDeJeu();
std::cout<<std::endl;
}
void Partie::PauseEfface()
{
system("pause"); //met en pause en attente d'une touche
system("cls"); //efface le contenu de la console
}
void Partie::TourDeJeu()
{
//Bonus Bonus1;
//Bonus1.tirageBonus();
//J1.TestToucherJ1(); Tester es constructeur
//J2.TestToucherJ2(); Tester les constructeur
Tir(TabBateauxJ2,TabTirJ1,J2);
affiche("J1");
PauseEfface();
//Bonus1.tirageBonus();
Tir(TabBateauxJ1,TabTirJ2,J1);
affiche("J2");
PauseEfface();
TourDeJeu();
} |