Exemple #1
0
        public Position?Enter(Position pos)
        {
            // if the position is outside of the map, return null
            if (pos.row < 0 || pos.row >= NumRows ||
                pos.col < 0 || pos.col >= NumCols)
            {
                return(null);
            }

            // based on the tile for the given position's char, enter it
            Position?newPos = tileDict[layout[pos.row, pos.col]].Enter(pos);

            // if it returned null, the character does not move so return null
            if (newPos == null)
            {
                return(null);
            }

            // otherwise see if the character should get a random encounter
            if (rand.NextDouble() < encounterChance)
            {
                encounterChance = 0.15;
                Game.GetGame().ChangeState(GameState.FIGHTING);
            }
            else
            {
                encounterChance += 0.10;
            }

            // return the new position
            return(newPos);
        }
Exemple #2
0
        public bool IsValidPos(Position pos)
        {
            if (pos.row < 0 || pos.row >= NumRows || pos.col < 0 || pos.col >= NumCols || layout[pos.row, pos.col] == 1)
            {
                return(false);
            }
            //DEBUG:ZAB
            if (rand.NextDouble() < encounterChance)
            {
                encounterChance = 0.15;
                Game.GetGame().ChangeState(GameState.FIGHTING);
            }
            //TODO:ZAB
            if (layout[pos.row, pos.col] == 3)
            {
                Game.GetGame().ChangeState(GameState.NEXT_LEVEL);
            }
            if (layout[pos.row, pos.col] == 4)
            {
                Game.GetGame().ChangeState(GameState.BOSSFIGHT);
            }
            if (layout[pos.row, pos.col] == 5)
            {
                Game.GetGame().ChangeState(GameState.DEAD);
            }
            else
            {
                //DEBUG:ZAB
                encounterChance += 0.10;
            }

            return(true);
        }
Exemple #3
0
        public static string[] LoadGame()
        {
            var game = Game.GetGame();
            var save = File.ReadAllText("save.txt");

            var lines = save.Split('\n');

            return(lines);
        }
Exemple #4
0
        public void MagicAttack(Mortal receiver)
        {
            float strCoeffient  = 0.2f;
            float ManaCoeffient = 0.5f;

            if (Mana >= 5)
            {
                float baseDamage = 0;
                Mana = Mana - 5;
                switch (Game.GetGame().Character.ClassType)
                {
                case classSystem.SCRUM:
                    strCoeffient  = 0.5f;
                    ManaCoeffient = 0.3f;


                    break;

                case classSystem.WARRIOR:
                    strCoeffient  = 0.8f;
                    ManaCoeffient = 0.3f;
                    break;

                case classSystem.MAGICIAN:
                    Mana          = Mana - 5;
                    strCoeffient  = 0.5f;
                    ManaCoeffient = 1.0f;
                    break;

                case classSystem.ARCHER:
                    strCoeffient  = 0.5f;
                    ManaCoeffient = 0.5f;


                    break;

                default:
                    strCoeffient  = 0.1f;
                    ManaCoeffient = 0.1f;
                    break;
                }
                baseDamage = Math.Abs(Str * strCoeffient + ManaCoeffient * MaxMana - receiver.Def);
                float randMax  = 1 + SIMPLEATTACK_RANDOM_AMT;
                float randMin  = 1 - SIMPLEATTACK_RANDOM_AMT;
                float randMult = (float)(rand.NextDouble() * (randMax - randMin)) + randMin;


                receiver.Health -= (baseDamage * randMult);
            }
            else
            {
                Console.WriteLine("YOU DONT HAVE ENOUGH MANA");
            }
        }
        public static Character InitializeMaps(string firstMapFolder, string characterImage, GroupBox grpBox, Func <string, Bitmap> LoadImg)
        {
            Map.grpBox = grpBox;
            loadImg    = LoadImg;

            mapDict.Clear();

            Map map = new Map();

            map.LoadMap(firstMapFolder);

            // resize GroupBox to match loaded map
            grpBox.Width  = CurrentMap.grpMap.Width;
            grpBox.Height = CurrentMap.grpMap.Height;
            grpBox.Top    = 5;
            grpBox.Left   = 5;

            encounterChance = 0.001;
            rand            = new Random();
            Game.GetGame().ChangeState(GameState.ON_MAP);

            // initialize character picture box
            PictureBox pb = new PictureBox()
            {
                Image    = LoadImg(characterImage),
                SizeMode = PictureBoxSizeMode.StretchImage,
                Width    = BLOCK_SIZE,
                Height   = BLOCK_SIZE,
                BackgroundImageLayout = ImageLayout.Stretch
            };



            Position p       = new Position(map.CharacterStartRow, map.CharacterStartCol);
            Position topleft = RowColToTopLeft(p);

            pb.Top  = topleft.row;
            pb.Left = topleft.col;
            grpBox.Controls.Add(pb);
            pb.BringToFront();

            // initialize the character and return it
            character = new Character(pb, p);

            // Plays level 1 theme upon entering player name
            System.IO.Stream str = Music.Music.L1Music;
            SoundPlayer      sp  = new SoundPlayer(str);

            sp.Play();

            return(character);
        }
