Skip to content

Commit

Permalink
Agregadas Opciones de Visualización
Browse files Browse the repository at this point in the history
  • Loading branch information
ROALOCH committed May 27, 2021
1 parent b6551b8 commit 0ea7660
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 18 deletions.
Binary file modified .vs/ProductorConsumidor/v16/.suo
Binary file not shown.
32 changes: 32 additions & 0 deletions Home.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 85 additions & 18 deletions Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,34 @@ namespace ProductorConsumidor
{
public partial class FORM_Home : Form
{
// Config //

static int containerCapacity = 20;

bool updateNumberOnDequeue = true;
Color emptyCellColor = Color.FromName("Control");
Color occupiedCellColor = Color.FromName("LightSkyBlue");
String directionOfVisualization = "LTR"; // Left To Right (LTR) or Right To Left (RTL)

// Logic //

Queue<int> container = new Queue<int>(20);
Queue<int> container = new Queue<int>(containerCapacity);

int headIndex = -1;
int tailIndex = -1;

int emptyCells = 20;
int emptyCells = containerCapacity;
int occupiedCells = 0;


// UI //

Label[] labelArray;

Color emptyCellColor = Color.FromName("Control");
Color occupiedCellColor = Color.FromName("LightSkyBlue");

public FORM_Home()
{
InitializeComponent();
InitializeLabelArray();

InitializeLabelArray(directionOfVisualization);
}

private void BTN_Start_Click(object sender, EventArgs e)
Expand All @@ -44,17 +49,26 @@ private void BTN_Start_Click(object sender, EventArgs e)

// Logic //

private bool IsEmpty()
{
return (container.Count == 0) ? true : false;
}

private bool IsFull()
{
return (container.Count == containerCapacity) ? true : false;
}

private void Queue()
{
if(container.Count == 20)
if(container.Count == containerCapacity)
{
MessageBox.Show("CONTAINER LLENO");
return;
}

headIndex++;

if(headIndex > 19)
if(headIndex > containerCapacity - 1)
{
headIndex = 0;
}
Expand All @@ -80,11 +94,10 @@ private void Dequeue()
{
if (container.Count == 0)
{
MessageBox.Show("CONTAINER VACIO");
return;
}

if(tailIndex > 19)
if(tailIndex > containerCapacity - 1)
{
tailIndex = 0;
}
Expand All @@ -96,18 +109,40 @@ private void Dequeue()
tailIndex++;

ChangeCellCount(++emptyCells, --occupiedCells);

if (updateNumberOnDequeue)
{
UpdateNumbers();
}
}

// UI //

private void InitializeLabelArray()
private void InitializeLabelArray(String direction)
{
labelArray = new Label[20];
labelArray = new Label[containerCapacity];

if(direction == "LTR")
{
for (int i = 0; i < containerCapacity; i++)
{
Label temp = (Label)Controls.Find($"LBL_{i}", true).First();
temp.Text = (i+1).ToString();
labelArray[i] = temp;
}
}

for(int i = 0; i < 20; i++)
else if(direction == "RTL")
{
Label temp = (Label)Controls.Find($"LBL_{i}", true).First();
labelArray[i] = temp;
int aux = containerCapacity - 1;

for(int i = 0; i < containerCapacity; i++)
{
Label temp = (Label)Controls.Find($"LBL_{aux}", true).First();
temp.Text = (i + 1).ToString();
labelArray[i] = temp;
aux--;
}
}
}

Expand All @@ -116,12 +151,44 @@ private void ChangeCellColor(int index, Color color)
labelArray[index].BackColor = color;
this.Refresh();
}

private void ChangeCellNumber(int index, String number)
{
labelArray[index].Text = number;
this.Refresh();
}
private void ChangeCellCount(int emptyCells, int occupiedCells)
{

LBL_Count.Text = $"Vacios: {emptyCells} Llenos: {occupiedCells}";
this.Refresh();
}
private void UpdateNumbers()
{
int counter = 1;
int index = tailIndex;

while (counter <= containerCapacity)
{
if (index > containerCapacity - 1)
{
index = 0;
}

ChangeCellNumber(index, counter.ToString());

index++;
counter++;
}
}

private void QUE_Click(object sender, EventArgs e)
{
Queue();
}

private void DEQ_Click(object sender, EventArgs e)
{
Dequeue();
}
}
}
Binary file modified bin/Debug/ProductorConsumidor.exe
Binary file not shown.
Binary file modified bin/Debug/ProductorConsumidor.pdb
Binary file not shown.
Binary file modified obj/Debug/ProductorConsumidor.csproj.GenerateResource.cache
Binary file not shown.
Binary file modified obj/Debug/ProductorConsumidor.exe
Binary file not shown.
Binary file modified obj/Debug/ProductorConsumidor.pdb
Binary file not shown.

0 comments on commit 0ea7660

Please sign in to comment.