用环境变量来控制。
dimenv 控制,线程ID1,线程ID2
控制=2
do
if 控制=2 then
启动线程 1和2
控制=0
Else If 控制=1 then
启动线程 1
控制=0
end if
loop
//
sub 线程1
打怪
end sub
//
sub 线程2
如果人物死亡,停止线程1,复活,移动到打怪点,控制=1
end sub
//
其实只需要写一个打怪的子程序,用监视死亡的子程序做主程序,就能很方便的控制其它线程了。
公共类MyTest的{
公共静态无效的主要(字符串参数[]){
扫描仪输入=新的Scanner(System.in);
System.out.println(“请输入您的用户名“);
字符串username = input.next();
如果(username.equals(”用户名“)){
System.out.println(”欢迎来到游戏“);
整型数= -1;
做{
System.out.println(“请输入游戏数字”);。
新ThreadController()开始();
数= input.nextInt();
}而(number! = 5);
System.exit(0); }
} }
公共类ThreadController扩展Thread {
公共无效的run(){
为(int i = 0; I < 20,我+ +){
尝试{
视频下载(1000);
}赶上(InterruptedException的E){
e.printStackTrace();
}
系统。通过out.println(“时间到”);
System.exit(0);
}
}