Exemple #6
0
        private void buyDef_Click(object sender, EventArgs e)
        {
            Character character = Game.GetGame().Character;

            if (character.Wallet >= 10 & character.HasWeapon)
            {
                character.GainCoin(-10);
                lblWallet.Text       = character.Wallet.ToString();
                character.WeaponDef += 5;
                character.IncAtt(2);
                lblWeaponDef.Text = character.WeaponDef.ToString();
            }
        }
 public override Position?Enter(Position pos)
 {
     if (defeated)
     {
         return(CurrentMap.tileDict[tileBelow].Enter(pos));
     }
     else
     {
         Game.GetGame().ChangeState(GameState.FIGHTING);
         Enemy enemy = new MapEnemy(this.callOnDeath, level, loadImg(enemyImage));
         Game.GetGame().SetEnemy(enemy);
         return(null);
     }
 }
Exemple #8
0
        public static void SaveGame()
        {
            var character = Game.GetGame().Character;

            string save = "";

            save += character.map.LevelName + "\n";
            save += character.Level + "\n";
            save += character.XP + "\n";
            save += character.Health + "\n";
            save += character.MaxMana + "\n";
            save += character.Wallet + "\n";
            save += character.HasWeapon + "\n";
            //save charcter position as well

            File.WriteAllText("save.txt", save);
        }
Exemple #9
0
        public static Character InitializeMaps(string firstMapFolder, string characterImage, GroupBox grpBox, Func <string, Bitmap> LoadImg)
        {
            Map.grpBox = grpBox;
            loadImg    = LoadImg;

            Map map = new Map();

            map.LoadMap(firstMapFolder);

            // resize GroupBox to match loaded map
            grpBox.Width  = CurrentMap.grpMap.Width;
            grpBox.Height = CurrentMap.grpMap.Height;
            grpBox.Top    = 5;
            grpBox.Left   = 5;

            // initialize for game
            encounterChance = 0.15;
            rand            = new Random();
            Game.GetGame().ChangeState(GameState.ON_MAP);

            // initialize character picture box
            PictureBox pb = new PictureBox()
            {
                Image    = LoadImg(characterImage),
                SizeMode = PictureBoxSizeMode.StretchImage,
                Width    = BLOCK_SIZE,
                Height   = BLOCK_SIZE,
                BackgroundImageLayout = ImageLayout.Stretch
            };

            Position p   = new Position(map.CharacterStartRow, map.CharacterStartCol);
            Position pPB = RowColToTopLeft(p);

            pb.Top  = pPB.row;
            pb.Left = pPB.col;
            grpBox.Controls.Add(pb);
            pb.BringToFront();

            // initialize the character and return it
            character = new Character(pb, p);
            return(character);
        }
Exemple #10
0
        public bool IsValidPos(Position pos)
        {
            if (pos.row < 0 || pos.row >= NumRows ||
                pos.col < 0 || pos.col >= NumCols ||
                layout[pos.row, pos.col] == 1)
            {
                return(false);
            }
            if (rand.NextDouble() < encounterChance)
            {
                encounterChance = 0.15;
                Game.GetGame().ChangeState(GameState.FIGHTING);
            }
            else
            {
                encounterChance += 0.10;
            }

            return(true);
        }
