Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

I got a problem in making the cards game...

  Asked By: Oscar    Date: Jul 12    Category: Java    Views: 466
  

this is the code I've made for shuffling the 52 cards
of the deck..... can u help me? the cards after being distributed
are not in ascending order always, and yes, could u find me a game of
cards to be played on java console??? I got this project and I'm
quite helpless..... I'd be grateful if any one would be kind enough
to help me.....

here's the coding that I've made for shuffling cards each time the
game begins.....

import java.io.*;
import java.util.Random;
import mytree;

class task2{

public static void main(String args[]) throws java.io.IOException {

int i = 0;
int a = 0;
int counter = 0;
int totalcards[] = new int[52];
int shuffledcards[] = new int[52];
WordTree computer = new WordTree();
WordTree user = new WordTree();


for(i=0;i<52;i++){
totalcards[i] = i+1;
}

for(i=0;i<52;i++){
System.out.print(totalcards[i]+ " ");
}

System.out.println();
System.out.println();



a = ((int) (Math.random() * 100));

System.out.print(a);
System.out.println();

if(a>90){
a = a-48;
}
else if(a>80){
a = a-38;
}
else if(a>70){
a = a-28;
}
else if(a>60){
a = a-18;
}
else if(a>53){
a = a-7;
}


System.out.print(a);

while(true){

a = ((int) (Math.random() * 100));

if(a>90){
a = a-48;
}
else if(a>80){
a = a-38;
}
else if(a>70){
a = a-28;
}
else if(a>60){
a = a-18;
}
else if(a>52){
a = a-8;
}
else if(a==0){
a = a+1;
}

System.out.println(a);

for(i=0;i<52;i++){

if(shuffledcards[i] == a){
//a=-1
break;
}

if(shuffledcards[i] == 0){
counter=-2;
System.out.println("reached");
break;
}

}//for

if(counter == -2){
shuffledcards[i] = a;
//counter = read.GetInt();
counter = 0;
}


for(i=0;i<52;i++){
System.out.print(shuffledcards[i] + " ");
if(i==51)
System.out.println();
}

if(shuffledcards[51] != 0)
break;

}//outer while

System.out.println();
System.out.println();

a=0;
int b = 0;
for(i=0;i<52;i++){
b = i+1;
System.out.print(b + " ");
a = a + b;

}
System.out.println();
System.out.print(a);

a=0;

for(i=0;i<52;i++){
b = shuffledcards[i];
a = a + b;
}
System.out.println(a);

System.out.println("Computer");

for(i=0;i<7;i++){
computer.add(String.valueOf(shuffledcards[i]));
}

computer.display();

System.out.println("User");

for(i=7;i<14;i++){
user.add(String.valueOf(shuffledcards[i]));
}

user.display();


}}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on I got a problem in making the cards game... Or get search suggestion and latest updates.




Tagged: