Essentially I'm wondering if this implementation of an interface is correct. I mostly don't like having to repeat the exact same getters and setters. Is there a better way or is this alright?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace TetrisPro
{
interface Block
{
Color GetColor();
Position[] GetPosition();
Position GetPosition(int i);
Position[] GetOldPosition();
Position GetOldPosition(int i);
}
class Square : Block
{
private Color color;
private Position[] position;
private Position[] oldPosition;
public Square()
{
this.color = Color.Firebrick;
this.position = new Position[4];
this.oldPosition = new Position[4];
SetPosition();
}
public Square(int x, int y)
{
this.color = Color.GreenYellow;
this.position = new Position[4];
this.oldPosition = new Position[4];
SetPosition();
SetPosition(x, y);
}
public void SetPosition()
{
this.position[0] = new Position(0, 0);
this.position[1] = new Position(0, 1);
this.position[2] = new Position(1, 0);
this.position[3] = new Position(1, 1);
}
public void SetPosition(int x, int y)
{
this.oldPosition = position;
this.position[0] = new Position(x, y);
this.position[1] = new Position(x, y + 1);
this.position[2] = new Position(x + 1, y);
this.position[3] = new Position(x + 1, y + 1);
}
public Color GetColor()
{
return this.color;
}
public Position[] GetPosition()
{
return this.position;
}
public Position GetPosition(int i)
{
return this.position[i];
}
public Position[] GetOldPosition()
{
return this.oldPosition;
}
public Position GetOldPosition(int i)
{
return this.oldPosition[i];
}
}
class Line : Block
{
private Color color;
private Position[] position;
private Position[] oldPosition;
public Line()
{
this.color = Color.BlueViolet;
this.position = new Position[4];
this.oldPosition = new Position[4];
SetPosition();
}
public void SetPosition()
{
this.position[0] = new Position(0, 0);
this.position[1] = new Position(0, 1);
this.position[2] = new Position(0, 2);
this.position[3] = new Position(0, 3);
}
public void SetPosition(int x, int y)
{
this.oldPosition = position;
this.position[0] = new Position(x, y);
this.position[1] = new Position(x, y + 1);
this.position[2] = new Position(x, y + 2);
this.position[3] = new Position(x, y + 3);
}
public Color GetColor()
{
return this.color;
}
public Position[] GetPosition()
{
return this.position;
}
public Position GetPosition(int i)
{
return this.position[i];
}
public Position[] GetOldPosition()
{
return this.oldPosition;
}
public Position GetOldPosition(int i)
{
return this.oldPosition[i];
}
}
class ZLeft : Block
{
private Color color;
private Position[] position;
private Position[] oldPosition;
public ZLeft()
{
this.color = Color.DodgerBlue;
this.position = new Position[4];
this.oldPosition = new Position[4];
SetPosition();
}
public void SetPosition()
{
this.position[0] = new Position(0, 0);
this.position[1] = new Position(1, 0);
this.position[2] = new Position(1, 1);
this.position[3] = new Position(2, 1);
}
public void SetPosition(int x, int y)
{
this.oldPosition = position;
this.position[0] = new Position(x, y);
this.position[1] = new Position(x + 1, y);
this.position[2] = new Position(x + 1, y + 1);
this.position[3] = new Position(x + 2, y + 1);
}
public Color GetColor()
{
return this.color;
}
public Position[] GetPosition()
{
return this.position;
}
public Position GetPosition(int i)
{
return this.position[i];
}
public Position[] GetOldPosition()
{
return this.oldPosition;
}
public Position GetOldPosition(int i)
{
return this.oldPosition[i];
}
}
// ... more classes
}