Exemple #11
0
        private void FrmStats_Load(object sender, EventArgs e)
        {
            Character character = Game.GetGame().Character;

            lblLevel.Text     = character.Level.ToString();
            lblHealth.Text    = ((float)Math.Round(character.Health)).ToString();
            lblMana.Text      = ((float)Math.Round(character.Mana)).ToString();
            lblPlayerStr.Text = ((float)Math.Round(character.Str)).ToString();
            lblPlayerDef.Text = ((float)Math.Round(character.Def)).ToString();
            if (character.HasWeapon)
            {
                lblWeaponStr.Text = character.WeaponStr.ToString();
                lblWeaponDef.Text = character.WeaponDef.ToString();
            }
            else
            {
                lblWeaponStr.Text = "N/A";
                lblWeaponDef.Text = "N/A";
            }

            //lblWeaponStr.Text = character.weapon.Str.ToString();
            //lblWeaponDef.Text = character.weapon.Def.ToString();
            lblWallet.Text = character.Wallet.ToString();
        }
Exemple #12
0
        public void WeaponAttack(Mortal reciever)
        {
            Character character = Game.GetGame().Character;

            reciever.Health = reciever.Health - (character.Str * 2);
        }
Exemple #13
0
        public bool IsValidPos(Position pos, int cX, int cY, Character character)
        {
            if (pos.row < 0 || pos.row >= NumRows ||
                pos.col < 0 || pos.col >= NumCols ||
                layout[pos.row, pos.col] == 1)
            {
                return(false);
            }

            if (layout[pos.row, pos.col] == 6)
            {
                Game.GetGame().ChangeState(GameState.LVL2);     // checks location for lvl2 space
            }
            else if (layout[pos.row, pos.col] == 5)
            {
                Game.GetGame().ChangeState(GameState.TITLE_SCREEN);     // checks location for quit space
            }
            // check if on boss space and set gamestate to boss if true
            else if (layout[pos.row, pos.col] == 4)
            {
                Game.GetGame().ChangeState(GameState.BOSS);
            }
            else if (pos.row == cY && pos.col == cX)
            {
                // Set character start position to checkpoint position
                this.CharacterStartCol = cX;
                this.CharacterStartRow = cY;
                // Check if necessary files and directories already exist
                if (!Directory.Exists("Resources"))
                {
                    // Create directory if doesn't exist
                    Directory.CreateDirectory("Resources");
                }
                else
                {
                    // Check if save files already exist, delete if they do
                    if (File.Exists("Resources/savedmap.txt"))
                    {
                        File.Delete("Resources/savedmap.txt");
                    }
                    if (File.Exists("Resources/savedcharacter.txt"))
                    {
                        File.Delete("Resources/savedcharacter.txt");
                    }
                }
                // Write character stats to saved character file
                using (StreamWriter writer = new StreamWriter("Resources/savedcharacter.txt")){
                    writer.WriteLine(character.Health);
                    writer.WriteLine(character.MaxHealth);
                    writer.WriteLine(character.Mana);
                    writer.WriteLine(character.MaxMana);
                    writer.WriteLine(character.Str);
                    writer.WriteLine(character.Def);
                    writer.WriteLine(character.Luck);
                    writer.WriteLine(character.Speed);
                    writer.WriteLine(character.XP);
                    writer.WriteLine(character.ShouldLevelUp);
                    writer.WriteLine(character.Level);
                    writer.WriteLine(character.Name);
                }
                // Some storage variables
                string[] file    = new string[10];
                int      lineNum = 0;
                // Edge case handling for changing levels if checkpoint already reached
                if (this.CurrentMap == "Resources/savedmap.txt")
                {
                    this.CurrentMap = "Resources/lvl2.txt";
                }
                // Read the current map
                using (StreamReader sr = new StreamReader(this.CurrentMap)) {
                    string line = sr.ReadLine();
                    // Write current map to array of strings
                    while (line != null)
                    {
                        file[lineNum] = line;
                        line          = sr.ReadLine();
                        lineNum++;
                    }
                    // Go through each string in array
                    for (int i = 0; i < lineNum; i++)
                    {
                        // Set character start position on the level to empty space
                        if (file[i].Contains("2"))
                        {
                            int index = file[i].IndexOf("2");
                            System.Text.StringBuilder strBuilder = new System.Text.StringBuilder(file[i]);
                            strBuilder[index] = '0';
                            file[i]           = strBuilder.ToString();
                        }
                        // Set checkpoint position on the level to character start position
                        if (file[i].Contains("3"))
                        {
                            int index = file[i].IndexOf("3");
                            System.Text.StringBuilder strBuilder = new System.Text.StringBuilder(file[i]);
                            strBuilder[index] = '2';
                            file[i]           = strBuilder.ToString();
                        }
                    }
                }
                // Write modified level file to save file
                using (StreamWriter sw = new StreamWriter("Resources/savedmap.txt")) {
                    for (int i = 0; i < lineNum; i++)
                    {
                        sw.WriteLine(file[i]);
                    }
                }
            }
            else
            {
                // Do combat checks, as on a empty tile
                if (STOP_ENCOUNTER == false)
                {
                    if (rand.NextDouble() < encounterChance)
                    {
                        encounterChance = 0.15;
                        Game.GetGame().ChangeState(GameState.FIGHTING);
                    }
                    else
                    {
                        encounterChance += 0.05;
                    }
                }
            }
            // Move is valid
            return(true);
        }
Exemple #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mapFile"></param>
        /// <param name="grpMap"></param>
        /// <param name="LoadImg"></param>
        /// <returns></returns>
        public void LoadMap(GroupBox grpMap, Func <string, Bitmap> LoadImg)
        {
            rand      = new Random();
            LevelName = "Resources/coinHunt.txt";

            // declare and initialize locals
            int           top       = TOP_PAD;
            int           left      = BOUNDARY_PAD;
            Character     character = Game.GetGame().Character;
            List <string> mapLines  = new List <string>();

            // read from map file
            using (FileStream fs = new FileStream(LevelName, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        mapLines.Add(line);
                        line = sr.ReadLine();
                    }
                }
            }

            // load map file into layout and create PictureBox objects
            layout = new int[mapLines.Count, mapLines[0].Length];
            int chance = (int)Math.Round(rand.NextDouble() * (mapLines.Count * mapLines[0].Length));
            int i      = 0;

            foreach (string mapLine in mapLines)
            {
                int j = 0;
                foreach (char c in mapLine)
                {
                    int val = c - '0';
                    if (chance == (i * mapLines.Count + j) && val == 0)
                    {
                        val    = 6;
                        chance = (int)Math.Round(rand.NextDouble() * (mapLines.Count * mapLines[0].Length));
                    }
                    layout[i, j] = val;
                    PictureBox pb = CreateMapCell(val, LoadImg);
                    if (pb != null)
                    {
                        pb.Top  = top;
                        pb.Left = left;
                        grpMap.Controls.Add(pb);
                    }
                    if (val == 2)
                    {
                        //CharacterStartRow = i;
                        //CharacterStartCol = j;
                        character.BackToStart();
                    }
                    left += BLOCK_SIZE;
                    j++;
                }
                left = BOUNDARY_PAD;
                top += BLOCK_SIZE;
                i++;
            }

            // resize Group
            grpMap.Width  = NumCols * BLOCK_SIZE + BOUNDARY_PAD * 2;
            grpMap.Height = NumRows * BLOCK_SIZE + TOP_PAD + BOUNDARY_PAD;
            grpMap.Top    = 5;
            grpMap.Left   = 5;

            // initialize for game
            Game.GetGame().ChangeState(GameState.COIN_HUNT);
        }
Exemple #15
0
        public void Move(MoveDir dir)
        {
            Position newPos = pos;

            switch (dir)
            {
            case MoveDir.UP:
                newPos.row--;
                break;

            case MoveDir.DOWN:
                newPos.row++;
                break;

            case MoveDir.LEFT:
                newPos.col--;
                break;

            case MoveDir.RIGHT:
                newPos.col++;
                break;
            }
            if (map.ChangeLevel(newPos) == 1)//TLF
            {
                Game.GetGame().ChangeState(GameState.CHANGE_LEVEL1);
                return;
            }
            if (map.ChangeLevel(newPos) == 2) // checks if player stepped on level change tile
            {
                Game.GetGame().ChangeState(GameState.CHANGE_LEVEL);
                return;
            }
            if (map.ChangeLevel(newPos) == 3)//quit TLF
            {
                Game.GetGame().ChangeState(GameState.QUIT);
            }
            //Checks to see if the game needs to be saved or loaded if so it does it. TLF
            if (map.Load_SaveGame(newPos) != 0 || Game.GetGame().State == GameState.RESPAWN)
            {
                if (map.Load_SaveGame(newPos) == 1)//This is save
                {
                    var dictionary = new Dictionary <string, float>();
                    dictionary["health"] = Health;
                    dictionary["mana"]   = Mana;
                    dictionary["def"]    = Def;
                    dictionary["str"]    = Str;
                    dictionary["hearts"] = hearts;
                    dictionary["lvl"]    = Level;
                    Write(dictionary, "dictionary.bin");


                    // var dictionary = new Dictionary<string, float>();
                    //                   Dict.dictionary["health"] = Health;
                    //                 Dict.dictionary["mana"] = Mana;
                    //                   Dict.dictionary["def"] = Def;
                    //                 Dict.dictionary["str"] = Str;
                    //               Dict.dictionary["hearts"] = hearts;
                    //GC.SuppressFinalize(Dict.dictionary);//limit Garbage Collection
                    //         Write((Dictionary<string, float>)Dict.dictionary, "C:\\dictionary.bin");
                    //       Dict.dictionary["lvl"] = 1;
                    //Dict.dictionary["lvl"] = this.Level;
                }
                else if (map.Load_SaveGame(newPos) == 2)//This is load
                {
                    var dictionary = Read("dictionary.bin");
                    this.Health = dictionary["health"];
                    this.Mana   = dictionary["mana"];
                    this.Def    = dictionary["def"];
                    this.Str    = dictionary["str"];
                    this.hearts = (int)dictionary["hearts"];
                    this.Level  = (int)dictionary["lvl"];
                    //     string[] allKeys = dictionary.AllKeys;
                    //   foreach (var Key in allKeys)
                    // {
                    //   string str = Convert.ToString(Key)
                    // this.str = dictionary[Key];
                    //     Console.WriteLine(Key);
                    //}
                    // if (Dict.dictionary != null)
                    //{
                    //   Dict.dictionary = Read("C:\\dictionary.bin");
                    // foreach (var pair in Dict.dictionary)
                    //{
                    //  Console.WriteLine(pair);
                    //}
                }
                void Write(Dictionary <string, float> dictionary, string file)
                {
                    using (FileStream fs = File.OpenWrite(file))
                        using (BinaryWriter writer = new BinaryWriter(fs))
                        {
                            // Put count.
                            writer.Write(dictionary.Count);
                            // Write pairs.
                            foreach (var pair in dictionary)
                            {
                                writer.Write(pair.Key);
                                writer.Write(pair.Value);
                            }
                        }
                }

                Dictionary <string, float> Read(string file)
                {
                    var result = new Dictionary <string, float>();

                    using (FileStream fs = File.OpenRead(file))
                        using (BinaryReader reader = new BinaryReader(fs))
                        {
                            // Get count.
                            int count = reader.ReadInt32();
                            // Read in all pairs.
                            for (int i = 0; i < count; i++)
                            {
                                string key   = reader.ReadString();
                                float  value = (float)reader.ReadSingle();
                                result[key] = value;
                            }
                        }
                    return(result);
                }
            }

            if (map.IsValidPos(newPos))
            {
                pos = newPos;
                Position topleft = map.RowColToTopLeft(pos);
                Pic.Left = topleft.col;
                Pic.Top  = topleft.row;
                return;
            }
        }
Exemple #16
0
 public void BackToStart()
 {
     Game.GetGame().ChangeState(GameState.RESPAWN);
     return;
 }
