static positon analyzeMatrix(int[,] mat)
        {
            int[] loxX = new int[mat.Length];
            int[] loxY = new int[mat.Length];

            positon p1 = new positon(mat.Length);



            int xloc = 0;

            for (int i = 0; i < mat.GetLength(0); i++)
            {
                for (int j = 0; j < mat.GetLength(1); j++)
                {
                    //Get co-ordinate of neighbours
                    int right = (j + 1) % (mat.GetLength(0));
                    int down  = (i + 1) % (mat.GetLength(0));
                    int up;
                    int left;

                    if (((i - 1) % (mat.GetLength(0)) >= 0))
                    {
                        up = (i - 1) % (mat.GetLength(0));
                    }
                    else
                    {
                        up = ((mat.GetLength(0))) + (i - 1) % (mat.GetLength(0));
                    }

                    if (((j - 1) % (mat.GetLength(0)) >= 0))
                    {
                        left = (j - 1) % (mat.GetLength(0));
                    }
                    else
                    {
                        left = ((mat.GetLength(0))) + (j - 1) % (mat.GetLength(0));
                    }



                    // Get values in the co-ordinates
                    int rightneighbour = mat[i, right];
                    int upneighbour    = mat[up, j];
                    int downneighbour  = mat[down, j];
                    int leftneighbour  = mat[i, left];


                    //Tag those elements who's neighours are 1, for replacement in the next flip.
                    if (rightneighbour == 1 | upneighbour == 1 | downneighbour == 1 | leftneighbour == 1)
                    {
                        p1.loxX[xloc] = i;
                        p1.loxY[xloc] = j;

                        xloc++;
                    }
                }
            }
            return(p1);
        }
        static int[,] makechangestoMat(int[,] mat, positon p1)
        {
            for (int i = 0; i < p1.loxX.Length; i++)
            {
                mat[p1.loxX[i], p1.loxY[i]] = 1;
            }

            return(mat);
        }
Example #3
0
        public canvas()
        {
            InitializeComponent();

            anzahl_wolken       = 0;
            counter_keine_wolke = 0;

            _x            = 200;
            _y            = 400;
            _objPostition = positon.Down;
            max_hoehe     = 200;
        }
Example #4
0
        private void Canvas_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up && _y >= 410)
            {
                _objPostition = positon.Up;
            }

            if (e.KeyCode == Keys.W)
            {
                _objPostition = positon.Up;
            }

            if (e.KeyCode == Keys.Down)
            {
                sneak = true;
            }
        }
        public Form1()
        {
            police1x = r.Next(0, 360);
            police1y = r.Next(0, 360);
            coin1x   = r.Next(0, 620);
            coin1y   = r.Next(0, 360);
            coin2x   = r.Next(0, 620);
            coin2y   = r.Next(0, 360);
            coin3x   = r.Next(0, 620);
            coin3y   = r.Next(0, 360);
            coin4x   = r.Next(0, 620);
            coin4y   = r.Next(0, 360);
            coin5x   = r.Next(0, 620);
            coin5y   = r.Next(0, 360);
            police2x = r.Next(0, 620);
            police2y = r.Next(0, 360);
            police3x = r.Next(0, 620);
            police3y = r.Next(0, 360);



            InitializeComponent();

            police3position = positon.Right;
            police1position = positon.Right;
            police2position = positon.Right;
            police1x        = r.Next(0, 620);
            police1y        = r.Next(0, 360);
            coin1x          = r.Next(0, 620);
            coin1y          = r.Next(0, 360);
            coin2x          = r.Next(0, 620);
            coin2y          = r.Next(0, 360);
            coin3x          = r.Next(0, 620);
            coin3y          = r.Next(0, 360);
            coin4x          = r.Next(0, 620);
            coin4y          = r.Next(0, 360);
            coin5x          = r.Next(0, 620);
            coin5y          = r.Next(0, 360);
            police2x        = r.Next(0, 620);
            police2y        = r.Next(0, 360);
            police3x        = r.Next(0, 620);
            police3y        = r.Next(0, 360);
        }
        static void Main(string[] args)
        {
            int[,] mat = { { 0, 0, 0 }, { 0, 1, 0 }, { 0, 0, 0 } };



            // displayMatrix(mat);
            positon result = null;

            while (repeatoperation(mat) == true)
            {
                result = analyzeMatrix(mat);
                mat    = makechangestoMat(mat, result);
                displayMatrix(mat);
            }



            Console.ReadKey();
        }
