como criar o jogo 2048 em java 8 e javafx
DESCRIPTION
Todo mundo já jogou 2048. E muita gente sabe programar em Java. Nesta palestra veremos como a versão JavaFX do jogo 2048 foi criada, usando animações da plataforma, estilos CSS, e inclusive os novos recursos da linguagem apresentados no Java 8, como Lambda expressions.TRANSCRIPT
Como Criar o Game 2048Com JavaFX e Java SE 8Bruno BorgesPrincipal Product ManagerJava Evangelist
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 123
• Java Evangelist• Orale Product Manager• Entusiasta JavaFX e IoT• Onde me encontrar
• @brunoborges
• plus.google.com/+BrunoBorges
Bruno Borges
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 124
Agenda
• Jogo 2048• Da idéia à execução, da execução ao Raspberry Pi
• Java para game developers• Java SE 8: Lambda expressions, Stream API
• JavaFX 8: Conceitos, CSS, Animações, 3D API
• Outros Exemplos
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 125
• Mova os números em uma matriz de 4x4
• Quando números iguais se encontram valores são somados
• Vence quando atingir 2048
• 2, 4, 8, 16, 32, 64, 128, 256, 512,
1024, 2048
O jogo
2048
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 126
Onde jogar 2048?
• iOS
• Android
• Web (Javascript)• gabrielecirulli.github.io/2048/
• JavaFX• PCs, Laptops, Tablets e Smartphones (que suportam Oracle Java SE 8),
Raspberry Pi e similares
Em quase todos os lugares!
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 127
• Classes de estrutura• Tile, Location, Direction
• GameManager
• Animações
• Eventos
• Estilos CSS
2048FX
Criando o jogo em JavaFX
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 128
Java ClassesJust a few
Direction, Location
Tile
GameManager
SessionManager
Game2048
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 129
Grid para o 2048y(i)
x(j)
Criando um grid com Lambda Expressions
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1210
Direction e LocationEstruturas básicas
X Y
UP 0 -1
RIGHT 1 0
DOWN 0 1
LEFT -1 0
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1211
TileRepresenta um “quadrado” no jogo, com valor atribuído
Novo tile aleatório. 90% chance para número “2”.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1212
Eventos de TecladoOuvindo eventos em JavaFX para movimentar os Tiles
Salva estado atual
Recupera último estado
Ignora teclas que não sejam setas “arrows”
Mapeia setas a Directions, chama GameManager
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1213
Eventos de TouchscreenAções mapeadas usando Lambda Expressions do Java 8
* Swipe images from quojs.tapquo.com
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1214
AnimaçõesMovendo os Tiles de um lado para o outro
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1215
Como saber se o jogo acabou?On Finish
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1216
Mostrar fim do jogogameOverProperty.set(true); ... Try again?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1217
Java para Game Developers
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1218
Java SE 8
Insert Picture Here
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1219
Lambda ExpressionsListeners
Com Java SE 8
Com Java SE 7
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1220
Lambda Expressions e Stream APIExemplo
Com Java SE 8
Com Java SE 7
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1221
Lambda Expression como ParâmetroMétodo que recebe uma expressão Lambda
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1222
Parallel StreamEncontrar Locations disponíveis no grid, usando multi-thread
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1223
JavaFX 8
Insert Picture Here
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1224
Arquitetura do JavaFX
• Prism – renderização nativa• OpenGL (Mac, Linux, Embedded)
• Direct 3D (9 em Windows XP/Vista, 11 em Windows 7)
• Java 2D (software rendering)
• Scene Graph• Nodes
• States
• Effects
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1225
JavaFX 3D
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1226 26
Insert Chart Here
Criando Formas e Materiais Primitivos
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1227
Colocando Textura em uma Esfera
27
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1228
Colocando Textura em uma Esfera
28
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1229
Colocando Textura em uma Esfera
29
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1230
Para saber mais
Documentação do Java 8: bit.ly/java8docs
Código-fonte do jogo 2048FX
github.com/brunoborges/fx2048
Twitter: @brunoborges
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
ORACLE e V.OFFICE
Parceria WDP (Workforce Development Program)
A Oracle University tem o prazer de anunciar a V.OFFICE Treinamentos como nosso mais novo parceiro WDP.
A Oracle Corporation lançou o WDP para resolver o déficit global e contínuo de trabalhadores na área de TI e a necessidade de treinamento acessível e de baixo custo nas habilidades correspondentes. O WDP permite que as instituições educacionais participantes forneçam treinamento em Oracle em tempo integral e meio-período a alunos em suas comunidades locais.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1232
The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract.It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1233
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1234