private void CloseConnection()
 {
     Sabitler.bagli_client.Remove(connectionID);
     Sabitler.oyuncu_cikti(connectionID.ToString());
     DataSender.SendOyuncuOyundanCikti(connectionID);
     socket.Close();
 }
        public static void CreateNewConnection(TcpClient tempClient)
        {
            Client client = new Client();

            client.socket       = tempClient;
            client.connectionID = ((IPEndPoint)tempClient.Client.RemoteEndPoint).Port;
            client.Start();
            clients.Add(client.connectionID, client);
            DataSender.SendConnect(client.connectionID);
        }
Exemplo n.º 3
0
 public static void CreateEngine(int player1, int player2)
 {
     Console.WriteLine("Player: {0} and Player: {1} Have been matched with match ID: {2}",
                       ClientManager.clients[player1].name, ClientManager.clients[player2].name, idCounter);
     ClientManager.clients[player1].gameEngineID = idCounter;
     ClientManager.clients[player2].gameEngineID = idCounter;
     gameEngines.Add(idCounter, new GameEngine(idCounter, player1, player2));
     idCounter++;
     DataSender.SendMatchMade(player1, player2);
     DataSender.SendMatchMade(player2, player1);
 }
Exemplo n.º 4
0
        public static void CreateNewConnection(TcpClient tempClient)
        {
            Client newClient = new Client();

            newClient.socket       = tempClient;
            newClient.connectionID = ((IPEndPoint)tempClient.Client.RemoteEndPoint).Port;
            newClient.Start();
            client.Add(newClient.connectionID, newClient);

            DataSender.SendWelcomeMessage(newClient.connectionID);
        }
Exemplo n.º 5
0
        public static void HandleMerhabaServer(int connectionID, byte[] data)
        {
            Kaan_ByteBuffer buffer = new Kaan_ByteBuffer();

            buffer.Bytes_Yaz(data);
            int    packetID = buffer.Int_Oku();
            string msg      = buffer.String_Oku();

            buffer.Dispose();
            Yazi.Gelen_Mesaj(connectionID + " " + msg);
            DataSender.SendHodsgeldinMesaji(connectionID);
        }
 private void SendUpdatedBoardAndStats()
 {
     foreach (int player in players)
     {
         DataSender.SendUpdatedStats(player, PackStats(player, playerToPlayer[player]));
     }
     foreach (int player in players)
     {
         DataSender.SendUpdatedBoard(player, playerMapHand[player], playerMapBench[player], playerMapAttackZone[player],
                                     playerMapBench[playerToPlayer[player]], playerMapAttackZone[playerToPlayer[player]]);
     }
 }
Exemplo n.º 7
0
        public static void Handle_Anim_Al(int connectionID, byte[] data)
        {
            Kaan_ByteBuffer buffer = new Kaan_ByteBuffer();

            buffer.Bytes_Yaz(data);
            int    packetID = buffer.Int_Oku();
            string animasyon_kimde_oynayacak = buffer.String_Oku();
            string anim_Adi = buffer.String_Oku();
            int    akiflik  = buffer.Int_Oku();

            DataSender.SendAnimGonder(connectionID, animasyon_kimde_oynayacak, anim_Adi, akiflik);

            buffer.Dispose();
        }
        public void Pass(int player)
        {
            Console.WriteLine("Player {0} passed", ClientManager.clients[player].name);
            if (turnPlayerId != player)
            {
                return;
            }

            if (endTurn)
            {
                NextTurn();
            }
            else
            {
                endTurn      = true;
                turnPlayerId = playerToPlayer[turnPlayerId];
                phase        = ClientManager.clients[turnPlayerId].name + "'s Turn";
                DataSender.SendUpdatedStats(player1ID, PackStats(player1ID, player2ID));
                DataSender.SendUpdatedStats(player2ID, PackStats(player2ID, player1ID));
            }
        }
