Help Need A Logic For Java

  • Work-from-home

Mahen

Alhamdulillah
VIP
Jun 9, 2012
21,845
16,877
1,313
laнore
@Don ap ye check kr lo iss sy agy mujy nhi samj aa rha :s

bool IsTurmTobeSuspend = false;

if((diceOneHas ==1) && (diceTwoHas ==1)) // check whether both dices has 1 on them?
{
bool IsTurmTobeSuspend = true;
}
else
{
bool IsTurmTobeSuspend = false;
}

if(
IsTurmTobeSuspend)
{
give turn to player, other wise, exit
}
else
{
return;
}


jub b dice roll kye jaen ge, sub se pehle I
sTurmTobeSuspend ko true ya false karaya jaye ga,


then dekha jaye ga k kya I
sTurmTobeSuspend true hai, agar true hai tou phir turn nae di jaye gi.



if(IsTurmTobeSuspend)
{
return; // terminate current turn }
else
{
 

Don

Administrator
Mar 15, 2007
11,035
14,651
1,313
Toronto, Ca
@Don ap ye check kr lo iss sy agy mujy nhi samj aa rha :s

bool IsTurmTobeSuspend = false;

if((diceOneHas ==1) && (diceTwoHas ==1)) // check whether both dices has 1 on them?
{
bool IsTurmTobeSuspend = true;
}
else
{
bool IsTurmTobeSuspend = false;
}

if(IsTurmTobeSuspend)
{
give turn to player, other wise, exit
}
else
{
return;
}


jub b dice roll kye jaen ge, sub se pehle IsTurmTobeSuspend ko true ya false karaya jaye ga,


then dekha jaye ga k kya IsTurmTobeSuspend true hai, agar true hai tou phir turn nae di jaye gi.



if(IsTurmTobeSuspend)
{ return; // terminate current turn }
else
{
Mahiya ap ki logic theek hai.. laykin ap ek baat bhol rahi hain k player1 and player2 ek hi loop k ander hain or loop tab break hoga jab kissi ek ka total 75 say bara hoga...

anyways, next day fresh mind k sath jaab may betha to do min may solve ho gaya tha... If you are interested I can tell you.. but pehle look at this for better understanding..

Code:
boolean skip = false ;
do {
if (dice1 == 1 && dice2 == 1 || dice1 == 6 && dice2 == 6)
    {
// roll the dice
//calculate the total from both dice
skip = true ; }
else
  { 
\\ roll the dice
// calculate the total from both dice
}
 
// player 2
if (dice1 == 1 && dice2 == 1 || dice1 == 6 && dice2 == 6)
    {
// roll the dice
//calculate the total from both dice
skip = true ; }
else
  { 
\\ roll the dice
// calculate the total from both dice
}
}
} while (totalPlayer1 < 75 && totalPlayer2 < 75);
 
  • Like
Reactions: Star24 and Mahen

Mahen

Alhamdulillah
VIP
Jun 9, 2012
21,845
16,877
1,313
laнore
Mahiya ap ki logic theek hai.. laykin ap ek baat bhol rahi hain k player1 and player2 ek hi loop k ander hain or loop tab break hoga jab kissi ek ka total 75 say bara hoga...

anyways, next day fresh mind k sath jaab may betha to do min may solve ho gaya tha... If you are interested I can tell you.. but pehle look at this for better understanding..

Code:
boolean skip = false ;
do {
if (dice1 == 1 && dice2 == 1 || dice1 == 6 && dice2 == 6)
    {
// roll the dice
//calculate the total from both dice
skip = true ; }
else
  {
\\ roll the dice
// calculate the total from both dice
}
 
// player 2
if (dice1 == 1 && dice2 == 1 || dice1 == 6 && dice2 == 6)
    {
// roll the dice
//calculate the total from both dice
skip = true ; }
else
  {
\\ roll the dice
// calculate the total from both dice
}
}
} while (totalPlayer1 < 75 && totalPlayer2 < 75);
ohh mi tou true false mi hi ulji rhi {(doh)} wrna loop tou many bhi wohi use ki jo ap ny ki hai hmm thori c mujy miss understanding ho gie {)^})
Well ab ho gya ap ka kam ?
 

Don

Administrator
Mar 15, 2007
11,035
14,651
1,313
Toronto, Ca
ohh mi tou true false mi hi ulji rhi {(doh)} wrna loop tou many bhi wohi use ki jo ap ny ki hai hmm thori c mujy miss understanding ho gie {)^})
Well ab ho gya ap ka kam ?
kaam to ho gaya but mere khayal say ap ko yeh complete karna chaiye :) for your practice :)
its very easy
 
  • Like
Reactions: Mahen

Don

Administrator
Mar 15, 2007
11,035
14,651
1,313
Toronto, Ca
yes wohi dye do ap :)
Code:
import java.util.*;
   
public class DICEGAME {
 
 
    public static void main(String[] args) {
 
        // Generating Random number below
        Random generator = new Random();
        // Group Members
        int dice1;
        int dice2;
        int total1 = 0;
        int total2 = 0;
       
        do {
            // Player1
                // Rolling dice
            dice1 = generator.nextInt (6) + 1;
            dice2 = generator.nextInt (6) + 1;
            // Checking for snake eye and Box cars
            if (dice1 ==1 && dice2 == 1 || dice1 == 6 && dice2 == 6)
            {
                System.out.println("Player 1 Losses a turn");
            }else {
            System.out.println ("Player 1 rolls a " + dice1 + " and a " + dice2 + " .");
            total1 = total1 + dice1 + dice2 ;
            System.out.println ("Player 1 now has " + total1);
            } // else ends here
           
            // Verifying if player1 still did not cross 75
            if (total1 <= 75){
            //Player2
                // Rolling Dice
            dice1 = generator.nextInt (6) + 1;
            dice2 = generator.nextInt (6) + 1;
                // Checking for snake eye and Box cars
            if (dice1 ==1 && dice2 == 1 || dice1 == 6 && dice2 == 6){
                System.out.println("Player 2 Losses a turn");
            }else {
            System.out.println ("Player 2 rolls a " + dice1 + " and a " + dice2 + " .");
            total2 = total2 + dice1 + dice2 ;
            System.out.println ("Player 2 now has " + total2);
            } // else ends here
            }
        } while (total1 < 75 && total2 < 75);
       
        // Announcing a winner
        if (total1 >= 75){
            System.out.println("Player 1 wins witht the total of " + total1);
        } else{
            System.out.println("Player 2 wins witht the total of " + total2);
        }
 
    }
 
}
Remember: 1 ya 6 ane k baad total count hoga but next sirf ek turn loose hogi.. same player ki
 
  • Like
Reactions: Star24 and Mahen

Mahen

Alhamdulillah
VIP
Jun 9, 2012
21,845
16,877
1,313
laнore
Code:
import java.util.*;
 
