<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

//using StopTheBunny.Logos;

namespace StopTheBunny
{
    public class GameEngine
    {
        public const int PointsFromBunny = 1;

        private int gameTime;
        private int bunnyCounter;
        private List<Bunny> bunnies;
        private List<Tower> towers;
        private LogoOfGame logoOfTheGame;
        private Menu menu;
        private Base newBase;
        private Player player;
        private IUserInterface userInterface;

        public GameEngine(IUserInterface keyboard)
        {
            this.bunnies = new List<Bunny>();
            this.towers = new List<Tower>();
            this.logoOfTheGame = new LogoOfGame();
            this.menu = new Menu();
            this.newBase = new Base(new PositionOfElement(7, 61));
            this.player = new Player(new PositionOfElement(0, 0));
            this.userInterface = keyboard;
            this.gameTime = 0;
            this.bunnyCounter = 1;
        }

        public virtual void MovePlayerLeft()
        {
            this.ClearPlayerPosition();
            this.player.MoveLeft();
        }

        public virtual void MovePlayerRight()
        {
            this.ClearPlayerPosition();
            this.player.MoveRight();
        }

        public virtual void MovePlayerUp()
        {
            this.ClearPlayerPosition();
            this.player.MoveUp();
        }

        public virtual void MovePlayerDown()
        {
            this.ClearPlayerPosition();
            this.player.MoveDown();
        }

        public void ClearPlayerPosition()
        {
            Console.SetCursorPosition(this.player.PositionOfElement.PositionCol, this.player.PositionOfElement.PositionRow);
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Write(' ');
        }


        public void AddTower()
        {
            this.towers.Add(new Turret(new PositionOfElement(this.player.PositionOfElement.PositionRow + 1, this.player.PositionOfElement.PositionCol)));
            this.towers.Last().Draw();
        }

        private void HandleBunnies()
        {
            if (this.gameTime % 7 == 0)
            {
                foreach (var bunny in this.bunnies)
                {
                    bunny.ClearPreviousPosition();

                    bunny.Move();
                    bunny.Draw();
                }
            }

            if (this.gameTime % 28 == 0)
            {
                if (this.bunnyCounter % 3 == 0)
                {
                    this.bunnies.Add(new AngryBunny());
                }
                else if (this.bunnyCounter % 5 == 0)
                {
                    this.bunnies.Add(new ZombieBunny());
                }
                else
                {
                    this.bunnies.Add(new CuteBunny());
                }
                bunnyCounter++;
            }            
        }

        private static bool IsInRange(Tower tower, Bunny bunny)
        {
            return ((bunny.PositionOfElement.PositionRow - tower.PositionOfElement.PositionRow + 1) *
                (bunny.PositionOfElement.PositionRow - tower.PositionOfElement.PositionRow + 1)) +
                ((bunny.PositionOfElement.PositionCol - tower.PositionOfElement.PositionCol + 1) *
                (bunny.PositionOfElement.PositionCol - tower.PositionOfElement.PositionCol + 1)) <
                (tower.Range * tower.Range);
        }

        static void CheckForAttackTarget(List<Tower> towers, List<Bunny> bunnies)
        {
            foreach (var tower in towers)
            {
                foreach (var bunny in bunnies)
                {
                    if (IsInRange(tower, bunny))
                    {
                        if (bunny.GetType() is CuteBunny)
                        {
                            bunny.CurrentHealth -= tower.Attack();
                            bunny.BackgroundColor = ConsoleColor.DarkYellow;
                        }                        
                    }
                    else
                    {
                        bunny.BackgroundColor = ConsoleColor.Green;
                    }
                }
            }
        }

        private void RemoveDeadBunnies(List<Bunny> bunnies)
        {
            foreach (var bunny in bunnies)
            {
                if (!bunny.IsAlive)
                {
                    this.player.ScoreOfPlayer.AddPoints(PointsFromBunny);

                    for (int row = bunny.PositionOfElement.PositionRow; row < bunny.PositionOfElement.PositionRow + bunny.ElementImage.GetLength(0); row++)
                    {
                        for (int col = bunny.PositionOfElement.PositionCol; col < bunny.PositionOfElement.PositionCol + bunny.ElementImage.GetLength(1); col++)
                        {
                            Console.SetCursorPosition(col, row);
                            Console.BackgroundColor = ConsoleColor.Green;
                            Console.Write(' ');<commit_msg>Add killing bunnies<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

//using StopTheBunny.Logos;

namespace StopTheBunny
{
    public class GameEngine
    {
        public const int PointsFromBunny = 1;

        private int gameTime;
        private int bunnyCounter;
        private List<Bunny> bunnies;
        private List<Tower> towers;
        private LogoOfGame logoOfTheGame;
        private Menu menu;
        private Base newBase;
        private Player player;
        private IUserInterface userInterface;

        public GameEngine(IUserInterface keyboard)
        {
            this.bunnies = new List<Bunny>();
            this.towers = new List<Tower>();
            this.logoOfTheGame = new LogoOfGame();
            this.menu = new Menu();
            this.newBase = new Base(new PositionOfElement(7, 61));
            this.player = new Player(new PositionOfElement(0, 0));
            this.userInterface = keyboard;
            this.gameTime = 0;
            this.bunnyCounter = 1;
        }

        public virtual void MovePlayerLeft()
        {
            this.ClearPlayerPosition();
            this.player.MoveLeft();
        }

        public virtual void MovePlayerRight()
        {
            this.ClearPlayerPosition();
            this.player.MoveRight();
        }

        public virtual void MovePlayerUp()
        {
            this.ClearPlayerPosition();
            this.player.MoveUp();
        }

        public virtual void MovePlayerDown()
        {
            this.ClearPlayerPosition();
            this.player.MoveDown();
        }

        public void ClearPlayerPosition()
        {
            Console.SetCursorPosition(this.player.PositionOfElement.PositionCol, this.player.PositionOfElement.PositionRow);
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Write(' ');
        }


        public void AddTower()
        {
            this.towers.Add(new Turret(new PositionOfElement(this.player.PositionOfElement.PositionRow + 1, this.player.PositionOfElement.PositionCol)));
            this.towers.Last().Draw();
        }

        private void HandleBunnies()
        {
            if (this.gameTime % 7 == 0)
            {
                foreach (var bunny in this.bunnies)
                {
                    bunny.ClearPreviousPosition();

                    bunny.Move();
                    bunny.Draw();
                }
            }

            if (this.gameTime % 28 == 0)
            {
                if (this.bunnyCounter % 3 == 0)
                {
                    this.bunnies.Add(new AngryBunny());
                }
                else if (this.bunnyCounter % 5 == 0)
                {
                    this.bunnies.Add(new ZombieBunny());
                }
                else
                {
                    this.bunnies.Add(new CuteBunny());
                }
                bunnyCounter++;
            }            
        }

        private static bool IsInRange(Tower tower, Bunny bunny)
        {
            return ((bunny.PositionOfElement.PositionRow - tower.PositionOfElement.PositionRow + 1) *
                (bunny.PositionOfElement.PositionRow - tower.PositionOfElement.PositionRow + 1)) +
                ((bunny.PositionOfElement.PositionCol - tower.PositionOfElement.PositionCol + 1) *
                (bunny.PositionOfElement.PositionCol - tower.PositionOfElement.PositionCol + 1)) <
                (tower.Range * tower.Range);
        }

        static void CheckForAttackTarget(List<Tower> towers, List<Bunny> bunnies)
        {
            foreach (var tower in towers)
            {
                foreach (var bunny in bunnies)
                {
                    if (IsInRange(tower, bunny))
                    {
                        if (bunny.GetType()==typeof(CuteBunny))
                        {
                            bunny.CurrentHealth -= tower.Attack();
                            bunny.BackgroundColor = ConsoleColor.DarkYellow;  
                        }                                              
                    }
                    else
                    {
                        bunny.BackgroundColor = ConsoleColor.Green;
                    }
                }
            }
        }

        private void RemoveDeadBunnies(List<Bunny> bunnies)
        {
            foreach (var bunny in bunnies)
            {
                if (!bunny.IsAlive)
                {
                    this.player.ScoreOfPlayer.AddPoints(PointsFromBunny);

                    for (int row = bunny.PositionOfElement.PositionRow; row < bunny.PositionOfElement.PositionRow + bunny.ElementImage.GetLength(0); row++)
                    {
                        for (int col = bunny.PositionOfElement.PositionCol; col < bunny.PositionOfElement.PositionCol + bunny.ElementImage.GetLength(1); col++)
                        {
                            Console.SetCursorPosition(col, row);
                            Console.BackgroundColor = ConsoleColor.Green;
                            Console.Write(' ');
{'fraction_non_alphanumeric': 0.08656080557707203, 'fraction_numerical': 0.004647560030983733, 'mean_word_length': 1.3395243488108721, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3373421', 'n_tokens_mistral': 2759, 'n_tokens_neox': 2512, 'n_words': 488}