Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace RMXP.Builtins
- {
- class Table
- {
- private int _xsize;
- private int _ysize;
- private int _zsize;
- private int[] _data;
- public int XSize { get { return _xsize; } }
- public int YSize { get { return _ysize; } }
- public int ZSize { get { return _zsize; } }
- public Table(int xsize, int ysize, int zsize)
- {
- if (xsize < 1 || ysize < 1 || zsize < 1)
- throw (new ArgumentException("Table dimensions cannot be less than 1"));
- else
- {
- _xsize = xsize;
- _ysize = ysize;
- _zsize = zsize;
- _data = new int[xsize * ysize * zsize];
- }
- }
- public Table(int xsize, int ysize) : this(xsize, ysize, 1) { }
- public Table(int xsize) : this(xsize, 1, 1) { }
- public Table() : this(1, 1, 1) { }
- public int GetData(int x, int y, int z)
- {
- return _data[x + y * _xsize + z * _xsize * _ysize];
- }
- public int GetData(int x, int y) { return GetData(x, y, 0); }
- public int GetData(int x) { return GetData(x, 0, 0); }
- public void SetData(int value, int x, int y, int z)
- {
- if (x > _xsize || y > _ysize || z > _zsize)
- throw (new ArgumentException("Index outside bounds of table"));
- else
- _data[x + y * _xsize + z * _xsize * _ysize] = value;
- }
- public void SetData(int value, int x, int y) { SetData(value, x, y, 0); }
- public void SetData(int value, int x) { SetData(value, x, 0, 0); }
- public void Resize(int xsize, int ysize, int zsize)
- {
- if (xsize < 1 || ysize < 1 || zsize < 1)
- throw (new ArgumentException("Table dimensions cannot be less than 1"));
- else
- {
- _xsize = xsize;
- _ysize = ysize;
- _zsize = zsize;
- int[] temp = new int[xsize * ysize * zsize];
- _data.CopyTo(temp, 0);
- _data = temp;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment