private void OnPlayerDeath()
 {
     if (ResetGame != null)
     {
         ResetGame.Invoke();
     }
 }
Exemple #2
0
        //Match func
        //Downlaod Move from db
        void GetOpponentMove() //REF
        {
            WebClient a      = new WebClient();
            string    gettxt = "type=3&name=" + player.Name + "&id=" + lobby;
            int       e      = 0;

            while (true)
            {
                string str = "?";
                try { str = a.DownloadString(host + gettxt); } catch (Exception) {};

                if (str == "?")
                {
                    if (e > 5)
                    {
                        output.Invoke((MethodInvoker)(() => output.Text += "|C| Game has canceled. Close the program" + Environment.NewLine));
                        return;
                    }

                    output.Invoke((MethodInvoker)(() => output.Text += "|C| Server is not responding for " + e + ". times." + Environment.NewLine));
                    e++;
                }

                if (str != "" && str != "?")
                {
                    try
                    {
                        string[] splitted = str.Split(';');

                        string wp   = splitted[0];
                        string bp   = splitted[1];
                        string move = splitted[2];
                        int    turn = int.Parse(splitted[3]);

                        if (move == "START")
                        {
                            findmatch.Invoke(new Player((wp == player.Name) ? bp : wp), (wp == player.Name) ? 1 : 2);
                        }
                        else if (move == "DODGE")
                        {
                            output.Invoke((MethodInvoker)(() => output.Text += "Your opponent left the game!" + Environment.NewLine));
                            resetgame.Invoke();
                            return;
                        }
                        else
                        {
                            string[] movesplitted = move.Split('*');
                            string[] startpos     = movesplitted[0].Split(':');
                            string[] movepos      = movesplitted[1].Split(':');

                            getplayermove.Invoke(int.Parse(startpos[0]), int.Parse(startpos[1]), new Move(int.Parse(movepos[0]), int.Parse(movepos[1])), turn);
                        }
                    }
                    catch (Exception) { output.Invoke((MethodInvoker)(() => output.Text += "|C| Server is not responding for " + e + ". times." + Environment.NewLine)); e++; }
                }
                Thread.Sleep(1000);
            }
        }
Exemple #3
0
 public void BackButton()
 {
     fader.gameObject.SetActive(true);
     fader.DOColor(Color.black, 2f).onComplete = () =>
     {
         mainMenuPanel.gameObject.SetActive(true);
         mainMenuPanel.alpha = 1;
         ResetGame?.Invoke();
     };
 }
Exemple #4
0
 private void btnResetGame_Click(object sender, RoutedEventArgs e)
 {
     ResetGame?.Invoke(this, EventArgs.Empty);
 }
 /// <summary>
 ///		lanza el evento de reset
 /// </summary>
 internal void RaiseEventReset()
 {
     ResetGame?.Invoke(this, EventArgs.Empty);
 }
 /// <summary>
 ///		lanza el evento de reset
 /// </summary>
 private void RaiseEventReset()
 {
     ResetGame?.Invoke(this, EventArgs.Empty);
 }
Exemple #7
0
 protected virtual void OnResetGame()
 {
     ResetGame?.Invoke();
 }
Exemple #8
0
        public bool Move(int x, int y, Move b, Player c)
        {
            Unit        selected = SelectUnitByXY(x, y);
            List <Move> aviable  = WithReversedMoves(GetMoves(selected), selected.EHJB);

            if (aviable.Count == 0)
            {
                return(false);
            }

            if (IsAviableMoves(aviable, b) && IsVaildMove(b, selected) && c == selected.player && turn > -1)
            {
                Unit FI = selected;
                Unit SI = SelectUnitByXY(selected.x + b.ChangeX, selected.y + b.ChangeY);

                if (SI.GetType() == typeof(Kiraly))
                {
                    return(false);
                }

                lastmove.x   = FI.x;
                lastmove.y   = FI.y;
                lastmove.end = b;

                int    srt1 = FI.x;
                int    srt2 = FI.y;
                Player str3 = FI.player;

                FI.x = SI.x;
                FI.y = SI.y;


                if (FI.GetType() == typeof(Gyalog) && (FI.y == 0 || FI.y == 7))
                {
                    units.Add(new KiralyN(FI.x, FI.y, str3));
                    units.Remove(FI);
                }

                if (SI.GetType() != typeof(Unit))
                {
                    unitdestroly.Invoke(SI);
                }

                units.Remove(SI);
                units.Add(new Unit(srt1, srt2));

                List <string> o = new List <string> {
                    "A", "B", "C", "D", "E", "F", "G", "H"
                };
                output.Invoke((MethodInvoker)(() => output.Text += "T:" + turn + " [" + c.Name + "] " + o[x] + (y + 1).ToString() + " => " + (o[x + b.ChangeX]).ToString() + (y + b.ChangeY + 1).ToString() + " with: " + selected.GetType().ToString().Split('.')[1] + Environment.NewLine));

                //Sakk / Matt
                Player given = null;
                players.ForEach((v) => {
                    int index = players.FindIndex((u) => u == v);
                    if (IsSakk(v))
                    {
                        sakkfor[index]++;
                        if (!(sakkfor[index] > 1))
                        {
                            output.Invoke((MethodInvoker)(() => output.Text += "SAKK for " + v.Name + Environment.NewLine));
                            given = v;
                        }
                        else
                        {
                            endgame = index;
                            output.Invoke((MethodInvoker)(() => output.Text += "SAKKMATT for " + v.Name + Environment.NewLine));
                            output.Invoke((MethodInvoker)(() => output.Text += "Win for " + players.Find((u) => u != v).Name + Environment.NewLine));
                            resetgame.Invoke();
                        }
                    }
                    else
                    {
                        sakkfor[index] = 0;
                    }
                });

                sakkfordel.Invoke(given);
                Show();

                if (!(turn < 0))
                {
                    turn++;
                }
                return(true);
            }
            return(false);
        }
Exemple #9
0
 private void button1_Click(object sender, EventArgs e)
 {
     ResetGame?.Invoke();
 }