internal void MenuItem_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; if (menuItem.Text.Equals("退出")) { this.Close(); } if (menuItem.Text.Equals("开始新游戏")) { PauseGametoolStripMenuItem.Text = "暂停游戏"; //新游戏初始状态,我家和敌方都从2开始,令牌为开始发牌 currentState = new CurrentState(0, 0, 0, 0,0,0,CardCommands.ReadyCards); currentRank = 0; isNew = true; whoIsBigger = 0; //初始化 init(); //开始定时器,进行发牌 timer.Start(); } }
//读取牌局 private void RestoreToolStripMenuItem_Click(object sender, EventArgs e) { PauseGametoolStripMenuItem.Text = "暂停游戏"; Stream stream = null; try { IFormatter formatter = new BinaryFormatter(); stream = new FileStream("backup", FileMode.Open, FileAccess.Read, FileShare.Read); CurrentState cs = (CurrentState)formatter.Deserialize(stream); currentState = cs; if (currentState.Master == 1 || currentState.Master == 2) { currentRank = currentState.OurCurrentRank; } else if(currentState.Master == 3 || currentState.Master == 4) { currentRank = currentState.OpposedCurrentRank; } else { isNew = true; currentRank = 0; } init(); timer.Start(); } catch (Exception ex) { } finally { if (stream != null) { stream.Close(); } } }