Example #7
0
        // Ticker der jede Sekunde durchläuft wird
        private void Timer1_Tick(object sender, EventArgs e)
        {
Start:
            _xobst -= 30;
            if (_xobst <= 0)
            {
                rng    = new Random();
                _xobst = rng.Next(1400, 1700);
            }

            if (_y + höhe >= 550)
            {
                _y = 400;
            }

            if (_x < _xobst + 20 + hitboxbreite && _x + breite > _xobst + 20 && _y < _yobst + hitboxhöhe && _y + höhe > _yobst)
            {
                _xobst = rng.Next(1400, 1700);
                Thread.Sleep(500);
                goto Start;
            }

            // Mensch wird hochgesetzt
            if (_objPostition == positon.Up)
            {
                sneak = false;
                if (_y >= max_hoehe + 20)
                {
                    _y -= 30;
                }
                else
                {
                    _objPostition = positon.Down;
                }
            }

            // Mensch wird runtergesetzt
            if (_objPostition == positon.Down)
            {
                _y += 30;
            }

            if (sneak == true)
            {
                höhe = 100;
                _y   = _y + 50;
            }
            else
            {
                höhe = 150;
            }


            if (counter_keine_wolke < dauer_bis_nächste_wolke)
            {
                counter_keine_wolke++;
            }
            else
            {
                Erzeuge_Wolke();
                counter_keine_wolke = 0;
            }


            int anzahl = anzahl_wolken;

            // Pro Durchlauf werden alle x-Koordinaten aller Wolken um 20 nach links verschoben
            for (int i = 0; i < anzahl; i++)
            {
                int [] aktuelleWolke = wolken_data[i];

                // Wenn die Wolke nicht mehr sichtbar ist, wird sie gelöscht
                if (aktuelleWolke[0] < -300)
                {
                    Lösche_Wolke(i);
                    anzahl--;
                }
                else
                {
                    aktuelleWolke[0] -= 20;
                }
            }



            // Aktualisiert die Oberfläche
            Invalidate();
        }
        private void police1tiner_Tick(object sender, EventArgs e)
        {
            if (coin)
            {
                if (police1position == positon.Right)
                {
                    if (police1x < x)
                    {
                        police1x += 1;
                    }
                    else
                    {
                        police1position = positon.Left;
                    }
                }
                if (police1position == positon.Left)
                {
                    if (police1x > x)
                    {
                        police1x -= 1;
                    }
                    else
                    {
                        police1position = positon.Up;
                    }
                }


                if (police1position == positon.Up)
                {
                    if (police1y > y)
                    {
                        police1y -= 1;
                    }
                    else
                    {
                        police1position = positon.Down;
                    }
                }
                if (police1position == positon.Down)
                {
                    if (police1y < y)
                    {
                        police1y += 1;
                    }
                    else
                    {
                        police1position = positon.Right;
                    }
                }



                if (police2position == positon.Right)
                {
                    if (police2x < x)
                    {
                        police2x += 1;
                    }
                    else
                    {
                        police2position = positon.Left;
                    }
                }
                if (police2position == positon.Left)
                {
                    if (police2x > x)
                    {
                        police2x -= 1;
                    }
                    else
                    {
                        police2position = positon.Up;
                    }
                }


                if (police2position == positon.Up)
                {
                    if (police2y > y)
                    {
                        police2y -= 1;
                    }
                    else
                    {
                        police2position = positon.Down;
                    }
                }
                if (police2position == positon.Down)
                {
                    if (police2y < y)
                    {
                        police2y += 1;
                    }
                    else
                    {
                        police2position = positon.Right;
                    }
                }
                if (police3position == positon.Right)
                {
                    if (police3x < x)
                    {
                        police3x += 1;
                    }
                    else
                    {
                        police3position = positon.Left;
                    }
                }
                if (police3position == positon.Left)
                {
                    if (police3x > x)
                    {
                        police3x -= 1;
                    }
                    else
                    {
                        police3position = positon.Up;
                    }
                }


                if (police3position == positon.Up)
                {
                    if (police3y > y)
                    {
                        police3y -= 1;
                    }
                    else
                    {
                        police3position = positon.Down;
                    }
                }
                if (police3position == positon.Down)
                {
                    if (police3y < y)
                    {
                        police3y += 1;
                    }
                    else
                    {
                        police3position = positon.Right;
                    }
                }



                Invalidate();
            }

            if ((police1x == x && police1y == y) || (police2x == x && police2y == y) || (police3x == x && police3y == y))
            {
                Close();
            }
        }