xxxxxxxxxx
46
class stack{
constructor(xpos, ypos, width, height, stack_max)
{
this.x = xpos
this.y = ypos
this.w = width
this.h = height
this.max = stack_max
console.log("created stack")
this.items = []
}
draw_empty(){
for (let i = 0; i < this.max; i++){
fill(0, 0, 0, 0)
stroke(255)
rect(this.x, this.y + (this.h * i), this.w, this.h)
}
}
draw_full(){
for (let i = 0; i < this.items.length; i++){
if (i > this.max - 1) fill(255, 0, 0, 127)
else fill(0, 0, 255, 127)
stroke(255)
let y = this.y + (this.h * ((this.max - 1) - i))
rect(this.x, y, this.w, this.h)
textSize(25);
textAlign(CENTER);
text(`${this.items[i].name}:\t\t${this.items[i].value}`,
this.x + this.w/2, y + this.h / 2 + 10)
}
}
draw(){
this.draw_empty()
this.draw_full()
}
push(item_name, value){
this.items.push({name: item_name, value: value})
console.log(`pushed item \{${item_name}, ${value}\}`)
console.log(`${this.items.length}`)
}
}