private void pictureBox_MouseDown(object sender, MouseEventArgs e) //---------------------------------------------------------------------- { if (((PictureBox)sender).Visible) { if (formGame.numOfColomLine == 8)// אם זה singe player { if (e.Button == MouseButtons.Left) { formGame.timerGame.Start(); formGame.timerPause.Start(); if (this.getStatus() == GraphicCell.Status.Empty && this.IsFlagShow == false) { formGame.FindNumbers(this.i, this.j); } formGame.DrawOnlyTrueEmptyCells(); if (this.getStatus() == GraphicCell.Status.Mine && this.IsFlagShow == false) { formGame.IfClickedOnMineShowAllMines(); formGame.lose.Show(); formGame.Hide(); this.IsShown = true; } if (this.getStatus() == GraphicCell.Status.Number && this.IsFlagShow == false) { int count = formGame.CheckMineNeerCell(this.i, this.j); this.IsShown = true; this.NoMinesToImage(count); } } if (e.Button == MouseButtons.Right) { formGame.timerGame.Start(); if (formGame.MouseRightClickHelper(this.i, this.j) == true) //אם יש דגל בתא { formGame.CounterUserFlags(this.IsFlagShow); //מעביר לו this.SetImage(Properties.Resources.cell); this.IsFlagShow = false; if (this.getStatus() == GraphicCell.Status.Mine) { formGame.WinCount--; } return; } if (formGame.MouseRightClickHelper(this.i, this.j) == false && this.IsShown == false) { formGame.CounterUserFlags(this.IsFlagShow); this.SetImage(Properties.Resources.BlueFlag); this.IsFlagShow = true; if (this.getStatus() == GraphicCell.Status.Mine) { formGame.WinCount++; } if (formGame.WinCount == 10 && formGame.counterUserFlag == 10) { formGame.win.Show(); formGame.Hide(); } } } } }// עבור סינגל פלייר if (formGame.numOfColomLine == 16) //עבור מולטי פלייר { if (formGame.Turn == true) { if (e.Button == MouseButtons.Left) { if (this.IsShown == false) //שהלחיצה תתאפשר רק בתאים שעוד לא לחצו עליהם { formGame.timerGame.Start(); if (this.getStatus() == GraphicCell.Status.Empty && this.IsFlagShow == false) { formGame.FindNumbers(this.i, this.j); formGame.Turn = false; formGame.TurnHelp = false; this.IsShown = true;///////// } formGame.DrawOnlyTrueEmptyCells(); if (this.getStatus() == GraphicCell.Status.Mine && this.IsFlagShow == false) { if (formGame.MouseRightClickHelper(this.i, this.j) == false && this.IsShown == false) { formGame.CounterUserFlags(this.IsFlagShow); this.SetImage(Properties.Resources.BlueFlag); this.IsFlagShow = true; formGame.Turn = true; formGame.TurnHelp = true; } } if (this.getStatus() == GraphicCell.Status.Number && this.IsFlagShow == false) { int count = formGame.CheckMineNeerCell(this.i, this.j); this.IsShown = true; this.NoMinesToImage(count); formGame.Turn = false; formGame.TurnHelp = false; } } if (formGame.Turn == false) { formGame.table.comAI.ComputerTurn(); //formGame.timerPause.Start(); //formGame.Turn = true; } } } } }
public void ComputerTurn() { ScanTheBordMarkTheNtCellsBomb(cells); //הופך את התאים לאמת אם פצצה לא יכולה להיות שם listArrCell = CheckTheCellsNumbersAndGetInToList(cells); //עובר על כל הלוח ומכניס לרשימה את כל התאים שיכולים להיות פצצה if (listArrCell.Count != 0) { CheckStacksInList(listArrCell);////הפעולה עוברת על כל הרשימה ובודקת האם ישנם מחסניות שלא צריכות להיות(שכל הפצצות התגלו } if (listArrCell.Count != 0) { stackOptimalBombCells = listArrCell[0]; int index = 0; while (stackOptimalBombCells.Count == 0 && index == 0)//כל עוד המחסנית ריקה { if (stackOptimalBombCells.Count == 0) { listArrCell.Remove(listArrCell[0]); } if (listArrCell.Count == 0) { index = 1; } if (index == 0) { stackOptimalBombCells = listArrCell[0]; } } if (index == 0)//אם האינדקס שווה ל0 כלומר הרשימה לא ריקה אז תבחר את התא הראשון ותעשה עליו פעולות { stackOptimalBombCells = listArrCell[0]; i = stackOptimalBombCells.Peek().getI(); j = stackOptimalBombCells.Peek().getJ(); lastIJ = ij; stackOptimalBombCells.Pop(); } } if (listArrCell.Count == 0)//אם ההרשימה ריקה אז תעבור על הלוח עד שאתה מוצא תא ריק ושהוא אופטימלי לפצצה { while (cells[i1, j1].IsShown == true || cells[i1, j1].BombCantBeOnTheCell == true) { i1++; if (i1 == 17) { i1 = 1; j1++; } } i = i1; j = j1; j1 = 1; i1 = 1; } if (formGame.Turn == false) { if (cells[i, j].getStatus() == GraphicCell.Status.Empty && cells[i, j].IsFlagShow == false)//אם התא ריק ולא הוצג { formGame.FindNumbers(cells[i, j].getI(), cells[i, j].getJ()); formGame.DrawOnlyTrueEmptyCells(); formGame.Turn = true; cells[i, j].IsShown = true; } if (cells[i, j].getStatus() == GraphicCell.Status.Mine && cells[i, j].IsFlagShow == false) { if (formGame.MouseRightClickHelper(cells[i, j].getI(), cells[i, j].getJ()) == false && cells[i, j].IsShown == false)//אם אין דגל בתא וגם הוא לא נראה עדיין { formGame.CounterCOMFlag(cells[i, j].IsFlagShow); cells[i, j].SetImage(Properties.Resources.RedFlag); cells[i, j].IsFlagShow = true; cells[i, j].IsShown = true; formGame.Turn = false; this.ComputerTurn(); //formGame.timerPause.Start(); } } if (cells[i, j].getStatus() == GraphicCell.Status.Number && cells[i, j].IsFlagShow == false) { int count = formGame.CheckMineNeerCell(cells[i, j].getI(), cells[i, j].getJ()); cells[i, j].IsShown = true; cells[i, j].NoMinesToImage(count); formGame.Turn = true; } } }