Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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);
                        }
                    }
                }
            }
        }