Exemple #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mapFile"></param>
        /// <param name="grpMap"></param>
        /// <param name="LoadImg"></param>
        /// <returns></returns>
        public Character LoadMap(string mapFile, GroupBox grpMap, Func <string, Bitmap> LoadImg)
        {
            //TOD: ZAB
            //clears the map of pictures
            grpMap.Controls.Clear();
            // declare and initialize locals
            int           top       = TOP_PAD;
            int           left      = BOUNDARY_PAD;
            Character     character = null;
            List <string> mapLines  = new List <string>();



            // read from map file
            using (FileStream fs = new FileStream(mapFile, FileMode.Open)) {
                using (StreamReader sr = new StreamReader(fs)) {
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        mapLines.Add(line);
                        line = sr.ReadLine();
                    }
                }
            }

            // load map file into layout and create PictureBox objects
            layout = new int[mapLines.Count, mapLines[0].Length];
            int i = 0;

            foreach (string mapLine in mapLines)
            {
                int j = 0;
                foreach (char c in mapLine)
                {
                    int val = c - '0';
                    layout[i, j] = (val == 1 ? 1 : 0);
                    //this is where it reads what the "vals" on the map to see which pictures to load.
                    PictureBox pb = CreateMapCell(val, LoadImg);
                    if (pb != null)
                    {
                        pb.Top  = top;
                        pb.Left = left;
                        grpMap.Controls.Add(pb);
                    }
                    if (val == 2)
                    {
                        CharacterStartRow = i;
                        CharacterStartCol = j;
                        //TODO : ZAB
                        //just a check probbily not needed
                        if (character == null)
                        {
                            character = new Character(pb, new Position(i, j), new Inventory(0, new List <Weapon>()), this);
                        }
                        else
                        {
                            layout[i, j] = 1;
                        }
                    }
                    //TODO : ZAB
                    //makes the 3(next_level) show up on the layout map along with other numbers
                    if (val == 3)
                    {
                        layout[i, j] = 3;
                    }
                    if (val == 4)
                    {
                        layout[i, j] = 4;
                    }
                    if (val == 5)
                    {
                        layout[i, j] = 5;
                    }
                    left += BLOCK_SIZE;
                    j++;
                }
                left = BOUNDARY_PAD;
                top += BLOCK_SIZE;
                i++;
            }

            // resize Group
            grpMap.Width  = NumCols * BLOCK_SIZE + BOUNDARY_PAD * 2;
            grpMap.Height = NumRows * BLOCK_SIZE + TOP_PAD + BOUNDARY_PAD;
            grpMap.Top    = 5;
            grpMap.Left   = 5;

            // initialize for game
            encounterChance = 0.15;
            rand            = new Random();
            Game.GetGame().ChangeState(GameState.ON_MAP);

            // return Character object from reading map
            return(character);
        }
 public override Position?Enter(Position pos)
 {
     Game.GetGame().SetEnemy(new Enemy(level, loadImg(enemyImage)));
     Game.GetGame().ChangeState(GameState.BOSS_FIGHT);
     return(null);
 }
Exemple #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mapFile"></param>
        /// <param name="grpMap"></param>
        /// <param name="LoadImg"></param>
        /// <returns></returns>
        public Character LoadMap(string mapFile, GroupBox grpMap, Func <string, Bitmap> LoadImg)
        {
            // declare and initialize locals
            int           top       = TOP_PAD;
            int           left      = BOUNDARY_PAD;
            Character     character = null;
            List <string> mapLines  = new List <string>();

            // read from map file
            using (FileStream fs = new FileStream(mapFile, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        mapLines.Add(line);
                        line = sr.ReadLine();
                    }
                }
            }
            // load map file into layout and create PictureBox objects
            layout = new int[mapLines.Count, mapLines[0].Length];
            int i = 0;

            foreach (string mapLine in mapLines)
            {
                int j = 0;
                foreach (char c in mapLine)
                {
                    int val = c - '0';
                    //layout[i, j] = (val == 1 ? 1 : 0);
                    //layout[i, j] = (val == 3 ? 3 : 0);
                    if (val == 1)         // wall
                    {
                        layout[i, j] = 1;
                    }
                    else if (val == 3)    // level 2
                    {
                        layout[i, j] = 3;
                    }
                    else if (val == 6)//Level 1 TLF
                    {
                        layout[i, j] = 6;
                    }
                    else if (val == 5)//quit game TLF
                    {
                        layout[i, j] = 5;
                    }
                    else if (val == 7)//save tile TLF
                    {
                        layout[i, j] = 7;
                    }
                    else if (val == 8)//load TLF
                    {
                        layout[i, j] = 8;
                    }
                    else if (val == 9) // options
                    {
                        layout[i, j] = 9;
                    }
                    else                  // walkable
                    {
                        layout[i, j] = 0;
                    }
                    PictureBox pb = CreateMapCell(val, LoadImg);
                    if (pb != null)
                    {
                        pb.Top  = top;
                        pb.Left = left;
                        grpMap.Controls.Add(pb);
                    }
                    if (val == 2)
                    {
                        CharacterStartRow = i;
                        CharacterStartCol = j;
                        character         = new Character(pb, new Position(i, j), this);
                    }
                    left += BLOCK_SIZE;
                    j++;
                }
                left = BOUNDARY_PAD;
                top += BLOCK_SIZE;
                i++;
            }

            // resize Group
            grpMap.Width  = NumCols * BLOCK_SIZE + BOUNDARY_PAD * 2;
            grpMap.Height = NumRows * BLOCK_SIZE + TOP_PAD + BOUNDARY_PAD;
            grpMap.Top    = 5;
            grpMap.Left   = 5;

            // initialize for game
            encounterChance = 0.15;
            rand            = new Random();
            Game.GetGame().ChangeState(GameState.ON_MAP);

            // return Character object from reading map
            return(character);
        }
Exemple #20
0
        public void SimpleAttack(Mortal receiver, Weapon weapon = null)
        {
            Boolean dodge  = false;
            Random  random = new Random();

            if (receiver is GameLibrary.Character)
            {
                int randomNumber = random.Next(0, 100);
                if (Game.GetGame().Character.ClassType == classSystem.ARCHER)
                {
                    if (Game.GetGame().Character.Luck *3 > randomNumber)
                    {
                        dodge = true;
                    }
                }
                else
                {
                    if (Game.GetGame().Character.Luck > randomNumber)
                    {
                        dodge = true;
                    }
                }
            }

            if (!dodge)
            {
                float baseDamage   = 0;
                float strCoeffient = 1.0f;
                switch (Game.GetGame().Character.ClassType)
                {
                case classSystem.SCRUM:
                    strCoeffient = 1.0f;

                    break;

                case classSystem.WARRIOR:

                    strCoeffient = 2.0f;
                    break;

                case classSystem.MAGICIAN:

                    strCoeffient = 0.7f;
                    break;

                case classSystem.ARCHER:
                    strCoeffient = 1.2f;


                    break;

                default:
                    baseDamage = 0;

                    break;
                }
                baseDamage = Math.Abs(Str * strCoeffient - receiver.Def);

                if (Game.GetGame().Character.ClassType == classSystem.ARCHER)
                {
                    if (Game.GetGame().Character.Luck > random.Next(0, 100))
                    {
                        Console.WriteLine(baseDamage);
                        baseDamage = baseDamage * (100f + 5.0f * Game.GetGame().Character.Luck) / 100.0f;
                        Console.WriteLine(baseDamage);
                    }
                }
                float randMax = 1 + SIMPLEATTACK_RANDOM_AMT;
                float randMin = 1 - SIMPLEATTACK_RANDOM_AMT;
                float randMult;
                if (weapon != null)
                {
                    if (weapon.wID == 3)
                    {
                        randMult = (float)((rand.NextDouble() * (randMax - randMin)) + randMin * (float)weapon.damMod);
                        double chance = rand.NextDouble();
                        if (chance < .15)
                        {
                            randMult *= (float)2.0;
                        }
                    }
                    else
                    {
                        randMult = (float)((rand.NextDouble() * (randMax - randMin)) + randMin * (float)weapon.damMod);
                    }
                }
                else
                {
                    randMult = (float)((rand.NextDouble() * (randMax - randMin)) + randMin);
                }



                if (receiver.Speed > 0)
                {
                }
                receiver.Health -= (baseDamage * randMult);
            }
        }
