Пример #1
0
        public void EnemyMoves()
        {
            for (int i = 0; i <= Stages[CurrentStage].Map.GetUpperBound(0); i++)
            {
                for (int j = 0; j <= Stages[CurrentStage].Map.GetUpperBound(1); j++)
                {
                    if (Stages[CurrentStage].Map[i, j] is RockDestroyer)
                    {
                        RockDestroyer r = Stages[CurrentStage].Map[i, j] as RockDestroyer;

                        //als speler binnen de ShootDistance vakken naast destroyer staat gaat destroyer schieten
                        if (r.IsInShootingDistance(Speler))
                        {
                            r.ShootLogic(Speler);
                        }
                        else
                        {
                            r.MoveLogic();
                        }
                    }
                    else if (Stages[CurrentStage].Map[i, j] is Monster)
                    {
                        Monster m = Stages[CurrentStage].Map[i, j] as Monster;
                        m.MoveLogic();
                    }
                }
            }
        }
        public void SpawnMonsters(int nrMonsters)
        {
            // Divide game field in sections based on nrMonsters and place a monster randomly in each section
            int dY = GameWidth / nrMonsters;

            for (int i = 0; i < nrMonsters; i++)
            {
                Monster monster;
                // Pick a type at random
                int type = rand.Next(0, 2);
                if (type == 0)
                {
                    monster = new Monster(Point.RandomPoint(Margin.X + 1, Margin.X + GameWidth * 2 - 1, Margin.Y + 1 + i * dY, Margin.Y + dY - 1 + i * dY), 'M');
                }
                else
                {
                    monster = new RockDestroyer(Point.RandomPoint(Margin.X + 1, Margin.X + GameWidth * 2 - 1, Margin.Y + 1 + i * dY, Margin.Y + dY - 1 + i * dY), 'D');
                }

                for (int r = 0; r < Terrain.Count; r++)
                {
                    if (monster.Location.Equals(Terrain[r].Location))
                    {
                        Terrain.RemoveAt(r);
                        r--;
                    }
                }

                Monsters.Add(monster);
            }
        }
Пример #3
0
        public void GenerateMapElements()
        {
            Random r = new Random();

            for (int i = 0; i < aantalRocks;)
            {
                int x = r.Next(1, 20);
                int y = r.Next(0, 20);

                if (Map[x, y] == null)
                {
                    Map[x, y] = new Rock()
                    {
                        Location = new Point(x, y)
                    };
                    i++;
                }
            }

            for (int i = 0; i < aantalMonsters;)
            {
                int x = r.Next(1, 20);
                int y = r.Next(0, 20);

                if (Map[x, y] == null)
                {
                    Map[x, y] = new Monster()
                    {
                        Location = new Point(x, y)
                    };
                    i++;
                }
            }

            for (int i = 0; i < aantalDestroyers;)
            {
                int x = r.Next(1, 20);
                int y = r.Next(0, 20);

                if (Map[x, y] == null)
                {
                    Map[x, y] = new RockDestroyer()
                    {
                        Location = new Point(x, y)
                    };
                    i++;
                }
            }
        }
 private static void MoveAi()
 {
     for (int i = 0; i < mapElements.Count; i++)
     {
         if (mapElements[i] is Monster)
         {
             Monster monster = (Monster)mapElements[i];
             monster.MoveValidationMonster(playField);
             UpdatePlayField();
         }
         else if (mapElements[i] is RockDestroyer)
         {
             RockDestroyer rockDestroyer = (RockDestroyer)mapElements[i];
             rockDestroyer.MoveValidationMonster(playField);
             UpdatePlayField();
         }
     }
 }
Пример #5
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            const int height = 21;
            const int width  = 21;

            Console.CursorVisible = false;
            Random rng = new Random();

            MapElement[,] field = new MapElement[width, height];

            field[0, height / 2] = new Player('♀');


            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    field[rng.Next(width - 1) + 1, rng.Next(height)] = new Rock('O');
                }

                for (int j = 0; j < 7; j++)
                {
                    field[rng.Next(width - 1) + 1, rng.Next(height)] = new Monster('♠');
                }

                for (int j = 0; j < 5; j++)
                {
                    field[rng.Next(width - 1) + 1, rng.Next(height)] = new RockDestroyer('♣');
                }
            }

            bool win = false;

            while (!win)
            {
                MapElement[,] newField = new MapElement[width, height];
                Teken(width, height, field);
                ConsoleKey input = Console.ReadKey(true).Key;
                int        xplus = 0;
                int        yplus = 0;
                bool       skip  = false;

                switch (input)
                {
                case ConsoleKey.LeftArrow: xplus = -1; break;

                case ConsoleKey.DownArrow: yplus = 1; break;

                case ConsoleKey.RightArrow: xplus = 1; break;

                case ConsoleKey.UpArrow: yplus = -1; break;

                default: skip = true; break;
                }

                if (!skip)
                {
                    for (int row = 0; row < height; row++)
                    {
                        for (int col = 0; col < width; col++)
                        {
                            if (field[col, row] is Player)
                            {
                                int xGoto = col + xplus;
                                int yGoto = row + yplus;
                                xGoto = Clamp(xGoto, 0, width - 1);
                                yGoto = Clamp(yGoto, 0, height - 1);

                                if (xGoto != col || yGoto != row)
                                {
                                    if (field[xGoto, yGoto] == null)
                                    {
                                        newField[xGoto, yGoto] = new Player('♀');
                                        field[col, row]        = null;

                                        if (xGoto == width - 1)
                                        {
                                            win = true;
                                        }
                                    }
                                    else
                                    {
                                        if (field[xGoto, yGoto] is Monster || field[xGoto, yGoto] is Rock)
                                        {
                                            field[xGoto, yGoto] = null;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    for (int row = 0; row < height; row++)
                    {
                        for (int col = 0; col < width; col++)
                        {
                            if (newField[col, row] != null)
                            {
                                field[col, row] = newField[col, row];
                            }
                        }
                    }

                    Teken(width, height, field);
                    newField = new MapElement[width, height];
                    System.Threading.Thread.Sleep(100);
                    for (int row = 0; row < height; row++)
                    {
                        for (int col = 0; col < width; col++)
                        {
                            if (field[col, row] is Monster)
                            {
                                int xMonsterPlus = 0;
                                int yMonsterPlus = 0;

                                switch (rng.Next(4))
                                {
                                case 0: xMonsterPlus = -1; break;

                                case 1: xMonsterPlus = 1; break;

                                case 2: yMonsterPlus = -1; break;

                                case 3: yMonsterPlus = 1; break;
                                }

                                int xGoto = xMonsterPlus + col;
                                int yGoto = yMonsterPlus + row;
                                xGoto = Clamp(xGoto, 0, width - 1);
                                yGoto = Clamp(yGoto, 0, height - 1);

                                if (xGoto != col || yGoto != row)
                                {
                                    if (field[xGoto, yGoto] == null)
                                    {
                                        if (field[col, row] is RockDestroyer)
                                        {
                                            newField[xGoto, yGoto] = new RockDestroyer('♣');
                                        }
                                        else
                                        {
                                            newField[xGoto, yGoto] = new Monster('♠');
                                        }
                                        field[col, row]     = null;
                                        field[xGoto, yGoto] = new Empty();
                                    }
                                    else
                                    {
                                        if (field[xGoto, yGoto] is IDestructableByMonster)
                                        {
                                            field[xGoto, yGoto] = null;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    for (int row = 0; row < height; row++)
                    {
                        for (int col = 0; col < width; col++)
                        {
                            if (newField[col, row] != null)
                            {
                                field[col, row] = newField[col, row];
                            }
                        }
                    }
                }
            }
            Console.Clear();
            Console.WriteLine("Proficiat!");
            Console.ReadLine();
        }
Пример #6
0
        static void Main(string[] args)
        {
            Random r = new Random();

            MapElement[,] Elements = new MapElement[20, 20];
            int Xplayer = 0; int Yplayer = 10;

            Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
            for (int i = 1; i < 20; i++)
            {
                int y = r.Next(0, 19);
                Elements[i, y] = new Rock('O', new Point(i, y));
                y = r.Next(0, 19);
                Elements[i, y] = new Rock('O', new Point(i, y));
                y = r.Next(0, 19);
                Elements[i, y] = new Rock('O', new Point(i, y));
            }
            for (int i = 1; i < 20; i++)
            {
                int y = r.Next(0, 19);
                Elements[i, y] = new Monster('M', new Point(i, y));
            }
            for (int i = 3; i < 20; i = i + 2)
            {
                int y = r.Next(0, 19);
                Elements[i, y] = new RockDestroyer('D', new Point(i, y));
                if (Elements[i - 1, y] is Rock)
                {
                    Elements[i - 1, y] = null;
                }
            }
            while (true)
            {
                Console.Clear();
                Reprint(Elements);
                Console.WriteLine("\nBeweeg met pijlen of schiet met S.");
                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.UpArrow:
                    if (Elements[Xplayer, Yplayer - 1] != null)
                    {
                        Console.WriteLine("You ve hited a {0}; you lost!.", Elements[Xplayer, Yplayer - 1].ToString().Split('.')[1]);
                        Console.ReadLine();
                        Elements[Xplayer, Yplayer] = null;
                        Xplayer = 0; Yplayer = 10;
                        Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                        break;
                    }
                    Elements[Xplayer, Yplayer] = null;
                    Yplayer--;
                    Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                    next(Elements[Xplayer, Yplayer].location, Elements);
                    Console.Clear();
                    Reprint(Elements);
                    break;

                case ConsoleKey.DownArrow:
                    if (Elements[Xplayer, Yplayer + 1] != null)
                    {
                        Console.WriteLine("You ve hited a {0}, you lost!.", Elements[Xplayer, Yplayer + 1].ToString().Split('.')[1]);
                        Console.ReadLine();
                        Elements[Xplayer, Yplayer] = null;
                        Xplayer = 0; Yplayer = 10;
                        Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                        break;
                    }
                    Elements[Xplayer, Yplayer] = null;
                    Yplayer++;
                    Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                    next(Elements[Xplayer, Yplayer].location, Elements);
                    Console.Clear();
                    Reprint(Elements);
                    break;

                case ConsoleKey.LeftArrow:
                    if (Elements[Xplayer - 1, Yplayer] != null)
                    {
                        Console.WriteLine("You ve hited a {0}, you lost!.", Elements[Xplayer - 1, Yplayer].ToString().Split('+')[1]);
                        Console.ReadLine();
                        Elements[Xplayer, Yplayer] = null;
                        Xplayer = 0; Yplayer = 10;
                        Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                        break;
                    }
                    Elements[Xplayer, Yplayer] = null;
                    Xplayer--;
                    Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                    next(Elements[Xplayer, Yplayer].location, Elements);
                    Console.Clear();
                    Reprint(Elements);
                    break;

                case ConsoleKey.RightArrow:
                    if (Xplayer == 18)
                    {
                        Console.WriteLine("You win!!");
                        Console.ReadLine();
                        Elements[Xplayer, Yplayer] = null;
                        Xplayer = 0; Yplayer = 10;
                        Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                        break;
                    }
                    if (Elements[Xplayer + 1, Yplayer] != null)
                    {
                        Console.WriteLine("You ve hited a {0}, you lost!.", Elements[Xplayer + 1, Yplayer].ToString().Split('+')[1]);
                        Console.ReadLine();
                        Elements[Xplayer, Yplayer] = null;
                        Xplayer = 0; Yplayer = 10;
                        Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                        break;
                    }
                    Elements[Xplayer, Yplayer] = null;
                    Xplayer++;
                    Elements[Xplayer, Yplayer] = new Player('X', new Point(Xplayer, Yplayer));
                    next(Elements[Xplayer, Yplayer].location, Elements);
                    Console.Clear();
                    Reprint(Elements);
                    break;

                case ConsoleKey.S:
                    Elements[Xplayer + 1, Yplayer] = null;
                    Console.Clear();
                    Reprint(Elements);
                    break;
                }
            }
        }