Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace CSHARPMEDIUM
- {
- class Program
- {
- static void Main(string[] args)
- {
- Random r = new Random();
- IItem[] items;
- FieldCreationStrategy[] strategyes = new FieldCreationStrategy[]
- {
- new StrategyOne(),
- new StrategyTwo(),
- new StrategyThree()
- };
- items = strategyes[r.Next(0, strategyes.Length)].CreateField();
- int offsetX = 0;
- while (true)
- {
- Console.Clear();
- foreach (IItem item in items)
- {
- item.Spawn(offsetX);
- }
- System.Threading.Thread.Sleep(1000);
- offsetX++;
- }
- }
- }
- public abstract class FieldCreationStrategy
- {
- public Item[] items = new Item[100];
- public int lastX = 0;
- public int lastY = 0;
- public Random r = new Random();
- public abstract IItem[] CreateField();
- }
- public class StrategyOne : FieldCreationStrategy
- {
- public override IItem[] CreateField()
- {
- for (int i = 0; i < 100; i++)
- {
- lastX += r.Next(1, 5);
- items[i] = new Item(new Vector2(lastX, r.Next(0, 15)), r.Next(1, 10), (Item.Type)r.Next(0, 4));
- }
- return items;
- }
- }
- public class StrategyTwo : FieldCreationStrategy
- {
- public override IItem[] CreateField()
- {
- for (int i = 0; i < 100; i++)
- {
- lastX += 1 + i % 2;
- items[i] = new Item(new Vector2(lastX, r.Next(0, 15)), r.Next(1, 10), (Item.Type)r.Next(0, 4));
- }
- return items;
- }
- }
- public class StrategyThree : FieldCreationStrategy
- {
- public override IItem[] CreateField()
- {
- int yDirection = 1;
- for (int i = 0; i < 100; i++)
- {
- lastX += 1;
- lastY += yDirection;
- if (lastY <= 0)
- {
- yDirection = 1;
- }
- else if (lastY > 15)
- {
- yDirection = -1;
- }
- items[i] = new Item(new Vector2(lastX, lastY), r.Next(1, 10), (Item.Type)r.Next(0, 4));
- }
- return items;
- }
- }
- public interface IItem
- {
- void Spawn(int ofsetX);
- }
- public class Item : IItem
- {
- public Vector2 Position { get; private set; }
- public int Value { get; private set; }
- public Type CurrentType { get; private set; }
- Random r = new Random();
- public Item(Vector2 position, int value, Type currentType)
- {
- Position = position;
- Value = value;
- CurrentType = currentType;
- }
- public void Spawn(int ofsetX)
- {
- if (Position.X - ofsetX > 0 && Position.X - ofsetX < Console.WindowWidth)
- {
- Console.SetCursorPosition(Position.X - ofsetX, Position.Y);
- switch (CurrentType)
- {
- case Item.Type.Gold:
- Console.Write('$');
- break;
- case Item.Type.Silver:
- Console.Write('@');
- break;
- case Item.Type.Health:
- Console.Write('H');
- break;
- case Item.Type.Bomb:
- Console.Write('B');
- break;
- }
- }
- }
- public enum Type
- {
- Gold,
- Silver,
- Health,
- Bomb
- }
- }
- public struct Vector2
- {
- public int X, Y;
- public Vector2(int x, int y)
- {
- X = x;
- Y = y;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement