示例#1
0
        public GameForm(StartForm startForm, int velicina, int mode)
        {
            InitializeComponent();
            this.startForm = startForm;
            this.velicina  = velicina;
            this.mode      = mode;
            this.tabla     = new Tabla((short)this.velicina);
            this.logPoruka = new LogPoruka();

            process = new Process();
            if (mode == 0)
            {
                process.StartInfo.FileName = "pvp.bat";
            }
            else
            {
                process.StartInfo.FileName = "cvp.bat";
            }

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.RedirectStandardInput  = true;
            process.EnableRaisingEvents = true;
            process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);

            processprikaz       = 0;
            processRacunarPotez = false;
            processPotezX       = false;
            processPotezY       = false;
            clickUp             = false;
            gameOver            = false;
            pomeranje           = false;

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
        }
示例#2
0
        void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            if (process.HasExited)
            {
                return;
            }
            //INICIJALIZACIJA
            if (outLine.Data.ToString() == "velicina")
            {
                process.StandardInput.WriteLine(this.velicina.ToString());
            }
            else if (outLine.Data.ToString() == "r")
            {
                if (this.mode == 0)
                {
                    process.StandardInput.WriteLine("r");
                }
                else if (this.mode == 1)
                {
                    process.StandardInput.WriteLine("r");
                }
                else if (this.mode == 2)
                {
                    process.StandardInput.WriteLine("igracprvi");
                }
            }

            //PRIKAZZZZZZZ
            else if (outLine.Data.ToString() == "prikaz")
            {
                this.tabla         = null;
                this.tabla         = new Tabla((short)this.velicina);
                this.processprikaz = 4;
            }
            else if (processprikaz == 4)
            {
                string minforwin = outLine.Data.ToString();
                this.skorMin = int.Parse(minforwin);
                processprikaz--;
            }
            else if (processprikaz == 3)
            {
                string skorx = outLine.Data.ToString();
                this.skorX = int.Parse(skorx);
                processprikaz--;
            }
            else if (processprikaz == 2)
            {
                string skoro = outLine.Data.ToString();
                this.skorY = int.Parse(skoro);
                processprikaz--;
                processprikazI = 0;
                processprikazJ = 0;
            }
            else if (processprikaz == 1)
            {
                string polje = outLine.Data.ToString();
                tabla.PopuniIzStringa(polje, processprikazI, processprikazJ);
                processprikazJ++;
                if (processprikazJ == velicina)
                {
                    processprikazI++;
                    processprikazJ = 0;
                }
                if (processprikazI == velicina)
                {
                    processprikaz = 0;
                    Invalidate();
                }
            }

            //Racunar potez
            else if (outLine.Data.ToString() == "racunarpotez")
            {
                processRacunarPotez = true;
            }
            else if (processRacunarPotez == true)
            {
                string        tmp  = "Computer played: ";
                string        tmp2 = outLine.Data.ToString();
                StringBuilder sb   = new StringBuilder(tmp2);

                int    s   = 0;
                char[] sep = new char[1];
                sep[0] = ' ';
                string[] niz = tmp2.Split(sep);

                int tmi = 0;
                s = 2;
                while (s < niz[0].Length)
                {
                    tmi = tmi * 10 + int.Parse(niz[0][s].ToString());
                    s++;
                }
                int tmj = 0;
                s = 0;
                while (niz[1][s] != ')')
                {
                    tmj = tmj * 10 + int.Parse(niz[1][s].ToString());
                    s++;
                }
                int tmk = 0;
                s = 1;
                while (s < niz[2].Length)
                {
                    tmk = tmk * 10 + int.Parse(niz[2][s].ToString());
                    s++;
                }
                int tml = 0;
                s = 0;
                while (niz[3][s] != ')')
                {
                    tml = tml * 10 + int.Parse(niz[3][s].ToString());
                    s++;
                }
                int tmh = int.Parse(niz[4][0].ToString());

                sb = new StringBuilder();
                sb.Append("((");
                sb.Append((char)(tmi + 65));
                sb.Append((" "));
                sb.Append((tmj + 1).ToString() + ") (");
                sb.Append((char)(tmk + 65));
                sb.Append((" "));
                sb.Append((tml + 1).ToString() + ") " + tmh.ToString() + ")");



                logPoruka.dodajString(tmp + sb.ToString());
                processRacunarPotez = false;


                Invalidate();
            }
            else if (outLine.Data.ToString() == "racunarnemapotez")
            {
                logPoruka.dodajString("Computer doesn't have a move.");
                Invalidate();
            }


            //IGRAC POTEZ
            else if (outLine.Data.ToString() == "potezx:")
            {
                logPoruka.dodajString("Black player's turn:");
                this.processPotezX = true;
                Invalidate();
            }
            else if (outLine.Data.ToString() == "potezo:")
            {
                logPoruka.dodajString("White player's turn:");
                this.processPotezY = true;
                Invalidate();
            }
            else if (outLine.Data.ToString() == "nevalidanpotez")
            {
                logPoruka.dodajString(potez + " is not valid move.");
                this.processPotezY = false;
                this.processPotezX = false;
                Invalidate();
            }
            else if (outLine.Data.ToString() == "nemapotezx")
            {
                logPoruka.dodajString("Black player doesn't have a move.");
            }
            else if (outLine.Data.ToString() == "nemapotezo")
            {
                logPoruka.dodajString("White player doesn't have a move.");
            }


            else if (outLine.Data.ToString() == "pobednikx")
            {
                logPoruka = new LogPoruka();
                logPoruka.dodajString("Black player is winner");
                gameOver = true;
            }
            else if (outLine.Data.ToString() == "pobedniko")
            {
                logPoruka = new LogPoruka();
                logPoruka.dodajString("White player is winner");
                gameOver = true;
            }
        }