public void SaveState(PuppetModel.Colour colour) { CreateDirs(); try { string content = ""; for (int x = 0; x < puppets.GetLength(0); x++) { for (int y = 0; y < puppets.GetLength(1); y++) { if (puppets[x, y] != null) { content = puppets[x, y].Color.ToString() + Constants.space + puppets[x, y].Typ.ToString() + Constants.space + x.ToString() + Constants.space + y.ToString() + Environment.NewLine; File.AppendAllText(path, content); } } } File.AppendAllText(path, colour.ToString()); FileInfo fInfo = new FileInfo(path) { IsReadOnly = true }; } catch (Exception e) { FileAlreadyExistsMessage(e); return; } }
public bool Turn(PuppetModel.Colour colour) { List <Position[]> possibleHits = SeekPuppetToHit(colour); List <Position[]> possibleMoves = SeekPuppetToMove(colour); Random r = new Random(); if (possibleHits.Count == 0) { if (possibleMoves.Count == 0) { return(false); } else { Position[] actMove = possibleMoves[r.Next(possibleMoves.Count - 1)]; Move(actMove[0], actMove[1], colour); } } else { Position[] actHit = possibleHits[r.Next(possibleHits.Count - 1)]; Hit(actHit[0], actHit[1], colour); } return(true); }
public bool Turn(PuppetModel.Colour colour, Position from, Position to) { Position[] poses = { from, to }; List <Position[]> possibleHits = SeekPuppetToHit(colour); List <Position[]> possibleMoves = SeekPuppetToMove(colour); if (possibleHits.Any(x => (x[0].x == from.x && x[0].y == from.y) && (x[1].x == to.x && x[1].y == to.y))) { Hit(from, to, colour); return(true); } else if (possibleMoves.Any(x => (x[0].x == from.x && x[0].y == from.y) && (x[1].x == to.x && x[1].y == to.y))) { Move(from, to, colour); return(true); } else if (possibleMoves.Contains(poses)) { Move(from, to, colour); return(true); } else { return(false); } }
protected bool PuppetIsExist(Position pos, PuppetModel.Colour colour)//az adott koordinátájú mezőn adott színű bábú szerepel-e { if ((puppets[pos.x, pos.y] != null) && puppets[pos.x, pos.y].Color == colour) { return(true); } return(false); }
protected PuppetModel.Colour NegateColour(PuppetModel.Colour colour) { if (colour == PuppetModel.Colour.Blue) { return(PuppetModel.Colour.Red); } return(PuppetModel.Colour.Blue); }
public void ManualTurn(Position from, Position to) { if (!manualPlayControl.Turn(nextPlayer, from, to)) { view.ShowError(Constants.invalidLepes); view.WaitForTurn(); } else { nextPlayer = NegateColour(nextPlayer); Start(); } }
protected void Move(Position from, Position to, PuppetModel.Colour colour) { puppets[to.x, to.y] = puppets[from.x, from.y]; //bábú áthelyezése puppets[from.x, from.y] = null; //bábú levétele if (colour == PuppetModel.Colour.Blue && to.x == 0) { puppets[to.x, to.y].Typ = PuppetModel.SimpleOrDama.Dama; } if (colour == PuppetModel.Colour.Red && to.x == 7) { puppets[to.x, to.y].Typ = PuppetModel.SimpleOrDama.Dama; } //View.DisplayTable(puppets); }
protected bool CanMove(Position from, Position to, PuppetModel.Colour colour) { try { PuppetModel freeSpace = puppets[to.x, to.y]; if (freeSpace == null) { return(true); } } catch (Exception) { } return(false); }
/// <summary> /// Handles manual and computer turn, manual->WaitForTurn(); computer->computerPlayControl.Turn(nextPlayer); /// </summary> public void Turn() { if (nextPlayer == PuppetModel.Colour.Blue) //Manual { view.WaitForTurn(); } else //Computer { if (computerPlayControl.Turn(nextPlayer)) { nextPlayer = NegateColour(nextPlayer); } Start(); } }
/// <summary> /// Is valid hit /// </summary> /// <param name="fromX">from coordinate</param> /// <param name="fromY">from coordinate</param> /// <param name="xdiff">up or down direction</param> /// <param name="colour">puppet colour</param> /// <param name="isRight">right or left</param> /// <returns>returns true if the hit is valid, false if not</returns> protected bool CanHit(Position from, Position to, PuppetModel.Colour colour) { try { PuppetModel enemy = puppets[(from.x + to.x) / 2, (from.y + to.y) / 2]; PuppetModel freeSpace = puppets[to.x, to.y]; if (enemy.Color == NegateColour(colour) && freeSpace == null) { return(true); } } catch (Exception) { } return(false); }
protected List <Position> PossibleMove(Position from, PuppetModel.Colour colour) { List <Position> possibleMoves = new List <Position>(); int length = puppets[from.x, from.y].Typ == PuppetModel.SimpleOrDama.Simple ? 2 : 4; //dáma 4 lehetőséget vizsgál, simple 2-t int xdiff = colour == PuppetModel.Colour.Blue ? 1 : -1; //kék előre piros hátra Position to; for (int i = 0; i < length; i++) { if (i == 2) { xdiff *= -1;//dáma } to = CalculateToCoordinatesMove(from, xdiff, i % 2 == 0); if (CanMove(from, to, colour)) { possibleMoves.Add(to); } } return(possibleMoves); }
protected List <Position> PossibleHit(Position from, PuppetModel.Colour colour) { List <Position> PossibleHits = new List <Position>(); int xdiff = colour == PuppetModel.Colour.Blue ? 1 : -1; Position to; int length = puppets[from.x, from.y].Typ == PuppetModel.SimpleOrDama.Simple ? 2 : 4; for (int i = 0; i < length; i++) { if (i == 2) { xdiff *= -1; } to = CalculateToCoordinatesHit(from, xdiff, i % 2 == 0); if (CanHit(from, to, colour)) { PossibleHits.Add(to); } } return(PossibleHits); }
protected List <Position[]> SeekPuppetToHit(PuppetModel.Colour colour) { List <Position[]> possibleHits = new List <Position[]>(); for (int x = 0; x < puppets.GetLength(0); x++) { for (int y = 0; y < puppets.GetLength(1); y++) { Position fromPos = new Position(x, y); if (PuppetIsExist(fromPos, colour)) { List <Position> allToCoordinatesHit = PossibleHit(fromPos, colour); foreach (var toPos in allToCoordinatesHit) { possibleHits.Add(new Position[2] { fromPos, toPos }); } } } } return(possibleHits); }
public void ComputerPlay(PuppetModel.Colour colour) { throw new NotImplementedException(); }
public void SaveState(PuppetModel.Colour colour) { throw new NotImplementedException(); }