Exemplo n.º 9
0
        public static void HandleLoginGiris(int connectionID, byte[] data)
        {
            Kaan_ByteBuffer buffer = new Kaan_ByteBuffer();

            buffer.Bytes_Yaz(data);
            int    packetID      = buffer.Int_Oku();
            string kullanici_adi = buffer.String_Oku();
            string sifre         = buffer.String_Oku();

            ArrayList Ara = new ArrayList();

            Ara.Add("kullanici_adi='" + kullanici_adi + "'");
            Ara.Add("sifre='" + sifre + "'");

            MySqlCommand cmd = Sabitler.Mysql_Data.MySql_Veri_Cek(Sabitler.bagli_client[connectionID].baglanti, null, "Select * From tum_kullanicilar", Ara);

            if (cmd != null)
            {
                MySqlDataReader oku = cmd.ExecuteReader();

                int id = 0;
                while (oku.Read())
                {
                    //////
                    id = (int)oku["id"];
                    Yazi.Log_yaz("Bağlanan Kullanıcın Kullancı ID si : " + id.ToString());
                }
                oku.Close();

                ///
                DataSender.SendLoginGirisCevap(connectionID, 1);
            }
            else
            {
                DataSender.SendLoginGirisCevap(connectionID, 0);
            }
            buffer.Dispose();
        }
        public void Mulligan(int playerID, List <Card> cards)
        {
            phase = ClientManager.clients[player1ID].name + "'s TURN";
            foreach (Card card in cards)
            {
                int index = -1;
                for (int x = 0; x < playerMapHand[playerID].Count; x++)
                {
                    if (card.id.Equals(playerMapHand[playerID][x].id))
                    {
                        index = x;
                        break;
                    }
                }
                if (index != -1)
                {
                    playerMapHand[playerID].RemoveAt(index);
                }
            }

            playerMapDeck[playerID].AddRange(cards);

            ShuffleDeck(playerMapDeck[playerID]);
            DrawCards(cards.Count, playerID);

            DataSender.SendMulligan(playerID, playerMapHand[playerID]);
            DataSender.SendUpdatedBoard(playerID, playerMapHand[playerID], playerMapBench[playerID], playerMapAttackZone[playerID],
                                        playerMapBench[playerToPlayer[playerID]], playerMapAttackZone[playerToPlayer[playerID]]);
            if (isMulliganDone)
            {
                DrawCards(1, player1ID);
                DrawCards(1, player2ID);
                attackPlayerId = player1ID;
                SendUpdatedBoardAndStats();
            }
            isMulliganDone = false ? true : true;
        }
Exemplo n.º 11
0
        public static void HandleCordinatBilgileriniGonder(int connectionID, byte[] data)
        {
            Kaan_ByteBuffer buffer = new Kaan_ByteBuffer();

            buffer.Bytes_Yaz(data);
            int packetID = buffer.Int_Oku();

            //Oyuncu Pozisyonları
            float posx = buffer.Float_Oku();
            float posy = buffer.Float_Oku();
            float posz = buffer.Float_Oku();

            //Oyuncu Rotasyonlarımız
            float rotx = buffer.Float_Oku();
            float roty = buffer.Float_Oku();
            float rotz = buffer.Float_Oku();
            float rotw = buffer.Float_Oku();

            Sabitler.bagli_client[connectionID].xCord = posx;
            Sabitler.bagli_client[connectionID].yCord = posy;
            Sabitler.bagli_client[connectionID].zCord = posz;
            DataSender.SendKordinatBilgileriniGonder(connectionID, posx, posy, posz, rotx, roty, rotz, rotw);
            buffer.Dispose();
        }
        public void Battle(int player)
        {
            Console.WriteLine("SENT BATTLE {0}", ClientManager.clients[player].name);
            if (!playerIsDefending[player] || turnPlayerId != player)
            {
                Console.WriteLine("Player defend is {0} and turnPlayer is {1} ", playerIsDefending[player], ClientManager.clients[turnPlayerId].name);
                return;
            }

            int enemy = playerToPlayer[player];

            for (int x = 0; x < playerMapAttackZone[enemy].Count; x++)
            {
                if (playerMapAttackZone[player][x] == null)
                {
                    playerMapHealth[player] -= playerMapAttackZone[enemy][x].attack;
                    playerMapBench[enemy].Add(playerMapAttackZone[enemy][x]);
                }
                else
                {
                    Console.WriteLine("Card: {0} Stats: {1}, {2} vs Card: {3} Stats: {4}, {5}",
                                      playerMapAttackZone[player][x].name, playerMapAttackZone[player][x].health, playerMapAttackZone[player][x].attack,
                                      playerMapAttackZone[enemy][x].name, playerMapAttackZone[enemy][x].health, playerMapAttackZone[enemy][x].attack
                                      );

                    CalculateBattle(playerMapAttackZone[player][x], playerMapAttackZone[enemy][x], x);

                    Console.WriteLine("Card: {0} Stats: {1}, {2} vs Card: {3} Stats: {4}, {5}",
                                      playerMapAttackZone[player][x].name, playerMapAttackZone[player][x].health, playerMapAttackZone[player][x].attack,
                                      playerMapAttackZone[enemy][x].name, playerMapAttackZone[enemy][x].health, playerMapAttackZone[enemy][x].attack
                                      );

                    foreach (int p in players)
                    {
                        if (playerMapAttackZone[p][x].health > 0)
                        {
                            playerMapBench[p].Add(playerMapAttackZone[p][x]);
                        }
                    }
                }
            }

            if (playerMapHealth[player1ID] <= 0)
            {
                DataSender.SendEndGame(player1ID, "Defeat");
                DataSender.SendEndGame(player2ID, "Victory");
            }
            else if (playerMapHealth[player2ID] <= 0)
            {
                DataSender.SendEndGame(player2ID, "Defeat");
                DataSender.SendEndGame(player1ID, "Victory");
            }
            playerMapAttackZone[player] = new List <Card>();
            playerMapAttackZone[playerToPlayer[player]] = new List <Card>();
            playerIsAttacking[playerToPlayer[player]]   = false;
            playerIsDefending[player] = false;
            canAttackerAttack         = false;
            turnPlayerId = playerToPlayer[turnPlayerId];
            phase        = ClientManager.clients[turnPlayerId].name + "'s Turn";
            SendUpdatedBoardAndStats();
        }