public void loadGame() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter= "Reversi (*.rvs)|*.rvs"; ofd.Title = "Load game"; if (ofd.ShowDialog()==DialogResult.OK) { FileName = ofd.FileName; try { using (FileStream fs = new FileStream(FileName, FileMode.Open)) { IFormatter formatter = new BinaryFormatter(); rvs = (Rvs)formatter.Deserialize(fs); updateGame(); changePanel2(); this.Text = "Reversi - " + FileName; Invalidate(true); } } catch (Exception ) { MessageBox.Show("Could not read file: " + FileName); FileName = null; return; } } }
public static Rvs DeepClone(Rvs obj) { using (var ms = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(ms, obj); ms.Position = 0; return (Rvs)formatter.Deserialize(ms); } }
public void newGame() { FileName = null; finished = false; int turn = new Random().Next(1, 3); rvs = new Rvs(turn); changePanel2(); lblPrv.Text = ""; lblPrv.ForeColor = colorp1; lblPrv.Text += p1.name + "\n" + " Coins: " + rvs.getFirst(); lblVtor.Text = ""; lblVtor.Text = p2.name + "\n" + " Coins: " + rvs.getSecond(); lblVtor.ForeColor = colorp2; p1.color = colorp1; p2.color = colorp2; rvs.p1 = p1; rvs.p2 = p2; Invalidate(true); move(); return; }
private void btnNewGame_Click(object sender, EventArgs e) { int turn = new Random().Next(1, 3); rvs = new Rvs(turn); changePanel2(); if (name1.Text.Trim().Length > 0) { p1.name = name1.Text; } if (ddl1.SelectedIndex == 0) p1.type = Type.Human; if (ddl1.SelectedIndex == 1) p1.type = Type.Easy; if (ddl1.SelectedIndex == 2) p1.type = Type.Hard; lblPrv.Text = ""; lblPrv.ForeColor = colorp1; lblPrv.Text += p1.name + "\n" + " Coins: " + rvs.getFirst(); if (name2.Text.Trim().Length > 0) { p2.name = name2.Text; } if (ddl2.SelectedIndex == 0) p2.type = Type.Human; if (ddl2.SelectedIndex == 1) p2.type = Type.Easy; if (ddl2.SelectedIndex == 2) p2.type = Type.Hard; lblVtor.Text = ""; lblVtor.Text = p2.name + "\n" + " Coins: " + rvs.getSecond(); lblVtor.ForeColor = colorp2; p1.color = colorp1; p2.color = colorp2; finished = false; rvs.p1 = p1; rvs.p2 = p2; Invalidate(true); move(); return; }