我试图用来setLv1Sunflower()
启动一个新线程,它显示植物在玩家选择的任何地方生长。按下种子按钮后,玩家选择placeHolder*
植物将开始生长的。我对每个工厂位置都有这个,例如placeHolder1(), placeHolder2()
等等。
//PLACE HOLDER ONCLICK SHOWS INFO ON PLANT OR IF WATERMODEON IS TRUE SHOWS FOUND ANIMAL OR NO ANIMAL
public void placeHolder1(View view){
if (waterModeOn == false){
Toast.makeText(getApplicationContext(), placeHolder1ToastMsg, Toast.LENGTH_LONG).show();
}
if (seedModeOn == true){
showSeedMenu();
selectedPlantImage = placeHolder1Image;
selectedPlantToastMsg = placeHolder1ToastMsg;
selectedPlantFoundAnimal = placeHolder1FoundAnimal;
selectedPlantFullyGrown = plant1FullyGrown;
}
else{
showFoundAnimalDialog();
}
}
然后这从他们拍摄的任何植物开始,atm 只有一个设置
//SETS A NEW PLANT TO A PLACE HOLDER
public void showSeedMenu(){
final CharSequence[] items = {"Lv1 SunFlower", "Lv1 Daisy", "Lv1 Violet"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick A Seed");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item == 0){
Lv1Seeds.setLv1Sunflower();
}
seedModeOn = false;
}
});
AlertDialog alert = builder.create();
alert.show();
}
这是Lv1Seeds.class
package com.gameplay.mysticgarden;
import android.app.Activity;
import android.view.View;
//LEVEL 1 SEED VALUES FOR PLACE HOLDERS
public class Lv1Seeds extends Activity {
//INTS FOR LOOPS
final static int a = 1;
final static int b = 2;
//LV1 SUNFLOWER VALUES
public static void setLv1Sunflower(){
GameScreen.selectedPlantFoundAnimal = false;
GameScreen.selectedPlantImage.setImageResource(R.drawable.plant_stage1);
GameScreen.selectedPlantImage.setVisibility(View.VISIBLE);
//FIRST THREAD TO START
/*Runnable runnable = new Runnable() {
@Override
public void run() {*/
//2 LINES OF TEST CODE
new Thread(new Runnable() {
public void run() {
//UDATE UI STAGE 1 OF PLANT AND SETS TOAST MSG WHILE PLANT IS SEEDLING
while (a < b){
//SETS ANIMAL TO GONE FOR WHEN LOOP STARTS AGAIN
GameScreen.selectedPlantFoundAnimal = false;
//IF PLANT IS NOT FULLY GROWN UPDATE UI AND TOAST FOR SEEDLING STAGE
if (GameScreen.selectedPlantFullyGrown == false){
GameScreen.selectedPlantToastMsg = "Lv1 Seedling Sunflower \\(Sunnious Brightium\\) \nWill Attract Bee's!";
}
//WAIT 20 SECONDS
//CHANGE OF VALUES MAKES SEEDLING STAGE LAST LONGER
try {
Thread.sleep(1000 * 10 * 1);
} catch (InterruptedException e) {
e.printStackTrace();
}
//UPDATE UI TO STAGE 2 OF PLANT
GameScreen.selectedPlantImage.post(new Runnable() {
@Override
public void run() {
//IF PLANT IS NOT FULLY GROWN UPDATE UI AND TOAST FOR STAGE 2
if (GameScreen.selectedPlantFullyGrown == false){
GameScreen.selectedPlantImage.setImageResource(R.drawable.plant_stage_2);
GameScreen.selectedPlantToastMsg = "Lv1 Half Grown Sunflower \\Sunnious Brightium\\ \nWill Attract Bee's!";
}
}
});
//WAIT 20 SECONDS
//CHANGE OF VALUE MAKES STAGE 2 LAST LONGER
try {
Thread.sleep(1000 * 10 * 1);
} catch (InterruptedException e) {
e.printStackTrace();
}
//UPDATE UI TO FULLY GROWN PLANT
GameScreen.selectedPlantImage.post(new Runnable() {
@Override
public void run() {
//IF PLANT IS NOT YET FULLY GROWN UPDATE UI AND TOAST FOR FULLY GROWN PLANT AND SETS plantFullyGrown TO TRUE
if (GameScreen.selectedPlantFullyGrown == false){
GameScreen.selectedPlantImage.setImageResource(R.drawable.flower_daisy);
GameScreen.selectedPlantToastMsg = "Lv1 Sunflower \\(Sunnious Brightium\\) \nWill Attract Bee's!";
GameScreen.selectedPlantFullyGrown = true;
}
//USED WHEN PLANT IS FULLY GROWN
else{
GameScreen.selectedPlantToastMsg = "Lv1 Sunflower \\(Sunnious Brightium\\) \nWill Attract Bee's!";
}
}
});
//WAIT 20 SECONDS
//CHANGE OF VALUES MAKE TIME LONGER BEFORE ANIMAL COMES, ONCE PLANT IS FULLY GROWN
try {
Thread.sleep(1000 * 10 * 1);
} catch (InterruptedException e) {
e.printStackTrace();
}
//SETS ANIMAL IN GARDEN
GameScreen.selectedPlantImage.post(new Runnable() {
@Override
public void run() {
GameScreen.selectedPlantFoundAnimal = true;
}
});
//ANIMAL STAYS FOR THIS TIME PERIOD
//CHANGE OF VALUE MAKES ANIMAL STAY LONGER
try {
Thread.sleep(1000 * 10 * 1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
//END OF SUNFLOWER()
}
//END OF CLASS
}
当第二个工厂启动时,setLv1Sunflower()
不会启动此方法的新实例 计划 1 停止做任何事情,第二个工厂只是从第一个工厂在该方法中的位置继续
这是我的问题.....第一个植物应该继续生长,而第二个植物开始新
游戏屏幕的 xml 是
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_sun_1" >
<Button
android:id="@+id/waterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/water_drop" />
<TextView
android:id="@+id/waterPoints"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/waterButton"
android:layout_alignBottom="@+id/waterButton"
android:layout_alignParentLeft="true"
android:layout_marginLeft="176dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="36sp" />
<ImageView
android:id="@+id/placedHolder1Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/placedHolder2Image"
android:background="@drawable/blackspaceflower"
android:onClick="placeHolder1"
android:visibility="invisible" />
<ImageView
android:id="@+id/placedHolder2Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/placedHolder3Image"
android:background="@drawable/blackspaceflower"
android:onClick="placeHolder2"
android:visibility="invisible" />
<ImageView
android:id="@+id/placedHolder3Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/blackspaceflower"
android:onClick="placeHolder3"
android:visibility="invisible" />
<ImageView
android:id="@+id/placedHolder4Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/placedHolder3Image"
android:background="@drawable/blackspaceflower"
android:onClick="placeHolder4"
android:visibility="invisible" />
<ImageView
android:id="@+id/placedHolder5Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/placedHolder4Image"
android:background="@drawable/blackspaceflower"
android:onClick="placeHolder5"
android:visibility="invisible" />
<Button
android:id="@+id/seedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="36dp"
android:layout_marginTop="22dp"
android:onClick="showSelectPlantDialog"
android:text="@string/seeds" />
</RelativeLayout>
我希望有人可以帮助我....您的时间非常感谢