Example #1
0
        /// <summary>
        /// maakt het standaard commandm
        /// afgesproken is om elk commando te beƫindigen met een #.
        /// </summary>
        /// <param name="commando">enumerator van commando.</param>
        /// <returns>De commandos als string.</returns>
        private static string CreateCommando(Commandos commando)
        {
            switch (commando)
            {
            case Commandos.VerzoekTotDeelnemenSpel:
                return("VerzoekTotDeelnemenSpel#");

            case Commandos.SpelTegenComputer:
                return("SpelTegenComputer#");

            case Commandos.WachtenOpAndereDeelnemer:
                return("WachtenOpAndereDeelnemer#");

            case Commandos.StartSpel:
                return("StartSpel#");

            case Commandos.DoeZet:
                return("DoeZet#");

            case Commandos.SpelerGestart:
                return("SpelerGestart#");

            case Commandos.NieuwRondje:
                return("nieuwRondje#");

            case Commandos.BeeindigSpel:
                return("BeeindigSpel#");

            default:
                throw new NotImplementedException();
            }
        }
Example #2
0
        /// <summary>
        /// knip de message op in een command en params.
        /// </summary>
        /// <param name="mess">de ontvangen message.</param>
        /// <param name="commandParams">het gedeelte na de #.</param>
        /// <returns>het gevonden commando.</returns>
        public static Commandos SplitCommandAndParamsFromMessage(string mess, out string commandParams)
        {
            commandParams = string.Empty;

            // Split de string voor # en na
            string[] opgeknipt = mess.Split(new char[] { '#' });

            // controleer of er wel een # aanwezig is
            if (opgeknipt.Length == 0)
            {
                throw new ArgumentOutOfRangeException("message bevat geen #.");
            }

            // wij hebben array met array[0] en array[1]
            // als het goorter is dan array[1] dan doe het maar bij array[1]
            if (opgeknipt.Length > 1)
            {
                commandParams = opgeknipt[1];
            }

            // probeer dan de eerste om te zetten naar een commandos
            Commandos result = Commandos.NotDefined;

            // Omzetten de string to enum
            if (Enum.TryParse(opgeknipt[0], true, out result))
            {
                if (Enum.IsDefined(typeof(Commandos), result))
                {
                    return(result);
                }
            }

            // niet gevonden, dus info was fout
            throw new NotImplementedException();
        }
Example #3
0
        /********************************************/
        public bool getTFReportApp(string appCod)
        {
            Commandos cmd = new Commandos();
            bool      res = false;

            res = cmd.getTFREporteAplicacion(appCod);
            return(res);
        }
Example #4
0
        /// <summary>
        /// Process van de server.
        /// </summary>
        /// <param name="stream">Stream die uit de client komt.</param>
        /// <param name="client"> Client.</param>
        /// <returns>informatie.</returns>
        /// <exception cref="System.InvalidOperationException">Wordt gegooid wanneer een commando wordt aangeroepen op een ongeldig moment.</exception>
        protected override string ProcessStream(string stream, TcpClient client)
        {
            // bepaal de opdracht
            // de opdracht is het gedeelte in de msg voor de #
            // daarna komen de parameters.
            string commandParams = string.Empty;
            string returnMessage = null;
            GameOX game          = null;

            Commandos commando = CommandoHelper.SplitCommandAndParamsFromMessage(stream, out commandParams);

            /*foreach (GameOX games in this.gameOXen)
             * {
             *  foreach (TcpClient tcp in games.TcpClients)
             *  {
             *      if (tcp == client)
             *      {
             *          game = games;
             *      }
             *  }
             * }*/

            // Add een client to clientLijst.
            try
            {
                switch (commando)
                {
                // Verdeel between de naam van de speler en de dimension van het bord
                // wanneer de commandos is equal VerzoekTotDeelnemenSpel
                case Commandos.VerzoekTotDeelnemenSpel:
                    VerzoekTotDeelnemenSpelCommandHandler handler = new VerzoekTotDeelnemenSpelCommandHandler(this.spelHandler, client);
                    returnMessage = handler.HandleFromMessage(commandParams, out game);
                    if (game.Status == GameOXStatussen.Gestart)
                    {
                        this.ProcessReturnMessage(returnMessage, game.TcpClients);
                        game.Start(client, game);
                    }
                    else
                    {
                        this.ProcessReturnMessage(returnMessage, client);
                    }

                    break;

                case Commandos.SpelTegenComputer:
                    VerzoekTotDeelnemenSpelCommandHandler handlerTegenComputerSpelen = new VerzoekTotDeelnemenSpelCommandHandler(this.spelHandler, client);
                    returnMessage = handlerTegenComputerSpelen.HandleFromMessage(commandParams, out game);
                    this.ProcessReturnMessage(returnMessage, client);

                    game = this.spelHandler.GetGameFromTcpClient(client);
                    game.Start(client, game);
                    break;

                case Commandos.SpelerGestart:
                    game = this.spelHandler.GetGameFromTcpClient(client);
                    Teken teken = TekenHelper.CreateTekenEnum(commandParams);
                    TekenHelper.AddTekenToSpeler(teken, game, client);
                    returnMessage = EventHelper.CreateEvents(Events.YourTurn);
                    this.ProcessReturnMessage(returnMessage, client);

                    // stuur een wacht bericht naar andere speler.
                    returnMessage = this.spelHandler.TegeHuidigeClient(client, game.TcpClients, out this.tegenHuidigeClient);
                    this.ProcessReturnMessage(returnMessage, this.tegenHuidigeClient);
                    break;

                case Commandos.StartSpel:
                    // returnMessage = EventHelper.CreateSpelerGestartEvent();
                    //  ProcessReturnMessage(returnMessage, tcpClients);
                    break;

                case Commandos.DoeZet:
                    // stuur een wacht bericht naar andere speler.
                    returnMessage = this.spelHandler.TegeHuidigeClient(client, game.TcpClients, out this.tegenHuidigeClient);
                    this.ProcessReturnMessage(returnMessage, this.tegenHuidigeClient);
                    short nummer = short.Parse(commandParams);

                    // Handel de info van de speler
                    this.spelHandler.GetGameFromTcpClient(client);
                    game = this.spelHandler.GetGameFromTcpClient(client);
                    game.ChekOfHetValidBeZitIs(client, nummer, game);
                    break;

                case Commandos.WachtenOpAndereDeelnemer:
                    if (game == null)
                    {
                        throw new InvalidOperationException($"Het commando {nameof(Commandos.WachtenOpAndereDeelnemer)} mag niet worden gebruikt wanneer er nog geen game is gestart.");
                    }

                    this.ProcessReturnMessage(returnMessage, game.TcpClients);
                    break;

                case Commandos.NieuwRondje:
                    if (game == null)
                    {
                        throw new InvalidOperationException($"Het commando {nameof(Commandos.WachtenOpAndereDeelnemer)} mag niet worden gebruikt wanneer er nog geen game is gestart.");
                    }

                    this.ProcessReturnMessage(returnMessage, game.TcpClients);
                    break;

                case Commandos.BeeindigSpel:
                    game = this.spelHandler.GetGameFromTcpClient(client);
                    game.StartNieuwRondje(client, game);

                    break;
                }
            }
            catch (Exception exp)
            {
                // ok dan krijg ik een foutmelding, stuur die dan terug
                returnMessage = EventHelper.CreateErrorEvent(exp);
            }

            return(returnMessage);
        }
Example #5
0
        public MarkButtonHandler(Texture2D markButton, Texture2D show, SoundEffect horseSound, SoundEffect clickSound, SoundEffect swordSound, SoundEffect arrowSound, Vector2 screenSize, SpriteFont font, int buttonPosition,
                                 int cutoff, int buttonPos2, int markButtonStartPos)
        {
            this.font       = font;
            this.clickSound = clickSound;
            this.markButton = markButton;
            parchment       = new Parchment(show, screenSize, font);
            buttonsList     = new List <List <EquipmentMarkButton> >();
            string tempname = "";

            numberlist = new List <int>();
            numberlist.Add(0);
            numberlist.Add(0);
            numberlist.Add(0);
            Equipment equipmentinput = new Equipment();
            int       p    = 0;
            int       yoff = 1;

            offsetBetweenButtons = 20;
            startPos             = markButtonStartPos;
            widthBetweenButtons  = 185;
            for (int i = 0; i < 9; i++)
            {
                buttonsList.Add(new List <EquipmentMarkButton>());
            }
            SoundEffect tempSound = swordSound;

            for (int i = 0; i < 10; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new SideArm();
                }
                else if (i == 1)
                {
                    equipmentinput = new Longsword();
                }
                else if (i == 2)
                {
                    equipmentinput = new Warhammer();
                }
                else if (i == 3)
                {
                    equipmentinput = new Shield();
                }
                else if (i == 4)
                {
                    equipmentinput = new DualWieldedWeapon();
                }
                else if (i == 5)
                {
                    equipmentinput = new Polearm();
                }
                else if (i == 6)
                {
                    equipmentinput = new Spear();
                }
                else if (i == 7)
                {
                    equipmentinput = new Pike();
                }
                else if (i == 8)
                {
                    equipmentinput = new Pavise();
                }
                else if (i == 9)
                {
                    equipmentinput = new Lance();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                if (buttonPos2 + (widthBetweenButtons * p) + 20 + (font.MeasureString(tempname).X * 0.75f) > cutoff)
                {
                    p = 0;
                    yoff++;
                }
                buttonsList[0].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, buttonPos2 + (widthBetweenButtons * p), startPos + (offsetBetweenButtons * yoff), tempname, tempSound, 0.5f));
                p++;
            }
            tempSound = clickSound;
            buttonsList[0][0].ChangeState();
            yoff++;
            p = 0;
            yoff++;
            for (int i = 0; i < 7; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new UnArmoured();
                }
                else if (i == 1)
                {
                    equipmentinput = new SparseArmour();
                }
                else if (i == 2)
                {
                    equipmentinput = new CoveringArmour();
                }
                else if (i == 3)
                {
                    equipmentinput = new FullPlateArmour();
                }
                else if (i == 4)
                {
                    tempSound      = horseSound;
                    equipmentinput = new PartialHorseArmour();
                }
                else if (i == 5)
                {
                    tempSound      = horseSound;
                    equipmentinput = new HeavyHorseArmour();
                }
                else if (i == 6)
                {
                    tempSound      = horseSound;
                    equipmentinput = new CoveringPlateHorseArmour();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                if (buttonPos2 + (widthBetweenButtons * p) + 20 + (font.MeasureString(tempname).X * 0.75f) > cutoff)
                {
                    p = 0;
                    yoff++;
                }
                buttonsList[1].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, buttonPos2 + (widthBetweenButtons * p), startPos + (offsetBetweenButtons * yoff), tempname, tempSound, 0.5f));
                p++;
            }
            tempSound = arrowSound;
            buttonsList[1][0].ChangeState();
            yoff += 2;
            p     = 0;
            for (int i = 0; i < 9; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new GoodOldFists();
                }
                else if (i == 1)
                {
                    equipmentinput = new Sling();
                }
                else if (i == 2)
                {
                    equipmentinput = new Shortbow();
                }
                else if (i == 3)
                {
                    equipmentinput = new Longbow();
                }
                else if (i == 4)
                {
                    equipmentinput = new LightCrossbow();
                }
                else if (i == 5)
                {
                    equipmentinput = new HeavyCrossbow();
                }
                else if (i == 6)
                {
                    equipmentinput = new Handgonne();
                }
                else if (i == 7)
                {
                    equipmentinput = new ThrowingWeapon();
                }
                else if (i == 8)
                {
                    equipmentinput = new Pistol();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                if (buttonPos2 + (widthBetweenButtons * p) + 20 + (font.MeasureString(tempname).X * 0.75f) > cutoff)
                {
                    p = 0;
                    yoff++;
                }
                buttonsList[2].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, buttonPos2 + (widthBetweenButtons * p), startPos + (offsetBetweenButtons * yoff), tempname, tempSound, 0.5f));
                p++;
            }
            tempSound = horseSound;
            p         = 0;
            yoff     += 2;
            buttonsList[2][0].ChangeState();
            for (int i = 0; i < 7; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new Feet();
                }
                else if (i == 1)
                {
                    equipmentinput = new Courser();
                }
                else if (i == 2)
                {
                    equipmentinput = new Charger();
                }
                else if (i == 3)
                {
                    equipmentinput = new Flyer();
                }
                else if (i == 4)
                {
                    equipmentinput = new MonsterousMount();
                }
                else if (i == 5)
                {
                    equipmentinput = new LightChariot();
                }
                else if (i == 6)
                {
                    equipmentinput = new HeavyChariot();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                if (buttonPos2 + (widthBetweenButtons * p) + 20 + (font.MeasureString(tempname).X * 0.75f) > cutoff)
                {
                    p = 0;
                    yoff++;
                }
                buttonsList[3].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, buttonPos2 + (widthBetweenButtons * p), startPos + (offsetBetweenButtons * yoff), tempname, tempSound, 0.5f));
                p++;
            }
            buttonsList[3][0].ChangeState();
            p     = 0;
            yoff += 2;
            int posVeteran = yoff;

            tempSound = clickSound;
            for (int i = 0; i < 12; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new GenericVeteran();
                }
                else if (i == 1)
                {
                    equipmentinput = new Skirmishers();
                }
                else if (i == 2)
                {
                    equipmentinput = new Rangers();
                }
                else if (i == 3)
                {
                    equipmentinput = new Commandos();
                }
                else if (i == 4)
                {
                    equipmentinput = new Zombify();
                }
                else if (i == 5)
                {
                    equipmentinput = new Possessed();
                }
                else if (i == 6)
                {
                    equipmentinput = new Fire_Arrows();
                }
                else if (i == 7)
                {
                    equipmentinput = new Winged();
                }
                else if (i == 8)
                {
                    equipmentinput = new Reckless();
                }
                else if (i == 9)
                {
                    equipmentinput = new MagicallyCharged();
                }
                else if (i == 10)
                {
                    equipmentinput = new Diciples();
                }
                else if (i == 11)
                {
                    equipmentinput = new SavageFighters();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                if (buttonPos2 + (widthBetweenButtons * p) + 20 + (font.MeasureString(tempname).X * 0.75f) > cutoff)
                {
                    p = 0;
                    yoff++;
                }
                buttonsList[4].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, buttonPos2 + (widthBetweenButtons * p), startPos + (offsetBetweenButtons * yoff), tempname, tempSound, 0.5f));
                p++;
            }
            buttonsList[4][0].ChangeState();
            yoff += 2;
            p     = 0;
            for (int i = 0; i < 4; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new NoFortifications();
                }
                else if (i == 1)
                {
                    equipmentinput = new SharpenedStakes();
                }
                else if (i == 2)
                {
                    equipmentinput = new WarWagon();
                }
                else if (i == 3)
                {
                    equipmentinput = new Mantles();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                if (buttonPos2 + (widthBetweenButtons * p) + 20 + (font.MeasureString(tempname).X * 0.75f) > cutoff)
                {
                    p = 0;
                    yoff++;
                }
                buttonsList[5].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, buttonPos2 + (widthBetweenButtons * p), startPos + (offsetBetweenButtons * yoff), tempname, tempSound, 0.5f));
                p++;
            }
            numberOfLines = yoff + 2;
            buttonsList[5][0].ChangeState();
            p    = 0;
            yoff = posVeteran;
            for (int i = 0; i < 7; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new NoArtillery();
                }
                else if (i == 1)
                {
                    equipmentinput = new Balista();
                }
                else if (i == 2)
                {
                    equipmentinput = new LightCatapult();
                }
                else if (i == 3)
                {
                    equipmentinput = new HeavyCatapult();
                }
                else if (i == 4)
                {
                    equipmentinput = new Cannon();
                }
                else if (i == 5)
                {
                    equipmentinput = new RibaultGun();
                }
                else if (i == 6)
                {
                    equipmentinput = new FlameThrower();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                if (buttonPos2 + (widthBetweenButtons * p) + 20 + (font.MeasureString(tempname).X * 0.75f) > cutoff)
                {
                    p = 0;
                    yoff++;
                }
                buttonsList[6].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, buttonPos2 + (widthBetweenButtons * p), startPos + (offsetBetweenButtons * yoff), tempname, tempSound, 0.5f));
                p++;
            }
            yoff = posVeteran;
            p    = 0;
            for (int i = 0; i < 9; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new GenericHero();
                }
                else if (i == 1)
                {
                    equipmentinput = new GreatWarrior();
                }
                else if (i == 2)
                {
                    equipmentinput = new EagleEyed();
                }
                else if (i == 3)
                {
                    equipmentinput = new InspiringLeader();
                }
                else if (i == 4)
                {
                    equipmentinput = new TrueHero();
                }
                else if (i == 5)
                {
                    equipmentinput = new Conjurer();
                }
                else if (i == 6)
                {
                    equipmentinput = new Enchanter();
                }
                else if (i == 7)
                {
                    equipmentinput = new ArmyStandard();
                }
                else if (i == 8)
                {
                    equipmentinput = new Dragonslayer();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                if (buttonPos2 + (widthBetweenButtons * p) + 20 + (font.MeasureString(tempname).X * 0.75f) > cutoff)
                {
                    p = 0;
                    yoff++;
                }
                buttonsList[7].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, buttonPos2 + (widthBetweenButtons * p), startPos + (offsetBetweenButtons * yoff), tempname, tempSound, 0.5f));
                p++;
            }
            buttonsList[7][0].ChangeState();
            buttonsList[6][0].ChangeState();
            for (int i = 0; i < 3; i++)
            {
                if (i == 0)
                {
                    equipmentinput = new UnitLeader();
                }
                else if (i == 1)
                {
                    equipmentinput = new Muscicians();
                }
                else if (i == 2)
                {
                    equipmentinput = new BannerBearer();
                }
                else if (i == 3)
                {
                    equipmentinput = new BannerBearer();
                }
                tempname = equipmentinput.GetName() + "/ " + equipmentinput.Cost() + "pts";
                buttonsList[8].Add(new EquipmentMarkButton(equipmentinput, markButton, 3, 1, 120 + (170 * i), buttonPosition - 30, tempname, tempSound));
            }
        }
Example #6
0
        /// <summary>
        /// behanelt het berichtje die uit een cleint wordt gestuurd.
        /// </summary>
        /// <param name="message">De bericht.</param>
        /// <param name="socket">De client.</param>
        public override void ProcessStream(string message, Socket socket)
        {
            try
            {
                if (message == string.Empty)
                {
                    throw new ArgumentException("Mag niet message empty zijn.");
                }

                if (socket == null)
                {
                    throw new ArgumentException("Mag niet een client null zijn.");
                }

                Game game;

                // [0] is altijd de commando.
                // [1.....] is de rest van de bericht.
                string[] opgeknipt = message.Split(new char[] { '%' });

                // change the string to enum.
                Commandos commando = EnumHelperl.EnumConvert <Commandos>(opgeknipt[0]);
                switch (commando)
                {
                case Commandos.VerzoekTotDeelnemenSpel:

                    this.Send(socket, this.handler.StreamOntvanger(message, socket));
                    break;

                // Geef een teken aan een speler.
                // en geef de andere speler de andere teken.
                case Commandos.ZetTeken:
                    string msg   = string.Empty;
                    Teken  teken = EnumHelperl.EnumConvert <Teken>(opgeknipt[1].ToString());
                    game = this.GetGame(socket);
                    game.TekenenBehandl(socket, teken);
                    msg = $"{Events.TegenSpelerHeeftTekenIngezet.ToString()}%%{opgeknipt[1]}%%{game.TegenSpeler(game.GetSpelerViaTcp(socket)).GebruikTeken.ToString()}";
                    this.SendBerichtNaarDeTegenSpeler(game, msg, socket);
                    Thread.Sleep(1000);
                    this.Send(socket, Events.TekenIngezet.ToString());
                    break;

                // start het spel.
                case Commandos.Starten:
                    this.GetGame(socket).StartHetSpel();
                    break;

                // doe zet op het speelvlak.
                case Commandos.DoeZet:
                    game = this.GetGame(socket);
                    if (game != null)
                    {
                        // eerst gaat het spel de inzet van de speler zetten.
                        // dan gaat de controller dat nummertje uit de properties speler op halen.
                        game.DoeInzet(opgeknipt[1], socket);
                        Speler speler = game.GetSpelerViaTcp(socket);
                        game.GameController.DoeInzet(speler);
                    }

                    break;

                case Commandos.NieuwRonde:
                    game = this.GetGame(socket);
                    if (game != null)
                    {
                        // Als de speler een nieuw rondje wil doen.
                        // Er staat alleen een speler dan de situatie verandert tot wachten op andere speler.
                        if (game.GetSpelers().Count == 1)
                        {
                            game.ZetSituatie(Status.Wachten);
                            Thread.Sleep(500);
                            this.SendBerichtNaarDeTegenSpeler(game, Events.WachtenNieuweSpeler.ToString(), socket);
                        }
                        else
                        {
                            // Als het spel twee spelers heeft dan gaat het door.
                            game.GameController.NieuwRonde();
                        }
                    }

                    break;

                case Commandos.WilNietNieuweRonde:
                    // neem de game.
                    game = this.GetGame(socket);
                    if (game != null)
                    {
                        this.VerWijdertHetSpelMetSpeller(socket);
                    }

                    socket.Close();
                    this.clienten.Remove(socket);
                    break;
                }
            }
            catch (Exception e)
            {
                throw new ArgumentException(e.Message);
            }
        }