Esempio n. 1
0
        static void Main(string[] args)
        {
            ConsoleKeyInfo key_info;
            Weapon gun = new Weapon();
            int t1, t2;
            int p;
            Bullet tmpB = new Bullet();
            string tmp;
            Regex rxNums = new Regex(@"^\d+$");
            Console.WriteLine("Нажмите s для добавления пули по-умолчанию\n\tp для добавления пули с параметром\n\th для выстрела\n\tq для заряда\n\tk для сложения пуль\n\tw для заряда нескольких\n\ti для выстрела нескольких");
            do
            {
                key_info = Console.ReadKey(true);

                if (key_info.Key != ConsoleKey.S && key_info.Key != ConsoleKey.P && key_info.Key != ConsoleKey.Q && key_info.Key != ConsoleKey.H && key_info.Key != ConsoleKey.Escape && key_info.Key != ConsoleKey.F && key_info.Key != ConsoleKey.K && key_info.Key != ConsoleKey.W && key_info.Key != ConsoleKey.I)
                {
                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                }
                if (key_info.Key == ConsoleKey.S)
                {
                    //tmpB.SetPower(1);
                    Weapon.AddBullet(1);
                }
                if (key_info.Key == ConsoleKey.P)
                {
                    do
                    {
                        Console.WriteLine("Введите мощьность от 1 до 5:\t");
                        tmp = Console.ReadLine();
                        if (rxNums.IsMatch(tmp))
                        {
                            p = int.Parse(tmp);
                            if(p > 0 && p < 6){
                                //tmpB.SetPower(p);
                                Weapon.AddBullet(p);
                                break;
                            }
                        }
                        else
                        {
                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                            Console.WriteLine("                               ");
                            Console.SetCursorPosition(0, Console.CursorTop - 2);
                        }
                    } while (true);
                }
                if (key_info.Key == ConsoleKey.H)
                {
                    gun--;
                }
                if (key_info.Key == ConsoleKey.Q)
                {
                    gun++;
                }
                if (key_info.Key == ConsoleKey.K)
                {
                    Weapon.PrintStock();
                    Console.WriteLine("Выбирете два номера");
                    #region do
                    do
                    {
                        tmp = Console.ReadLine();
                        if (rxNums.IsMatch(tmp))
                        {
                            t1 = int.Parse(tmp);
                            if (t1 > 0 && t1 <= Weapon.GetCountStock())
                            {
                                do
                                {
                                    tmp = Console.ReadLine();
                                    if (rxNums.IsMatch(tmp))
                                    {
                                        t2 = int.Parse(tmp);
                                        if (t2 > 0 && t2 <= Weapon.GetCountStock() && t2 != t1)
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                                            Console.WriteLine("                               ");
                                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                                        }
                                    }
                                    else
                                    {
                                        Console.SetCursorPosition(0, Console.CursorTop - 1);
                                        Console.WriteLine("                               ");
                                        Console.SetCursorPosition(0, Console.CursorTop - 1);
                                    }
                                } while (true);
                                break;
                            }
                            else
                            {
                                Console.SetCursorPosition(0, Console.CursorTop - 1);
                                Console.WriteLine("                               ");
                                Console.SetCursorPosition(0, Console.CursorTop - 1);
                            }
                        }
                        else
                        {
                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                            Console.WriteLine("                               ");
                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                        }
                    } while (true);
                    #endregion
                    Weapon.ConcatBullet(t1, t2);
                }
                if (key_info.Key == ConsoleKey.W)
                {
                    Console.WriteLine("Введите кол-во зарядов:\t");
                    tmp = Console.ReadLine();
                    if (rxNums.IsMatch(tmp))
                    {
                        p = int.Parse(tmp);
                        gun += p;
                    }
                }
                if (key_info.Key == ConsoleKey.I)
                {
                    do
                    {
                        Console.WriteLine("Введите кол-во выстрелов от 1 до 7:\t");
                        tmp = Console.ReadLine();
                        if (rxNums.IsMatch(tmp))
                        {
                            p = int.Parse(tmp);
                            if (p > 0 && p < 8)
                            {
                                gun -= p;
                                break;
                            }
                        }
                        else
                        {
                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                            Console.WriteLine("                               ");
                            Console.SetCursorPosition(0, Console.CursorTop - 2);
                        }
                    } while (true);
                }
                Console.WriteLine("Дальше");
            } while (key_info.Key != ConsoleKey.Escape);
        }
Esempio n. 2
0
 public static void ConcatBullet(int t1, int t2)
 {
     tmpB = stock.ElementAt(t1-1);
     tmpB2 = stock.ElementAt(t2-1);
     tmpB += tmpB2;
     stock.RemoveAt(t1-1);
     stock.Insert(t1-1, tmpB);
     stock.RemoveAt(t2-1);
 }
Esempio n. 3
0
 public static void AddBullet(int p)
 {
     tmpB = new Bullet(p);
     stock.Add(tmpB);
 }
