我正在編寫一個名爲Flipper的程序,其中有3x3個單元格用於拼圖。每個單元格(按鈕)在初始時都具有綠色。當點擊某個單元格時,該單元格及其相鄰單元格會翻轉(更改顏色)。另一個要求是撤消功能,這是回到前一階段。我不知道如何實現這一點。這些是遊戲中發生的主要事情。如何實現撤銷功能
public Puzzle(Form1 form1)
{
buttons = new Button[3, 3] { { form1.button1, form1.button2, form1.button3 },
{ form1.button4, form1.button5, form1.button6 },
{ form1.button7, form1.button8, form1.button9 } };
//button reference from form1
}
public void reset()
{
//reset all the colors of buttons in the puzzle to lime
}
public void FlipCells(int row, int col)
{
//when certain button is clicked(this event is done in the form1.cs), say for (0,0) change color of cell (0,0),///(0,1) and (1,0) by calling changeColor method
}
public void changeColor(int row, int col)
{
//test current color of the cell, and change it
}
我要求在一個名爲撤消的類中實現撤消功能。任何想法是讚賞!