Sugestão de Jogo para Iniciantes

19 respostas
pvrsouza

Galera,

Na faculdade foi solicitado a criação de um jogo em Java para estudo de POO. O tema é livre apesar de terem dados sugestões do tipo: Campo Minado, Jogo da Velha, Resta 1, Freecell etc etc etc… Como nunca desenvolvi jogo utilizando interfaces grafica, não sei o grau de complexidade para tal, gostaria da opinião de vocês. O jogo deve prover o estudo de POO e deve ser desenvolvido em Java + Swing(pelo inicialmente).

Vocês tem alguma sugestão? Eu pensei em Dominó ou Sudoku. São muito complexos para um iniciante em POO?

Brigado!

19 Respostas

Preco

Aqui o pessoal costuma fazer o joguinho da Forca… Poderia ter uma classe Palavra, contendo um array de letras e tals…

Marky.Vasconcelos

Jogo da velha e campo minado é o mais interessante.

ViniGodoy

Campo minado ou jogo da velha.

FreeCell, Paciência e Copas não são boas opções, pois precisam do baralho.

pvrsouza

Eita…pelo que eu to vendo não vou conseguir fugir do Campo Minado e/ou Jogo da Velha. Rsrsrsrs. Eu ja fiz um jogo da velha em Java, que rodava em DOS.

Confesso que fiquei tentado a fazer o Sudoku. Será que rola?

F

Cara sudoku é legal…

eu fiz um em desktop na facul…

e tem algums desafios legais para iniciantes em POO… assim como o campo minado…

apesar de que o sudoku é bem mais complexo do que o campo minado… no caso de gerar um jogo valido… e a validação… e tudo mais…

se tiver tempo, vontade, e quiser treinar a logica tambem fora POO… faça o sudoku…

ViniGodoy

Se você quiser fazer algo mais elaborado, pode fazer o Space Invaders, Pong ou Arkanoid. Vão exigir Java 2D e que você faça um game loop, mas não é tão difícil quanto parece. Dê uma olhada:
http://www.cokeandcode.com/node/6

Diabo_Loiro

eu faria um game tipo super trunfo ou uno

e tbm vejam k

Para melhor visualização escolha full screen e aperte o botão HD
[youtube]http://www.youtube.com/watch?v=sUvtfBzj9fo[/youtube]

pvrsouza

Gostei das ideias.

Muito joguinho que eu não conhecia…(será que eu tive infancia?Rsrsrsrs)

O Space Invaders fica legal. Mas tenho que avaliar com o professor se rola usar Java 2d…de repente ele pilha com isso…

pvrsouza

Voces que tem muiiitoo mais experiencia do que eu. O que acham do dominó? Muito complicado pra meu grau de conhecimento(apredendo POO)?

Marky.Vasconcelos

Campo minado man.

E Diabo Loiro eu tinha feito um MMORPG que estava igual o seu a unica diferença é que era possivel se mover mais pros lados e a tela que ia rolando.

Até o problema da animação dos sprites se movendo era o mesmo.

Diabo_Loiro

Legal eu já resolvi o bug e implementei isometria mais o projeto ta parado agora by scwcd kkk

pvrsouza

Galera,

Em primeiro lugar brigadão pelas dicas e sugestões!

Nós, do grupo de trabalho da faculdade, decidimos fazer um Dominó pelo fato de ter um apelo visual interessante, possibilidade de jogar na rede, possibilidade de colocar um bate-papo entre os participantes e outras “coisitas”.

Agora o problema é: por onde comecar? Como imaginar as classes e tudo mais. Rsrsrsrsrs. Vamos ver on que dá. Nunca fizemos um jogo utilizando POO. Vou mostrar a voces depois o resultado e com certeza vou abusar da boa vontae de vcs para dirimir alguma dúvida!

Brigadão pela ajuda de todos!

H

Aproveitando o tópico tenho que fazer o jogo da paciência p faculdade alguém sabe onde encontro código???

pvrsouza

UHauhahuauhauhahua…“onde encontro código?” Foi ótimo!. Já tentou procurar na sua cabeça? Já tetou procurar fazer? Nesses dois lugares com certeza vc encontra.

Hellmanss

Aqui voce encontra o codigo completo.

Link retirado pelo Moderador . Desculpe a brincadeira :smiley:

Marky.Vasconcelos

P%rr@ cara… não coloca link dessas coisas não, a cabei de abrir aqui no trampo e não foi nada agradavel.
Se não vai contribui também não f%d#.

H
UAHAUHUAHUAHUA Tem que ser baiano p responder desse jeito!!!!! auahauhauhua
package paciencia.solitaire;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.Calendar;
import java.util.Locale;
import java.util.ResourceBundle;

import paciencia.card.*;
import paciencia.util.*;

public class Paciencia extends Frame
{
       public static final int SEQ_STACK_CNT = 4;

      public static final Point DECK_POS              = new Point( 5, 5 );
    public static final Point REVEALED_CARDS_POS    = new Point( DECK_POS.x + ClassicCard.DEFAULT_WIDTH + 5, 5 );
    public static final Point SEQ_STACK_POS         = new Point( REVEALED_CARDS_POS.x + ClassicCard.DEFAULT_WIDTH + 92, DECK_POS.y );
    public static final Point SOL_STACK_POS         = new Point( DECK_POS.x, SEQ_STACK_POS.y + ClassicCard.DEFAULT_HEIGHT + 5 );

    public static final Color TABLE_COLOR           = new Color( 0, 150, 0 );

	public Paciencia( boolean isApplet )
	{
		super();
		setLayout( new BorderLayout( 0, 0 ) );
		setResizable( false );

        class LocaleListener implements ItemListener {
            public LocaleListener( Locale locale ) {
                this.locale = locale;
            }

            public void itemStateChanged( ItemEvent e ) {
                Paciencia.this.setLocale( locale );
            }

            Locale locale;
        }

        class LicenseListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                String title = resBundle.getString( "License" );
                String msg = resBundle.getString( "LicenseText" );
                DialogMsg licenseWindow = new DialogMsg( Paciencia.this, title, true, msg );
                licenseWindow.setLocation( 20, 20 );
                licenseWindow.setSize( 500, 300 );
                licenseWindow.setFont( new Font( "Arial", Font.PLAIN, 14 ) );
                licenseWindow.setResizable( true );
                licenseWindow.setVisible( true );
            }
        }

		//Menus
		menubar = new MenuBar();
		setMenuBar( menubar );

		//Menu Options
		menuOptions = new Menu( "Options" );
		menubar.add( menuOptions );
		menuItemNewGame = new MenuItem( "NewGame");
		menuItemNewGame.addActionListener( new NewGameListener() );
		menuOptions.add( menuItemNewGame );

        menuItemEnglish = new CheckboxMenuItem( "English" );
        menuItemEnglish.addItemListener( new LocaleListener( Locale.ENGLISH ) );
        menuItemFrench = new CheckboxMenuItem( "French" );
        menuItemFrench.addItemListener( new LocaleListener( Locale.FRENCH ) );

        menuLanguage = new Menu( "Language" );
        menuLanguage.add( menuItemEnglish );
        menuLanguage.add( menuItemFrench );

        menuOptions.add( new MenuItem( "-" ) );
        menuOptions.add( menuLanguage );

		//Menu Help
		menuHelp = new Menu( "Help" );
		menubar.add( menuHelp );
		menuItemRules = new MenuItem( "Rules" );
		menuItemRules.addActionListener( new RulesListener() );
		menuItemAbout = new MenuItem( "About" );
		menuItemAbout.addActionListener( new AboutListener() );
        menuItemLicense = new MenuItem();
        menuItemLicense.addActionListener( new LicenseListener() );
		menuHelp.add( menuItemRules );
		menuHelp.add( new MenuItem( "-" ) );
		menuHelp.add( menuItemAbout );
        menuHelp.add( menuItemLicense );

		//String backgroundImageName = "test";
		//backgroundImage = Util.getImageResourceFile( "images/" + backgroundImageName + ".jpg", Solitaire.class );

		//Table
		table = new Table();
		add("Center", table);
		MouseManager mouseManager = new MouseManager();
		table.addMouseListener( mouseManager );
		table.addMouseMotionListener( mouseManager );

		setSize((ClassicCard.DEFAULT_WIDTH + 5) * SOL_STACK_CNT + 10 + getInsets().left + getInsets().right + 3,560);
        setVisible( true );

        addWindowListener(
            new SolitaireWindowManager( this,
                isApplet ? WindowManager.HIDE_ON_CLOSE : WindowManager.EXIT_ON_CLOSE ) );

	    newGame();
    }

        public void setVisible(boolean b)
	{
	    Dimension scrSize = getToolkit().getScreenSize();
	    Dimension size = getSize();
		if(b)
		{
			setLocation( (scrSize.width - size.width) / 2, (scrSize.height - size.height) / 2 );
		}
		super.setVisible(b);
	}

        public void setLocale( Locale locale ) {
        super.setLocale( locale );
        
		resBundle = ResourceBundle.getBundle( Paciencia.class.getName() + "Ress", locale );
        
        menuOptions.setLabel( resBundle.getString( "Options" ) );
        menuItemNewGame.setLabel( resBundle.getString( "NewGame" ) );
        menuHelp.setLabel( resBundle.getString( "Help" ) );
        menuItemRules.setLabel( resBundle.getString( "Rules" ) );
        menuItemAbout.setLabel( resBundle.getString( "About" ) );
        menuLanguage.setLabel( resBundle.getString( "Language" ) );
        menuItemLicense.setLabel( resBundle.getString( "License" ) );
        menuItemEnglish.setLabel( resBundle.getString( "English" ) );
        menuItemFrench.setLabel( resBundle.getString( "Portuguese" ) );

        menuItemEnglish.setState( Locale.ENGLISH.equals( locale ) );
        menuItemFrench.setState( Locale.FRENCH.equals( locale ) );

        setTitle( resBundle.getString( "Solitaire" ) );

        if( frameAbout != null )
            frameAbout.setLocale( locale );
        if( frameRules != null )
            frameRules.setLocale( locale );
    }
    
    public static void main( String[] args ) {
        Locale loc = null;
        if( args.length == 0 )
            loc = Locale.ENGLISH;
        else if( args.length == 1 )
            loc = args[ 0 ].equals( "fr" ) ? Locale.FRENCH : Locale.ENGLISH;

        if( loc == null )
            System.out.println( "Usage : java com.fbergeron.solitaire.Solitaire [locale]\n\n" +
                "locale may be fr (for french) or en (for english).\n" );
        else {
            Paciencia sol = new Paciencia( false );
            sol.setLocale( loc );
        }
    }

       public void newGame() {
        deck = new ClassicDeck( table );
        deck.shuffle();
        deck.setLocation( DECK_POS.x, DECK_POS.y );

        revealedCards = new Stack();
        revealedCards.setLocation( REVEALED_CARDS_POS.x, REVEALED_CARDS_POS.y );

        seqStack = new SequentialStack[ SEQ_STACK_CNT ];
        for ( int i = 0; i < SEQ_STACK_CNT; i++ ) {
            seqStack[ i ] = new SequentialStack();
            seqStack[ i ].setLocation( SEQ_STACK_POS.x + i * (ClassicCard.DEFAULT_WIDTH + 5), SEQ_STACK_POS.y );
        }

        PacienciaStack [] solStack = new PacienciaStack[ SOL_STACK_CNT ];
        for ( int i = 0; i < SOL_STACK_CNT; i++ ) {
            solStack[ i ] = new PacienciaStack();
            solStack[ i ].setSpreadingDirection( Stack.SPREAD_SOUTH );
            solStack[ i ].setSpreadingDelta( 20 );
            solStack[ i ].setLocation( SOL_STACK_POS.x + i * (ClassicCard.DEFAULT_WIDTH + 5), SOL_STACK_POS.y );
        }

        currStack = new Stack();
        currStack.setSpreadingDirection( Stack.SPREAD_SOUTH );
        currStack.setSpreadingDelta( 20 );

        distributeCards();
        if( table != null )
            table.repaint();
    }

        public void getNewCards() {
        //First, restore the deck if it's empty.
        if( deck.isEmpty() ) {
            for( ; !revealedCards.isEmpty(); ) {
                ClassicCard c = ((ClassicCard)revealedCards.pop());
                c.turnFaceDown();
                deck.push( c );
            }
        }

        for( int i = 0; !deck.isEmpty() && i < FREED_CARDS_CNT; i++ ) {
            ClassicCard c = ((ClassicCard)deck.pop());
            c.turnFaceUp();
            revealedCards.push( c );
        }

        if( table != null )
            table.repaint();
    }

       public void play( Stack curr, Stack src, Stack dst ) {
        if( curr != null )
            curr.reverse();
        if( dst != null && dst.isValid( curr ) ) {
            for( ; !curr.isEmpty(); )
                dst.push( curr.pop() );
            if( !src.isEmpty() && src.top().isFaceDown() ) {
                ClassicCard topCard = ((ClassicCard)src.top());
                topCard.turnFaceUp();
            }
            if( isGameWon() )
                congratulate();
        }
        else {
            for( ; !curr.isEmpty(); )
                src.push( curr.pop() );
        }
        if( table != null )
            table.repaint();
    }

    /** Each time a new game begins, we have to distribute the
     * cards in colums.  The number of columns is equal to SOL_STACK_CNT.
     */
    private void distributeCards() {
        for( int i = 0; i < SOL_STACK_CNT; i++ ) {
            ClassicCard c = ((ClassicCard)deck.pop());
            c.turnFaceUp();
            solStack[ i ].push( c );
            for( int j = i+1; j < SOL_STACK_CNT; j++ )
                solStack[ j ].push( deck.pop() );
        }
    }

    /**
     * @return <CODE>true</CODE>, if the game is won.
     * <CODE>false</CODE> otherwise.
     */
    private boolean isGameWon() {
        boolean gameWon = deck.isEmpty() && revealedCards.isEmpty();
        if( gameWon )
            for( int i = 0; i < SOL_STACK_CNT && gameWon; i++ )
                gameWon = gameWon && solStack[ i ].isEmpty();
        return( gameWon );
    }

    /**
     * Shows a frame congratulating the player.
     */
    private void congratulate() {
        FrameCongratulations f = new FrameCongratulations();
        f.setVisible( true );
    }

    class AboutListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if( frameAbout == null )
                frameAbout = new FrameAbout();
            frameAbout.setLocale( Paciencia.this.getLocale() );
            frameAbout.setVisible( true );
        }
    }

	class NewGameListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            newGame();
        }
    }

	class RulesListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if( frameRules == null )
                frameRules = new FrameRules();
            frameRules.setLocale( Paciencia.this.getLocale() );
            frameRules.setVisible( true );
        }
    }

    class MouseManager extends MouseAdapter implements MouseMotionListener {
        public void mouseMoved(MouseEvent e) {
        }

        public void mouseDragged(MouseEvent e) {
            if( currStack != null && translation != null ) {
                Point p = e.getPoint();
                currStack.setLocation( p.x - translation.x, p.y - translation.y );
                table.repaint();
            }
        }

        public void mousePressed(MouseEvent e) {
            if( !e.isMetaDown() && !e.isControlDown() && !e.isShiftDown() ) {
                ClassicCard c = null;
                Point p = e.getPoint();

                if( deck.contains( p ) )
                    getNewCards();
                else {
                    if( !revealedCards.isEmpty() && revealedCards.top().contains( p ) ) {
                        src = revealedCards;
                        c = ((ClassicCard)src.top());
                    }
                    else {
                        for( int i = 0; i < SOL_STACK_CNT && src == null; i++ ) {
                            if( !solStack[ i ].isEmpty() && solStack[ i ].contains( p ) ) {
                                src = solStack[ i ];
                                c = ((ClassicCard)src.getClickedCard( p ));
                            }
                        }
                        for( int i = 0; i < SEQ_STACK_CNT && src == null; i++ ) {
                            if( !seqStack[ i ].isEmpty() && seqStack[ i ].contains( p ) ) {
                                src = seqStack[ i ];
                                c = ((ClassicCard)src.top());
                            }
                        }
                    }
                    //We don't allow to drag hidden cards
                    if( c != null && c.isFaceDown() ) {
                        src = null;
                        c = null;
                    }
                    if( src != null && c != null ) {
                        Point loc = c.getLocation();
                        translation = new Point( p.x - loc.x, p.y - loc.y );
                        currStack = src.pop( c );
                        currStack.reverse();
                        curr = currStack;
                    }
                }
            }
        }

        public void mouseReleased(MouseEvent e) {
            Point p = e.getPoint();

            for( int i = 0; i < SOL_STACK_CNT && dst == null; i++ ) {
                if( solStack[ i ].contains( p ) )
                    dst = solStack[ i ];
            }
            for( int i = 0; i < SEQ_STACK_CNT && dst == null; i++ ) {
                if( seqStack[ i ].contains( p ) )
                    dst = seqStack[ i ];
            }
            if( curr != null && src != null )
                play( curr, src, dst );
            curr = src = dst = null;
        }

        private   Stack   curr;
        private   Stack   src;
        private   Stack   dst;
        private   Point   translation;
    }

    class Table extends Canvas
    {
    	public void update( Graphics g ) {
    	    paint( g );
    	}

        public void paint( Graphics g ) {
            //Create offscreen
            Dimension dim = this.getSize();
            if( offscreen == null ) {
                offscreen = this.createImage( dim.width, dim.height );
                offscreenGr = offscreen.getGraphics();
            }

            //Draw background
            offscreenGr.setColor( TABLE_COLOR );
            offscreenGr.fillRect( 0, 0, dim.width, dim.height );

            //Draw background image
            //offscreenGr.drawImage( backgroundImage, 0, 0, dim.width, dim.height, this );

            //Draw deck
            if( deck != null )
                if( deck.isEmpty() ) {
                    Point loc = deck.getLocation();
                    offscreenGr.setColor( Color.darkGray );
                    offscreenGr.fillRect( loc.x, loc.y, ClassicCard.DEFAULT_WIDTH, ClassicCard.DEFAULT_HEIGHT );
                    offscreenGr.setColor( Color.black );
                    offscreenGr.drawRect( loc.x, loc.y, ClassicCard.DEFAULT_WIDTH, ClassicCard.DEFAULT_HEIGHT );
                }
                else
                    deck.top().paint( offscreenGr );

            //Draw revealedCards
            if( revealedCards != null && !revealedCards.isEmpty() )
                revealedCards.top().paint( offscreenGr );

            //Draw sequential stacks
            if( seqStack != null )
                for( int i = 0; i < Paciencia.SEQ_STACK_CNT; i++ )
                    seqStack[ i ].paint( offscreenGr );

            //Draw solitaire stacks
            if( solStack != null )
                for( int i = 0; i < Paciencia.SOL_STACK_CNT; i++ )
                    solStack[ i ].paint( offscreenGr );

            //Draw current stack
            if( currStack != null && !currStack.isEmpty())
                currStack.paint( offscreenGr );

            g.drawImage( offscreen, 0, 0, this );
        }

    	public void destroy() {
    	    offscreenGr.dispose();
    	}

        private Image       offscreen;
        private Graphics    offscreenGr;
    }

    class SolitaireWindowManager extends WindowManager {

        SolitaireWindowManager( Window window, int action ) {
            super( window, action );
        }

        public void windowClosing( WindowEvent e ) {
            if( frameAbout != null ) {
                frameAbout.dispose();
                frameAbout = null;
            }
            if( frameRules != null ) {
                frameRules.dispose();
                frameRules = null;
            }
            super.windowClosing( e );
        }
    }
                
    //protected   Image               backgroundImage;
    protected   Stack               currStack;
    protected   ClassicDeck         deck;
    protected   Stack               revealedCards;
    protected   SolitaireStack[]    solStack;
    protected   SequentialStack[]   seqStack;
    protected   Table               table;

    static protected ResourceBundle resBundle;

    private MenuBar             menubar;
    private Menu                menuOptions;
    private Menu                menuLanguage;
    private Menu                menuHelp;
    private MenuItem            menuItemNewGame;
    private MenuItem            menuItemRules;
    private MenuItem            menuItemAbout;
    private MenuItem            menuItemLicense;
    private CheckboxMenuItem    menuItemEnglish;
    private CheckboxMenuItem    menuItemPortuguese;

    private FrameAbout          frameAbout;
    private FrameRules          frameRules;
}
essa é só uma das classes!!!!!!!! auhaauhuahua vai la e faz o seu jogo da velha !!!!! ahuahauhua
ViniGodoy

Removi o link. Helmanns, atenção com as normas do fórum. Na próxima, linke para sites como “use a porra do google”, eheheh.

Hiroshi, sempre que postar códigos, use a tag code:

Seu código aqui

Dessa vez já apliquei a tag para você, mas na próxima, procure observar essa regrinha. Caso contrário, o código fica completamente ilegível.

H

OK

Criado 10 de fevereiro de 2010
Ultima resposta 30 de abr. de 2010
Respostas 19
Participantes 8