// Méthode appelée après un tir, ou bien après un placement de bateau. Elle doit être utilisée plutôt que le set(EtatBateau) // car elle donne le symbole à afficher sur la grille. public void ChangerEtat(EtatCase _Etat) { Etat = _Etat; switch (Etat) { case EtatCase.Eau: Symbole = "-"; break; case EtatCase.TirRate: Symbole = "o"; break; case EtatCase.Bateau: Symbole = "s"; break; case EtatCase.BateauTouche: Symbole = "X"; break; case EtatCase.Coulé: Symbole = "#"; break; case EtatCase.Inaccessible: Symbole = " "; break; case EtatCase.EauInaccessible: Symbole = "-"; break; } }
private static bool Jeuxgagnant(EtatCase etatCase) { //Cas d'une ligne for (int ligne = 0; ligne < 3; ligne++) { if (grille[ligne, 0] == etatCase && grille[ligne, 1] == etatCase && grille[ligne, 2] == etatCase) { return(true); } } //Cas d'une colone for (int colonne = 0; colonne < 3; colonne++) { if (grille[colonne, 0] == etatCase && grille[colonne, 1] == etatCase && grille[colonne, 2] == etatCase) { return(true); } } //Cas des diagonales if (grille[0, 0] == etatCase && grille[1, 1] == etatCase && grille[2, 2] == etatCase) { return(true); } if (grille[2, 0] == etatCase && grille[1, 1] == etatCase && grille[0, 2] == etatCase) { return(true); } //par defaut on a pas gagné return(false); }
public bool IsPlayable(int column, int line, bool isWhite) { //1. Verify if the tile is empty ! if (theBoard[column, line] != (int)EtatCase.Empty) { return(false); } //2. Verify if at least one adjacent tile has an opponent tile EtatCase opponent = isWhite ? EtatCase.Black : EtatCase.White; EtatCase ownColor = (!isWhite) ? EtatCase.Black : EtatCase.White; int c = column, l = line; bool playable = false; List <Tuple <int, int, int> > catchDirections = new List <Tuple <int, int, int> >(); for (int dLine = -1; dLine <= 1; dLine++) { for (int dCol = -1; dCol <= 1; dCol++) { c = column + dCol; l = line + dLine; if ((c < BOARDSIZE_X) && (c >= 0) && (l < BOARDSIZE_Y) && (l >= 0) && (theBoard[c, l] == (int)opponent)) // Verify if there is a friendly tile to "pinch" and return ennemy tiles in this direction { int counter = 0; while (((c + dCol) < BOARDSIZE_X) && (c + dCol >= 0) && ((l + dLine) < BOARDSIZE_Y) && ((l + dLine >= 0))) { c += dCol; l += dLine; counter++; if (theBoard[c, l] == (int)ownColor) { playable = true; break; } else if (theBoard[c, l] == (int)opponent) { continue; } else if (theBoard[c, l] == (int)EtatCase.Empty) { break; //empty slot ends the search } } } } } return(playable); }
public bool PlayMove(int column, int line, bool isWhite) { //0. Verify if indices are valid if ((column < 0) || (column >= BOARDSIZE_X) || (line < 0) || (line >= BOARDSIZE_Y)) { return(false); } //1. Verify if it is playable if (IsPlayable(column, line, isWhite) == false) { return(false); } //2. Create a list of directions {dx,dy,length} where tiles are flipped int c = column, l = line; bool playable = false; EtatCase opponent = isWhite ? EtatCase.Black : EtatCase.White; EtatCase ownColor = (!isWhite) ? EtatCase.Black : EtatCase.White; List <Tuple <int, int, int> > catchDirections = new List <Tuple <int, int, int> >(); for (int dLine = -1; dLine <= 1; dLine++) { for (int dCol = -1; dCol <= 1; dCol++) { c = column + dCol; l = line + dLine; if ((c < BOARDSIZE_X) && (c >= 0) && (l < BOARDSIZE_Y) && (l >= 0) && (theBoard[c, l] == (int)opponent)) // Verify if there is a friendly tile to "pinch" and return ennemy tiles in this direction { int counter = 0; while (((c + dCol) < BOARDSIZE_X) && (c + dCol >= 0) && ((l + dLine) < BOARDSIZE_Y) && ((l + dLine >= 0)) && (theBoard[c, l] == (int)opponent)) // pour éviter les trous { c += dCol; l += dLine; counter++; if (theBoard[c, l] == (int)ownColor) { playable = true; theBoard[column, line] = (int)ownColor; catchDirections.Add(new Tuple <int, int, int>(dCol, dLine, counter)); } } } } } // 3. Flip ennemy tiles foreach (var v in catchDirections) { int counter = 0; l = line; c = column; while (counter++ < v.Item3) { c += v.Item1; l += v.Item2; theBoard[c, l] = (int)ownColor; } } //Console.WriteLine("CATCH DIRECTIONS:" + catchDirections.Count); computeScore(); return(playable); }
public void ChangerEtatCase(EtatCase nouvEtat, int x, int y) { tableauCases[x, y].SetEtat(nouvEtat); }
public void SetEtat(EtatCase etat) { this.etat = etat; }
public Case(EtatCase etat, object gameObject) { this.etat = etat; contenuCase = gameObject; }
public Case(EtatCase etatCase) { etat = etatCase; }
public Case() { etat = EtatCase.Empty; }