以下为具体变化:
击鼓传花小游戏:
package DoubleCycleLinkListDem;
import org.w3c.dom.Node;
public class Game {
int num;
int key;
LinkList list = new LinkList();
public Game(int num, int key){
this.num = num;
this.key = key;
}
public void play() throws Exception{
System.out.println("----------------游戏开始之前-----------------");
for(int i=0;i<num;i++){
list.insert(i, i);
}
for(int i=0;i<list.size;i++)
{
System.out.print(list.get(i)+" ");
}
System.out.println("---------------------游戏开始----------------------");
int iCount = num;
int math = 0;
DoubleCycleLinkListDem.Node node = list.head;
while(iCount != 1){
if(node.getElement()!=null&&Integer.parseInt(node.getElement().toString()) != -1){
math++;
if(math%key == 0){
node.setElement(-1);
iCount--;
System.out.println();
for(int i=0;i<list.size;i++){
System.out.print(list.get(i)+" ");
}
}
}
node = node.next;
}
System.out.print("----------游戏结束----------------");
for(int i=0;i<list.size;i++)
{
System.out.print(list.get(i)+" ");
}
}
}