/// <summary> /// the event that scrolls the whole game from the start to the end /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void replayButton_Click(Object sender, EventArgs e) { var ctr = (Button)(Control)sender; currentIndex = replayButton.ToList().IndexOf(ctr); var ListOfWays = Directory.EnumerateFiles(Program.Path + @"\" + (1 + currentIndex) + @"\" + "X"); for (int i = 1; i <= ListOfWays.Count(); i++) { var scrollStep2 = 0; if (historyBar[currentIndex].Maximum % 2 == 0) { scrollStep2 = i / 2; } else { scrollStep2 = i / 2 + 1; } historyBar[currentIndex].Value = i; nowTurn[currentIndex].Text = "Current movement: " + scrollStep2; nowTurn[currentIndex].Refresh(); previousScrollStep[currentIndex] = i; var field = new GraphicField(i, Program.g[currentIndex]); DrawField(currentIndex, graphic[currentIndex], field); Thread.Sleep(100); } historyBar[currentIndex].Value = historyBar[currentIndex].Maximum; }
/// <summary> /// draw a specified field in the picture box /// </summary> /// <param name="numOfField">an index of the field</param> /// <param name="g">a graphic element of the field</param> /// <param name="field">a field that needs to draw</param> void DrawField(int numOfField, Graphics g, GraphicField field) { for (int i = 0; i < cellNums; i++) { for (int j = 0; j < cellNums; j++) { if (field.Field[i, j] != previousField[numOfField].Field[i, j]) { switch (field.Field[i, j]) { case 'X': g.DrawImage(new Bitmap(new Bitmap( Program.Path + @"\X.jpg"), cellSize, cellSize), j * fullCellSize + 2, (cellNums - 1 - i) * fullCellSize + 2); break; case 'O': g.DrawImage(new Bitmap(new Bitmap( Program.Path + @"\O.jpg"), cellSize, cellSize), j * fullCellSize + 2, (cellNums - 1 - i) * fullCellSize + 2); break; case '.': g.FillRectangle(new SolidBrush(Color.White), j * fullCellSize + 2, (cellNums - 1 - i) * fullCellSize + 2, cellSize, cellSize); break; } } } } previousField[numOfField].Field = field.Field; fieldBox[numOfField].Refresh(); }
/// <summary> /// Constructor of the class /// </summary> /// <param name="numberOfGame"></param> /// <param name="player1">"X" player</param> /// <param name="player2">"O" player</param> /// <param name="timeLimit">timeLimit for game. Now it's changed to timeLimit for every player. /// They are assign in Program.cs</param> /// <param name="field">Picture of a game board.</param> public Game(int numberOfGame, IPlayer player1, IPlayer player2, double timeLimit, GraphicField field) { this.numberOfGame = numberOfGame; this.field = field; this.timeLimit = timeLimit; numberOfTurn = 0; this.player1 = player1; this.player2 = player2; for (int i = 0; i < endOfField + 1; i++) { freeColumn.Add(true); } }
/// <summary> /// An event to move forward and backward through the play history /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void historyBar_Scroll(Object sender, EventArgs e) { var ctr = (TrackBar)(Control)sender; currentIndex = historyBar.ToList().IndexOf(ctr); scrollStep = historyBar[currentIndex].Value; var scrollStep2 = 0; if (historyBar[currentIndex].Maximum % 2 == 0) { scrollStep2 = scrollStep / 2; } else { scrollStep2 = scrollStep / 2 + 1; } nowTurn[currentIndex].Text = "Current movement: " + scrollStep2; nowTurn[currentIndex].Refresh(); previousScrollStep[currentIndex] = scrollStep; var field = new GraphicField(scrollStep, Program.g[currentIndex]); DrawField(currentIndex, graphic[currentIndex], field); }