Now to my question: Will this still count as object oriented if i add a new drawmethod to the ColoredBox and adding two arguments to that draw method? I remember my teacher had tons of complains last time i made a drawmethod too essential
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assignment1._3
{
class Program
{
static void Main(string[] args)
{
int färg = 4;
Random xR = new Random();
for (int i = 0; i < 10; i++)
{
int r1 = xR.Next(39);
int r2 = xR.Next(24);
färg = xR.Next(10);
Point p = new Point(r2, r1, (ConsoleColor)färg + 1);
ColoredBox c1 = new ColoredBox(4, 5, p);
}
//Box b = new Box(r2, r1, p);
Console.ReadKey();
}
}
class Point
{
int x = 0, y = 0;
ConsoleColor color = ConsoleColor.Yellow;
public Point(int x, int y, ConsoleColor color)
{
this.x = x;
this.y = y;
this.color = color;
}
public int X
{
get { return x; }
set { x = value; }
}
public int Y
{
get { return y; }
set { y = value; }
}
public ConsoleColor Color
{
get { return color; }
set { color = value; }
}
public void draw(string utskrift)
{
//Console.SetCursorPosition(width, height);
Console.SetCursorPosition(x, y);
Console.ForegroundColor = color;
Console.Write(utskrift);
}
}
class Box
{
Point topCorner;
int width;
int height;
string utskrift;
public Box()
{
}
public Box(int witdh, int height, Point p)
{
this.width = witdh;
this.height = height;
this.topCorner = p;
draw("*");
}
public int Width
{
get { return width; }
set { width = value; }
}
public int Height
{
get { return height; }
set { height = value; }
}
Point TopCorner
{
get { return topCorner; }
set { topCorner = value; }
}
public string Utskrift
{
get { return utskrift; }
set { utskrift = value; }
}
public void draw(string utskrift)
{
Point drawpoint = new Point(topCorner.X, topCorner.Y, topCorner.Color);
for (int r = 0; r < height; r++)
{
for (int c = 0; c < width; c++)
{
drawpoint.X = topCorner.X + c;
drawpoint.Y = topCorner.Y + r;
drawpoint.draw(utskrift);
}
}
}
}
class ColoredBox : Box
{
TitleBox t1;
public ColoredBox()
{
}
public ColoredBox(int height, int width, Point point)
: base (height, width, point)
{
Background = ConsoleColor.Cyan;
cDraw();
}
public ConsoleColor Background { get; set; }
public void cDraw()
{
Console.BackgroundColor = Background;
draw(" ");
}
}
class TitleBox : ColoredBox
{
string title;
ConsoleColor titlecolor;
public TitleBox(string title, int height, int width, Point point)
:base (height, width, point)
{
}
public string Title { get; set; }
public ConsoleColor Titlecolor { get; set; }
}
}

New Topic/Question
Reply



MultiQuote




|