コード例 #1
0
 public PlayerPosition(BinaryInput Input)
 {
     this.x    = 319 - (int)Input.ReadInt();
     this.y    = 207 - (int)Input.ReadInt();
     this.vx   = -(int)Input.ReadInt();
     this.vy   = -(int)Input.ReadInt();
     this.dead = Input.ReadBool();
 }
コード例 #2
0
ファイル: LzwCompress.cs プロジェクト: FuGangqiang/algorithms
        public void Expand()
        {
            string[] st = new string[L];
            int      i; // next available codeword value

            // initialize symbol table
            for (i = 0; i < R; i++)
            {
                st[i] = "" + (char)i;
            }
            st[i++] = "";    // (unused) lookahead for EOF

            int    codeword = input.ReadInt(W);
            string val      = st[codeword];

            while (true)
            {
                output.Write(val);
                codeword = input.ReadInt(W);
                if (codeword == R)
                {
                    // EOF
                    break;
                }
                string s = st[codeword];
                if (i == codeword)
                {
                    // If lookahead is invalid, make codeword from last one
                    s = val + val[0];
                }
                if (i < L)
                {
                    // Add new entry to code table
                    st[i++] = val + s[0];
                }
                val = s;
            }
            output.Close();
        }
コード例 #3
0
        public void GetGift(int PlayerIndex, int GiftIndex, BinaryOutput Output, BinaryInput Input)
        {
            switch (GiftIndex)
            {
            case 0:
                this.framesPerPixel = 4;
                this.stepsPerFrame  = 1;
                Program.PlayerMsg(this.playerNr, "Slow speed");
                break;

            case 1:
                this.framesPerPixel = 5;
                this.stepsPerFrame  = 1;
                Program.PlayerMsg(this.playerNr, "Slower speed");
                break;

            case 2:
                this.framesPerPixel = 6;
                this.stepsPerFrame  = 1;
                Program.PlayerMsg(this.playerNr, "Slowest speed");
                break;

            case 3:
                this.framesPerPixel = 2;
                this.stepsPerFrame  = 1;
                Program.PlayerMsg(this.playerNr, "Fast speed");
                break;

            case 4:
                this.framesPerPixel = 1;
                this.stepsPerFrame  = 1;
                Program.PlayerMsg(this.playerNr, "Faster speed");
                break;

            case 5:
                this.framesPerPixel = 1;
                this.stepsPerFrame  = 2;
                if (this.shotSpeed < 2)
                {
                    this.shotSpeed = 2;
                }
                Program.PlayerMsg(this.playerNr, "Fastest speed");
                break;

            case 6:
                this.framesPerPixel = 3;
                this.stepsPerFrame  = 1;
                Program.PlayerMsg(this.playerNr, "Normal speed");
                break;

            case 7:
                this.shotPower = 5;
                Program.PlayerMsg(this.playerNr, "Tiny bullets");
                break;

            case 8:
                this.shotPower = 10;
                Program.PlayerMsg(this.playerNr, "Small bullets");
                break;

            case 9:
                this.shotPower = 15;
                Program.PlayerMsg(this.playerNr, "Normal bullets");
                break;

            case 10:
                this.shotPower = 20;
                Program.PlayerMsg(this.playerNr, "Large bullets");
                break;

            case 11:
                this.shotPower = 25;
                Program.PlayerMsg(this.playerNr, "Huge bullets");
                break;

            case 12:
                this.shotPower = 30;
                Program.PlayerMsg(this.playerNr, "Humongous bullets");
                break;

            case 13:
                this.shotPower = 50;
                Program.PlayerMsg(this.playerNr, "Peace-maker bullets");
                break;

            case 14:
                this.tail = false;
                Program.PlayerMsg(this.playerNr, "No tail");
                break;

            case 15:
                this.tail = true;
                Program.PlayerMsg(this.playerNr, "Tail");
                break;

            case 16:
                this.shotSpeed = Math.Max(1, this.stepsPerFrame);
                Program.PlayerMsg(this.playerNr, "Slow bullets");
                break;

            case 17:
                this.shotSpeed = Math.Max(2, this.stepsPerFrame);
                Program.PlayerMsg(this.playerNr, "Fast bullets");
                break;

            case 18:
                this.shotSpeed = Math.Max(3, this.stepsPerFrame);
                Program.PlayerMsg(this.playerNr, "Faster bullets");
                break;

            case 19:
                this.shotSpeed = Math.Max(4, this.stepsPerFrame);
                Program.PlayerMsg(this.playerNr, "Fastest bullets");
                break;

            case 20:
                int  X, Y;
                int  dx, dy;
                bool Ok;
                int  TriesLeft = 100;
                int  Black     = Color.Black.ToArgb();

                if (!(Input is null))
                {
                    this.x = 319 - (int)Input.ReadInt();
                    this.y = 207 - (int)Input.ReadInt();
                }
                else
                {
                    Ok = false;

                    while (TriesLeft-- > 0 && !Ok)
                    {
                        X  = RetroApplication.Random(30, 290);
                        Y  = RetroApplication.Random(38, 170);
                        Ok = true;
                        for (dy = -5; dy < 5; dy++)
                        {
                            for (dx = -5; dx < 5; dx++)
                            {
                                if (RetroApplication.Raster[X + dx, Y + dy].ToArgb() != Black)
                                {
                                    Ok = false;
                                    dy = 5;
                                    break;
                                }
                            }
                        }

                        if (Ok)
                        {
                            Output.WriteInt(X);
                            Output.WriteInt(Y);

                            this.x = X;
                            this.y = Y;
                        }
                    }

                    if (!Ok && !(Output is null))
                    {
                        Output.WriteInt(this.x);
                        Output.WriteInt(this.y);
                    }
                }

                Program.PlayerMsg(this.playerNr, "Teleport");
                break;
コード例 #4
0
ファイル: Program.cs プロジェクト: PeterWaher/RetroSharp
        public static void Main(string[] args)
        {
            ManualResetEvent Terminated = new ManualResetEvent(false);

            Initialize();

            Console.Out.WriteLine("Move the mouse to move the pointer on the screen.");
            Console.Out.WriteLine("Press left mouse button while moving to draw.");
            Console.Out.WriteLine("Press the ESC key to close the application.");
            Console.Out.WriteLine("You will be able to see what others draw as well.");

            OnKeyDown += (sender, e) =>
            {
                if (e.Key == Key.Escape || (e.Key == Key.C && e.Control))
                {
                    Terminated.Set();
                }
            };

            FillRectangle(0, 0, ScreenWidth, ScreenHeight, C64Colors.Blue);

            int          PointerTexture = AddSpriteTexture(GetResourceBitmap("Pointer.png"), System.Drawing.Color.FromArgb(0, 0, 255), true);
            Point        P       = GetMousePointer();
            Point        LastP   = P;
            Sprite       Pointer = CreateSprite(P.X, P.Y, PointerTexture);
            Random       Rnd     = new System.Random();
            int          R       = Rnd.Next(128, 255);
            int          G       = Rnd.Next(128, 255);
            int          B       = Rnd.Next(128, 255);
            Color        Color   = Color.FromArgb(R, G, B);
            bool         Draw    = false;
            BinaryOutput Payload;

            using (MqttConnection MqttConnection = ConnectToMqttServer("iot.eclipse.org", false, string.Empty, string.Empty))
            {
                WriteLine("<" + MqttConnection.State.ToString() + ">", C64Colors.LightGreen);

                MqttConnection.TrustServer = true;

                MqttConnection.OnConnectionError += (sender, ex) =>
                {
                    WriteLine("Unable to connect:", C64Colors.Red);
                };

                MqttConnection.OnError += (sender, ex) =>
                {
                    WriteLine(ex.Message, C64Colors.Red);
                };

                MqttConnection.OnStateChanged += (sender, state) =>
                {
                    WriteLine("<" + MqttConnection.State.ToString() + ">", C64Colors.LightGreen);

                    if (state == MqttState.Connected)
                    {
                        MqttConnection.SUBSCRIBE("RetroSharp/Examples/Networking/MultiUserDraw");
                    }
                };

                OnMouseMove += (sender, e) =>
                {
                    P = e.Position;
                    Pointer.SetPosition(P);

                    int DX = P.X - RasterWidth / 2;
                    int DY = P.Y - RasterHeight / 2;

                    Pointer.Angle = 90 + 22.5 + System.Math.Atan2(DY, DX) * 180 / System.Math.PI;

                    if (Draw)
                    {
                        Payload = new BinaryOutput();
                        Payload.WriteString(MqttConnection.ClientId);
                        Payload.WriteInt(LastP.X);
                        Payload.WriteInt(LastP.Y);
                        Payload.WriteInt(P.X);
                        Payload.WriteInt(P.Y);
                        Payload.WriteColor(Color);

                        MqttConnection.PUBLISH("RetroSharp/Examples/Networking/MultiUserDraw", MqttQualityOfService.AtMostOne, false, Payload);

                        DrawLine(LastP.X, LastP.Y, P.X, P.Y, Color);
                    }

                    LastP = P;
                };

                OnMouseDown += (sender, e) =>
                {
                    Draw = e.LeftButton;
                };

                OnMouseUp += (sender, e) =>
                {
                    Draw = e.LeftButton;
                };

                MqttConnection.OnContentReceived += (sender, Content) =>
                {
                    BinaryInput Input    = Content.DataInput;
                    string      ClientId = Input.ReadString();
                    if (ClientId != MqttConnection.ClientId)
                    {
                        int   X1 = (int)Input.ReadInt();
                        int   Y1 = (int)Input.ReadInt();
                        int   X2 = (int)Input.ReadInt();
                        int   Y2 = (int)Input.ReadInt();
                        Color cl = Input.ReadColor();

                        DrawLine(X1, Y1, X2, Y2, cl);
                    }
                };

                while (!Terminated.WaitOne(1000))
                {
                    ;
                }
            }

            Terminate();
        }