public class DICEGAME {
 
 
    public static void main(String[] args) {
 
        // Generating Random number below
        Random generator = new Random();
        // Group Members
        int dice1;
        int dice2;
        int total1 = 0;
        int total2 = 0;
     
        do {
            // Player1
                // Rolling dice
            dice1 = generator.nextInt (6) + 1;
            dice2 = generator.nextInt (6) + 1;
            // Checking for snake eye and Box cars
            if (dice1 ==1 && dice2 == 1 || dice1 == 6 && dice2 == 6)
            {
                System.out.println("Player 1 Losses a turn");
            }else {
            System.out.println ("Player 1 rolls a " + dice1 + " and a " + dice2 + " .");
            total1 = total1 + dice1 + dice2 ;
            System.out.println ("Player 1 now has " + total1);
            } // else ends here
         
            // Verifying if player1 still did not cross 75
            if (total1 <= 75){
            //Player2
                // Rolling Dice
            dice1 = generator.nextInt (6) + 1;
            dice2 = generator.nextInt (6) + 1;
                // Checking for snake eye and Box cars
            if (dice1 ==1 && dice2 == 1 || dice1 == 6 && dice2 == 6){
                System.out.println("Player 2 Losses a turn");
            }else {
            System.out.println ("Player 2 rolls a " + dice1 + " and a " + dice2 + " .");
            total2 = total2 + dice1 + dice2 ;
            System.out.println ("Player 2 now has " + total2);
            } // else ends here
            }
        } while (total1 < 75 && total2 < 75);
     
        // Announcing a winner
        if (total1 >= 75){
            System.out.println("Player 1 wins witht the total of " + total1);
        } else{
            System.out.println("Player 2 wins witht the total of " + total2);
        }
 
    }
 
}
Remember: 1 ya 6 ane k baad total count hoga but next sirf ek turn loose hogi.. same player ki
thanks {}{43r5 hmm ho gya clear :) bs kuch baty mind mi nhi aa rhi ti ab clear ho gie hai :)
wasie bhi programming mai basic things clear ho jaye tou next zadha problem nhi hoti :)
 

zehar

VIP
Apr 29, 2012
26,600
16,302
1,313
Code:
import java.util.*;
 
public class DICEGAME {
 
 
    public static void main(String[] args) {
 
        // Generating Random number below
        Random generator = new Random();
        // Group Members
        int dice1;
        int dice2;
        int total1 = 0;
        int total2 = 0;
     
        do {
            // Player1
                // Rolling dice
            dice1 = generator.nextInt (6) + 1;
            dice2 = generator.nextInt (6) + 1;
            // Checking for snake eye and Box cars
            if (dice1 ==1 && dice2 == 1 || dice1 == 6 && dice2 == 6)
            {
                System.out.println("Player 1 Losses a turn");
            }else {
            System.out.println ("Player 1 rolls a " + dice1 + " and a " + dice2 + " .");
            total1 = total1 + dice1 + dice2 ;
            System.out.println ("Player 1 now has " + total1);
            } // else ends here
         
            // Verifying if player1 still did not cross 75
            if (total1 <= 75){
            //Player2
                // Rolling Dice
            dice1 = generator.nextInt (6) + 1;
            dice2 = generator.nextInt (6) + 1;
                // Checking for snake eye and Box cars
            if (dice1 ==1 && dice2 == 1 || dice1 == 6 && dice2 == 6){
                System.out.println("Player 2 Losses a turn");
            }else {
            System.out.println ("Player 2 rolls a " + dice1 + " and a " + dice2 + " .");
            total2 = total2 + dice1 + dice2 ;
            System.out.println ("Player 2 now has " + total2);
            } // else ends here
            }
        } while (total1 < 75 && total2 < 75);
     
        // Announcing a winner
        if (total1 >= 75){
            System.out.println("Player 1 wins witht the total of " + total1);
        } else{
            System.out.println("Player 2 wins witht the total of " + total2);
        }
 
    }
 
}
Remember: 1 ya 6 ane k baad total count hoga but next sirf ek turn loose hogi.. same player ki
ye konsi game hai .... merey pass online dice game hai 2 players wali ager ap usko daikh kr koi help lai saktey hai tou mai share kr sakti hon...:)
 
  • Like
Reactions: Mahen

Don

Administrator
Mar 15, 2007
11,035
14,651
1,313
Toronto, Ca
ye konsi game hai .... merey pass online dice game hai 2 players wali ager ap usko daikh kr koi help lai saktey hai tou mai share kr sakti hon...:)
agar ap game k coding ki bat kar rahi hain to yes you can share... otherwise, I do not play such games. :) Thanks[DOUBLEPOST=1354832402][/DOUBLEPOST]
thanks {}{43r5 hmm ho gya clear :) bs kuch baty mind mi nhi aa rhi ti ab clear ho gie hai :)
wasie bhi programming mai basic things clear ho jaye tou next zadha problem nhi hoti :)
so, can you solve it now ?
 
  • Like
