示例#1
0
        /// <summary>
        /// we hebben genoeg spelers en alle informatie die we nodig hebben, we gaan starten.
        /// </summary>
        /// <param name="tcpClient">De client.</param>
        /// <param name="oX">Het Spel.</param>
        public void Start(TcpClient tcpClient, GameOX oX)
        {
            string bord;
            string msg = string.Empty;

            // maak een bord, met de jusite dimension
            Bord huidigeBord = new Bord(oX.Dimension);

            huidigeBord.ResetBord();

            bord = huidigeBord.TekenBord();
            if (oX.TcpClients.Count == 1)
            {
                msg = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.SpelerGestart), bord);
                this.ProcessStream(msg, tcpClient);
            }
            else
            {
                // hoe bepaal je wie mag beginnen?
                foreach (Speler speler in this.Spelers)
                {
                    if (speler.TcpClient == tcpClient)
                    {
                        msg = string.Format("{0}&{1}", EventHelper.CreateWachtenOpEenAndereDeelnemenEvent(), bord);
                        this.ProcessStream(msg, speler.TcpClient);
                    }
                    else
                    {
                        msg = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.SpelerGestart), bord);
                        this.ProcessStream(msg, speler.TcpClient);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Doe een zet op het bord.
        /// </summary>
        /// <param name="nummer">Het nummer die de speler heeft gekozen.</param>
        /// <param name="huidigBord">Huidig bord.</param>
        /// <param name="game">Huidig spel.</param>
        public void Zet(short nummer, Bord huidigBord, GameOX game)
        {
            Bord bord = huidigBord;

            string tekenBords     = string.Empty;
            short  indexOpHetBord = nummer;

            bord.DoeZet(this, indexOpHetBord);
        }
示例#3
0
        /// <summary>
        /// Check als het valid plaats is of niet.
        /// </summary>
        /// <param name="client">De client.</param>
        /// <param name="nummer">Het nummer.</param>
        /// <param name="gameOX">Het Spel.</param>
        public void ChekOfHetValidBeZitIs(TcpClient client, short nummer, GameOX gameOX)
        {
            Bord bord = gameOX.bords.First();

            if (bord.MagZetten(nummer))
            {
                this.SpelGestart(client, nummer, gameOX);
            }
            else
            {
                bord.HetBordIsVol(client, gameOX);
                this.nogNietBezit = false;
            }
        }
示例#4
0
        /// <summary>
        /// Als de spelers willen een nieuw rondje doen.
        /// </summary>
        /// <param name="tcpClient">Deze client.</param>
        /// <param name="oX">Het Spel.</param>
        public void StartNieuwRondje(TcpClient tcpClient, GameOX oX)
        {
            string bord;
            string msg        = string.Empty;
            Bord   huidigBord = oX.bords.First();

            huidigBord.ResetBord();
            bord = huidigBord.TekenBord();

            foreach (Speler speler in this.Spelers)
            {
                if (speler.TcpClient == tcpClient)
                {
                    msg = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.YourTurn), bord);

                    this.ProcessStream(msg, speler.TcpClient);
                }
            }
        }
示例#5
0
        /// <inheritdoc/>
        public override void SpelStartedHandler(short nummer, GameOX gameOX, Bord bord)
        {
            bool         magZet      = true;
            List <short> vrijeVelden = bord.VrijVelden();

            foreach (short index in vrijeVelden)
            {
                bord.DoeZet(this, index);

                // als ik mijn teken daar invul, win ik dan.
                // of wint de tegenstander dan?
                if (bord.HeeftTekenGewonnen(this.TeGebruikenTeken))
                {
                    bord.ResetVeld(index);
                    this.Zet(index, bord, gameOX);
                    magZet = false;
                    break;
                }
                else
                {
                    Speler tegenSpeler = gameOX.TegenSpeler(this);

                    bord.DoeZet(tegenSpeler, index);
                    if (bord.HeeftTekenGewonnen(tegenSpeler.TeGebruikenTeken))
                    {
                        // tegenstander heeft gewonnen
                        bord.ResetVeld(index);
                        this.Zet(index, bord, gameOX);
                        magZet = false;
                        break;
                    }
                    else
                    {
                        bord.ResetVeld(index);
                    }
                }
            }

            if (magZet)
            {
                this.Zet(vrijeVelden[0], bord, gameOX);
            }
        }
示例#6
0
 /// <summary>
 /// afvangen van het event dat het spel is gestart.
 /// </summary>
 /// <param name="nummer">Het nummer die de speler heeft gekozen.</param>
 /// <param name="gameOX">Het spel.</param>
 /// <param name="bord">Het bord.</param>
 public virtual void SpelStartedHandler(short nummer, GameOX gameOX, Bord bord)
 {
 }
