示例#1
0
        void Server_Received(object sender, Client.TransmitEventArgs e)
        {
            if (e.Text.StartsWith("#Player "))
            {
                Me = int.Parse(e.Text.Substring(8));
                if (Me == 1)
                {
                    SetStatus("Waiting for an opponent...");
                }
            }

            if (e.Text.StartsWith("#Countdown "))
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
                {
                    for (int i = 0; i < int.Parse(e.Text.Substring(11)); i++)
                    {
                        SetStatus("Get ready: " + (3 - i).ToString(), WarningColor);
                        Thread.Sleep(1000);
                    }
                }));
            }

            if (e.Text == "#Draw")
            {
                GameOver = true;
                SetStatus("It's a DRAW!", WarningColor);
            }

            if (e.Text.StartsWith("#Winner "))
            {
                GameOver = true;
                if (int.Parse(e.Text.Substring(8)) == Me)
                {
                    SetStatus("You're the WINNER!", SuccessColor);
                }
                else
                {
                    SetStatus("You LOST!", ErrorColor);
                }
            }

            if (e.Text.StartsWith("#Status "))
            {
                string[] pqq = e.Text.Substring(8).Split('\t');
                Wall         = FromRepresentation(pqq[0]);
                Food         = FromRepresentation(pqq[1]);
                Turbo        = FromRepresentation(pqq[2]);
                Delay        = FromRepresentation(pqq[3]);
                SnakeOne     = FromRepresentation(pqq[4]);
                SnakeTwo     = FromRepresentation(pqq[5]);
                TurboEnabled = pqq[6] == "E";
                TurboCounter = int.Parse(pqq[7]);
                ClearStatus();
                Draw = true;
                RePaint();
            }
        }
示例#2
0
        void Client_Received(object sender, Client.TransmitEventArgs e)
        {
            if (e.Text.StartsWith("#D "))
            {
                switch (e.Text.Substring(3))
                {
                case "U": DirectionQueue.Add(Direction.Up); break;

                case "D": DirectionQueue.Add(Direction.Down); break;

                case "L": DirectionQueue.Add(Direction.Left); break;

                case "R": DirectionQueue.Add(Direction.Right); break;
                }
                if (DirectionQueue.Count > 2)
                {
                    DirectionQueue = DirectionQueue.Skip(DirectionQueue.Count - 2).Take(2).ToList();
                }
            }

            if (e.Text == "#Turbo on")
            {
                if (this.Turbo > 0)
                {
                    this.TurboEnabled = true;
                }
            }

            if (e.Text == "#Turbo off")
            {
                this.TurboEnabled = false;
            }

            if (e.Text == "#MaxTurbo")
            {
                this.Turbo = 100;
            }
        }