Highscore page, Match page and Game page

This commit is contained in:
Lorenzo Iovino 2017-06-14 14:21:49 +02:00
parent b5b62e2b07
commit ce32f58909
35 changed files with 1246 additions and 417 deletions

View file

@ -0,0 +1,142 @@
package com.texttwist.client.pages;
import com.texttwist.client.constants.Palette;
import com.texttwist.client.ui.*;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadLocalRandom;
/**
* Created by loke on 14/06/2017.
*/
public class Game extends Page {
private TTContainer gamecontainer;
private DefaultListModel<String> letters = new DefaultListModel<String>();
private DefaultListModel<String> words = new DefaultListModel<String>();
private DefaultListModel<Point> letterSpawningPoint = new DefaultListModel<Point>();
public Game(JFrame window) throws IOException {
super(window);
createUIComponents();
letters = fetchLetters();
letterSpawningPoint = setLetterSpawningPoint();
showLetters();
window.setVisible(true);
}
private DefaultListModel<Point> setLetterSpawningPoint(){
DefaultListModel l = new DefaultListModel<Point>();
//FirstRow
l.addElement(new Point(100,30));
l.addElement(new Point(200,15));
l.addElement(new Point(300,30));
l.addElement(new Point(400,15));
l.addElement(new Point(500,25));
//SecondRow
l.addElement(new Point(15,80));
l.addElement(new Point(65,95));
l.addElement(new Point(440,80));
l.addElement(new Point(500,90));
//ThirdRow
l.addElement(new Point(50,140));
l.addElement(new Point(150,130));
l.addElement(new Point(250,125));
l.addElement(new Point(350,145));
l.addElement(new Point(450,140));
l.addElement(new Point(550,130));
return l;
}
private DefaultListModel<String> fetchLetters(){
DefaultListModel l = new DefaultListModel<String>();
l.addElement("C");
l.addElement("A");
l.addElement("E");
l.addElement("P");
l.addElement("C");
l.addElement("I");
l.addElement("L");
l.addElement("S");
return l;
}
private Callable<Object> getWords(){
return null;
}
public boolean addWordToWordsList(String word) {
words.addElement(word);
return true;
}
private Point getRandomPosition(){
if(letterSpawningPoint.size()>1) {
int index = ThreadLocalRandom.current().nextInt(0, letterSpawningPoint.size() - 1);
System.out.println(index);
Point placeholder = letterSpawningPoint.get(index);
letterSpawningPoint.remove(index);
return placeholder;
}
return new Point(0,0);
}
public void showLetters(){
for(int i = 0; i< letters.size(); i++){
TTLetter letter = new TTLetter(
getRandomPosition(),
letters.get(i),
gamecontainer);
}
window.repaint();
window.revalidate();
}
@Override
public void createUIComponents() throws IOException {
addLogo(root);
gamecontainer = new TTContainer(
null,
new Dimension(1150,220),
Palette.root_backgroundColor,
-1,
root);
TTGameBox searchUserBar = new TTGameBox(
new Point(150, 90),
new Dimension(250, 40),
"Word!",
new DefaultListModel(),
getWords(),
gamecontainer);
addFooter(root);
addNext(footer,
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 70),
null,
"Done!",
new Callable<Object>() {
@Override
public Object call() throws Exception {
return new Menu(Page.window);
}
});
addTimer(footer,
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40),
null,
"00:00");
}
}

View file

