예제 #1
0
        public void CreateFunction()
        {
            if (chosenDeck != null)
            {
                searching = false;
                GamePacket packet = new GamePacket(OperationType.SELECT_FLEET, chosenDeck.GetFleet());
                Game1.self.Connection.Send(packet);
                packet = Game1.self.Connection.GetReceivedPacket();
                if (packet.OperationType == OperationType.SUCCESS)
                {
                    CustomGameRoom room = new CustomGameRoom(nameInputBox.Text, "", true, Game1.self.player.Username);
                    packet = new GamePacket(OperationType.PLAY_CUSTOM_CREATE, room);
                    Game1.self.Connection.Send(packet);
                    packet = Game1.self.Connection.GetReceivedPacket();
                    if (packet.OperationType == OperationType.SUCCESS)
                    {
                        labelError.Text = "Created room with name: " + nameInputBox.Text;
                        searching       = true;
                        while (searching)
                        {
                            packet = Game1.self.Connection.GetReceivedPacket(10);
                            if (packet != null)
                            {
                                if (packet.OperationType == OperationType.SUCCESS)
                                {
                                    if (timer != null)
                                    {
                                        timer.Dispose();
                                    }
                                    #region TextureExchange
                                    List <TexturePair> pairs = new List <TexturePair>();
                                    foreach (var shipAndSkin in Game1.self.ShipsSkins)
                                    {
                                        TexturePair pair = new TexturePair();
                                        pair.TextureBytes = shipAndSkin.skin != null
                                            ? Utils.TextureToBytes(shipAndSkin.ship)
                                            : null;

                                        pair.TemplateName = shipAndSkin.ship;
                                        pairs.Add(pair);
                                    }
                                    Textures textures = new Textures(pairs);


                                    packet = new GamePacket(OperationType.TEXTURES_EXCHANGE, textures);
                                    Game1.self.Connection.Send(packet);
                                    Console.WriteLine(packet.Packet);


                                    packet = Game1.self.Connection.GetReceivedPacket();
                                    if (packet.OperationType == OperationType.TEXTURES_EXCHANGE)
                                    {
                                        Game1.self.EnemyShipsSkins.Clear();
                                        Textures incomingTextures = (Textures)packet.Packet;
                                        foreach (var incomingTexturesPlayerTexture in incomingTextures.PlayerTextures)
                                        {
                                            Game1.ShipAndSkin pair = new Game1.ShipAndSkin();
                                            pair.ship = incomingTexturesPlayerTexture.TemplateName;
                                            pair.skin = incomingTexturesPlayerTexture.TextureBytes != null
                                                ? Utils.BytesToTexture(incomingTexturesPlayerTexture.TextureBytes)
                                                : null;

                                            Game1.self.EnemyShipsSkins.Add(pair);
                                        }
                                    }
                                    #endregion


                                    Game1.self.SetFleetMenu(chosenDeck.GetFleet());
                                    Game1.self.ReadyToPlay = true;
                                    searching = false;
                                    popup.SetActive(false);
                                    SetClickables(true);
                                    Game1.self.popupToDraw = null;
                                    ClickableToRemove.ForEach(p => Clickable.Remove(p));
                                    searching        = false;
                                    startedSearching = false;
                                    stopSearching    = false;
                                    popup.layout     = null;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (stopSearching)
                            {
                                stopSearching = false;
                                packet        = new GamePacket(OperationType.ABANDON_GAME, new object());
                                Game1.self.Connection.Send(packet);
                                searching        = false;
                                startedSearching = false;
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public void searchFunction()
        {
            if (chosenDeck != null)
            {
                searching = false;
                GamePacket packet = new GamePacket(OperationType.SELECT_FLEET, chosenDeck.GetFleet());
                Game1.self.Connection.Send(packet);
                packet = Game1.self.Connection.GetReceivedPacket();
                if (packet.OperationType == OperationType.SUCCESS)
                {
                    var autoEvent = new AutoResetEvent(false);
                    time  = 0;
                    timer = new Timer(timerStart, autoEvent, 0, 1000);
                    //TODO not tested
                    packet = new GamePacket(OperationType.PLAY_RANKED, null);
                    Game1.self.Connection.Send(packet);
                    packet = Game1.self.Connection.GetReceivedPacket();
                    if (packet.OperationType == OperationType.SUCCESS)
                    {
                        searching = true;
                        while (searching)
                        {
                            packet = Game1.self.Connection.GetReceivedPacket(10);
                            if (packet != null)
                            {
                                if (packet.OperationType == OperationType.SUCCESS)
                                {
                                    if (timer != null)
                                    {
                                        timer.Dispose();
                                    }

                                    #region TextureExchange
                                    List <TexturePair> pairs = new List <TexturePair>();
                                    foreach (var shipAndSkin in Game1.self.ShipsSkins)
                                    {
                                        TexturePair pair = new TexturePair();
                                        pair.TextureBytes = shipAndSkin.skin != null
                                            ? Utils.TextureToBytes(shipAndSkin.ship)
                                            : null;

                                        pair.TemplateName = shipAndSkin.ship;
                                        pairs.Add(pair);
                                    }
                                    Textures textures = new Textures(pairs);


                                    packet = new GamePacket(OperationType.TEXTURES_EXCHANGE, textures);
                                    Game1.self.Connection.Send(packet);
                                    Console.WriteLine(packet.Packet);


                                    packet = Game1.self.Connection.GetReceivedPacket();
                                    if (packet.OperationType == OperationType.TEXTURES_EXCHANGE)
                                    {
                                        Game1.self.EnemyShipsSkins.Clear();
                                        Textures incomingTextures = (Textures)packet.Packet;
                                        foreach (var incomingTexturesPlayerTexture in incomingTextures.PlayerTextures)
                                        {
                                            Game1.ShipAndSkin pair = new Game1.ShipAndSkin();
                                            pair.ship = incomingTexturesPlayerTexture.TemplateName;
                                            pair.skin = incomingTexturesPlayerTexture.TextureBytes != null
                                                ? Utils.BytesToTexture(incomingTexturesPlayerTexture.TextureBytes)
                                                : null;

                                            Game1.self.EnemyShipsSkins.Add(pair);
                                        }
                                    }
                                    #endregion
                                    Game1.self.SetFleetMenu(chosenDeck.GetFleet());
                                    Game1.self.ReadyToPlay = true;
                                    searching = false;
                                    popup.SetActive(false);
                                    SetClickables(true);
                                    Game1.self.popupToDraw = null;
                                    ClickableToRemove.ForEach(p => Clickable.Remove(p));
                                    searching        = false;
                                    startedSearching = false;
                                    stopSearching    = false;
                                    popup.layout     = null;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (stopSearching)
                            {
                                stopSearching = false;
                                packet        = new GamePacket(OperationType.ABANDON_GAME, new object());
                                Game1.self.Connection.Send(packet);
                                searching        = false;
                                startedSearching = false;
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public void onJoin()
        {
            if (chosenDeck != null && nameInputBox.Text.Length > 0 && creatornameInputBox.Text.Length > 0)
            {
                GamePacket packet = new GamePacket(OperationType.SELECT_FLEET, chosenDeck.GetFleet());
                Game1.self.Connection.Send(packet);
                packet = Game1.self.Connection.GetReceivedPacket();
                if (packet.OperationType == OperationType.SUCCESS)
                {
                    CustomGameRoom room = new CustomGameRoom(nameInputBox.Text);
                    room.CreatorsUsername = creatornameInputBox.Text;
                    packet = new GamePacket(OperationType.PLAY_CUSTOM_JOIN, room);
                    Game1.self.Connection.Send(packet);
                    packet = Game1.self.Connection.GetReceivedPacket();
                    if (packet.OperationType == OperationType.SUCCESS)
                    {
                        packet = Game1.self.Connection.GetReceivedPacket();
                        if (packet.OperationType == OperationType.SUCCESS)
                        {
                            #region TextureExchange
                            List <TexturePair> pairs = new List <TexturePair>();
                            foreach (var shipAndSkin in Game1.self.ShipsSkins)
                            {
                                TexturePair pair = new TexturePair();
                                pair.TextureBytes = shipAndSkin.skin != null
                                    ? Utils.TextureToBytes(shipAndSkin.ship)
                                    : null;

                                pair.TemplateName = shipAndSkin.ship;
                                pairs.Add(pair);
                            }
                            Textures textures = new Textures(pairs);


                            packet = new GamePacket(OperationType.TEXTURES_EXCHANGE, textures);
                            Game1.self.Connection.Send(packet);
                            Console.WriteLine(packet.Packet);


                            packet = Game1.self.Connection.GetReceivedPacket();
                            if (packet.OperationType == OperationType.TEXTURES_EXCHANGE)
                            {
                                Game1.self.EnemyShipsSkins.Clear();
                                Textures incomingTextures = (Textures)packet.Packet;
                                foreach (var incomingTexturesPlayerTexture in incomingTextures.PlayerTextures)
                                {
                                    Game1.ShipAndSkin pair = new Game1.ShipAndSkin();
                                    pair.ship = incomingTexturesPlayerTexture.TemplateName;
                                    pair.skin = incomingTexturesPlayerTexture.TextureBytes != null
                                        ? Utils.BytesToTexture(incomingTexturesPlayerTexture.TextureBytes)
                                        : null;

                                    Game1.self.EnemyShipsSkins.Add(pair);
                                }
                            }
                            #endregion

                            Game1.self.SetFleetMenu(chosenDeck.GetFleet());
                            Game1.self.ReadyToPlay = true;
                            Game1.self.popupToDraw = null;
                            popup.SetActive(false);
                            SetClickables(true);
                            Game1.self.popupToDraw = null;
                            popup.layout           = null;
                            ClickableToRemove.ForEach(p => Clickable.Remove(p));
                            packet = Game1.self.Connection.GetReceivedPacket(100);
                        }
                    }
                    else
                    {
                        labelError.Text = "There is no free room with that name";
                    }
                }
            }
        }