Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Security.Cryptography.X509Certificates;
- namespace _12_het
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.Write("m = ");
- int m = int.Parse(Console.ReadLine());
- Console.Write("b = ");
- int b = int.Parse(Console.ReadLine());
- //Field mezo = new Field(m);
- //Buffalo boleny = new Buffalo(0,0);
- ////Console.WriteLine($"CÊl: ({mezo.TargetX},{mezo.TargetY})");
- ////int tempx = 3;
- ////int tempy = 6;
- ////Console.WriteLine($"Megengedett -e: {mezo.AllowedPosition(tempx,tempy)}");
- //mezo.Show();
- //boleny.Show();
- Game jatek = new Game(m, b);
- jatek.Run();
- }
- }
- }
- ---------------------------------------------------------------------------------------------
- namespace _12_het
- {
- internal class Field
- {
- int[,] jatekter;
- public Field(int m)
- {
- jatekter = new int[m, m];
- }
- public int TargetX()
- {
- return jatekter.GetLength(0) - 1;
- }
- public int TargetY()
- {
- return jatekter.GetLength(1) - 1;
- }
- public bool AllowedPosition(int x, int y)
- {
- return x <= TargetX() && y <= TargetY() && x >= 0 && y >= 0;
- }
- public void Show()
- {
- for (int i = 0; i < jatekter.GetLength(0); i++)
- {
- for (int j = 0; j < jatekter.GetLength(1); j++)
- {
- if (i == 0 || i == jatekter.GetLength(0) - 1)
- {
- Console.Write("-");
- }
- else
- {
- if (j == 0 || j == jatekter.GetLength(1) - 1)
- {
- Console.Write("|");
- }
- else
- {
- Console.Write(" ");
- }
- }
- }
- Console.WriteLine();
- }
- }
- }
- }
- ---------------------------------------------------------------------------------------------
- namespace _12_het
- {
- internal class Buffalo
- {
- int aktualisBolenyX;
- int aktualisBolenyY;
- bool allapot;
- public Buffalo(int aktualisBolenyX, int aktualisBolenyY)
- {
- this.aktualisBolenyX = 0;
- this.aktualisBolenyY = 0;
- allapot = true;
- }
- public int X()
- {
- return aktualisBolenyX;
- }
- public int Y()
- {
- return aktualisBolenyY;
- }
- public void Move(Field jatekter)
- {
- Random rnd = new Random();
- int lepsek = rnd.Next(3);
- if (lepsek == 0)
- {
- if (jatekter.AllowedPosition(aktualisBolenyX + 1, aktualisBolenyY) == true)
- {
- this.aktualisBolenyX += 1;
- }
- }
- if (lepsek == 1)
- {
- if (jatekter.AllowedPosition(aktualisBolenyX, aktualisBolenyY + 1) == true)
- {
- this.aktualisBolenyY += 1;
- }
- }
- if (lepsek == 1)
- {
- if (jatekter.AllowedPosition(aktualisBolenyX + 1, aktualisBolenyY + 1) == true)
- {
- this.aktualisBolenyX += 1;
- this.aktualisBolenyY += 1;
- }
- }
- }
- public void Deactivate()
- {
- allapot = false;
- }
- public void Show()
- {
- if (allapot == true)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- }
- Console.SetCursorPosition(aktualisBolenyX, aktualisBolenyY);
- Console.WriteLine("B");
- Console.ResetColor();
- }
- }
- }
- ---------------------------------------------------------------------------------------------
- using System.Security.Cryptography.X509Certificates;
- namespace _12_het
- {
- internal class Game
- {
- Field jatekter;
- List<Buffalo> bolenyek;
- public bool IsOver { get; private set; }
- public Game(int jatekmeret, int bolenyCount)
- {
- jatekter = new Field(jatekmeret);
- bolenyek = new List<Buffalo>();
- for (int i = 0; i < bolenyCount; i++)
- {
- bolenyek.Add(new Buffalo(0, 0));
- }
- IsOver = false;
- }
- private void VisualizeElements()
- {
- Console.Clear();
- jatekter.Show();
- for (int i = 0; i < bolenyek.Count; i++)
- {
- bolenyek[i].Show();
- }
- }
- private void Shoot(int x, int y)
- {
- for (int i = 0; i < bolenyek.Count; i++)
- {
- if (x == bolenyek[i].X() && y == bolenyek[i].Y())
- {
- bolenyek[i].Deactivate();
- }
- }
- }
- public void Run()
- {
- while (!IsOver)
- {
- VisualizeElements();
- Console.SetCursorPosition(0,jatekter.TargetY()+2);
- Console.Write("x = ");
- int x = int.Parse(Console.ReadLine());
- Console.Write("\ny = ");
- int y = int.Parse(Console.ReadLine());
- Shoot(x, y);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement