Well today I got feedback from a #unity #csharp #gamedev job today, "The general feedback from the team is that your code style doesn't look like you are familiar with c#". Harsh but if it's true, It needed to be said. I want to get better. So I'm going to post the question. Then my answer. Then I'm hoping the community can point me in the direction so I can improve and learn.
The question,
Is a screenshot of the PDF that reddit won't currently allow me to upload, so,
question
Here was my answer,
using System; using System.Collections.Generic; namespace SomeCompanyGames_CodeTest { class Program { //Shapes Intersection //An infinite 2D board contains a number of shapes.These shapes are either a Circle or a //Rectangle. Each shape has a unique id. Write a function (see below) that takes a list of Shapes //and returns a dictionary of each shapes id mapped to a list of the shape ids it intersects with. public class Shape { protected int _id; protected string _type; protected byte _typeFlag; //1 = rect 2 = circle protected int _sides; protected float _x, _y, _width, _height, _radius; public virtual int GetID() { return _id; } public virtual int GetSideCount() { return _sides; } public virtual float GetX() { return _x; } public virtual float GetY() { return _y; } public virtual float GetWidth() { return _width; } public virtual float GetHeight() { return _height; } public virtual float GetRadius() { //The area of a circle is pi times the radius squared return _radius; } public virtual void SetRadius(float radius) { _radius = radius; } public virtual string GetTypeStr() { return _type; } public virtual byte GetTypeFlag() { return _typeFlag; } } public class Rectangle : Shape { public Rectangle(int id, float x, float y, float width, float height) { _id = id; _sides = 4; _x = x; _y = y; _width = width; _height = height; _type = "Rectangle"; _typeFlag = 1; } } public class Circle : Shape { //The area of a circle is pi times the radius squared public Circle(int id, float x, float y, float radius) { _id = id; _sides = 1; _x = x; _y = y; _radius = radius; _type = "Circle"; _typeFlag = 2; } } //static public void FindIntersections(List<Shape> shapes) static public Dictionary<int, List<int>> FindIntersections(List<Shape> shapes) { //Objective: Must return dictionary of shapes. // Each shape ID must be mapped to List of shape ID intersected. Dictionary<int, List<int>> collidedShapes = new Dictionary<int, List<int>>(); List<int> collidedId = new List<int>(); //foreach (Shape shape in shapes) //{ // //if(shape.GetX() + shape.GetWidth()) // //if(Collision(shape, shapes.) //} int max = shapes.Count; int id = -1; for(int i = 0; i < max; i++) { for(int j = 0; j < max; j++) { if(Collision(shapes[i], shapes[j])) { Console.WriteLine("\nShapes collision= true!"); collidedId.Add(shapes[j].GetID()); id = i; } } collidedShapes.Add(shapes[id].GetID(), collidedId); collidedId = new List<int>(); //collidedId.Clear(); } //collidedShapes.Add(shapes[id].GetID(), collidedId); return collidedShapes; } //static public bool Collision(Rectangle shape_a, Rectangle shape_b) static public bool Collision(Shape shape_a, Shape shape_b) { byte collisionFlag = 0; //1=rect vs rect 2=circle vs circle 3=opposite shape types byte collisionIncrement = 0; //Decide on what type of collision we should process. #region DetermineCollisionType if (shape_a.GetTypeFlag() == 1 && shape_b.GetTypeFlag() == 1)//shape_b.GetTypeStr() == "Rectangle" { collisionFlag = 1; } if (shape_a.GetTypeFlag() == 2 && shape_b.GetTypeFlag() == 2) { collisionFlag = 2; } if (shape_a.GetTypeFlag() == 1 && shape_b.GetTypeFlag() == 2 || shape_a.GetTypeFlag() == 2 && shape_b.GetTypeFlag() == 1) { collisionFlag = 3; }
No comments:
Post a Comment