Example #1
0
 public override bool StartEvent(PressEvent key, ref int x, ref int y)
 {
     if (keyPressEvent != null)
     {
         if (keyPressEvent(ref x, ref y, key))
         {
             return(true);
         }
     }
     return(false);
 }
        public void SandBox()
        {
            int        x = 0, y = 0;
            PressEvent key = new PressEvent();

            key.KeyInfo = Console.ReadKey();

            KeyPress action = new KeyPress(key.KeyInfo);

            while (true)
            {
                key.KeyInfo = Console.ReadKey();
                key.Cells   = this;
                if (action.StartEvent(key, ref x, ref y))
                {
                    Console.WriteLine("exit");
                    return;
                }
            }
        }
Example #3
0
        public override bool React(ref int x, ref int y, PressEvent press)
        {
            ConsoleKeyInfo save;

            switch (press.KeyInfo.Key)
            {
            case ConsoleKey.W:
            {
                x--;
                if (x < 0)
                {
                    Console.WriteLine($"range y {x}");
                    y = 0;
                    break;
                }
                press.Cells.show();
                Console.Clear();

                press.Cells.field[x][y].Live = true;
                press.Cells.show();
                save = Console.ReadKey();
                if (save.Key == ConsoleKey.Q)
                {
                    Console.WriteLine("Save!");
                    press.Cells.field[x][y].Saved = true;
                    Console.ReadKey();
                }
                else
                {
                    if (press.Cells.field[x][y].Saved != null && press.Cells.field[x][y].Saved)
                    {
                        break;
                    }
                    else
                    {
                        press.Cells.field[x][y].Live  = false;
                        press.Cells.field[x][y].Saved = false;
                    }
                }
                break;
            }

            case ConsoleKey.D:
            {
                y++;
                if (y >= press.Cells.field[x].Length)
                {
                    Console.WriteLine($"range y {y}");
                    y = 0;
                    break;
                }
                press.Cells.show();
                Console.Clear();

                press.Cells.field[x][y].Live = true;
                press.Cells.show();
                save = Console.ReadKey();
                if (save.Key == ConsoleKey.Q)
                {
                    Console.WriteLine("Save!");
                    press.Cells.field[x][y].Saved = true;
                    Console.ReadKey();
                }
                else
                {
                    if (press.Cells.field[x][y].Saved != null && press.Cells.field[x][y].Saved)
                    {
                        break;
                    }
                    else
                    {
                        press.Cells.field[x][y].Live  = false;
                        press.Cells.field[x][y].Saved = false;
                    }
                }
                break;
            }

            case ConsoleKey.A:
            {
                y--;

                if (y < 0)
                {
                    Console.WriteLine($"range y {y}");
                    y = 0;
                    break;
                }
                press.Cells.show();
                Console.Clear();

                press.Cells.field[x][y].Live = true;
                press.Cells.show();
                save = Console.ReadKey();
                if (save.Key == ConsoleKey.Q)
                {
                    Console.WriteLine("Save!");
                    press.Cells.field[x][y].Saved = true;
                    Console.ReadKey();
                }
                else
                {
                    if (press.Cells.field[x][y].Saved != null && press.Cells.field[x][y].Saved)
                    {
                        break;
                    }
                    else
                    {
                        press.Cells.field[x][y].Live  = false;
                        press.Cells.field[x][y].Saved = false;
                    }
                }
                break;
            }

            case ConsoleKey.S:
            {
                x++;

                if (x > press.Cells.field.Length)
                {
                    Console.WriteLine($"range y {x}");
                    y = 0;
                    break;
                }
                press.Cells.show();
                Console.Clear();
                press.Cells.field[x][y].Live = true;
                press.Cells.show();
                save = Console.ReadKey();
                if (save.Key == ConsoleKey.Q)
                {
                    Console.WriteLine("Save!");
                    press.Cells.field[x][y].Saved = true;
                    Console.ReadKey();
                }
                else
                {
                    if (press.Cells.field[x][y].Saved != null && press.Cells.field[x][y].Saved)
                    {
                        break;
                    }
                    else
                    {
                        press.Cells.field[x][y].Live  = false;
                        press.Cells.field[x][y].Saved = false;
                    }
                }
                break;
            }

            case ConsoleKey.Escape:
            {
                return(true);

                break;
            }
            }
            return(false);
        }