Reactions: Star24 and Mahen

Mahen

Alhamdulillah
VIP
Jun 9, 2012
21,845
16,877
1,313
laнore
ye konsi game hai .... merey pass online dice game hai 2 players wali ager ap usko daikh kr koi help lai saktey hai tou mai share kr sakti hon...:)
star Appi ap shadi k bad mi games khalti hw :D itna time mil jata ap ko :eek:[DOUBLEPOST=1354853642][/DOUBLEPOST]
agar ap game k coding ki bat kar rahi hain to yes you can share... otherwise, I do not play such games. :) Thanks[DOUBLEPOST=1354832402][/DOUBLEPOST]
so, can you solve it now ?
Star Appi jo programming krty ha wohh games nhi khalty :D just create krty hai ab khalny wala kam ap jasy bacho ka hai :D
@Don
yes many solve kr liya ta :) thanks! jaha sy samj nhi apni cunz ka srr khaa liya she said maheen games ku create krny lg gie tum :rolleyes:
 
  • Like
Reactions: Star24

Don

Administrator
Mar 15, 2007
11,035
14,651
1,313
Toronto, Ca
star Appi ap shadi k bad mi games khalti hw :D itna time mil jata ap ko :eek:[DOUBLEPOST=1354853642][/DOUBLEPOST]
Star Appi jo programming krty ha wohh games nhi khalty :D just create krty hai ab khalny wala kam ap jasy bacho ka hai :D
@Don
yes many solve kr liya ta :) thanks! jaha sy samj nhi apni cunz ka srr khaa liya she said maheen games ku create krny lg gie tum :rolleyes:
can I see your solution ?
 
  • Like
Reactions: Star24 and Mahen

zehar

VIP
Apr 29, 2012
26,600
16,302
1,313
agar ap game k coding ki bat kar rahi hain to yes you can share... otherwise, I do not play such games. :) Thanks[DOUBLEPOST=1354832402][/DOUBLEPOST]
so, can you solve it now ?
G mai daikhney key liye keh rhi hon.wo 5 dice game hai 2 players key liye mujhey lga shayed ap usko daikh kr mazeed kuch points add kr sakey.[DOUBLEPOST=1354867941][/DOUBLEPOST]
star Appi ap shadi k bad mi games khalti hw :D itna time mil jata ap ko :eek:[DOUBLEPOST=1354853642][/DOUBLEPOST]
Star Appi jo programming krty ha wohh games nhi khalty :D just create krty hai ab khalny wala kam ap jasy bacho ka hai :D
@Don
yes many solve kr liya ta :) thanks! jaha sy samj nhi apni cunz ka srr khaa liya she said maheen games ku create krny lg gie tum :rolleyes:
Kyon shadi key bad insan nhi rehta koi.hehehehe.arey merey pass time hi time hai.
 
  • Like
Reactions: Mahen

Mahen

Alhamdulillah
VIP
Jun 9, 2012
21,845
16,877
1,313
laнore
can I see your solution ?
No {(nooo)} coz many complete type hi nhi kia {(popcorn)} thora sa kr k daka ta orr
apni cousin sy discuss kiya ta laga k samj aa gie hai so baki apny mind mi type kr liya :D
subha mera paper hai w/s engineering ka {(book)} so time kam hony ki waja sy chor diya ta ..
thanks for guides and sorry for late cos subha TM bilkul hi work nhi kr rhi tae mery pass {(book)}
 

zehar

VIP
Apr 29, 2012
26,600
16,302
1,313
The following error occurred

The server responded with an error. The error message is in the JavaScript console.
@Don
@Don
mujhey posting krney pr ye msg show ho rha hai...:eek: [DOUBLEPOST=1355572057][/DOUBLEPOST]@Don
@Don
 
  • Like
Reactions: Mahen
Top