Example #1
0
 public void KeyPressed(KeyPressEventArgs e)
 {
     if (Settings.Default.EnableWinKey && (e.KeyChar == Settings.Default.WinKey))
     {
         this.gameTimer.Enabled = false;
         frmGameEnd end = new frmGameEnd(this.players[this.playerToMove].playerName, "Was checkmated by the other player", frmGameEnd.Remedy.Ignore);
         end.ShowDialog();
         if (!end.continueGame)
         {
             base.Close();
         }
         else
         {
             this.gameTimer.Enabled = true;
         }
     }
     else if (Settings.Default.EnablePauseKey && (e.KeyChar == Settings.Default.PauseKey))
     {
         if (this.lblPaused.Visible)
         {
             this.gameTimer.Enabled = true;
             base.Height           -= 0x27;
         }
         else
         {
             this.gameTimer.Enabled = false;
             base.Height           += 0x27;
         }
         this.lblPaused.Visible = !this.lblPaused.Visible;
     }
     else if (!this.lblPaused.Visible)
     {
         this.SwitchPlayerMoving();
     }
 }
Example #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Player.Status status = this.players[this.playerToMove].Step(TimeSpan.FromMilliseconds((double)this.gameTimer.Interval));
            if (status > Player.Status.GoingOver)
            {
                this.gameTimer.Enabled = false;
                string            reason = "";
                frmGameEnd.Remedy none   = frmGameEnd.Remedy.None;
                switch (status)
                {
                case Player.Status.MovesOverInGame:
                    reason = "Total moves over in game exceeded limit.";
                    none   = frmGameEnd.Remedy.Ignore;
                    break;

                case Player.Status.MovesOverInRow:
                    reason = "Moves over in-a-row exceeded limit.";
                    none   = frmGameEnd.Remedy.Ignore;
                    break;

                case Player.Status.GameTimeUsed:
                    reason = "Game time has exceeded limit.";
                    none   = frmGameEnd.Remedy.IncreaseGameTime;
                    break;

                case Player.Status.GameOverTimeUsed:
                    reason = "Total turn over time has exceeded limit.";
                    none   = frmGameEnd.Remedy.IncreaseTotalTurnOverTime;
                    break;

                case Player.Status.TurnOverTimeUsed:
                    reason = "Time gone over this turn exceeded limit.";
                    none   = frmGameEnd.Remedy.MoveThenIgnore;
                    break;
                }
                frmGameEnd end = new frmGameEnd(this.players[this.playerToMove].playerName, reason, none);
                end.ShowDialog();
                if (!end.continueGame)
                {
                    base.Close();
                }
                else
                {
                    switch (none)
                    {
                    case frmGameEnd.Remedy.Ignore:
                        this.gameTimer.Enabled = true;
                        break;

                    case frmGameEnd.Remedy.MoveThenIgnore:
                        this.SwitchPlayerMoving();
                        break;

                    case frmGameEnd.Remedy.IncreaseTotalTurnOverTime:
                        this.players[this.playerToMove].IncreaseTotalTurnOverTime(end.increaseBy);
                        this.gameTimer.Enabled = true;
                        break;

                    case frmGameEnd.Remedy.IncreaseGameTime:
                        this.players[this.playerToMove].IncreaseGameTime(end.increaseBy);
                        this.gameTimer.Enabled = true;
                        break;
                    }
                }
            }
            stopwatch.Stop();
        }