Esempio n. 4
0
 public Weapon()
 {
     max = 7;
     cont = 0;
     holder = new Stack<Bullet>();
     tmpB = new Bullet();
 }
Esempio n. 5
0
 static public void AddBullet(int p)
 {
     tmpB = new Bullet(p);
     stock.Add(tmpB);
 }
Esempio n. 6
0
        static void Main(string[] args)
        {
            ConsoleKeyInfo key_info;
            Weapon         gun = new Weapon();
            int            t1, t2;
            int            p;
            Bullet         tmpB = new Bullet();
            string         tmp;
            Regex          rxNums = new Regex(@"^\d+$");

            Console.WriteLine("Нажмите s для добавления пули по-умолчанию\n\tp для добавления пули с параметром\n\th для выстрела\n\tq для заряда\n\tk для сложения пуль\n\tw для заряда нескольких\n\ti для выстрела нескольких");
            do
            {
                key_info = Console.ReadKey(true);

                if (key_info.Key != ConsoleKey.S && key_info.Key != ConsoleKey.P && key_info.Key != ConsoleKey.Q && key_info.Key != ConsoleKey.H && key_info.Key != ConsoleKey.Escape && key_info.Key != ConsoleKey.F && key_info.Key != ConsoleKey.K && key_info.Key != ConsoleKey.W && key_info.Key != ConsoleKey.I)
                {
                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                }
                if (key_info.Key == ConsoleKey.S)
                {
                    //tmpB.SetPower(1);
                    Weapon.AddBullet(1);
                }
                if (key_info.Key == ConsoleKey.P)
                {
                    do
                    {
                        Console.WriteLine("Введите мощьность от 1 до 5:\t");
                        tmp = Console.ReadLine();
                        if (rxNums.IsMatch(tmp))
                        {
                            p = int.Parse(tmp);
                            if (p > 0 && p < 6)
                            {
                                //tmpB.SetPower(p);
                                Weapon.AddBullet(p);
                                break;
                            }
                        }
                        else
                        {
                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                            Console.WriteLine("                               ");
                            Console.SetCursorPosition(0, Console.CursorTop - 2);
                        }
                    } while (true);
                }
                if (key_info.Key == ConsoleKey.H)
                {
                    gun--;
                }
                if (key_info.Key == ConsoleKey.Q)
                {
                    gun++;
                }
                if (key_info.Key == ConsoleKey.K)
                {
                    Weapon.PrintStock();
                    Console.WriteLine("Выбирете два номера");
                    #region do
                    do
                    {
                        tmp = Console.ReadLine();
                        if (rxNums.IsMatch(tmp))
                        {
                            t1 = int.Parse(tmp);
                            if (t1 > 0 && t1 <= Weapon.GetCountStock())
                            {
                                do
                                {
                                    tmp = Console.ReadLine();
                                    if (rxNums.IsMatch(tmp))
                                    {
                                        t2 = int.Parse(tmp);
                                        if (t2 > 0 && t2 <= Weapon.GetCountStock() && t2 != t1)
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                                            Console.WriteLine("                               ");
                                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                                        }
                                    }
                                    else
                                    {
                                        Console.SetCursorPosition(0, Console.CursorTop - 1);
                                        Console.WriteLine("                               ");
                                        Console.SetCursorPosition(0, Console.CursorTop - 1);
                                    }
                                } while (true);
                                break;
                            }
                            else
                            {
                                Console.SetCursorPosition(0, Console.CursorTop - 1);
                                Console.WriteLine("                               ");
                                Console.SetCursorPosition(0, Console.CursorTop - 1);
                            }
                        }
                        else
                        {
                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                            Console.WriteLine("                               ");
                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                        }
                    } while (true);
                    #endregion
                    Weapon.ConcatBullet(t1, t2);
                }
                if (key_info.Key == ConsoleKey.W)
                {
                    Console.WriteLine("Введите кол-во зарядов:\t");
                    tmp = Console.ReadLine();
                    if (rxNums.IsMatch(tmp))
                    {
                        p    = int.Parse(tmp);
                        gun += p;
                    }
                }
                if (key_info.Key == ConsoleKey.I)
                {
                    do
                    {
                        Console.WriteLine("Введите кол-во выстрелов от 1 до 7:\t");
                        tmp = Console.ReadLine();
                        if (rxNums.IsMatch(tmp))
                        {
                            p = int.Parse(tmp);
                            if (p > 0 && p < 8)
                            {
                                gun -= p;
                                break;
                            }
                        }
                        else
                        {
                            Console.SetCursorPosition(0, Console.CursorTop - 1);
                            Console.WriteLine("                               ");
                            Console.SetCursorPosition(0, Console.CursorTop - 2);
                        }
                    } while (true);
                }
                Console.WriteLine("Дальше");
            } while (key_info.Key != ConsoleKey.Escape);
        }