Help with Java Assignment


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help with Java Assignment
# 1  
Old 12-03-2011
Help with Java Assignment

1. The problem statement, all variables and given/known data:
Hey there, I am currently working on an assignment which is due in on Monday 5th December and I am close to completing it, however there are two sections of the program I am running in which I am confused by.

Basically I have created a coded version of the card game Solitare, and I have made commands to replace the previous card, the card 2 places over, and also to amalgamate these as well. However I first need to create an option to play the game for me automatically, using most of the codes I have already created.

My second problem is that whenever the played deals a card from the original deck of cards I have created in classes, usually a card is placed into a new deck, which then gets displayed on the menu option I have created, as well as with the graphics. However when the user draws from the original deck when no cards are in there, I have created a score method which records the users name and score from the game, and from this I create a method to save the score, and exit the game. However instead of now exiting the game automatically, I wish to reset the game and all the cards moved to the different deck into the original deck, and to basically start the game over.

2. Relevant commands, code, scripts, algorithms:
I'm not sure what to say here, so maybe I will just show you examples of the past move methods I have used to make some of the cards move in the game from my other methods.

Play For Me
Code:
public void amalgamate(int a, int b) {
        if (b-a==1 || b-a==3 ) {
            Card last=cards.get(b);
            Card prev=cards.get(a);
            if(last.getSuit().equals(prev.getSuit())||
            last.getValue().equals(prev.getValue())){
                cards.remove(b);
                cards.set(a, last);
            }
        }
    }

    public void simple() {
        int number=cards.size()-1;
        Card last=cards.get(number);
        Card prev=cards.get(number-1);
        if(last.getSuit().equals(prev.getSuit())||
        last.getValue().equals(prev.getValue())){
            cards.remove(number);
            cards.set(number-1, last);
        }
    }

    public void leap() {
        int number=cards.size()-1;
        Card last=cards.get(number);
        Card prev=cards.get(number-3);
        if(last.getSuit().equals(prev.getSuit())||
        last.getValue().equals(prev.getValue())){
            cards.remove(number);
            cards.set(number-3, last);
        }
    }

And apparently I have been told by some advisors that using my 'amalgamate' method will be very helpful in the method to play the game for me.

Reset game (this methods shows both how to deal a card, followed by the score method)
Code:
if(deck.getCards().size()>0) {
                    Card tempCard;
                    tempCard = deck.getCard();
                    dealtCards.addCard(tempCard);
                    deck.removeCard();
                }                                        //This methods first les me add a new card from the original deck by removing it from there,
                //and then add this into a new deck which is called 'dealtCards'. 
                else {
                    System.out.println("The Game is over!");
                    System.out.println("Please enter your name: ");
                    String name= scan.next();
                    score= new Score(dealtCards.getCards().size(),name);
                    scores.add(score);
                    System.out.println(scores);
                    this.saveScores();
                    System.out.println("Thanks you for your Patience, hope you enjoyed the game!");
                    System.exit(0);
                }

3. The attempts at a solution (include all code and scripts):
I have tried a whole batch arrays, yet I am not sure how to really use them in the right way. The game goes with Collection commands.

And I am unsure if there is already a method to reset a game to the start already, well, one that won't erase any saved data I have got from previous games anyway.


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Aberystwyth University, Aberystwyth, Wales, Lynda Thomas, CS12230

I hope I haven't done any of this wrong, and I truly hope someone can help me out in this time of great need, otherwise I'll just have to leave the project unfinished, which I'm alright with, but it would never hurt to do a little bit extra. Smilie

Last edited by DukeNuke2; 12-03-2011 at 06:04 PM..
# 2  
Old 12-05-2011
One of points you commented, maybe JUnit help you:
-----> JUnit - Tutorial
-----> Java(TM) Boutique - Unit Testing Java Programs

I hope it helps. =o)
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question