Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
0
        static void Main()
        {
            MainMenu test = new MainMenu();

            test.ShowDialog();
            //Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Red;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.OutputEncoding  = System.Text.Encoding.UTF8;
            Console.CursorVisible   = false;
            Console.Title           = "New Ball Game";
            //Console.SetWindowSize(field1.Y * 5, field1.X + Convert.ToInt32(field1.X * 0.5));
            int c;

            //game setup
            //Timer t = new Timer(TimerCallback, null, 0, 1000);
            //Timer v = new Timer(TimerCallback1, null, 0, 100);
            t.Elapsed += new ElapsedEventHandler(TimerT);
            t.Interval = 1000;
            v.Elapsed += new ElapsedEventHandler(TimerV);
            v.Interval = 200;
            //s.Elapsed += new ElapsedEventHandler(TimerS);
            //s.Interval = 200;
            //s.Start();

            //Timer with additional arguments
            //var timer = new System.Timers.Timer { Interval = 1500 };
            //timer.Elapsed += (sender, e) => MyElapsedMethod(sender, e, field1);
            //timer.Start();


            //exit statement
            for (; ;)
            {
                if (!mainmenu)
                {
                    if (!endgame)
                    {
                        if (startgame)
                        {
                            field1.CreateField();
                            t.Start();
                            v.Start();
                            startgame = false;
                        }
                        else
                        {
                            if (field1.ball1.NextTrap(field1))
                            {
                                endgame = true;
                            }
                            var ch = Console.ReadKey(true).Key;
                            switch (ch)
                            {
                            case ConsoleKey.LeftArrow:
                                field1.selector.MoveLeft();
                                break;

                            case ConsoleKey.RightArrow:
                                field1.selector.MoveRight();
                                break;

                            case ConsoleKey.DownArrow:
                                field1.selector.MoveUp();
                                break;

                            case ConsoleKey.UpArrow:
                                field1.selector.MoveDown();
                                break;

                            case ConsoleKey.Z:
                                field1.selector.SetS(field1);
                                break;

                            case ConsoleKey.X:
                                field1.selector.SetBS(field1);
                                break;

                            case ConsoleKey.C:
                                field1.selector.SetC(field1);
                                break;

                            case ConsoleKey.Escape:
                                Environment.Exit(0);
                                break;

                            case ConsoleKey.R:
                                v.Stop();
                                t.Stop();
                                totaltime     = 0;
                                clearedfields = 0;
                                endgame       = false;
                                startgame     = false;
                                mainmenu      = true;
                                break;
                            }
                            //Console.ReadLine();
                        }
                    }
                    else
                    {
                        totaltime += field1.time;
                        GameEndField(t, v);
                    }
                }
                else
                {
                    t.Stop();
                    v.Stop();
                    Console.Clear();

                    for (bool lol = false; !lol;)
                    {
                        Console.Clear();
                        //mainmenu text
                        Console.WriteLine("\n\n\n");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write("          MAIN MENU\n\n\n          ");
                        if (selector == 1)
                        {
                            Console.BackgroundColor = ConsoleColor.Green;
                        }
                        else
                        {
                            Console.BackgroundColor = ConsoleColor.Black;
                        }
                        Console.Write("Start game\n\n");
                        Console.BackgroundColor = ConsoleColor.Black;
                        Console.Write("          ");
                        if (selector == 2)
                        {
                            Console.BackgroundColor = ConsoleColor.Green;
                        }
                        else
                        {
                            Console.BackgroundColor = ConsoleColor.Black;
                        }
                        Console.Write("Hall of fame\n\n");
                        Console.BackgroundColor = ConsoleColor.Black;
                        Console.Write("          ");
                        if (selector == 3)
                        {
                            Console.BackgroundColor = ConsoleColor.Green;
                        }
                        else
                        {
                            Console.BackgroundColor = ConsoleColor.Black;
                        }
                        Console.Write("Exit game\n\n");
                        Console.BackgroundColor = ConsoleColor.Black;
                        Console.WriteLine("Use arrows to choose, enter to select");
                        s.Start();

                        var ch = Console.ReadKey(true).Key;
                        switch (ch)
                        {
                        case ConsoleKey.DownArrow:
                            if (selector == 1)
                            {
                                selector = 2;
                            }
                            else if (selector == 2)
                            {
                                selector = 3;
                            }
                            else if (selector == 3)
                            {
                                selector = 1;
                            }
                            break;

                        case ConsoleKey.UpArrow:
                            if (selector == 2)
                            {
                                selector = 1;
                            }
                            else if (selector == 1)
                            {
                                selector = 3;
                            }
                            else if (selector == 3)
                            {
                                selector = 2;
                            }
                            break;

                        case ConsoleKey.Enter:
                            if (selector == 1)
                            {
                                startgame = true;
                                Console.Clear();
                                c        = GetInt();
                                field1   = new GameField(c, c);
                                mainmenu = false;
                                s.Stop();
                                lol = true;
                            }
                            else if (selector == 3)
                            {
                                Environment.Exit(0);
                            }
                            else if (selector == 2)
                            {
                                Form1 form = new Form1();
                                form.ShowDialog();
                            }
                            break;

                        case ConsoleKey.Escape:
                            Environment.Exit(0);
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public Selector(int T, GameField field1) : base(T)
 {
     MaxX = field1.X;
     MaxY = field1.Y;
 }