Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Lamya
stacks in java
0 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners


i am doing a program that i have to finish it before monday so i only have tomorow to finish it. it about the stacks im designing the role of spider card game. i have to move more than one card together from one column to another i can move one card usinf pop and push method but if its more that one card togther for example if i want to move 6,5 and 4 to put it in another column in the top of 7. i dont know what to use to move them together. this is the method that im having the problem with currently it moves one card to another columna and only if its in the right order and then if the column is empty then it has to add only jack or bigger card. then the part where im have problem with which to move a list of cards together. please i need help urgently..... thank you


* @pre 0<=c<7 (i.e. the index of the source column is within range)
* && 0<=d<7 (i.e. the index of the target column is within range)
* && 0<=i<columns[c].size() (i.e. the index i is within range)
* && the i-th card in the c-th column is face up
*
* @post If the rules permit, the i-th card of the c-th column has
* been moved onto the bottom of the d-th column, (along with any
* cards displayed below it), leaving all other cards where they were.
* If the rules do not permit this move, all cards are left
* where they were before.
*

public void moveCardBetweenColumnsIfPossible(int c, int i, int d){

CardStack stack = new CardStack();

if (columns[d].isEmpty()&& columns[c].peek().getRank()>=Card.JACK){
Card move=columns[c].pop();
columns[d].push(move);
}

if (((!columns[d].isEmpty()&& columns[c].peek().getRank()==columns[d].peek().getRank()-1))&& (!columns[c].peek().getColour().equals(columns[d].peek().getColour())))
{
Card value=columns[c].pop();
columns[d].push(value);


// to move a list of cards together i is the selected card and d is the destination where you want to move the card to and c is the coloumn

for( int I = columns[c].size() - 1 ; I >= i ; I--)
{


Card card = columns[c].peek();
columns[c].pop();

stack.push(card);


while(!stack.isEmpty())


columns[d].push(columns[c].peek());


}
}

}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
stacks in java - Java Beginners
stacks in java  i am doing a program that i have to finish it before monday so i only have tomorow to finish it. it about the stacks im designing the role of spider card game. i have to move more than one card together from one
Java Stacks - Java Beginners
Java Stacks  Hello..Help me with this assignment plzz. Programming Assignment: A) Consider the outpatient pharamacy at University Hospital. At the entrance of the pharmacy, the patient gives his prescriptions
Advertisements
Java Convert decimal to binary using Stacks
Java Convert decimal to binary using Stacks In this section, you will learn how to convert decimal into binary using stacks. You all are aware of Stacks. It performs two basic operations push and pop. The push operation adds an element
implementation of stacks using linked lists in c++
implementation of stacks using linked lists in c++  how to implementation of stacks using linked lists in c++   #include<stdio.h> #include<stdlib.h> #include<conio.h> struct node{ int data
Java stack help
Java stack help  How would I use stacks in java to do a calculation like: 4*((3+3)/(5-3
making trees - Java Beginners
making trees   pls i do't know what this yerms mean in terms of java trees and stacks? Inorder traverse Switch statement Doing something to the stack thanks in advance
java programming - Java Beginners
java programming  how can i program the queue and the stacks.   Refer Complete Reference  Hi friend, import java.util....) ; } } ----------------------------------------- Read for more information. http://www.roseinida.net/java/ Thanks
hashtable - Java Beginners
hashtable  pls what is a hashtable in java and how can we use it to compine queue and stacks. thnks in advance.  Hi , A hash-table...://www.roseindia.net/java/ Thanks. Amardeep
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
java
java  diff bt core java and java
java
java  what is java
java
java  different between java & core java
Java
Java   Whether Java is pure object oriented Language
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Advertisements
 

 

 

DMCA.com