예제 #1
0
        public string JatekosBabujanakMozgatasa(int[] regiPozicio, int[] ujPozicio, Tabla tabla)
        {
            bool megfeleloALepesszam = EgyetLepett(regiPozicio, ujPozicio);
            bool nemLepettAtlosan    = NemLepettAtlosan(regiPozicio, ujPozicio);
            bool uresAzUjMezo        = UresAzUjMezo(ujPozicio, tabla);


            if (!UgrasE(regiPozicio, ujPozicio, tabla))
            {
                return("You can't move more than one step");
            }

            if (!nemLepettAtlosan)
            {
                return("You can't move diagonally");
            }

            if (!uresAzUjMezo)
            {
                return("The target field is not empty");
            }

            for (int i = 0; i < MainClass.JelenlegiJatekos.Babuk.Length; i++)
            {
                if (MainClass.JelenlegiJatekos.Babuk[i].Pozicio[0] == regiPozicio[0] &&
                    MainClass.JelenlegiJatekos.Babuk[i].Pozicio[1] == regiPozicio[1])
                {
                    MainClass.JelenlegiJatekos.Babuk[i].Pozicio = ujPozicio;
                    return("");
                }
            }

            return("The start field isn't yours");
        }
예제 #2
0
        public bool UgrasE(int[] regiPozicio, int[] ujPozicio, Tabla tabla)
        {
            int index;

            if (regiPozicio[1] == ujPozicio[1])
            {
                if (regiPozicio[0] < ujPozicio[0])
                {
                    index = regiPozicio[0] + 1;

                    while (index < ujPozicio[0] && !tabla.JatekTer[index, regiPozicio[1]].Equals('-'))
                    {
                        index++;
                    }
                    return(index >= ujPozicio[0]);
                }
                else
                {
                    index = ujPozicio[0] + 1;

                    while (index < regiPozicio[0] && !tabla.JatekTer[index, regiPozicio[1]].Equals('-'))
                    {
                        index++;
                    }
                    return(index >= regiPozicio[0]);
                }
            }
            if (regiPozicio[0] == ujPozicio[0])
            {
                if (regiPozicio[1] < ujPozicio[1])
                {
                    index = regiPozicio[1] + 1;

                    while (index < ujPozicio[1] && !tabla.JatekTer[regiPozicio[0], index].Equals('-'))
                    {
                        index++;
                    }
                    return(index >= ujPozicio[1]);
                }
                else
                {
                    index = ujPozicio[1] + 1;

                    while (index < regiPozicio[1] && !tabla.JatekTer[regiPozicio[0], index].Equals('-'))
                    {
                        index++;
                    }
                    return(index >= regiPozicio[1]);
                }
            }
            else
            {
                return(true);
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            Console.Clear();
            Console.Write("Select game type to start the game [1 or 2]: ");
            JatekTipus = int.Parse(Console.ReadLine());

            Jatekos ElsoJatekos    = new Jatekos(1, JatekTipus);
            Jatekos MasodikJatekos = new Jatekos(2, JatekTipus);

            Jatekos[] jatekosok = new Jatekos[] { ElsoJatekos, MasodikJatekos };
            Tabla     Tabla     = new Tabla(jatekosok, ElsoJatekos);

            JelenlegiJatekos = ElsoJatekos;

            Tabla.AlapTablaKirajzolasa();
            Tabla.JatekosokFelallitasa(Tabla.Jatekosok);

            Console.Write("(" + JelenlegiJatekos.JatekosSzam + ") ");
            Parancs = Console.ReadLine();

            while (!JatekVege)
            {
                if (Parancs.Length > 4 && Parancs.Substring(0, 4) == "move")
                {
                    string[] koordinatak    = Parancs.Split(' ');
                    char[]   regiKoordinata = new char[2];
                    char[]   ujKoordinata   = new char[2];
                    int[]    regiIndex      = new int[2];
                    int[]    ujIndex        = new int[2];

                    regiKoordinata[0] = (char)koordinatak[1][0];
                    regiKoordinata[1] = (char)koordinatak[1][1];
                    ujKoordinata[0]   = (char)koordinatak[2][0];
                    ujKoordinata[1]   = (char)koordinatak[2][1];

                    for (int i = 0; i < Tabla.Betuk.Length; i++)
                    {
                        if (Tabla.Betuk[i] == regiKoordinata[0])
                        {
                            regiIndex[0] = i;
                        }
                        if (Tabla.Betuk[i] == ujKoordinata[0])
                        {
                            ujIndex[0] = i;
                        }
                    }

                    for (int j = 0; j < Tabla.Szamok.Length; j++)
                    {
                        if (Tabla.Szamok[j] == regiKoordinata[1])
                        {
                            regiIndex[1] = j;
                        }
                        if (Tabla.Szamok[j] == ujKoordinata[1])
                        {
                            ujIndex[1] = j;
                        }
                    }

                    string valasz = Tabla.JatekosBabujanakMozgatasa(regiIndex, ujIndex, Tabla);

                    if (valasz == "")
                    {
                        Tabla.JatekTer[regiIndex[0], regiIndex[1]] = '-';

                        if (JelenlegiJatekos == ElsoJatekos)
                        {
                            JelenlegiJatekos = MasodikJatekos;
                        }
                        else
                        {
                            JelenlegiJatekos = ElsoJatekos;
                        }
                    }

                    Tabla.TablaFrissitese(valasz);
                }

                else if (Parancs == "help")
                {
                    Tabla.TablaFrissitese("COMMANDS: move <X1 Y2> | save <fileName> | open <fileName> | giveup | help | exit");
                }

                else if (Parancs == "exit")
                {
                    Environment.Exit(0);
                }

                else if (Parancs == "giveup")
                {
                    Console.WriteLine("Player number {0} won the game!", Tabla.MasikJatekosVisszaadasa().JatekosSzam);
                    Environment.Exit(0);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Tabla.TablaFrissitese("This command does not exist!");
                }
            }
        }
예제 #4
0
 public bool UresAzUjMezo(int[] ujPozicio, Tabla tabla)
 {
     return(tabla.JatekTer[ujPozicio[0], ujPozicio[1]].Equals('-'));
 }