Exemplo n.º 1
0
        /// <summary>
        /// Resets and refreshes the labels during gameplay
        /// </summary>
        private void ResetLabels()
        {
            // Set label values
            if (world.cubes.ContainsKey(playerId))
            {
                FPSValue.Text   = "" + fps[0];
                FoodValue.Text  = "" + world.foodCount;
                MassValue.Text  = "" + (int)world.cubes[playerId].Mass;
                WidthValue.Text = "" + (int)world.cubes[playerId].width;
            }

            // Refresh all the labels
            FPSLabel.Refresh();
            FPSValue.Refresh();

            FoodLabel.Refresh();
            FoodValue.Refresh();

            MassLabel.Refresh();
            MassValue.Refresh();

            WidthLabel.Refresh();
            WidthValue.Refresh();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called to draw background
        /// </summary>
        private void AdCubioForm_Paint(object sender, PaintEventArgs e)
        {
            if (GameState == 1)
            {
                List <Cube> PlayerList = null;
                List <Cube> CubeList   = null;

                lock (TheWorld)
                {
                    PlayerList = TheWorld.PlayerCubes.Values.ToList <Cube>();
                    CubeList   = TheWorld.DictionaryOfCubes.Values.ToList <Cube>();
                }

                int NumOfFood = 0;

                //// Draw all other cubes
                foreach (Cube cube in CubeList)
                {
                    if (cube.FoodStatus == true)
                    {
                        NumOfFood += 1;
                    }
                    // Set brush color
                    myBrush = new SolidBrush(Color.FromArgb(cube.argb_color));
                    // Draw cube
                    e.Graphics.FillRectangle(myBrush, cube.X - (cube.getWidth() / 2), cube.Y - (cube.getWidth() / 2), cube.getWidth() + 3, cube.getWidth() + 3);

                    // Draw player name
                    myBrush = new SolidBrush(Color.Black);
                    e.Graphics.DrawString(cube.Name, new Font("Times New Roman", 15.0f), myBrush, new PointF(cube.X - 20, cube.Y));
                }
                // Update food label
                FoodLabel.Text = NumOfFood.ToString();
                FoodLabel.Refresh();

                // Used to display current player mass
                int mass = 0;

                // Draw all player cubes
                foreach (Cube cube in PlayerList)
                {
                    // Update width and masses
                    mass       += (int)cube.Mass;
                    PlayerMass += cube.Mass;
                    PlayerWidth = cube.getWidth();
                    if (cube.Mass != 0)
                    {
                        // Set brush to cube color
                        myBrush = new SolidBrush(Color.FromArgb(cube.argb_color));
                        // Draw cube
                        float width = cube.getWidth();
                        e.Graphics.FillRectangle(myBrush, cube.X - (cube.getWidth() / 2), cube.Y - (cube.getWidth() / 2), cube.getWidth(), cube.getWidth());

                        // Draw player name
                        myBrush = new SolidBrush(Color.Black);
                        e.Graphics.DrawString(cube.Name, new Font("Times New Roman", 15.0f), myBrush, new PointF(cube.X, cube.Y - 5));
                    }
                }

                // Player has died
                if (mass == 0 && GameState == 1 && PlayerMass != 0)
                {
                    MessageBox.Show("You died!\n Your final mass was: " + PlayerMass);
                    Close();
                }

                // Update width label
                WidthLabel.Text = "Width: " + PlayerWidth;
                WidthLabel.Refresh();

                // Update mass label
                MassLabel.Text = "Mass: " + mass;
                MassLabel.Refresh();

                // Send move request
                sendRequest("move", Mousex, Mousey);
                // Calculate FPS then paint
                CalcFrames();
                Invalidate();
            }
        }