Exemple #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mapFile"></param>
        /// <param name="grpMap"></param>
        /// <param name="LoadImg"></param>
        /// <returns></returns>
        ///

        public Character LoadMap(string mapFile, GroupBox grpMap, Func <string, Bitmap> LoadImg)
        {
            grpMap.Controls.Clear();
            // declare and initialize locals
            int top  = TOP_PAD;
            int left = BOUNDARY_PAD;

            CurrentMap = mapFile;
            Character     character = null;
            List <string> mapLines  = new List <string>();

            // read from map file
            using (FileStream fs = new FileStream(mapFile, FileMode.Open)) {
                using (StreamReader sr = new StreamReader(fs)) {
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        mapLines.Add(line);
                        line = sr.ReadLine();
                    }
                }
            }

            // load map file into layout and create PictureBox objects
            layout = new int[mapLines.Count, mapLines[0].Length];
            int i = 0;

            foreach (string mapLine in mapLines)
            {
                int j = 0;
                foreach (char c in mapLine)
                {
                    int val = c - '0';
                    layout[i, j] = (val);
                    PictureBox pb = CreateMapCell(val, LoadImg);
                    if (pb != null)
                    {
                        pb.Top  = top;
                        pb.Left = left;
                        grpMap.Controls.Add(pb);
                    }
                    if (val == 2)
                    {
                        CharacterStartRow = i;
                        CharacterStartCol = j;
                        character         = new Character(pb, new Position(i, j), this);
                    }
                    if (val == 3)
                    {
                        CheckX = j;
                        CheckY = i;
                    }
                    left += BLOCK_SIZE;
                    j++;
                }
                left = BOUNDARY_PAD;
                top += BLOCK_SIZE;
                i++;
            }

            // resize Group
            grpMap.Width  = NumCols * BLOCK_SIZE + BOUNDARY_PAD * 2;
            grpMap.Height = NumRows * BLOCK_SIZE + TOP_PAD + BOUNDARY_PAD;
            grpMap.Top    = 5;
            grpMap.Left   = 5;

            // initialize for game
            if (STOP_ENCOUNTER == false)
            {
                encounterChance = 0.15;
            }

            rand = new Random();
            Game.GetGame().ChangeState(GameState.ON_MAP);

            // return Character object from reading map
            return(character);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="mapFile"></param>
        /// <param name="grpMap"></param>
        /// <param name="LoadImg"></param>
        /// <returns></returns>
        public Character LoadMap(List <string> mapFile, GroupBox grpMap, Func <string, Bitmap> LoadImg)
        {
            // declare and initialize locals
            int           top       = TOP_PAD;
            int           left      = BOUNDARY_PAD;
            Character     character = null;
            Item          item      = null;
            List <string> mapLines  = mapFile;

            // read from map file

            /*using (StreamReader sr = new StreamReader(mapFile)) {
             * string line = sr.ReadLine();
             *  while (line != null) {
             *  mapLines.Add(line);
             *  line = sr.ReadLine();
             * }
             * }*/


            // load map file into layout and create PictureBox objects
            layout = new int[mapLines.Count, mapLines[0].Length];
            int i = 0;

            foreach (string mapLine in mapLines)
            {
                int j = 0;
                foreach (char c in mapLine)
                {
                    int val = c - '0';
                    layout[i, j] = val;
                    PictureBox pb = CreateMapCell(val, LoadImg);
                    if (pb != null)
                    {
                        pb.Top  = top;
                        pb.Left = left;
                        grpMap.Controls.Add(pb);
                    }
                    if (val == 2)
                    {
                        CharacterStartRow = i;
                        CharacterStartCol = j;
                        character         = new Character(pb, new Position(i, j), this);
                    }
                    if (val == 6)
                    {
                        ItemSpawnRow = i;
                        ItemSpawnCol = j;
                        item         = new Item(pb, new Position1(i, j), this);
                    }
                    left += BLOCK_SIZE;
                    j++;
                }
                left = BOUNDARY_PAD;
                top += BLOCK_SIZE;
                i++;
            }

            // resize Group
            grpMap.Width  = NumCols * BLOCK_SIZE + BOUNDARY_PAD * 2;
            grpMap.Height = NumRows * BLOCK_SIZE + TOP_PAD + BOUNDARY_PAD;
            grpMap.Top    = 5;
            grpMap.Left   = 5;

            // initialize for game
            encounterChance = 0.15;
            rand            = new Random();
            Game.GetGame().ChangeState(GameState.ON_MAP);

            // return Character object from reading map
            return(character);
        }