예제 #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (FilterButton.BackgroundImage == null)
            {
                return;
            }
            var bm = new Bitmap(FilterButton.BackgroundImage, new Size(FilterButton.Width, FilterButton.Height));

            FilterButton.BackgroundImage = bm;

            PopupForm    popup        = new PopupForm();
            DialogResult dialogresult = popup.ShowDialog();

            if (popup.GoodPassword && dialogresult == DialogResult.OK)
            {
                HandleConnection();
                WindowState   = FormWindowState.Normal;
                ShowInTaskbar = true;

                CopiedTimer.Elapsed += (s, args) =>
                {
                    InfoLabel.Invoke(new MethodInvoker(delegate { InfoLabel.Visible = false; }));
                    CopiedTimer.Enabled = false;
                };
            }
            else if (!popup.GoodPassword || dialogresult == DialogResult.Cancel)
            {
                Application.Exit();
            }
            popup.Dispose();
        }
예제 #2
0
        /// <summary>
        /// Wysyłanie odpowiedzi po strzale przeciwnika
        /// </summary>
        /// <param name="cord"></param>
        void SendCordInfo(string[] cord)
        {
            switch (VariableClass.MePlayer.Board[Int32.Parse(cord[0]), Int32.Parse(cord[1])].BattleState)
            {
            case State.Battle:
                VariableClass.MePlayer.Board[Int32.Parse(cord[0]), Int32.Parse(cord[1])].BattleState      = State.Hit;
                VariableClass.MePlayer.Board[Int32.Parse(cord[0]), Int32.Parse(cord[1])].Button.BackColor = Color.Red;
                SendMessageToOp(cord[0] + ";" + cord[1] + ";hit");
                VariableClass.BattleCount--;
                return;

            case State.Empty:
                VariableClass.MePlayer.Board[Int32.Parse(cord[0]), Int32.Parse(cord[1])].Button.BackColor = Color.Blue;
                SendMessageToOp(cord[0] + ";" + cord[1] + ";fail");
                VariableClass.MyMove = true;
                InfoLabel.Invoke(new Action(() => InfoLabel.Text = "Twój ruch"));

                return;
            }
        }
예제 #3
0
        // Downloads and saves all new images.
        public void DownloadImages(string subReddits)
        {
            if (!downloading)
            {
                InfoLabel.Text = "Getting new images...";
                downloading    = true;
                var process = Task.Factory.StartNew(() =>
                {
                    try
                    {
                        List <string> posts;
                        if (subReddits.Contains("imgur"))
                        {
                            posts = ir.getImageURLsImgurAlbum(subReddits);
                        }
                        else
                        {
                            posts = ir.getImageURLs(subReddits);
                        };
                        images = new List <string>();
                        foreach (string s in posts)
                        {
                            if (!sm.IsImageDownloaded(s))
                            {
                                if ((s.Contains(".jpg") || s.Contains(".jpeg")))
                                {
                                    images.Add(s);
                                }
                                else if (s.Contains(".png"))
                                {
                                    images.Add(s);
                                }
                            }
                        }
                        int counter = 0;
                        InfoLabel.Invoke(new Action(delegate() { InfoLabel.Text = "Starting downloads..."; }));
                        foreach (string s in images)
                        {
                            if ((s.Contains(".jpg") || s.Contains(".jpeg")))
                            {
                                if (TryToDownload(s, ".jpg"))
                                {
                                    counter++;
                                }
                            }
                            else if (s.Contains(".png"))
                            {
                                if (TryToDownload(s, ".png"))
                                {
                                    counter++;
                                }
                            }
                            if (currentImage == 0 && counter > 0)
                            {
                                pictureBox1.Invoke(new Action(delegate() { pictureBox1.Image = Image.FromFile(sm.Images[0].LocalPath); }));
                            }

                            InfoLabel.Invoke(new Action(delegate() { InfoLabel.Text = "Completed\n" + counter + " of " + images.Count; }));
                        }
                    }
                    finally
                    {
                        sm.SetLastNumber(counter);
                        InfoLabel.Invoke(new Action(delegate() { InfoLabel.Text = "Done!"; }));
                        downloading = false;
                    }
                });
            }
        }
예제 #4
0
        private void GameLoop()
        {
            VariableClass.CanPlay = true;
            while (true)
            {
                if (VariableClass.BattleCount == 0 && VariableClass.GameReady && VariableClass.OpPlayer.Ready)
                {
                    MessageBox.Show("Przegrałeś :(");
                    Thread.Sleep(3000);
                    Environment.Exit(0);
                    this.Close();
                }

                byte[] data;
                try
                {
                    data = VariableClass.ReceiveAll(VariableClass.Client.Client);
                }
                catch
                {
                    continue;
                }
                if (data == null)
                {
                    continue;
                }
                string ret = Encoding.ASCII.GetString(data);
                Debug.WriteLine(ret);
                if (ret.CompareTo("ready") == 0 && VariableClass.MePlayer.Ready)
                {
                    VariableClass.GameReady = true;
                    Debug.WriteLine("Prawda ret==ready");
                    InfoLabel.Invoke(new Action(() => InfoLabel.Text = "Gra się rozpoczeła"));
                    GenerateOpBoard();
                    VariableClass.OpPlayer.Ready = true;
                    VariableClass.MyMove         = true;
                    InfoLabel.Invoke(new Action(() => InfoLabel.Text = "Twój ruch"));

                    continue;
                }
                else
                {
                    if (ret.CompareTo("ready") == 0 && !VariableClass.MePlayer.Ready)
                    {
                        VariableClass.OpPlayer.Ready = true;
                        VariableClass.MyMove         = false;
                        if (InfoLabel.InvokeRequired)
                        {
                            InfoLabel.Invoke(new Action(() => InfoLabel.Text = "Przeciwnik jest juz gotowy"));
                        }
                        else
                        {
                            InfoLabel.Text = "Przeciwnik jest juz gotowy";
                        }
                        continue;
                    }
                }

                string[] rearray = ret.Split(';');
                if (rearray.Length == 2)
                {
                    SendCordInfo(rearray);
                    continue;
                }
                if (rearray.Length == 3)
                {
                    if (rearray[2].CompareTo("hit") == 0)
                    {
                        VariableClass.OpPlayer.Board[Int32.Parse(rearray[0]), Int32.Parse(rearray[1])].BattleState      = State.Hit;
                        VariableClass.OpPlayer.Board[Int32.Parse(rearray[0]), Int32.Parse(rearray[1])].Button.BackColor = Color.Red;
                    }
                    if (rearray[2].CompareTo("fail") == 0)
                    {
                        VariableClass.OpPlayer.Board[Int32.Parse(rearray[0]), Int32.Parse(rearray[1])].BattleState      = State.Empty;
                        VariableClass.OpPlayer.Board[Int32.Parse(rearray[0]), Int32.Parse(rearray[1])].Button.BackColor = Color.Blue;
                        VariableClass.MyMove = false;
                        InfoLabel.Invoke(new Action(() => InfoLabel.Text = "Ruch przeciwnika"));
                    }
                }
            }
        }