we are working on a school project (a learning game) and atm we are using a class that generate a value from a “Stack”. our problem is that after the values of the stack runs out the game / program crash and stops.
i want to change it to a array with fix values and cells in it that gives me a random value each time that i address it.
right now the code is this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for CellInfoRepository
/// </summary>
public class CellProducer
{
System.Collections.Generic.Stack<Cell> _stack = new Stack<Cell>();
public CellProducer()
{
_stack.Push(new Cell { InstrumentName = "גיטרה", InstrumentFamily = 1, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "עוד", InstrumentFamily = 1, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "סיטאר", InstrumentFamily = 1, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "כינור", InstrumentFamily = 1, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "צ'לו", InstrumentFamily = 1, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "ויולה", InstrumentFamily = 1, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "נבל", InstrumentFamily = 1, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "בנג'ו", InstrumentFamily = 1, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "תופים", InstrumentFamily = 2, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "מצילה", InstrumentFamily = 2, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "שליש", InstrumentFamily = 2, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "קסטנייטה", InstrumentFamily = 2, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "פעמוניה", InstrumentFamily = 2, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "קסילופון", InstrumentFamily = 2, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "טמבורין", InstrumentFamily = 2, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "פעמוני רוח", InstrumentFamily = 2, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "קרן יער", InstrumentFamily = 3, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "בריטון", InstrumentFamily = 3, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "טרומבון", InstrumentFamily = 3, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "טובה", InstrumentFamily = 3, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "סקסופון", InstrumentFamily = 3, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "חליל", InstrumentFamily = 3, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "קלרינט", InstrumentFamily = 3, myPlayer = 0 });
_stack.Push(new Cell { InstrumentName = "משרוקית", InstrumentFamily = 3, myPlayer = 0 });
}
public Cell ProduceNextCell()
{
return _stack.Pop();
}
}
any idea how i keep the name of the class, but only change the inside for a array that generade random values?
btw, the “cell” is another class that we made, and the array should be made from him:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
/// <summary>
/// Summary description for Cells
/// </summary>
public class Cell:Panel //מחלקת משושים
{
protected string _instrumentName; //שם כלי הנגינה //
protected int _insturmentFamily; //סוג כלי הנגינה - המשפחה //
protected int _myPlayer; //ערכים מספריים של 0 - אין שחקן - 1 ו2 לפי השחקנים
public string InstrumentName
{
get
{
return _instrumentName;
}
set
{
_instrumentName = value;
}
}
public int InstrumentFamily
{
get
{
return _insturmentFamily;
}
set
{
_insturmentFamily = value;
}
}
public int myPlayer
{
get
{
return _myPlayer;
}
set
{
_myPlayer = value;
}
}
}
public class CellPosition // מחלקה ששומרת את מיקומי התאים
{
private int _Column;
private int _Row;
public int Column
{
get
{
return _Column;
}
set
{
_Column = value;
}
}
public int Row
{
get
{
return _Row;
}
set
{
_Row = value;
}
}
}
thanks for the help and sorry for all the notes in Hebrew!
I haven’t tested it, but i think it would work: