AionMuster1988 Δημοσ. 11 Δεκεμβρίου 2011 Δημοσ. 11 Δεκεμβρίου 2011 Αν καποιος ξερει απο android-Java ας με κανει PM εχω καποιες αποριες με μια εργασια
AionMuster1988 Δημοσ. 12 Δεκεμβρίου 2011 Μέλος Δημοσ. 12 Δεκεμβρίου 2011 Γιατί δε ρωτάς κατευθείαν εδώ; (το interface αποτελειτε απο 25 κουμπια δηλαδη το παιχνιδι ειναι 5Χ5.)το ροβλημα μου ειναι οτι θελω εναν αλγορηθμο να κατασκευαζει τις ναρκες και εναν να τις βαζει στα κουμπια τυχαία
virxen75 Δημοσ. 12 Δεκεμβρίου 2011 Δημοσ. 12 Δεκεμβρίου 2011 σε java θα έκανα αυτό > JButton[][] button=new JButton[5][5]; for (int i=0;i<5;i++){ button[i]=new JButton[5]; } for (int i=0;i<5;i++){ for(int j=0;j<5;j++){ button[i][j]=new JButton(); } } φτιάxνεις δηλαδή έναν πίνακα 5χ5 κουμπιών(JButton)
gallaki Δημοσ. 12 Δεκεμβρίου 2011 Δημοσ. 12 Δεκεμβρίου 2011 Μπορείς να βάλεις τα κουμπιά σε πίνακα όπως έκανε ο virxen και με μια random να παράγεις τυχαίους αριθμούς (χ,υ) οι οποίοι θα αντιστοιχούν στις νάρκες.
AionMuster1988 Δημοσ. 12 Δεκεμβρίου 2011 Μέλος Δημοσ. 12 Δεκεμβρίου 2011 σε java θα έκανα αυτό > JButton[][] button=new JButton[5][5]; for (int i=0;i<5;i++){ button[i]=new JButton[5]; } for (int i=0;i<5;i++){ for(int j=0;j<5;j++){ button[i][j]=new JButton(); } } φτιάxνεις δηλαδή έναν πίνακα 5χ5 κουμπιών(JButton) ετσι το ηξερα και εγω ομως τα κουμπia που εχω βαλει δεν ειναι σε γραμμες και στειλες .. υπαρχει τροπος να βαλω και τα 25 κουμπια σε πινακα ????? ...αν θελετε να βαλω το intarface να δειτε Μπορείς να βάλεις τα κουμπιά σε πίνακα όπως έκανε ο virxen και με μια random να παράγεις τυχαίους αριθμούς (χ,υ) οι οποίοι θα αντιστοιχούν στις νάρκες. μπορεις να μου γραψεις την random κλαση
moukoublen Δημοσ. 12 Δεκεμβρίου 2011 Δημοσ. 12 Δεκεμβρίου 2011 ετσι το ηξερα και εγω ομως τα κουμπia που εχω βαλει δεν ειναι σε γραμμες και στειλες .. υπαρχει τροπος να βαλω και τα 25 κουμπια σε πινακα ????? ...αν θελετε να βαλω το intarface να δειτε Να τα βάλεις σε πινακα εννοείς στη διεπαφή του προγράμματος ή στον κώδικα;
gallaki Δημοσ. 12 Δεκεμβρίου 2011 Δημοσ. 12 Δεκεμβρίου 2011 Χρειάζεσαι >import java.util.Random; και το χρησιμοποιείς έτσι >int randomInt = randomGenerator.nextInt(100); ή nextFloat κτλπ.... το (100) είναι μεχρι ποιόν αριθμό θέλεις να σου εμφανίσει εναν τυχαίο (στην περίπτωση απο 0 εως 100) αμα βάλεις τα κουμπιά πχ σε εναν πίνακα 5χ5 θα χρειαστείς 2 randomGenerator απο 0 εως 5 και θα σου εμφανίσει τις συντεταγμένες για τις βόμβες.
virxen75 Δημοσ. 12 Δεκεμβρίου 2011 Δημοσ. 12 Δεκεμβρίου 2011 μία απλή προσέγγιση είναι > import javax.swing.*; import java.util.Random; import java.util.ArrayList; public class Test{ private int maxNarkes=5; class JButtonNarki{//βοηθητική κλάση public JButton button; public boolean exeiNarki=false; } public Test(){ JButtonNarki[][] buttons=new JButtonNarki[5][5]; for (int i=0;i<5;i++){ buttons[i]=new JButtonNarki[5]; } int number=1; for (int i=0;i<5;i++){ for(int j=0;j<5;j++){ buttons[i][j]=new JButtonNarki(); buttons[i][j].button=new JButton(""+number++); } } int row=0,column=0,random=0; Random narki=new Random(); for (int i=0;i<maxNarkes;i++){//μέχρι maxNarkes νάρκες random=narki.nextInt(25); row = random / 5; column=random%5; if (buttons[row][column].exeiNarki==false){ buttons[row][column].exeiNarki=true; }else i--; } for (int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(buttons[i][j].exeiNarki) System.out.print("1 "); else System.out.print("0 "); } System.out.println(); } } public static void main(String[]args){ new Test(); } }
AionMuster1988 Δημοσ. 12 Δεκεμβρίου 2011 Μέλος Δημοσ. 12 Δεκεμβρίου 2011 Σας βαζω το interface κια τον source code να δειτε να καταλαβεται untarface: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/btnNew" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Game" android:layout_gravity="center_vertical|center"/> <TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> </LinearLayout> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearLayout4" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> </LinearLayout> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearLayout6" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn14" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> </LinearLayout> </TableRow> <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearLayout8" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn17" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn18" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn19" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn20" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn21" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> </LinearLayout> </TableRow> <TableRow android:id="@+id/tableRow5" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearLayout10" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn22" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn23" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn24" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn25" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> <Button android:id="@+id/btn26" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:width="45px" android:enabled="false"/> </LinearLayout> </TableRow> </TableLayout> </LinearLayout> source code: ackage com.narkaliefths; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class NarkaliefthsActivity extends Activity { private String g_strSymbol="M"; private Button g_btnNew; private Button g_btn2; private Button g_btn3; private Button g_btn4; private Button g_btn5; private Button g_btn6; private Button g_btn7; private Button g_btn8; private Button g_btn9; private Button g_btn10; private Button g_btn11; private Button g_btn12; private Button g_btn13; private Button g_btn14; private Button g_btn15; private Button g_btn16; private Button g_btn17; private Button g_btn18; private Button g_btn19; private Button g_btn20; private Button g_btn21; private Button g_btn22; private Button g_btn23; private Button g_btn24; private Button g_btn25; private Button g_btn26; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); g_btnNew=(Button)findViewById(R.id.btnNew); g_btnNew.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { NewGame(); } } ); g_btn2=(Button)findViewById(R.id.btn2); g_btn2.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn2); } } ); g_btn3=(Button)findViewById(R.id.btn3); g_btn3.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn3); } } ); g_btn4=(Button)findViewById(R.id.btn4); g_btn4.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn4); } } ); g_btn5=(Button)findViewById(R.id.btn5); g_btn5.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn5); } } ); g_btn6=(Button)findViewById(R.id.btn6); g_btn6.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn6); } } ); g_btn7=(Button)findViewById(R.id.btn7); g_btn7.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn7); } } ); g_btn8=(Button)findViewById(R.id.btn8); g_btn8.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn8); } } ); g_btn9=(Button)findViewById(R.id.btn9); g_btn9.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn9); } } ); g_btn10=(Button)findViewById(R.id.btn10); g_btn10.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn10); } } ); g_btn11=(Button)findViewById(R.id.btn11); g_btn11.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn11); } } ); g_btn12=(Button)findViewById(R.id.btn12); g_btn12.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn12); } } ); g_btn13=(Button)findViewById(R.id.btn13); g_btn13.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn13); } } ); g_btn14=(Button)findViewById(R.id.btn14); g_btn14.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn14); } } ); g_btn15=(Button)findViewById(R.id.btn15); g_btn15.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn15); } } ); g_btn16=(Button)findViewById(R.id.btn16); g_btn16.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn16); } } ); g_btn17=(Button)findViewById(R.id.btn17); g_btn17.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn17); } } ); g_btn18=(Button)findViewById(R.id.btn18); g_btn18.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn18); } } ); g_btn19=(Button)findViewById(R.id.btn19); g_btn19.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn19); } } ); g_btn20=(Button)findViewById(R.id.btn20); g_btn20.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn20); } } ); g_btn21=(Button)findViewById(R.id.btn21); g_btn21.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn21); } } ); g_btn22=(Button)findViewById(R.id.btn22); g_btn22.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn22); } } ); g_btn23=(Button)findViewById(R.id.btn23); g_btn23.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { SetSymbol(g_btn23); } } ); g_btn24=(Button)findViewById(R.id.btn24); g_btn24.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { } } ); g_btn25=(Button)findViewById(R.id.btn25); g_btn25.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { } } ); g_btn26=(Button)findViewById(R.id.btn26); g_btn26.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { } } ); } private void SetSymbol(Button a_btn) { a_btn.setText(g_strSymbol); //this.Check(a_btn); a_btn.setEnabled(false); //g_strSymbol=this.GetSymbol(); } // private String GetSymbol() { int i; for (i=0; i<=4; i++) { if(g_strSymbol.equals("M")) { // return "MINE"; } } } private void NewGame() { g_btn2.setEnabled(true); g_btn3.setEnabled(true); g_btn4.setEnabled(true); g_btn5.setEnabled(true); g_btn6.setEnabled(true); g_btn7.setEnabled(true); g_btn8.setEnabled(true); g_btn9.setEnabled(true); g_btn10.setEnabled(true); g_btn11.setEnabled(true); g_btn12.setEnabled(true); g_btn13.setEnabled(true); g_btn14.setEnabled(true); g_btn15.setEnabled(true); g_btn16.setEnabled(true); g_btn17.setEnabled(true); g_btn18.setEnabled(true); g_btn19.setEnabled(true); g_btn20.setEnabled(true); g_btn21.setEnabled(true); g_btn22.setEnabled(true); g_btn23.setEnabled(true); g_btn24.setEnabled(true); g_btn25.setEnabled(true); g_btn26.setEnabled(true); } } αθτο εχω κανει και απο εδω και περα εχω κολισει
gallaki Δημοσ. 12 Δεκεμβρίου 2011 Δημοσ. 12 Δεκεμβρίου 2011 καταρχήν βάζε τους κώδικες σου σε [ c o d e ] [ / c o d e ] δευτερον στο xml κάνεις την ζωή σου δύσκολη χωρίς λόγο.... μπορείς να βάλεις όλα τα κουμπιά σε έναν πίνακα πολύ απλά έτσι > <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/btnNew" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Game" android:layout_gravity="center_vertical|center"/> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" android:layout_below="@id/main_text" android:paddingTop="20dip" android:id="@+id/table" > <TableRow> <Button android:id="@+id/b_1" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_2" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_3" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_4" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/b_5" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> <TableRow> <Button android:id="@+id/b_1" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_2" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_3" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_4" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/b_5" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> <TableRow> <Button android:id="@+id/b_1" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_2" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_3" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_4" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/b_5" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> <TableRow> <Button android:id="@+id/b_1" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_2" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_3" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_4" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/b_5" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> <TableRow> <Button android:id="@+id/b_1" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_2" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_3" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/b_4" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/b_5" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> </TableLayout> </LinearLayout> τα id τα άφησα ίδια γιατί βαριόμουνα να τα αλλάζω. τρίτον αφού τα δηλώνεις όλα τα button απλά μπορείς στην αρχή να παράγεις χ αριθμούς απο το 1 ως ως το 25 τα οποία θα αντιστοιχούν στα κουμπιά που έχουν τις νάρκες και μόλις πατηθεί κάποιο κουμπί θα κάνεις έναν έλεγχο εάν το κουμπί που πατήθηκε αντιστοιχεί σε κάποια νάρκη. επίσης στην newgame δεν θέλεις απλά να κάνει enable τα button. Θέλεις να διαγράφει όλα τα δεδομένα, να κάνει enable τα button να παράγει σε νέες τυχαίες θέσεις τις νάρκες και μετά να ξεκινάει το παιχνίδι. Για τις νάρκες μπορείς μέσα στην setsymbol που έχεις κάνει, μπορείς να την καλείς με έναν αριθμό (τον αριθμό του κάθε κουμπιού) και να κάνεις εκει μέσα τον έλεγχο για το αν είναι νάρκη ή οχι
Directx Δημοσ. 12 Δεκεμβρίου 2011 Δημοσ. 12 Δεκεμβρίου 2011 Στα γρήγορα.. Εγώ θα τοποθετούσα όλα τα πλήκτρα (Button) σε ένα Array ανάλογων διαστάσεων, πχ. Button[][] (με την βοήθεια των getChildCount/getChildAt έκαστου LinearLayout που έχεις ορίσει στο αρχικό σου UI XML, για να μην γράφω συνεχώς τα R.id. τους). Ύστερα με την χρήση της Random class θα αποφάσιζα (πχ. με την βοήθεια της .nextBoolean και ενός loop που θα διέτρεχε τον πίνακα..) σε ποία πλήκτρα θα ανέθετα κάθε νάρκη ορίζοντας το Button.Tag σε true αν το πλήκτρο θα έχει νάρκη ή false αν όχι (πχ. Button.setTag(true/false..) και τέλος θα έκανα σύνδεση των πλήκτρων σε ένα κοινό onClick event το οποίο με βάση το getId του View του θα εμφάνιζε το περιεχόμενο του πλήκτρου που πατήθηκε με βάση το .getTag του. Λύση σκάρτη 80 γραμμές κώδικα (μάλλον).. Καλή συνέχεια!! Υ.Γ. Καθώς πρόκειται για άσκηση, στο πλαίσιο του fairplay δεν θεωρώ σωστό να δώσω κώδικα - και άλλωστε δεν είναι και το ζητούμενο αυτό πέραν κάποιων γενικών hints.
AionMuster1988 Δημοσ. 16 Δεκεμβρίου 2011 Μέλος Δημοσ. 16 Δεκεμβρίου 2011 >public void newgame() { Random l_random=new Random(); g_btna=l_random.nextInt(4); } public void check() { if(((Button)g_btn2.getText()).equals(g_btna)) { this.Show(g_strSymbol); } else if(((Button)g_btn3.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn4.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn5.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn6.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn7.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn8.getText()).equals(g_btna)) { this.Show(g_strSymbol); } else if(((Button)g_btn9.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn10.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn11.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn12.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn13.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn14.getText()).equals(g_btna)) { this.Show(g_strSymbol); } else if(((Button)g_btn15.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn16.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn17.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn18.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn19.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn20.getText()).equals(g_btna)) { this.Show(g_strSymbol); } else if(((Button)g_btn21.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn22.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn23.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn24.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn25.getText()).equals(g_btna)) { this.Show(g_strSymbol); } if(((Button)g_btn26.getText()).equals(g_btna)) { this.Show(g_strSymbol); } } private void Show(String a_strSymbol) {//show message AlertDialog.Builder dlgAlert=new AlertDialog.Builder(this); dlgAlert.setTitle("© 2011 by teiion"); dlgAlert.setMessage("Κέρδισε το"+a_strSymbol); dlgAlert.setPositiveButton("Ok",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { finish(); } }); dlgAlert.setCancelable(true); dlgAlert.create().show(); } } πως γινετε απο την random κλαση "" >g_btna=l_random.nextInt(4); "" το g_btna να ειναι ενα απο τα κουμπια για να μπορω να ελεγχο μεσα στην >public void check() αν εχει ναρκη η οχι Η ολο το απ πανω ειναι λαθος
virxen75 Δημοσ. 16 Δεκεμβρίου 2011 Δημοσ. 16 Δεκεμβρίου 2011 για στείλε μία φωτο από την διεπαφή(κεντρική οθόνη του παιχνιδιού σου) σου να δω πως έχεις τοποθετήσει τα κουμπιά σου. αφού το θες σε ένα πίνακα είναι πιο απλό το παρακάτω: > import java.util.Random; import java.awt.Button; public class Test{ private int maxNarkes=5;//πόσες νάρκες να τοποθετήσει class ButtonNarki{//κλάση που έχει ιδιότητες public Button button;//ένα κουμπί,αυτό που //έχεις στην οθόνη σου public boolean exeiNarki=false;//και μια μεταβλητή που μας // λέει αν το παραπάνω κουμπί έχει νάρκη ή όχι } public Test(){ ButtonNarki[] buttons=new ButtonNarki[25];//ορίζω ένα πίνακα τύπου --> ButtonNarki(κουμπί,έχει νάρκη(true/false) ) for (int i=0;i<25;i++){ buttons[i]=new ButtonNarki();//αρχικοποιώ τα δεδομένα των στοιχείων του πίνακα } Random narki=new Random();//επιλέγω τυχαία ένα νούμερο το οποίο θα δηλώνει την θέση ενός από τα 25 κουμπιά στον πίνακα μου buttons. for (int i=0;i<maxNarkes;i++){ int random=narki.nextInt(25);//βρίσκω τυχαίο νούμερο από 0..24(θέσεις πίνακα) if (buttons[random].exeiNarki==false){//αν δεν έχω τοποθετήσει ξανά νάρκη στο ίδιο κουμπί τότε... buttons[random].exeiNarki=true;//βάζω μία νάρκη! }else//αλλιώς ,το κουμπί έχει ήδη νάρκη i--;//αφαιρώ 1 για να μην μετρήσει η συγκεκριμμένη αποτυχημένη προσπάθεια τοποθέτησης νάρκης. } for (int i=0;i<25;i++){//τυπώνω τα στοιχεία του πίνακα buttons ως προς το αν έχουν νάρκη--->1 ή όχι--->0 if(buttons[i].exeiNarki) System.out.print("1 "); else System.out.print("0 "); } } public static void main(String[]args){ new Test(); } }
AionMuster1988 Δημοσ. 16 Δεκεμβρίου 2011 Μέλος Δημοσ. 16 Δεκεμβρίου 2011 ><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/btnNew" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Game" android:layout_gravity="center_vertical|center"/> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" android:layout_below="@id/main_text" android:paddingTop="20dip" android:id="@+id/table" > <TableRow> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn5" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/btn6" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> <TableRow> <Button android:id="@+id/btn7" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn8" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn9" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn10" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/btn11" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> <TableRow> <Button android:id="@+id/btn12" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn13" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn14" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn15" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/btn16" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> <TableRow> <Button android:id="@+id/btn17" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn18" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn19" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn20" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/btn21" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> <TableRow> <Button android:id="@+id/btn22" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn23" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn24" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:id="@+id/btn25" android:layout_width="wrap_content" android:layout_height="wrap_content" > </Button> <Button android:id="@+id/btn26" android:layout_width="wrap_content" android:layout_height="fill_parent"> </Button> </TableRow> </TableLayout> </LinearLayout> δεν με αφινει να κανω επισυναψη αρχειου ο forum
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα