-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSysteme.java
More file actions
154 lines (142 loc) · 4.64 KB
/
Systeme.java
File metadata and controls
154 lines (142 loc) · 4.64 KB
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
import java.io.*;
import java.util.Scanner;
public class Systeme {
private int lignePieceABouger;
private int colonnePieceABouger;
private int lignePiece;
private int colonnePiece;
private Echiquier e;
private Scanner s = new Scanner(System.in);
public Systeme()
{
System.out.println("Voulez-vous charger une partie ?");
String reponse = s.nextLine().toUpperCase();
if (reponse.equals("OUI") || reponse.equals("O")) charger();
else e = new Echiquier();
}
public Systeme(boolean b) {}
public void demandeJoueur()
{
boolean positionNonValide = true;
s = new Scanner(System.in);
while(positionNonValide)
{
System.out.println("Quel est la position de la pièce à jouer ? (si vous voulez quitter écrivez \"q\")");
String str = s.nextLine().toUpperCase();
if (!(str.isEmpty()))
{
char pc = str.charAt(0);
if (Character.toString(pc).equals("Q")) quitter();
if(str.length()>1)
{
this.lignePieceABouger = Character.getNumericValue(str.charAt(1))-1;
this.colonnePieceABouger = pc-65;
if(e.siPiecePresente(lignePieceABouger, colonnePieceABouger) && e.verifCouleur(lignePieceABouger, colonnePieceABouger))
{
System.out.println("Ou voulez-vous déplacer la pièce ?");
String strd = s.nextLine().toUpperCase();
if (!(strd.isEmpty())&& strd.length()>1)
{
char pcd = strd.charAt(0);
this.lignePiece = Character.getNumericValue(strd.charAt(1))-1;
this.colonnePiece = pcd-65;
}
if(lignePieceABouger==lignePiece && colonnePieceABouger==colonnePiece) System.out.println("Déplacement sur la même case \n");
else {
positionNonValide = !(bouger());
}
}
}
}
}
}
public static String Pro()
{
String str = "";
Scanner sc = new Scanner(System.in);
while(str.isEmpty())
{
System.out.println("Pion à promouvoir, choisir entre R: \"Reine\", C: \"Cavalier\", T: \"Tour\", F: \"Fou\"" );
str = sc.nextLine().toUpperCase();
}
return str;
}
public boolean bouger()
{
return e.bouger(lignePieceABouger,colonnePieceABouger,lignePiece,colonnePiece);
}
public void rafraichir()
{
System.out.println(e.affichage());
}
public void quitter()
{
System.out.println("Voulez-vous sauvegarder votre partie ? (Quitter sans sauvegarder signifierai un abandon)");
String reponse = s.nextLine().toUpperCase();
if (reponse.equals("OUI") || reponse.equals("O")) sauver();
s.close();
System.out.println("Fin du programme...");
System.exit(0);
}
public void sauver()
{
try
{
File fichier = new File("echeq.ser") ;
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichier)) ;
oos.writeObject(this.e);
System.out.println("Sauvegarde partie...");
oos.close();
}
catch(Exception e)
{
System.err.println(e);
}
}
public void charger()
{
try
{
File fichier = new File("echeqAuR.ser") ;
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fichier)) ;
Echiquier m = (Echiquier)ois.readObject();
this.e = m;
System.out.println("Chargement partie...");
ois.close();
}
catch (Exception e)
{
System.out.println("Sauvegarde non trouvé ou corrompu, création d'une nouvelle partie..");
this.e = new Echiquier();
}
}
public void couleur()
{
System.out.println("Au tour du joueur de pièces "+ e.getCouleur() + " de jouer");
}
public boolean echec()
{
return e.getEnEchec();
}
/*public boolean mat()
{
return e.verifMAT();
}
public boolean pat()
{
return e.verifPAT();
}*/
public static void main(String[] args)
{
Systeme s = new Systeme();
s.rafraichir();
while(true)
{
s.couleur();
//if(s.echec()) s.mat();
//if(s.pat()) s.quitter();
s.demandeJoueur();
s.rafraichir();
}
}
}