Ejemplo n.º 1
0
        public Field()
        {
            InitializeComponent();

            t.Tick    += new EventHandler(TimerT);
            t.Interval = 1000;
            v.Tick    += new EventHandler(TimerV);
            v.Interval = 200;
            field1     = new GameField(10, 10);
            field1.CreateField();
            t.Start();
            v.Start();
            startgame = false;
        }
Ejemplo n.º 2
0
        void TimerT(object sender, EventArgs e)
        {
            //Case of all orbs absorbed
            if (field1.IsCleared())
            {
                clearedfields++;
                totaltime += field1.time;
                field1.ClearField();
                field1.CreateField();
            }

            if (field1.ball1.NextTrap(field1))
            {
                GameEndField();
            }

            //moveball
            field1.ball1.Move(field1);

            //Forced garbage collect
            GC.Collect();
        }
Ejemplo n.º 3
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;
                        }
                    }
                }
            }
        }