示例#1
0
        public void CreateField()
        {
            //Creating walls
            for (int i = 0; i < X; i++)
            {
                Table[i, 0]     = new GameElement(7);// 0 - #, 1 - @, 2 - •, 3 - /, 4 - \, 5 - ₴, 6 - +, 7 - ;8 - ■
                Table[i, Y - 1] = new GameElement(7);
                Table[i, 0].SetCoordinates(i, 0);
                Table[i, 0].SetCoordinates(i, Y - 1);
            }
            for (int i = 0; i < Y; i++)
            {
                Table[0, i]     = new GameElement(7);
                Table[X - 1, i] = new GameElement(7);
                Table[0, i].SetCoordinates(0, i);
                Table[X - 1, i].SetCoordinates(X - 1, i);
            }

            //RANDOM generator
            Random random  = new Random();
            int    tempint = 0;

            for (int i = 1; i < X - 1; i++)
            {
                for (int x = 1; x < Y - 1; x++)
                {
                    if (i > 2 || x > 2)
                    {
                        tempint = random.Next(1, 130);//add some ↑
                        if (tempint < 61)
                        {
                            Table[i, x] = new GameElement(7);
                        }
                        else if (tempint > 60 && tempint < 76)
                        {
                            Table[i, x] = new GameElement(0);
                        }
                        else if (tempint > 75 && tempint < 88)
                        {
                            Table[i, x] = new GameElement(1);
                        }
                        else if (tempint > 87 && tempint < 96)
                        {
                            Table[i, x] = new GameElement(5);
                        }
                        else if (tempint > 95 && tempint < 101)
                        {
                            Table[i, x] = new GameElement(9);
                        }
                        else if (tempint > 100 && tempint < 106)
                        {
                            Table[i, x] = new GameElement(10);
                        }
                        else if (tempint > 105 && tempint < 111)
                        {
                            Table[i, x] = new GameElement(11);
                        }
                        else if (tempint > 110 && tempint < 116)
                        {
                            Table[i, x] = new GameElement(12);
                        }
                        else if (tempint > 115 && tempint < 121)
                        {
                            Table[i, x] = new GameElement(13);
                        }
                        else if (tempint > 120 && tempint < 126)
                        {
                            Table[i, x] = new GameElement(6);
                        }
                        else if (tempint > 125)
                        {
                            Random rand = new Random();
                            while (true)
                            {
                                int tempX = rand.Next(0, X);
                                int tempY = rand.Next(0, Y);

                                if (Table[tempX, tempY] != null)
                                {
                                    if (Table[tempX, tempY].type == ' ')
                                    {
                                        linkedTP tempTP = new linkedTP(14);
                                        Table[i, x]         = tempTP;
                                        Table[tempX, tempY] = Table[i, x];
                                        Table[tempX, tempY].SetCoordinates(tempX, tempY);
                                        tempTP.X1 = tempX;
                                        tempTP.Y1 = tempY;
                                        break;
                                    }
                                }
                                else
                                {
                                    linkedTP tempTP = new linkedTP(14);
                                    Table[i, x]         = tempTP;
                                    Table[tempX, tempY] = Table[i, x];
                                    Table[tempX, tempY].SetCoordinates(tempX, tempY);
                                    tempTP.X1 = tempX;
                                    tempTP.Y1 = tempY;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        Table[i, x] = new GameElement(7);
                    }
                    Table[i, x].SetCoordinates(i, x);
                }
            }

            //PATTERN generator+fill with random if not patterned
            if (X > 5)//playzone is bigger than 3
            {
                Pattern pattern;
                GameElement[,] array;
                int c = 0;
                for (int i = X - 2 / 3; i > 0; i--)//count of pattern structs
                {
                    //for (int z = 2; z < (X - 2) * (X - 2); z++)//count of elements
                    //{
                    for (int x = (X - 2) % 3 + 1; x < X - 3; x++)
                    {
                        for (int y = (X - 2) % 3 + 1; y < X - 3; y++)
                        {
                            if (this.AreaIsClear(this, new[] { x, y }, new[] { x + 2, y + 2 }))
                            {
                                pattern = new Pattern(random.Next(1, 2));//3x3 structs
                                array   = pattern.ReturnPattern();
                                for (int l = x; l < x + 3; l++)
                                {
                                    for (int m = y; m < y + 3; m++)
                                    {
                                        Table[l, m] = array[l - x, m - y];
                                    }
                                }
                                c++;
                                if (c == i)
                                {
                                    goto Foo;
                                }
                            }
                        }
                    }
                    //}
                }
Foo:
                Nothing();
            }


            //Setting up ball
            ball1.SetCoordinates(1, 1);

            //Setting up layer table for selector
            selector = new Selector(8, this);
            selector.SetCoordinates(0, 0);
        }
示例#2
0
        public void Move(GameField field1)
        {
            if (X + Dx > field1.X - 1)
            {
                X = 0;
            }
            else if (X + Dx < 0)
            {
                X = field1.X - 1;
            }
            else if (Y + Dy > field1.Y - 1)
            {
                Y = 0;
            }
            else if (Y + Dy < 0)
            {
                Y = field1.Y - 1;
            }
            else if (field1.Table[X + Dx, Y + Dy].type == ' ' || field1.Table[X + Dx, Y + Dy].type == '₴')//move if free
            {
                X += Dx;
                Y += Dy;
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '#')//move back if wall
            {
                Dx = -Dx;
                Dy = -Dy;
                Console.Beep(300, 150);//beep 2
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '+')
            {
                Random rand = new Random();
                while (true)
                {
                    int tempX = rand.Next(0, field1.X);
                    int tempY = rand.Next(0, field1.Y);
                    if (field1.Table[tempX, tempY].type == ' ')
                    {
                        X = tempX;
                        Y = tempY;
                        break;
                    }
                }
            }
            else if (field1.Table[X + Dx, Y + Dy].type == 'æ')
            {
                linkedTP tempTP = (linkedTP)field1.Table[X + Dx, Y + Dy];
                X = tempTP.X1;
                Y = tempTP.Y1;
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '↑')//move back if wall
            {
                X += Dx;
                Y += Dy;
                Dx = -1;
                Dy = 0;
                Console.Beep(500, 200);                        //beep 2
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '←') //move back if wall
            {
                X += Dx;
                Y += Dy;
                Dx = 0;
                Dy = -1;
                Console.Beep(500, 200);                        //beep 2
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '→') //move back if wall
            {
                X += Dx;
                Y += Dy;
                Dx = 0;
                Dy = 1;
                Console.Beep(500, 200);                        //beep 2
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '↓') //move back if wall
            {
                X += Dx;
                Y += Dy;
                Dx = 1;
                Dy = 0;
                Console.Beep(500, 200);                        //beep 2
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '@') //collect if orb
            {
                X += Dx;
                Y += Dy;
                field1.Orbs++;
                field1.Table[X, Y] = new GameElement(7);
                field1.Table[X, Y].SetCoordinates(X, Y);
                Console.Beep(600, 100);
                //beep wow
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '/')//bounce if /
            {
                if (Dx != 0)
                {
                    X += Dx;

                    if (Dx > 0)
                    {
                        Dy = -1;
                    }
                    else
                    {
                        Dy = 1;
                    }
                    Dx = 0;
                }
                else
                {
                    Y += Dy;
                    if (Dy > 0)
                    {
                        Dx = -1;
                    }
                    else
                    {
                        Dx = 1;
                    }
                    Dy = 0;
                }

                Console.Beep(300, 150);                         //beep like wall
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '\\') // bounce if \
            {
                if (Dx != 0)
                {
                    X += Dx;
                    if (Dx > 0)
                    {
                        Dy = 1;
                    }
                    else
                    {
                        Dy = -1;
                    }
                    Dx = 0;
                }
                else
                {
                    Y += Dy;
                    if (Dy > 0)
                    {
                        Dx = 1;
                    }
                    else
                    {
                        Dx = -1;
                    }
                    Dy = 0;
                }
                Console.Beep(300, 150);                        //beep like wall
            }
            else if (field1.Table[X + Dx, Y + Dy].type == '↑') //move up if arrow
            {
                Dx = 0;
                Dy = -Dy;
            }
        }