@ -23,26 +23,23 @@ public class Highscores extends Page{
private DefaultListModel fetchHighscores(){
DefaultListModel<String> highscoreList = new DefaultListModel<String>();
highscoreList.addElement("USA");
highscoreList.addElement("India");
highscoreList.addElement("Vietnam");
highscoreList.addElement("Canada");
highscoreList.addElement("Denmark");
highscoreList.addElement("France");
highscoreList.addElement("France");
highscoreList.addElement("Great Britain");
highscoreList.addElement("Japan");
highscoreList.addElement("France");
highscoreList.addElement("Great Britain");
highscoreList.addElement("Japan");
highscoreList.addElement("France");
highscoreList.addElement("Great Britain");
highscoreList.addElement("Japan");
highscoreList.addElement("Great Britain");
highscoreList.addElement("Japan");
highscoreList.addElement("Pippo 41");
highscoreList.addElement("Paperino 37");
highscoreList.addElement("Gaia 34");
highscoreList.addElement("Luigi 32");
highscoreList.addElement("Marco 31");
highscoreList.addElement("Minnie 30");
highscoreList.addElement("Franco 30");
highscoreList.addElement("Qua 29");
highscoreList.addElement("Luca 27");
highscoreList.addElement("Qui 26");
highscoreList.addElement("Jorge 25");
highscoreList.addElement("David 22");
highscoreList.addElement("Quo 21");
highscoreList.addElement("Raphael 21");
highscoreList.addElement("Miguel 16");
highscoreList.addElement("Carmen 14");
highscoreList.addElement("Beatriz 12");
return highscoreList;
}
@Override
@ -64,11 +61,13 @@ public class Highscores extends Page{
highscoreContainer);
TTScrollList highscoreList = new TTScrollList(
new Point(0, 60),
new Dimension(575, 142),
new Point(20, 60),
new Dimension(515, 142),
fetchHighscores(),
highscoreContainer);
addBack(root,
addFooter(root);
addBack(footer,
new Callable<Object>() {
@Override
public Object call() throws Exception {

View file

@ -28,19 +28,19 @@ public class Home extends Page {
root);
TTInputField usernameField = new TTInputField(
new Point(70,60),
new Dimension(210,50),
new Point(50,60),
new Dimension(220,50),
"Username",
loginDataContainer);
TTPasswordField passwordField = new TTPasswordField(
new Point(290,60),
new Dimension(210,50),
new Point(280,60),
new Dimension(220,50),
loginDataContainer);
TTButton loginBtn = new TTButton(
new Point(70,120),
new Dimension(430,50),
new Point(50,120),
new Dimension(450,50),
"Go!",
new Callable<Object>() {
@Override

View file

@ -1,12 +1,70 @@
package com.texttwist.client.pages;
import com.texttwist.client.constants.Palette;
import com.texttwist.client.ui.*;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.concurrent.Callable;
/**
* Created by loke on 14/06/2017.
*/
public class MatchRequests extends Page{
public MatchRequests(JFrame window){
public TTContainer matchsContainer;
MatchRequests(JFrame window) throws IOException {
super(window);
createUIComponents();
window.setVisible(true);
}
//TODO Spostare i metodi di fetches nella classe MatchRequestService per separare MVC
private DefaultListModel fetchMatches(){
DefaultListModel<String> matchsList = new DefaultListModel<String>();
matchsList.addElement("Pippo ti ha sfidato ------- Accetta/Declina");
matchsList.addElement("Paperino ti ha sfidato ------- Accetta/Declina");
matchsList.addElement("Minnie ti ha sfidato ------- Accetta/Declina");
matchsList.addElement("Luca ti ha sfidato ------- Accetta/Declina");
matchsList.addElement("Gino ti ha sfidato ------- Accetta/Declina");
matchsList.addElement("Filippo ti ha sfidato ------- Accetta/Declina");
matchsList.addElement("Yuri ti ha sfidato ------- Accetta/Declina");
return matchsList;
}
@Override
public void createUIComponents() throws IOException {
addLogo(root);
matchsContainer = new TTContainer(
null,
new Dimension(1150,220),
Palette.root_backgroundColor,
-1,
root);
TTLabel title = new TTLabel(
new Point(150,0),
new Dimension(350,50),
"Pending matches",
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
null,
matchsContainer);
TTScrollList highscoreList = new TTScrollList(
new Point(20, 60),
new Dimension(520, 142),
fetchMatches(),
matchsContainer);
addFooter(root);
addBack(footer,
new Callable<Object>() {
@Override
public Object call() throws Exception {
return new Menu(Page.window);
}
});
}
}

View file

@ -1,12 +1,120 @@
package com.texttwist.client.pages;
import com.texttwist.client.constants.Palette;
import com.texttwist.client.ui.*;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.concurrent.Callable;
/**
* Created by loke on 14/06/2017.
*/
public class MatchSetup extends Page {
public MatchSetup(JFrame window){
public class MatchSetup extends Page{
public TTContainer matchSetupContainer;
MatchSetup(JFrame window) throws IOException {
super(window);
createUIComponents();
window.setVisible(true);
}
private Callable addUserToInvitationList(){
return null;
}
//TODO Spostare i metodi di fetches nella classe MatchSetupService per separare MVC
private DefaultListModel fetchUsers(){
DefaultListModel<String> usersList = new DefaultListModel<String>();
usersList.addElement("Pippo");
usersList.addElement("Paperino");
usersList.addElement("Gaia");
usersList.addElement("Luigi");
usersList.addElement("Marco");
usersList.addElement("Minnie");
usersList.addElement("Franco");
usersList.addElement("Qua");
usersList.addElement("Luca");
usersList.addElement("Qui");
usersList.addElement("Jorge");
usersList.addElement("David");
usersList.addElement("Quo");
usersList.addElement("Raphael");
usersList.addElement("Miguel");
usersList.addElement("Carmen");
usersList.addElement("Beatriz");
return usersList;
}
@Override
public void createUIComponents() throws IOException {
addLogo(root);
matchSetupContainer = new TTContainer(
null,
new Dimension(1150,220),
Palette.root_backgroundColor,
-1,
root);
TTLabel title = new TTLabel(
new Point(170,0),
new Dimension(350,50),
"Invite players",
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
null,
matchSetupContainer);
TTLabel playerFinder_flavourText = new TTLabel(
new Point(20,40),
new Dimension(350,50),
"<html>Search players to invite...</html>",
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
null,
matchSetupContainer);
TTSearchBar searchUserBar = new TTSearchBar(
new Point(20, 80),
new Dimension(250, 40),
"Username",
new DefaultListModel(),
addUserToInvitationList(),
matchSetupContainer);
TTLabel playerToSendInvite_flavourText = new TTLabel(
new Point(305,40),
new Dimension(350,50),
"Click on user for remove it",
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
null,
matchSetupContainer);
TTScrollList playerToSendInvite = new TTScrollList(
new Point(305, 80),
new Dimension(232, 135),
new DefaultListModel(),
matchSetupContainer);
addFooter(root);
addNext(footer,
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40),
null,
"Play!",
new Callable<Object>() {
@Override
public Object call() throws Exception {
return new Game(Page.window);
}
});
addBack(footer,
new Callable<Object>() {
@Override
public Object call() throws Exception {
return new Menu(Page.window);
}
});
}
}

View file

@ -84,7 +84,9 @@ public class Menu extends Page{
}
},
menuBar);
addBack(root,
addFooter(root);
addBack(footer,
new Callable<Object>() {
@Override
public Object call() throws Exception {

View file

@ -1,10 +1,7 @@
package com.texttwist.client.pages;
import com.texttwist.client.constants.Palette;
import com.texttwist.client.ui.TTContainer;
import com.texttwist.client.ui.TTImage;
import com.texttwist.client.ui.TTImageBtn;
import com.texttwist.client.ui.TTLabel;
import com.texttwist.client.ui.*;
import javax.swing.*;
import java.awt.*;
@ -18,6 +15,7 @@ import java.util.concurrent.Callable;
public class Page {
public TTContainer root;
public TTContainer footer;
public static JFrame window;
public Page(JFrame window){
@ -60,21 +58,46 @@ public class Page {
public void addBack(TTContainer parent, Callable<Object> clickHandler) {
try {
TTImageBtn back = new TTImageBtn(
new Point(0, 800),
new Dimension(0, 0),
new Point(0, 0),
new Dimension(50, 50),
new ImageIcon(new File("./Client/resources/images/back.png").getCanonicalPath()),
clickHandler,
parent);
TTLabel registerText = new TTLabel(
new Point(55,775),
new Dimension(350,0),
"Back",
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 24),
null,
parent);
} catch (IOException e) {
e.printStackTrace();
}
}
public void addFooter(TTContainer root) {
footer = new TTContainer(
null,
new Dimension(1150, 60),
Palette.root_backgroundColor,
-1,
root);
}
public void addNext(TTContainer parent, Font font, Color fontColor, String caption, Callable<Object> clickHandler) {
TTLabelBtn next = new TTLabelBtn(
new Point(500, 0),
new Dimension(150, 50),
caption,
null,
null,
clickHandler,
parent);
}
public void addTimer(TTContainer parent, Font font, Color fontColor, String caption) {
TTLabel next = new TTLabel(
new Point(0, 0),
new Dimension(150, 50),
caption,
font,
fontColor,
parent);
}
}

View file

@ -57,7 +57,8 @@ public class Register extends Page {
}
},
registerDataContainer);
addBack(root,
addFooter(root);
addBack(footer,
new Callable<Object>() {
@Override
public Object call() throws Exception {

View file

@ -0,0 +1,42 @@
package com.texttwist.client.ui;
import com.texttwist.client.constants.Palette;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.Callable;
/**
* Created by loke on 14/06/2017.
*/
public class TTGameBox extends TTInputField{
private DefaultListModel words = new DefaultListModel();
public TTGameBox(Point position,
Dimension dimension,
String placeholer,
DefaultListModel listModel,
Callable<Object> clickHandler,
TTContainer parent){
super(position, dimension, placeholer, parent);
setBackground(Palette.scrollPanel_backgroundColor);
setFont(Palette.inputBox_font);
setBounds(position.x, position.y, dimension.width, dimension.height);
setPreferredSize(dimension);
setForeground(Palette.fontColor);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
//Every time i press a key, execute a search of users
}
});
parent.add(this);
}
}

View file

@ -0,0 +1,23 @@
package com.texttwist.client.ui;
import com.texttwist.client.constants.Palette;
import javax.swing.*;
import java.awt.*;
/**
* Created by loke on 14/06/2017.
*/
public class TTLetter extends TTLabel{
public TTLetter(Point position, String caption, JPanel parent) {
super(position,
new Dimension(50,50),
caption,
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 40),
Palette.fontColor,
parent);
parent.add(this);
}
}

View file

@ -0,0 +1,49 @@
package com.texttwist.client.ui;
import com.texttwist.client.constants.Palette;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.Callable;
/**
* Created by loke on 14/06/2017.
*/
public class TTSearchBar extends TTInputField{
private DefaultListModel matchedUsers = new DefaultListModel();
public TTSearchBar(Point position,
Dimension dimension,
String placeholer,
DefaultListModel listModel,
Callable<Object> clickHandler,
TTContainer parent){
super(position, dimension, placeholer, parent);
setBackground(Palette.scrollPanel_backgroundColor);
setFont(Palette.inputBox_font);
setBounds(position.x, position.y, dimension.width, dimension.height);
setPreferredSize(dimension);
setForeground(Palette.fontColor);
TTScrollList userList = new TTScrollList(
new Point(20,120),
new Dimension(250,95),
matchedUsers,
parent
);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
//Every time i press a key, execute a search of users
}
});
parent.add(this);
}
}