program stuck in loops in same part(console applicarion)

Mar 7 2012 11:47 PM
well i dont know its sepose to be a game that you want to attack a monster in simple c# sharp code but it gets stuck in a loop when you go attack a monster and continue attacking it (pressing 1 and enter)
for the job there only a warrior now so sorry

well here it is


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        public class player
        {
            private int errors;
            private int HP, MP, level;
            private string name, job, error;
            private bool alive;
           
            public void cngName(string newname)
            {
                name = newname;
            }
            public void cngJob(string newjob)
            {
                errors = 1;
                job = newjob;
                while (errors == 1)
                {
                    if (job == "warrior" || job == "Warrior")
                    {
                        HP = 130;
                        MP = 100;
                        level = 1;
                        alive = true;
                        errors = 0;
                    }
                    else
                    {
                        Console.WriteLine("error please choose other job now:");
                        job = Console.ReadLine();
                        errors = 1;
                    }
                }
                
            }
            public string getName()
            {
                return name;
            }
            public string getJob()
            {
                return job;
            }
            public int getlvl()
            {
                return level;
            }
            public int gethp()
            {
                return HP;
            }
            public int getmp()
            {
                return MP;
            }
                
        }

        public class Monster
        {
            private int temp;
            private int hp, mp, level;
            private string name;
            private Random rnd = new Random();

            public void cngLevel(int charlevel)
            {
                level = charlevel + rnd.Next(0, 3);
                hp = 100 + (level * 20);
                mp = 100 + (level * 5);
                name = "Ogre";
            }
            public int gethp()
            {
                return hp;
            }
            public int getmp()
            {
                return mp;
            }
            public int getlvl()
            {
                return level;
            }
        }



        static void Main(string[] args)
        {
            int action = 0,escape = 0,faction = 0,exit = 0;
            string name, job;
            Console.WriteLine("Enter your hero name now:");
            name = Console.ReadLine();
            Console.WriteLine("Enter your Job now:");
            job = Console.ReadLine();
            player player1;
            player1 = new player();
            player1.cngName(name);
            player1.cngJob(job);
            Console.Clear();

            Console.WriteLine("so your name is:" + player1.getName() + "");
            Console.WriteLine("and your job is:" + player1.getJob() + "");
            Console.WriteLine();
            do
            {
                Console.Clear();
                Console.WriteLine("so what do you want to do");
                Console.WriteLine("1 = fight a monster          2 = exit");
                action = int.Parse(Console.ReadLine());
                int health, mana, Mhealth, Mmana;
                if (action == 1)
                {
                    Monster Ogre;
                    Ogre = new Monster();
                    health = player1.gethp();
                    mana = player1.getmp();
                    Mhealth = Ogre.gethp();
                    Mmana = Ogre.getmp();
                    do
                    {
                        Ogre.cngLevel(player1.getlvl());
                        Console.WriteLine("A wild Ogre apear");
                        Console.WriteLine("what will you do?");
                        Console.WriteLine("1 = fight               2 = try to run");
                        faction = int.Parse(Console.ReadLine());
                        if (faction == 2)
                        {
                            Random rnd = new Random();
                            if (rnd.Next(0, 11) % 2 == 0)
                            {
                                escape = 1;
                                action = 0;
                            }
                            else
                            {
                                health = Mhealth - Ogre.getlvl();
                                action = 0;
                            }
                        }
                        else if (faction == 1)
                        {
                            Console.WriteLine("You attacked the monster");
                            Console.WriteLine("You did 50 damage");
                            Mhealth = Mhealth - 50;
                            if (Mhealth < 1)
                            {
                                faction = 3;
                                action = 0;
                                escape = 1;
                            }
                        }
                        else if (faction == 3)
                        {
                            escape = 1;
                            action = 0;
                        }
                    } while (health > 1 || Mhealth > 1 || escape == 1);
                }
                else if (action == 2)
                {
                    exit = 1;
                }
            } while (exit != 1);
            System.Environment.Exit(1);
        }
    }
}


Answers (1)