Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] == null)
            {
                Session["ErrorMessage"] = "You need to be logged in first";
                Response.Redirect("~/Login.aspx");
            }
            user = (UserObject)Session["User"];

            //update the battle counter from db
            user.battleCounter = controller.refreshUserBattleCount(user.userId.Value);

            lblBCounter.Text = "Battles Left: " + user.battleCounter;
            if (user.character == null)
            {
                Session["ErrorMessage"] = "You can create a Card Character here first before battling.";
                Response.Redirect("~/CreateAChar.aspx");
            }
            self = user.character;

            //update user's battlec counter in case they have not done a fresh login
            //refresh user object
            //controller.updateBattleCounter(user);

            /**
             *  Get a list of opponents.
             */
            opp = controller.getOpponentsList(row_size);
            for (int x = 0; x < row_size; x = x + 2)
            {
                Panel row = new Panel();
                row.CssClass = "row";
                for (int y = 0; y < 2 && (x + y < row_size); y++)
                {
                    int index = x + y;
                    if (opp[index] != null)
                    {
                        Panel oppItem = new Panel();
                        oppItem.ID = "OPP" + index;
                        oppItem.CssClass = "opp-item";

                        LiteralControl name = new LiteralControl("<p class='big-font'>" + opp[index].Name + "</p>");
                        ImageButton imb = new ImageButton();
                        imb.ID = "OPPImg" + index;
                        imb.Attributes["idx"] = Convert.ToString(index);
                        imb.CssClass = "xsprint";
                        imb.ImageUrl = opp[index].ImageUrl;
                        imb.AlternateText = "Character Image";
                        imb.Click += this.btnAtk_Click;

                        String atk = "?"; //opp[index].Attack.ToString();
                        Panel atkLine = createStatisticLine(atk, "~/images/Attack-Icon.png");

                        String hp = "?/?"; //opp[index].Health + "/" + opp[index].MaxHealth;
                        Panel hpLine = createStatisticLine(hp, "~/images/HP-Icon.png");

                        String spd = opp[index].Speed.ToString();
                        Panel spdLine = createStatisticLine(spd, "~/images/Speed-Icon.png");

                        Label lblReward = new Label();
                        lblReward.Text = "Reward: " + opp[index].Reward + "MP";
                        lblReward.CssClass = "pad-left-5";

                        Panel statBar = new Panel();
                        statBar.CssClass = "stat-bar";
                        statBar.Controls.Add(atkLine);
                        statBar.Controls.Add(hpLine);
                        statBar.Controls.Add(spdLine);

                        oppItem.Controls.Add(name);
                        oppItem.Controls.Add(imb);
                        oppItem.Controls.Add(statBar);
                        oppItem.Controls.Add(lblReward);
                        row.Controls.Add(oppItem);
                    }
                }
                oppContainer.Controls.Add(row);
            }
        }
Exemple #2
0
        private CharacterObject buildCharacter(SqlDataReader reader)
        {
            CharacterObject character = null;
            if (reader.Read())
            {
                int charId = Convert.ToInt32(reader["CharId"]);
                String name = Convert.ToString(reader["Name"]);
                int attack = Convert.ToInt32(reader["Attack"]);
                int health = Convert.ToInt32(reader["Health"]);
                int maxhp = Convert.ToInt32(reader["MaxHealth"]);
                int speed = Convert.ToInt32(reader["Speed"]);

                String imageUrl = Convert.ToString(reader["imageUrl"]);
                DateTime? finishTime = null;
                int? trainingType = null;
                if (!System.DBNull.Value.Equals(reader["TrainingFinishTime"]))
                {
                    finishTime = Convert.ToDateTime(reader["TrainingFinishTime"]);
                    trainingType = Convert.ToInt32(reader["TrainingType"]);
                }
                character = new CharacterObject(charId, name, attack, health, maxhp, speed, 1, imageUrl, finishTime, trainingType);
            }
            return character;
        }
Exemple #3
0
        public CharacterObject[] getOpponentsList(int rowsize)
        {
            CharacterObject[] opp = new CharacterObject[rowsize];

            openSQLConnection();
            string query = "SELECT TOP " + rowsize + " CharId, Name, ImageUrl, Attack, Health, Speed, Rewards " +
                           "FROM monbattle.NeutralCharacters";
            using (SqlCommand cmd = new SqlCommand(query, this.sqlConnection))
            {
                try
                {
                    SqlDataReader reader = cmd.ExecuteReader();
                    int ind = 0;
                    while (reader.Read())
                    {
                        int charID = Convert.ToInt32(reader["CharID"]);
                        string name = Convert.ToString(reader["Name"]);
                        int attack = Convert.ToInt32(reader["Attack"]);
                        int health = Convert.ToInt32(reader["Health"]);
                        int speed = Convert.ToInt32(reader["Speed"]);
                        int rew = Convert.ToInt32(reader["Rewards"]);
                        string imageUrl = Convert.ToString(reader["ImageUrl"]);
                        opp[ind] = new CharacterObject(charID, name, attack, health, health, speed, rew, imageUrl, null, null);
                        ind++;
                    }
                    return opp;
                }
                catch (SqlException exception)
                {
                    throw exception;
                }
                finally
                {
                    closeSQLConnection();
                }
            }
        }
Exemple #4
0
 public int startTrainCharacter(UserObject user, CharacterObject character, DateTime trainingTime, int trainingType, int cost)
 {
     int succ = dataModel.startTrainCharacter(user.userId.Value, character.charId, trainingTime, trainingType, cost);
     if (succ != 0)
     {
         character.trainingFinishTime = trainingTime;
         character.trainingType = (CharacterObject.trainingTypeEnum)trainingType;
         user.points -= cost;
     }
     return succ;
 }