Beispiel #1
0
        static void Main(string[] args)
        {
            var hum = new Person();

            hum.Do();
            hum.Think();
            hum.Move();
        }
Beispiel #2
0
        public bool Play()         // play the game
        {
            bool valid = false;    //check validty of inputs
            bool moved = false;    //check if moved. Print only when moved

            minefield.DrawLevel(); //first instance of minefield
            //Continue game as long as player still has life or has not reached exit
            while (player.GetLife() > 0 && minefield.GetSpace(minefield.GetSize() - 1, minefield.GetSize() - 1) != 1)
            {
                Console.Write("Make your move: ");
                valid = GetValidInput(Console.ReadLine(), out input);
                if (valid == false)
                {
                    break;
                }
                else
                {
                    moved = player.Move(input, minefield);
                    //print current state of minefield only if player was able to move
                    if (moved)
                    {
                        steps++;
                        if (StepOnMine(player.GetX(), player.GetY(), minefield.GetMines()))
                        {
                            player.TakeDamage();
                            if (player.GetLife() < 1)
                            {
                                return(false); //died
                            }
                        }
                        else if (player.GetX() == minefield.GetSize() - 1 && player.GetY() == minefield.GetSize() - 1)
                        {
                            return(true);
                        }
                        else
                        {
                            minefield.DrawLevel();
                        }
                    }
                }
            }
            //below if condition is failsafe incase Play() does not work as intended
            if (player.GetLife() > 0)
            {
                return(true); //success!
            }
            else
            {
                return(false); //died :(
            }
        }