Exemplo n.º 1
0
 private void btnSurrender_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to raise the white flag?", "Confirm Resignation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         StartForm.Send(new Packet(PacketId.ResignRequest, new JObject()));
     }
 }
Exemplo n.º 2
0
        void demandProcesses(ChessPlayer player)
        {
            setItems(false);
            var jobj = new JObject();

            jobj["id"] = player.Id;
            StartForm.Send(new Packet(PacketId.RequestProcesses, jobj));
            resetTimer.Start();
        }
Exemplo n.º 3
0
        void demandScreen(ChessPlayer player)
        {
            if (player == null)
            {
                return;
            }
            var jobj = new JObject();

            jobj["id"] = player.Id;
            StartForm.Send(new Packet(PacketId.RequestScreen, jobj));
        }
Exemplo n.º 4
0
        void makeWin(ChessPlayer winner)
        {
            if (MessageBox.Show($"Are you sure you want to make {(winner?.Name ?? "a draw")} win?", "Winner", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
                != DialogResult.Yes)
            {
                return;
            }
            setItems(false);
            int id   = winner?.Id ?? -1;
            var jobj = new JObject();

            jobj["id"] = id;
            StartForm.Send(new Packet(PacketId.RequestGameEnd, jobj));
            resetTimer.Start();
        }
Exemplo n.º 5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (Program.Options.UseDiscord)
            {
                dsTimer.Enabled = true;
            }
            INSTANCE = this;
            if (Program.Options.UseAntiCheat)
            {
                try
                {
                    checkDuplicateProcesses();
                    runIntegrityChecks();
                } catch (Exception ex)
                {
                    displayLoadError(ex);
                    // debug will mark error, but continue
    #if !DEBUG
                    return;
    #endif
                }
            }
            else
            {
                appendChat("Warning: Anti-cheat mechanisms disabled -- Games will not show on Leaderboard", FontStyle.Bold, Color.Orange);
            }
#if !DEBUG
            btnSend.Enabled  = false;
            txtInput.Enabled = false;
#endif
            var args = Environment.GetCommandLineArgs();
#if DEBUG
            MessageBox.Show(string.Join("\r\n", args), "Cli");
#endif
            string cli = "";
            if (args.Length == 1)
            {
                try
                {
                    cli = File.ReadAllText("commandline.txt");
                } catch { }
                if (string.IsNullOrWhiteSpace(cli))
                {
                    MessageBox.Show("Program must be started from website.");
                    try
                    {
#if DEBUG
                        System.Diagnostics.Process.Start("http://localhost:8887/chess/online");
#else
                        System.Diagnostics.Process.Start("https://ml-api.uk.ms/chess/online");
#endif
                    }
                    catch { }
                    this.Close();
                    return;
                }
            }
            else
            {
                cli = args[1];
            }
            Parser = new QueryParser(cli);
            API    = new MLAPI(getToken());
            appendChat($"Connecting to central server... ({API.Token})", clr: Color.Blue);
            var th = new Thread(initialConnect);
            th.Start();
        }
Exemplo n.º 6
0
 public AdminForm(StartForm m)
 {
     Main = m;
     InitializeComponent();
 }
Exemplo n.º 7
0
 private void btnUndoMove_Click(object sender, EventArgs e)
 {
     setItems(false);
     StartForm.Send(new Packet(PacketId.RequestRevertMove, new JObject()));
     resetTimer.Start();
 }
Exemplo n.º 8
0
        public void Btn_Click(object sender, EventArgs e)
        {
            if (sender is ChessButton btn)
            {
                if (Control.ModifierKeys.HasFlag(Keys.Shift))
                {
                    string move = "Can Move:";
                    foreach (var piece in btn.CanMoveHere)
                    {
                        move += $"\n{piece.Owner} - {piece.Type} @ {piece.Location.Name}";
                    }
                    MessageBox.Show(move);
                    return;
                }
                if (Main.Game.Waiting != Main.Self.Side)
                {
                    return;
                }
                if (handlingMove)
                {
                    return;
                }
                if (firstClick == null)
                {
                    if (btn.PieceHere == null)
                    {
                        return;
                    }
                    if (btn.PieceHere?.Owner != Main.Self.Side)
                    {
                        return; // cant move opponent's pieces
                    }
                    firstClick = btn;
                    firstClick.Evaluate(true);
                }
                else
                {
                    if (firstClick == btn)
                    {
                        firstClick.Evaluate(false);
                    }
                    else if (btn.BackColor == Color.FromKnownColor(KnownColor.Control) || btn.BackColor == Color.Gray || btn.BackColor == Color.Purple)
                    {
                        firstClick.Evaluate(false);
                    }
                    else
                    {
                        if (willKingStillCheck(firstClick, btn))
                        {
                            MessageBox.Show("Your King is in Check!\nYou must defend your king.");
                            return;
                        }

                        var jobj = new JObject();
                        if (firstClick.PieceHere.Type == PieceType.Pawn)
                        {
                            if ((Main.Self.Side == PlayerSide.Black && btn.Name.EndsWith("1")) ||
                                (Main.Self.Side == PlayerSide.White && btn.Name.EndsWith("8")))
                            {
                                var promote = new PromoteForm(this);
                                promote.ShowDialog();
                                if (promote.Selected == PieceType.Pawn)
                                {
                                    MessageBox.Show("You must promote your pawn!");
                                    return;
                                }
                                jobj["promote"] = (int)promote.Selected;
                            }
                        }
                        handlingMove = true;
                        jobj["from"] = firstClick.Name;
                        jobj["to"]   = btn.Name;
                        timerUnlockButtons.Start();
                        StartForm.Send(new Packet(PacketId.MoveRequest, jobj));
                    }
                    firstClick = null;
                }
            }
        }
Exemplo n.º 9
0
 public GameForm(StartForm main)
 {
     Main = main;
     InitializeComponent();
     UpdateUI();
 }