Esempio n. 1
0
        public override bool check_step(Tuple <int, int> destination, BoardClass board)
        {
            int  start  = -1;
            bool result = false;

            foreach (var step in chess_steps)
            {
                Tuple <int, int> new_cord = chess_cord;

                while (new_cord.Item1 < board.Height && new_cord.Item2 < board.Width && new_cord.Item1 > start && new_cord.Item2 > start)
                {
                    new_cord = sum_tuples(step, new_cord);
                    if (new_cord.Equals(destination))
                    {
                        result = true;
                        break;
                    }
                    if (board.find_chess_by_coords(new_cord) != null)
                    {
                        break;
                    }
                }

                if (result)
                {
                    break;
                }
            }
            return(result);
        }
Esempio n. 2
0
        public void load_game()
        {
            BinaryFormatter formatter = new BinaryFormatter();
            DirectoryInfo   info      = new DirectoryInfo(Directory.GetCurrentDirectory());

            FileInfo[] files = info.GetFiles();

            find_only_dat_files(files);
            Console.WriteLine("Games Saved:");
            DisplayClass.show_file_info(files);
            Console.WriteLine("Input game name: ");
            string name = $"{Console.ReadLine()}.dat";

            if (name.Length > 0 && find_file_name(files, name))
            {
                using (FileStream fs = new FileStream(name, FileMode.OpenOrCreate))
                {
                    try
                    {
                        board         = (BoardClass)formatter.Deserialize(fs);
                        CurrentPlayer = (Player)formatter.Deserialize(fs);
                        GameStarted   = true;
                    }
                    catch (SerializationException)
                    {
                        Console.WriteLine("LoadError!");
                    }
                }
            }
            else
            {
                Console.WriteLine("LoadError!!!");
            }
        }
Esempio n. 3
0
 public GameEngineClass()
 {
     board          = new BoardClass();
     PlayerOneBlack = new Player(0);
     PlayerTwoWhite = new Player(1);
     codes          = new Dictionary <string, int>();
     message_buf    = new Stack <string>();
     set_dict();
 }
Esempio n. 4
0
        public virtual bool check_step(Tuple <int, int> destination, BoardClass board)
        {
            bool result = false;

            foreach (var step in chess_steps)
            {
                Tuple <int, int> new_cord = sum_tuples(step, chess_cord);
                if (new_cord.Equals(destination))
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Esempio n. 5
0
        public static void show_table(BoardClass board, Stack <string> message_buf)
        {
            char symb_ver           = '8',
                 space_sybmol_white = '•',
                 space_sybmol_black = '•';

            for (int i = 0; i < message_buf.Count; i++)
            {
                Console.WriteLine(message_buf.Pop());
            }
            print_alphas();
            bool flag;

            for (int i = 0; i < board.Height; i++, symb_ver--)
            {
                Console.Write(symb_ver + " ");
                for (int j = 0; j < board.Width; j++)
                {
                    flag = false;
                    for (int k = 0; k < board.Chesses.Count; k++)
                    {
                        if (board.Chesses[k].GetCords.Equals(new Tuple <int, int>(j, i)))
                        {
                            Console.Write(board.Chesses[k] + " ");
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        if ((i + j) % 2 == 0)
                        {
                            Console.Write(space_sybmol_black + " ");
                        }
                        else
                        {
                            Console.Write(space_sybmol_white + " ");
                        }
                    }
                }
                Console.Write(symb_ver + " ");
                Console.Write('\n');
            }
            print_alphas();
        }
Esempio n. 6
0
        public override bool check_step(Tuple <int, int> destination, BoardClass board)
        {
            int              repeat   = is_started ? 1 : 2;
            bool             result   = false;
            Tuple <int, int> step_one = sum_tuples(chess_cord, attack_steps[0]);
            Tuple <int, int> step_two = sum_tuples(chess_cord, attack_steps[1]);
            bool             one      = (step_one.Equals(destination) && board.find_chess_by_coords(step_one) != null);
            bool             two      = (step_two.Equals(destination) && board.find_chess_by_coords(step_two) != null);

            if (one || two)
            {
                result = true;
            }
            foreach (var step in chess_steps)
            {
                if (result)
                {
                    break;
                }
                Tuple <int, int> new_cord = chess_cord;
                for (int i = 0; i < repeat; i++)
                {
                    new_cord = sum_tuples(step, new_cord);
                    if (board.find_chess_by_coords(new_cord) != null)
                    {
                        break;
                    }
                    if (new_cord.Equals(destination))
                    {
                        result = true;
                        break;
                    }
                }
            }
            return(result);
        }