Esempio n. 1
0
        internal void Move(Map game)
        {
            game.FindMonster();
            game.FindPlayer();
            targetX = game.playerLocation[1];
            targetY = game.playerLocation[0];
            monsterX = game.monsterLocation[1];
            monsterY = game.monsterLocation[0];
            bool monxBigger;
            bool monyBigger;

            if (monsterX > targetX) { xDiff = monsterX - targetX; monxBigger = true; }
            else { xDiff = targetX - monsterX; monxBigger = false; }
            if (monsterY > targetY) { yDiff = monsterY - targetY; monyBigger = true; }
            else { yDiff = targetY - monsterY; monyBigger = false; }

            if (xDiff > yDiff)
            {
                if(monxBigger == true) { game.MoveMonster(monsterY, monsterX - 1); }
                else { game.MoveMonster(monsterY, monsterX + 1); }
            }
            else
            {
                if(monyBigger == true) { game.MoveMonster(monsterY - 1, monsterX); }
                else { game.MoveMonster(monsterY + 1, monsterX); }
            }
        }
Esempio n. 2
0
 static void Main(string[] args)
 {
     Map game1 = new Map();
     game1.CreateGame();
     game1.PrintMap();
     game1.StartGame();  
 }
Esempio n. 3
0
 internal int[] FindMonster(Map game)
 {
     for (int i = 0; i < game.mapY; i++)
     {
         for (int j = 0; j < game.mapX; j++)
         {
             if (game.map[i, j] == 'm')
             {
                 monsterLocation[0] = i;
                 monsterLocation[1] = j;
             }
         }
     }
     return monsterLocation;
 }
Esempio n. 4
0
 internal int[] FindPlayer(Map game)
 {
     for(int i = 0; i < game.mapY; i++)
     {
         for (int j = 0; j < game.mapX; j++)
         {
             if (game.map[i,j] == '@')
             {
                 playerLocation[0] = i;
                 playerLocation[1] = j;
             }
         }
     }
     return playerLocation;
 }
Esempio n. 5
0
        internal void Move(Map game)
        {
                while ((command = Console.ReadKey(true)).Key != ConsoleKey.Escape && game.gameOn == true)
                {
                    game.PrintMap();
                    Console.WriteLine("Press escape to exit.");
                    Console.WriteLine("Map size: " + game.mapSize);
                    game.FindPlayer();
                    x = game.playerLocation[1];
                    y = game.playerLocation[0];
                    game.morko.Move(game);
                    switch (command.Key)
                    {
                        case ConsoleKey.LeftArrow:
                            if (y > 1)
                            {
                                y--;
                                game.MovePlayer(x, y);
                            }
                            break;

                        case ConsoleKey.UpArrow:
                            if (x > 1)
                            {
                                x--;
                                game.MovePlayer(x, y);
                            }
                            break;

                        case ConsoleKey.RightArrow:
                            if (y < game.mapY - 2)
                            {
                                y++;
                                game.MovePlayer(x, y);
                            }
                            break;

                        case ConsoleKey.DownArrow:
                            if (x < game.mapX - 2)
                            {
                                x++;
                                game.MovePlayer(x, y);
                            }
                            break;




                    }
                game.FindMonster();
                game.FindPlayer();

                if (game.monsterLocation[1] == game.playerLocation[1])
                {
                    if(game.monsterLocation[0] - game.playerLocation[0] < 2 && game.monsterLocation[0] - game.playerLocation[0] > -1) { game.gameOn = false; game.gameOver = true; }
                    else if(game.playerLocation[0] - game.monsterLocation[0] < 2 && game.playerLocation[0] - game.monsterLocation[0] > -1) { game.gameOn = false; game.gameOver = true; }
                }
                
                else if(game.monsterLocation[0] == game.playerLocation[0])
                {
                    if (game.monsterLocation[1] - game.playerLocation[1] < 2 && game.monsterLocation[1] - game.playerLocation[1] > -1) { game.gameOn = false; game.gameOver = true; }
                    else if (game.playerLocation[1] - game.monsterLocation[1] < 2 && game.playerLocation[1] - game.monsterLocation[1] > -1) { game.gameOn = false; game.gameOver = true; }
                }  
                }             
            
        }
Esempio n. 6
0
 private void MapSize(Map game)
 {
     mapSize = game.mapX * game.mapY;
 }