Example #1
0
        private void btDangNhap_Click(object sender, EventArgs e)
        {
            string        sql        = "select username,isLoggedIn from users where username='******' and password='******'";
            SQLConnection connection = new SQLConnection(SQLConnection.GetDatabasePath(txtboxDatabaseIP.Text + ",6969", "doan", "admin", "cuong123"));
            SqlDataReader reader     = connection.Query(sql);

            if (reader.HasRows && reader.Read() && reader.GetInt32(1) == 0)
            {
                //create new connection to update login status
                SQLConnection conn   = new SQLConnection(SQLConnection.GetDatabasePath(txtboxDatabaseIP.Text + ",6969", "doan", "admin", "cuong123"));
                string        sqlcmd = "update users set isLoggedIn=1 where username='******'";
                conn.AddRemoveAlter(sqlcmd);
                conn.Close();
                //
                MessageBox.Show("Đăng nhập thành công");
                txtboxUsername.Text   = txtboxID.Text;
                txtboxID.Text         = "";
                txtboxPassword.Text   = "";
                txtboxRivalIP.Enabled = true;
                btCreateRoom.Enabled  = true;
                btEnterRoom.Enabled   = true;
                Const.username        = txtboxUsername.Text;
                Const.serverIP        = txtboxDatabaseIP.Text;
            }
            else if (reader.HasRows && reader.GetInt32(1) == 1)
            {
                MessageBox.Show("Tài khoản đang được đăng nhập ở nơi khác !!!");
            }
            else
            {
                MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu !!!");
            }
            connection.Close();
        }
Example #2
0
        private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //logout current user
            string        sql  = "update users set isLoggedIn=0 where username='******'";
            SQLConnection conn = new SQLConnection(SQLConnection.GetDatabasePath(txtboxDatabaseIP.Text + ",6969", "doan", "admin", "cuong123"));

            conn.AddRemoveAlter(sql);
            conn.Close();
            Application.Exit();
        }
Example #3
0
        bool IsValidUsername(string username)
        {
            //Chuan bi cau lenh query viet bang SQL
            String        sqlQuery   = "select * from users where username='******'";
            SQLConnection connection = new SQLConnection(SQLConnection.GetDatabasePath(txtboxDatabaseIP.Text + ",6969", "doan", "admin", "cuong123"));
            SqlDataReader reader     = connection.Query(sqlQuery);

            if (reader.HasRows)
            {
                connection.Close();
                return(false);
            }
            connection.Close();
            return(true);
        }
Example #4
0
 private void btDangki_Click(object sender, EventArgs e)
 {
     if (IsValidUsername(txtboxID.Text))
     {
         string        sql        = String.Format("insert into users values('{0}','{1}','{2}',{3})", txtboxID.Text, txtboxPassword.Text, 0, 0);
         SQLConnection connection = new SQLConnection(SQLConnection.GetDatabasePath(txtboxDatabaseIP.Text + ",6969", "doan", "admin", "cuong123"));
         connection.AddRemoveAlter(sql);
         connection.Close();
         MessageBox.Show("Đăng kí thành công");
     }
     else
     {
         MessageBox.Show("username đã tồn tại !!!");
     }
 }
Example #5
0
        private void LoadDataToTable(string databaseIP)
        {
            //Chuan bi cau lenh query viet bang SQL
            String        sqlQuery   = "select username,won_matchs from users order by won_matchs desc";
            SQLConnection connection = new SQLConnection(SQLConnection.GetDatabasePath(databaseIP + ",6969", "doan", "admin", "cuong123"));
            SqlDataReader reader     = connection.Query(sqlQuery);

            //Su dung reader de doc tung dong du lieu
            //va thuc hien thao tac xu ly mong muon voi du lieu doc len
            while (reader.HasRows)//con dong du lieu thi doc tiep
            {
                if (reader.Read() == false)
                {
                    return;                        //doc ko duoc thi return
                }
                //xu ly khi da doc du lieu len
                dataGridView1.Rows.Add(reader.GetString(0), reader.GetInt32(1));
            }
            connection.Close();
        }
