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 { } }