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; }
public void move() { if (finished == true) return; Invalidate(true); lblPrv.Text = p1.name + "\n" + " Coins: " + rvs.getFirst(); lblVtor.Text = p2.name + "\n" + " Coins: " + rvs.getSecond(); if (rvs.p1.canMove == false && rvs.p2.canMove == false) { p1.canMove = true; p2.canMove = true; if (rvs.getFirst()>rvs.getSecond()) { finished = true; if (rvs.p2.type==Type.Human) { DialogResult dr = MessageBox.Show("The game is finished. " + p1.name + " is the winner. Do you want your result to be added to the Highscore list?", "Reversi", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { hscore.addItem(new RankedPlayers(rvs.p1.name, rvs.p2.name, rvs.getFirst(), rvs.getSecond())); serHighScores(hscore); } } else { DialogResult dr= MessageBox.Show("The game is finished. " + p1.name + " is the winner. Do you want your result to be added to the Highscore list?", "Reversi", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { hscore.addItem(new RankedPlayers(rvs.p1.name,rvs.p2.name, rvs.getFirst(), rvs.getSecond())); serHighScores(hscore); } } return; } else if (rvs.getFirst() < rvs.getSecond()) { finished = true; if (rvs.p2.type == Type.Human) { DialogResult dr = MessageBox.Show("The game is finished. " + p2.name + " is the winner. Do you want your result to be added to the Highscore list?", "Reversi", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { hscore.addItem(new RankedPlayers(rvs.p2.name, rvs.p1.name, rvs.getSecond(), rvs.getFirst())); serHighScores(hscore); } } else { MessageBox.Show("The game is finished. " + p2.name + " is the winner.", "Reversi", MessageBoxButtons.OK, MessageBoxIcon.Information); } return; } else { MessageBox.Show("The game is finished. It's draw.","Reversi",MessageBoxButtons.OK,MessageBoxIcon.Information); finished = true; return; } } rvs.findPossibleMoves(); if (rvs.turn==1) { if (rvs.noPossibleMoves()) { rvs.p1.canMove = false; rvs.changeTurn(); move(); return; } else { rvs.p1.canMove = true; return; } } else { if (rvs.noPossibleMoves()) { rvs.p2.canMove = false; rvs.changeTurn(); move(); return; } else { rvs.p2.canMove = true; if (rvs.p2.type != Type.Human) { //if (rvs.possibleMoves.Count == 0) //{ // rvs.p2.canMove = false; // rvs.changeTurn(); // move(); // return; // } timer.Start(); } return; } } Invalidate(true); }