Example #6
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Listen();
            try
            {
                //remove trops
                //reset attacker's index for each trops
                //check win/lose
                for (int i = 0; i < Const.listTrops.Count; i++)
                {
                    //play hit sound if match has any trops fighting
                    if (Const.listTrops[i].CurrentStatus)
                    {
                        try {
                            p.Kill();
                            p.Start();
                        }
                        catch { }
                    }
                    //process win/lose
                    //trop outside screen
                    //and trop is my team
                    if (Const.listTrops[i].CurrentLocation.X <0 || Const.listTrops[i].CurrentLocation.X> this.ClientSize.Width &&
                        Const.listTrops[i].CurrentTeam == Const.currentTeam)
                    {
                        timer1.Stop();
                        timer_increase_money.Stop();

                        //notify rival that he was lose
                        Program.socket.Send(new SocketData((int)SocketCommand.END_GAME, currentItem, Point.Empty));
                        //update won_matchs in database
                        SQLConnection conn = new SQLConnection(SQLConnection.GetDatabasePath(Const.serverIP + ",6969", "doan", "admin", "cuong123"));
                        string        sql  = "update users set won_matchs+=1 where username='******'";
                        conn.AddRemoveAlter(sql);
                        conn.Close();
                        MessageBox.Show("You win");
                        this.Close();
                        Program.login.Show();
                    }
                    //remove trops died
                    if (Const.listTrops[i].CurrentHP <= 0)
                    {
                        //set attack status of attackers that are attacking this to false
                        foreach (int attackerIndex in Const.listTrops[i].BeingAttackedBy)
                        {
                            Const.listTrops[attackerIndex].CurrentStatus = false;
                        }
                        //remove trops
                        Const.listTrops.RemoveAt(i);
                    }
                    //reset attacker's index for each trops
                    Const.listTrops[i].BeingAttackedBy.Clear();
                }
                //check and set attack status for trops
                if (Const.listTrops.Count == 1)
                {
                    Const.listTrops[0].CurrentStatus = false;
                }
                for (int i = 0; i < Const.listTrops.Count - 1; i++)
                {
                    for (int j = i + 1; j < Const.listTrops.Count; j++)
                    {
                        // 2 trops are rival and in the same lane
                        if (Const.listTrops[i].CurrentTeam != Const.listTrops[j].CurrentTeam &&
                            Const.listTrops[i].CurrentLocation.Y == Const.listTrops[j].CurrentLocation.Y)
                        {
                            // trops[i] is left team
                            //trops[j] is right team
                            if (Const.listTrops[i].CurrentTeam)
                            {
                                //trops[i] is ready to attack
                                if (Const.listTrops[i].CurrentLocation.X + Const.listTrops[i].Sprite.Width / 3 + Const.listTrops[i].AttackRange >= Const.listTrops[j].CurrentLocation.X)
                                {
                                    Const.listTrops[i].CurrentStatus = true;   //attack
                                    Const.listTrops[i].CurrentVictim = j;      //set victim index
                                    Const.listTrops[j].BeingAttackedBy.Add(i); //store attacker's index to set attacker status to running after die
                                }

                                //trops[j] is reader to attack
                                if (Const.listTrops[j].CurrentLocation.X - Const.listTrops[j].AttackRange <= Const.listTrops[i].CurrentLocation.X + Const.listTrops[i].Sprite.Width / 3)
                                {
                                    Const.listTrops[j].CurrentStatus = true;   //attack
                                    Const.listTrops[j].CurrentVictim = i;      //set victim index
                                    Const.listTrops[i].BeingAttackedBy.Add(j); //store attacker's index to set attacker status to running after die
                                }
                            }
                            //trops[i] is right team
                            //trops[j] is left team
                            else
                            {
                                //trops[j] is ready to attack
                                if (Const.listTrops[j].CurrentLocation.X + Const.listTrops[j].Sprite.Width / 3 + Const.listTrops[j].AttackRange >= Const.listTrops[i].CurrentLocation.X)
                                {
                                    Const.listTrops[j].CurrentStatus = true;   //attack
                                    Const.listTrops[j].CurrentVictim = i;      //set victim index
                                    Const.listTrops[i].BeingAttackedBy.Add(j); //store attacker's index to set attacker status to running after die
                                }
                                //trops[i] is reader to attack
                                if (Const.listTrops[i].CurrentLocation.X - Const.listTrops[i].AttackRange <= Const.listTrops[j].CurrentLocation.X + Const.listTrops[j].Sprite.Width / 3)
                                {
                                    Const.listTrops[i].CurrentStatus = true;   //attack
                                    Const.listTrops[i].CurrentVictim = j;      //set victim index
                                    Const.listTrops[j].BeingAttackedBy.Add(i); //store attacker's index to set attacker status to running after die
                                }
                            }
                        }
                    }
                }
                //check trops in the affect range of spells
                for (int i = 0; i < Const.listTrops.Count; i++)
                {
                    for (int j = 0; j < Const.listSpells.Count; j++)
                    {
                        // trops in affect range of spell
                        if (Const.listSpells[j].CurrentLocation.X + Const.listSpells[j].Sprite.Width / 3 >= Const.listTrops[i].CurrentLocation.X &&
                            Const.listSpells[j].CurrentLocation.X <= Const.listTrops[i].CurrentLocation.X + Const.listTrops[i].Sprite.Width / 3 &&
                            Const.listSpells[j].CurrentLocation.Y <= Const.listTrops[i].CurrentLocation.Y + Const.listTrops[i].Sprite.Height / 4 &&
                            Const.listSpells[j].CurrentLocation.Y + Const.listSpells[j].Sprite.Height / 4 >= Const.listTrops[i].CurrentLocation.Y)
                        {
                            //add
                            Const.listSpells[j].AffectedTrops.Add(i);
                        }
                    }
                }
                //make spell affect on trops
                for (int i = 0; i < Const.listSpells.Count; i++)
                {
                    Const.listSpells[i].Drop();
                }
                //set trops running or attacking base on its status
                //check trop move outside screen --> process win/lose
                for (int i = 0; i < Const.listTrops.Count; i++)
                {
                    //running
                    if (!Const.listTrops[i].CurrentStatus)
                    {
                        Const.listTrops[i].Move();
                    }
                    //attacking
                    else if (Const.listTrops[i].CurrentStatus)
                    {
                        Const.listTrops[i].Attack();
                    }
                }

                //render all
                RenderTool.Render();
            }
            catch { }
        }