示例#7
0
        /// <summary>
        /// Hier de spel is gestart.
        /// </summary>
        /// <param name="tcp">Huidige speler.</param>
        /// <param name="nummer">Wat de speler heeft gekozen.</param>
        /// <param name="gameOX">Het Spel.</param>
        public void SpelGestart(TcpClient tcp, short nummer, GameOX gameOX)
        {
            Bord   hetBord   = null;
            string tekenBord = string.Empty;
            string msge      = string.Empty;

            foreach (Bord bord in gameOX.bords)
            {
                hetBord = bord;
            }

            foreach (Speler speler in gameOX.Spelers)
            {
                // Human Speler tegen computer.
                if (gameOX.TcpClients.Count == 1)
                {
                    if (hetBord.HeeftTekenGewonnen(speler.TeGebruikenTeken))
                    {
                        if (speler.TcpClient != tcp)
                        {
                            tekenBord = hetBord.TekenBord();
                            speler.BeeindigBord();
                            string msg = string.Format("{0}&{1},{2}", EventHelper.CreateEvents(Events.Winnaar), speler.Punten.ToString(), speler.Naam);
                            this.ProcessStream(msg, tcp);
                            msge = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.NieuwRondje), tekenBord);
                            this.ProcessStream(msge, tcp);
                            break;
                        }
                    }
                    else
                    {
                        speler.SpelStartedHandler(nummer, gameOX, hetBord);
                        if (!hetBord.IsBordFinished())
                        {
                            if (speler.TcpClient == tcp)
                            {
                                if (hetBord.HeeftTekenGewonnen(speler.TeGebruikenTeken))
                                {
                                    speler.BeeindigBord();
                                    string msg = string.Format("{0}&{1},{2}", EventHelper.CreateEvents(Events.Winnaar), speler.Punten.ToString(), speler.Naam);
                                    this.ProcessStream(msg, tcp);

                                    tekenBord = hetBord.TekenBord();
                                    msge      = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.NieuwRondje), tekenBord);
                                    this.ProcessStream(msge, tcp);
                                    break;
                                }
                            }
                            else
                            {
                                tekenBord = hetBord.TekenBord();
                                string msg = string.Format("{0}&{1}{2}", EventHelper.CreateEvents(Events.YourTurn), tekenBord, this.vrijVeldenText);
                                this.ProcessStream(msg, tcp);
                            }
                        }
                        else
                        {
                            tekenBord = hetBord.TekenBord();
                            msge      = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.BordIsVol), tekenBord);
                            this.ProcessStream(msge, tcp);
                            msge = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.NieuwRondje), tekenBord);
                            this.ProcessStream(msge, tcp);
                            break;
                        }
                    }
                }

                // Human speler tegen andre human speler.
                else
                {
                    if (speler.TcpClient == tcp)
                    {
                        speler.SpelStartedHandler(nummer, gameOX, hetBord);
                        tekenBord = hetBord.TekenBord();
                        if (hetBord.HeeftTekenGewonnen(speler.TeGebruikenTeken))
                        {
                            speler.BeeindigBord();
                            msge = string.Format("{0}&{1},{2}", EventHelper.CreateEvents(Events.Winnaar), speler.Punten.ToString(), speler.Naam);
                            this.ProcessReturnMessage(msge, this.TcpClients);
                            msge = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.NieuwRondje), tekenBord);
                            this.ProcessStream(msge, tcp);
                            break;
                        }
                        else if (hetBord.IsBordFinished())
                        {
                            msge = string.Format("{0}&{1}", EventHelper.CreateEvents(Events.NieuwRondje), tekenBord);
                            this.ProcessStream(msge, tcp);
                        }
                        else
                        {
                            msge = string.Format("{0}&{1},{2}", EventHelper.CreateWachtenOpEenAndereDeelnemenEvent(), tekenBord, speler.Naam);
                            this.ProcessStream(msge, speler.TcpClient);
                        }

                        TcpClient tegenHuidigeSpeler;
                        tegenHuidigeSpeler = this.TegenHuidigeSpeler(speler, gameOX);
                        this.vrijVeldenText.Clear();
                        List <short> vrijVelden = hetBord.VrijVelden();
                        foreach (short velder in vrijVelden)
                        {
                            this.vrijVeldenText.AppendFormat("{0},", velder);
                        }

                        if (this.nogNietBezit)
                        {
                            tekenBord = hetBord.TekenBord();
                            string msg = string.Format("{0}&{1}{2}", EventHelper.CreateEvents(Events.YourTurn), tekenBord, this.vrijVeldenText);
                            this.ProcessStream(msg, tegenHuidigeSpeler);
                        }
                    }
                }
            }
        }