Share on Google+Share on Google+

Lamya
stacks in java
0 Answer(s)      7 years 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());


}
}

}

Ads

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   Whether Java is pure object oriented Language
java
java  different between java & core java
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
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads