public void newGameToolStripMenuItem_Click(object sender, EventArgs e) { if (player1TextBox.Text == "" || player2TextBox.Text == "") { MessageBox.Show("Please set the player names"); } else { gameInProgress = true; gameBoard = new GImageArray(this, gameSpace, 50, 50, 50, 50, 0, imageDirectory); gameBoard.Which_Element_Clicked += new GImageArray.ImageClickedEventHandler(Which_Element_Clicked); player1Score = 2; player0Score = 2; player0ScoreLabel.Text = player0Score.ToString(); player1ScoreLabel.Text = player1Score.ToString(); player0ScoreLabel.Visible = true; player1ScoreLabel.Visible = true; blackPlayingLabel.Visible = true; whitePlayingLabel.Visible = false; } }
public void loadGame() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "txt files(*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.Title = "Load your game"; if (openFileDialog.ShowDialog() == DialogResult.OK) { var filePath = openFileDialog.FileName; var fileStream = openFileDialog.OpenFile(); StreamReader sr = new StreamReader(fileStream); string line = sr.ReadLine(); List <List <int> > array = new List <List <int> > { }; var split = line.Split(","); //returns array - returns a 64 element array with each digit (int) in the array for (int i = 0; i <= 7; i++) //looping over rows { List <int> row = new List <int> { }; for (int j = 0; j <= 7; j++) //looping over columns { int index = i * 8 + j; var elementString = split[index]; int element = Int32.Parse(elementString); row.Add(element); } array.Add(row); } gameSpace = new int[8, 8] { { array[0][0], array[0][1], array[0][2], array[0][3], array[0][4], array[0][5], array[0][6], array[0][7] }, { array[1][0], array[1][1], array[1][2], array[1][3], array[1][4], array[1][5], array[1][6], array[1][7] }, { array[2][0], array[2][1], array[2][2], array[2][3], array[2][4], array[2][5], array[2][6], array[2][7] }, { array[3][0], array[3][1], array[3][2], array[3][3], array[3][4], array[3][5], array[3][6], array[3][7] }, { array[4][0], array[4][1], array[4][2], array[4][3], array[4][4], array[4][5], array[4][6], array[4][7] }, { array[5][0], array[5][1], array[5][2], array[5][3], array[5][4], array[5][5], array[5][6], array[5][7] }, { array[6][0], array[6][1], array[6][2], array[6][3], array[6][4], array[6][5], array[6][6], array[6][7] }, { array[7][0], array[7][1], array[7][2], array[7][3], array[7][4], array[7][5], array[7][6], array[7][7] } }; string playerInfo = sr.ReadLine(); var splitPlayerInfo = playerInfo.Split(","); gameInProgress = true; gameBoard = new GImageArray(this, gameSpace, 50, 50, 50, 50, 0, imageDirectory); gameBoard.Which_Element_Clicked += new GImageArray.ImageClickedEventHandler(Which_Element_Clicked); player1TextBox.Text = splitPlayerInfo[0]; player2TextBox.Text = splitPlayerInfo[1]; player0Score = Int32.Parse(splitPlayerInfo[2]); player1Score = Int32.Parse(splitPlayerInfo[3]); player1ScoreLabel.Text = player1Score.ToString(); player0ScoreLabel.Text = player0Score.ToString(); player0ScoreLabel.Visible = true; player1ScoreLabel.Visible = true; isPlaying = Int32.Parse(splitPlayerInfo[4]); SetIsPlayingLabel(); } }