Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package progettoas.hearts.client;
- import progettoas.hearts.controller.Controller;
- import com.google.gwt.core.client.EntryPoint;
- import com.google.gwt.event.dom.client.ChangeEvent;
- import com.google.gwt.event.dom.client.ChangeHandler;
- import com.google.gwt.event.dom.client.ClickEvent;
- import com.google.gwt.event.dom.client.ClickHandler;
- import com.google.gwt.event.dom.client.KeyCodes;
- import com.google.gwt.event.dom.client.KeyUpEvent;
- import com.google.gwt.event.dom.client.KeyUpHandler;
- import com.google.gwt.http.client.Request;
- import com.google.gwt.user.client.Command;
- import com.google.gwt.user.client.DOM;
- import com.google.gwt.user.client.Window;
- import com.google.gwt.user.client.ui.Button;
- import com.google.gwt.user.client.ui.DockPanel;
- import com.google.gwt.user.client.ui.Grid;
- import com.google.gwt.user.client.ui.HTML;
- import com.google.gwt.user.client.ui.Label;
- import com.google.gwt.user.client.ui.ListBox;
- import com.google.gwt.user.client.ui.MenuBar;
- import com.google.gwt.user.client.ui.MenuItem;
- import com.google.gwt.user.client.ui.Panel;
- import com.google.gwt.user.client.ui.PasswordTextBox;
- import com.google.gwt.user.client.ui.RadioButton;
- import com.google.gwt.user.client.ui.RootPanel;
- import com.google.gwt.user.client.ui.SimplePanel;
- import com.google.gwt.user.client.ui.SourcesTableEvents;
- import com.google.gwt.user.client.ui.TableListener;
- import com.google.gwt.user.client.ui.TextArea;
- import com.google.gwt.user.client.ui.TextBox;
- import com.google.gwt.user.client.ui.VerticalPanel;
- import com.google.gwt.user.client.ui.HasHorizontalAlignment;
- import com.google.gwt.user.client.ui.HasVerticalAlignment;
- /**
- * Entry point classes define <code>onModuleLoad()</code>.
- */
- public class Hearts implements EntryPoint {
- static final int chatW = 300;
- static final int menuH = 40;
- static final int marginSize = 8;
- static final int cardW = 50;
- static final int cardH = 80;
- static final int nCard = 13;
- static final int LOGIN = 1;
- static final int WELCOME = 2;
- static final int PLAY_GAME = 3;
- static final int WATCH_GAME = 4;
- static final int STARTED_TAB = 5;
- static final int TOPSCORES = 6;
- static final int LOGUSR = 7;
- static final int PROFILE = 8;
- static final int HELP = 9;
- static final int ABOUT = 10;
- static final int STATE = 11;
- static final int NEWGAME = 12;
- static final int GAMEEND = 13;
- static final int TABLELIST_W = 14;
- static final int TABLELIST_P = 15;
- int currentPanel = 0;
- Boolean isAuthenticated = false;
- Boolean isPlaying = false;
- int nbot;
- int NTable = 0;
- Controller controller = new Controller();
- SimplePanel init = new SimplePanel();
- DockPanel panel = new DockPanel();
- MenuBar menutop = new MenuBar();
- SimplePanel chatPanel = new SimplePanel();
- VerticalPanel loginPanel = new VerticalPanel();
- VerticalPanel welcomePanel = new VerticalPanel();
- VerticalPanel topscorePanel = new VerticalPanel();
- VerticalPanel logUsrPanel = new VerticalPanel();
- VerticalPanel profilePanel = new VerticalPanel();
- VerticalPanel helpPanel = new VerticalPanel();
- VerticalPanel aboutPanel = new VerticalPanel();
- VerticalPanel statePanel = new VerticalPanel();
- DockPanel gamePanel = new DockPanel();
- VerticalPanel newGamePanel = new VerticalPanel();
- VerticalPanel gameEndPanel = new VerticalPanel();
- VerticalPanel wTableListPanel = new VerticalPanel();
- VerticalPanel pTableListPanel = new VerticalPanel();
- DockPanel watchGamePanel = new DockPanel();
- /**
- * The message displayed to the user when the server cannot be reached or
- * returns an error.
- */
- private static final String SERVER_ERROR = "An error occurred while "
- + "attempting to contact the server. Please check your network "
- + "connection and try again.";
- /**
- * Create a remote service proxy to talk to the server-side Greeting service.
- */
- // private final GreetingServiceAsync greetingService = GWT
- // .create(GreetingService.class);
- /**
- * This is the entry point method.
- */
- public void onModuleLoad() {
- panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- panel.setPixelSize(Window.getClientWidth()-marginSize, Window.getClientHeight()-marginSize);
- panel.addStyleName("panel");
- panel.add(init,DockPanel.WEST);
- drawMenu();
- drawChatPanel();
- panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- panel.add(menutop, DockPanel.NORTH);
- panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
- panel.add(chatPanel, DockPanel.WEST);
- panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
- if (!isAuthenticated) {
- drawLoginPanel();
- renderNewPanel(loginPanel);
- currentPanel = LOGIN;
- } else {
- drawWelcomePanel();
- renderNewPanel(welcomePanel);
- currentPanel = WELCOME;
- }
- RootPanel rootPanel = RootPanel.get("panelContainer");
- rootPanel.add(panel);
- }
- private void renderNewPanel(Panel p) {
- Panel pp = null;
- switch(currentPanel) {
- case LOGIN: pp = loginPanel; break;
- case WELCOME: pp = welcomePanel; break;
- case TOPSCORES: pp = topscorePanel; break;
- case LOGUSR: pp = logUsrPanel; break;
- case PROFILE: pp = profilePanel; break;
- case HELP: pp = helpPanel; break;
- case ABOUT: pp = aboutPanel; break;
- case STATE: pp = statePanel; break;
- case PLAY_GAME: pp = gamePanel; break;
- case NEWGAME: pp = newGamePanel; break;
- case GAMEEND: pp = gameEndPanel; break;
- case TABLELIST_W: pp = wTableListPanel; break;
- case TABLELIST_P: pp = pTableListPanel; break;
- case WATCH_GAME: pp = watchGamePanel; break;
- default: pp = init; break;
- }
- pp.clear();
- panel.remove(pp);
- panel.add(p,DockPanel.WEST);
- }
- private void drawMenu() {
- // Definition of commands to perform for each menu choice
- Command newGameCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing game!");
- } else if (isAuthenticated) {
- drawNewGamePanel();
- renderNewPanel(newGamePanel);
- currentPanel = NEWGAME;
- } else {
- Window.alert("You must be logged to start a new game!");
- }
- }
- };
- Command joinGameCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else if (isAuthenticated) {
- //TODO: ask model table list (not playing yet)
- int ntable = 8;
- drawPTableListPanel(ntable);
- renderNewPanel(pTableListPanel);
- currentPanel = TABLELIST_P;
- } else {
- Window.alert("You must be logged to join a table!");
- }
- }
- };
- Command leaveGameCmd = new Command() {
- public void execute() {
- if (!isPlaying) {
- Window.alert("You are not playing a game!");
- } else if (isAuthenticated) {
- isPlaying = false;
- drawWelcomePanel();
- renderNewPanel(welcomePanel);
- currentPanel = WELCOME;
- } else {
- Window.alert("You must be logged to leave a game!");
- }
- }
- };
- Command watchGameCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else if (isAuthenticated) {
- //TODO: ask model table list
- int ntable = 5;
- drawWTableListPanel(ntable);
- renderNewPanel(wTableListPanel);
- currentPanel = TABLELIST_W;
- } else {
- Window.alert("You must be logged to watch a game!");
- }
- }
- };
- Command showTopCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else {
- //TODO action: ask model for info about top 10 players
- drawTopScoresPanel();
- renderNewPanel(topscorePanel);
- currentPanel = TOPSCORES;
- }
- }
- };
- Command showUsrCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else if (isAuthenticated) {
- //TODO action: ask model list of logged users
- int nusr = 5;
- drawLoggedUsersPanel(nusr);
- renderNewPanel(logUsrPanel);
- currentPanel = LOGUSR;
- } else {
- Window.alert("You must be logged to see online users!");
- }
- }
- };
- Command gameStateCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else if (isAuthenticated) {
- //TODO action: ask model game state
- drawStatePanel();
- renderNewPanel(statePanel);
- currentPanel = STATE;
- } else {
- Window.alert("You must be logged to see game state!");
- }
- }
- };
- Command showInfoCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else if (isAuthenticated) {
- //TODO action: ask model player's profile info
- drawProfilePanel();
- renderNewPanel(profilePanel);
- currentPanel = PROFILE;
- } else {
- Window.alert("You must be logged to see your profile!");
- }
- }
- };
- Command logOutCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else if (isAuthenticated) {
- Window.alert("LOG OUT!");
- isAuthenticated = false;
- drawLoginPanel();
- renderNewPanel(loginPanel);
- currentPanel = LOGIN;
- } else {
- Window.alert("You must be logged to log out!");
- }
- }
- };
- Command logInCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else if (isAuthenticated) {
- Window.alert("You are already logged!");
- } else {
- drawLoginPanel();
- renderNewPanel(loginPanel);
- currentPanel = LOGIN;
- }
- }
- };
- Command rulesCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else {
- drawHelpPanel();
- renderNewPanel(helpPanel);
- currentPanel = HELP;
- }
- }
- };
- Command aboutCmd = new Command() {
- public void execute() {
- if (isPlaying) {
- Window.alert("You are playing a game!");
- } else {
- drawAboutPanel();
- renderNewPanel(aboutPanel);
- currentPanel = ABOUT;
- }
- }
- };
- // Definition of menu and menu items
- menutop.addStyleName("menuItem");
- MenuBar gameMenu = new MenuBar(true);
- MenuItem newGame = new MenuItem("New Game", newGameCmd);
- MenuItem joinGame = new MenuItem("Join Game", joinGameCmd);
- MenuItem leaveGame = new MenuItem("Leave Game", leaveGameCmd);
- MenuItem watchGame = new MenuItem("Watch Game", watchGameCmd);
- gameMenu.addItem(newGame);
- gameMenu.addItem(joinGame);
- gameMenu.addItem(leaveGame);
- gameMenu.addItem(watchGame);
- gameMenu.addStyleName("menuItem");
- menutop.addItem("Game", gameMenu);
- MenuBar statMenu = new MenuBar(true);
- MenuItem showTop = new MenuItem("Top 10 players", showTopCmd);
- MenuItem showUsr = new MenuItem("Logged Users", showUsrCmd);
- MenuItem showState = new MenuItem("Game State", gameStateCmd);
- statMenu.addItem(showTop);
- statMenu.addItem(showUsr);
- statMenu.addItem(showState);
- statMenu.addStyleName("menuItem");
- menutop.addItem("Stats", statMenu);
- MenuBar profMenu = new MenuBar(true);
- MenuItem showInfo = new MenuItem("Show Profile Info", showInfoCmd);
- MenuItem logOut = new MenuItem("Logout", logOutCmd);
- MenuItem logIn = new MenuItem("Login", logInCmd);
- profMenu.addItem(showInfo);
- profMenu.addItem(logOut);
- profMenu.addItem(logIn);
- profMenu.addStyleName("menuItem");
- menutop.addItem("Profile", profMenu);
- MenuBar helpMenu = new MenuBar(true);
- MenuItem rules = new MenuItem("Game Rules", rulesCmd);
- MenuItem about = new MenuItem("About", aboutCmd);
- helpMenu.addItem(rules);
- helpMenu.addItem(about);
- helpMenu.addStyleName("menuItem");
- menutop.addItem("Help", helpMenu);
- }
- private void drawChatPanel() {
- final Label title = new Label("CHAT");
- chatPanel.add(title);
- chatPanel.addStyleName("chatPanel");
- chatPanel.setPixelSize(chatW, Window.getClientHeight()-menuH-marginSize);
- }
- private void drawLoginPanel() {
- final Grid gr = new Grid(3,2);
- final Label loginLab = new Label("Please login to play Hearts!");
- final Label userLab = new Label("User:");
- final Label passLab = new Label("Password:");
- final TextBox userField = new TextBox();
- final PasswordTextBox passField = new PasswordTextBox();
- final Button loginButton = new Button("Login");
- loginButton.addStyleName("button");
- loginButton.setFocus(true);
- loginLab.addStyleName("title");
- gr.setWidget(0,0, userLab);
- gr.setWidget(0,1, userField);
- gr.setWidget(1,0, passLab);
- gr.setWidget(1,1, passField);
- gr.setWidget(2,1, loginButton);
- loginPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- loginPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- loginPanel.add(loginLab);
- loginPanel.add(gr);
- loginButton.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- checkAuthentication(userField, passField);
- }
- });
- passField.addKeyUpHandler(new KeyUpHandler() {
- public void onKeyUp(KeyUpEvent event) {
- if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
- checkAuthentication(userField, passField);
- }
- }
- });
- }
- private void checkAuthentication(TextBox user,
- PasswordTextBox pass) {
- //TODO: connect to server and check if user,pass are ok
- isAuthenticated = true;
- user.setText("");
- pass.setText("");
- drawWelcomePanel();
- renderNewPanel(welcomePanel);
- currentPanel = WELCOME;
- }
- private void drawWelcomePanel() {
- Label welcome = new Label("WELCOME TO HEARTS GAME:");
- Label welcome2 = new Label("ENJOY!!");
- welcome.addStyleName("title");
- welcome2.addStyleName("title");
- welcomePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- welcomePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- welcomePanel.add(welcome);
- welcomePanel.add(welcome2);
- }
- private void drawTopScoresPanel() {
- Grid gr = new Grid(11,5);
- Label pos = new Label("Position");
- Label name = new Label("Username");
- Label played = new Label("Played Games");
- Label won = new Label("Won Games");
- Label score = new Label("Score");
- gr.setWidget(0, 0, pos);
- gr.setWidget(0,1, name);
- gr.setWidget(0,2, played);
- gr.setWidget(0,3, won);
- gr.setWidget(0,4, score);
- for(int i=1;i<=10;i++){ gr.setWidget(i, 0, new Label(Integer.toString(i))); }
- gr.setSize("700px", "500px");
- gr.addStyleName("table-center");
- gr.setCellSpacing(3);
- Label title = new Label("TOP SCORES");
- title.addStyleName("title");
- topscorePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- topscorePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- topscorePanel.add(title);
- topscorePanel.add(gr);
- }
- private void drawLoggedUsersPanel(int n_usr) {
- Grid gr = new Grid(n_usr,3);
- Label name = new Label("Username");
- Label state = new Label("User State");
- Label score = new Label("Score");
- gr.setWidget(0,0, name);
- gr.setWidget(0,1, state);
- gr.setWidget(0,2, score);
- //for(int i=1;i<n_usr;i++){ gr.setWidget(i, 0, new Label()); } //write user infoin the grid
- gr.setSize("400px", Integer.toString(n_usr*50)+"px");
- gr.addStyleName("table-center");
- gr.setCellSpacing(3);
- gr.addStyleName("grid");
- Label title = new Label("USERS ONLINE");
- title.addStyleName("title");
- logUsrPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- logUsrPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- logUsrPanel.add(title);
- logUsrPanel.add(gr);
- }
- private void drawProfilePanel() {
- Grid gr = new Grid(5,2);
- Label name = new Label("Username");
- Label state = new Label("User State");
- Label played = new Label("Played Games");
- Label won = new Label("Won Games");
- Label score = new Label("Score");
- gr.setWidget(0,0, name);
- gr.setWidget(1,0, state);
- gr.setWidget(2,0, played);
- gr.setWidget(3,0, won);
- gr.setWidget(4,0, score);
- //for(int i=1;i<n_usr;i++){ gr.setWidget(i, 0, new Label()); } //write user info in the grid
- gr.setSize("300px", "400px");
- gr.addStyleName("table-center");
- gr.setCellSpacing(3);
- gr.addStyleName("grid");
- Label title = new Label("PROFILE");
- title.addStyleName("title");
- profilePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- profilePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- profilePanel.add(title);
- profilePanel.add(gr);
- }
- private void drawHelpPanel() {
- TextArea text = new TextArea();
- text.setSize("500px", "400px");
- text.setText("Testo di esempio per provare se funziona.\nA capo\nprova\nHELP sul gioco");
- text.addStyleName("gwt-TextArea-readonly");
- Label title = new Label("HELP");
- title.addStyleName("title");
- helpPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- helpPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- helpPanel.add(title);
- helpPanel.add(text);
- }
- private void drawAboutPanel() {
- TextArea text = new TextArea();
- text.setSize("500px", "400px");
- text.setText("Testo di esempio per provare se funziona.\nA capo\nprova\nINFO about the developers");
- text.addStyleName("gwt-TextArea-readonly");
- Label title = new Label("ABOUT");
- title.addStyleName("title");
- aboutPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- aboutPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- aboutPanel.add(title);
- aboutPanel.add(text);
- }
- private void drawStatePanel() {
- Grid gr = new Grid(4,2);
- Label onlineUsr = new Label("Number of Logged Users");
- Label playingUsr = new Label("Number of Playing Users");
- Label createdTbl = new Label("Number of Created Tables");
- Label playingTbl = new Label("Number of Started Tables");
- gr.setWidget(0, 0, onlineUsr);
- gr.setWidget(1, 0, playingUsr);
- gr.setWidget(2, 0, createdTbl);
- gr.setWidget(3, 0, playingTbl);
- gr.setSize("600px", "300px");
- gr.addStyleName("table-center");
- gr.setCellSpacing(3);
- gr.addStyleName("grid");
- Label title = new Label("GAME STATE");
- title.addStyleName("title");
- statePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- statePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- statePanel.add(title);
- statePanel.add(gr);
- }
- @SuppressWarnings("deprecation")
- private void drawGamePanel(){
- gamePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- gamePanel.setPixelSize(Window.getClientWidth()-chatW-marginSize,Window.getClientHeight()-menuH-marginSize);
- gamePanel.addStyleName("game");
- VerticalPanel vPanel = new VerticalPanel();
- vPanel.setPixelSize(Window.getClientWidth()-chatW-marginSize,200);
- final Grid gr = new Grid(1,nCard);
- gr.setPixelSize(cardW*nCard, cardH);
- for (int i=0;i<nCard;i++){
- gr.getCellFormatter().setStyleName(0, i, "card");
- DOM.setStyleAttribute(gr.getCellFormatter().getElement(0, i),
- "border", "1px solid #000");
- }
- Label plName = new Label("Logged User"); //TODO: get player name from the model
- vPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- vPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- vPanel.add(gr);
- vPanel.add(plName);
- gamePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- gamePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- gamePanel.add(vPanel,DockPanel.SOUTH);
- Label pl2 = new Label("Player2");
- Label pl3 = new Label("Player3");
- Label pl4 = new Label("Player4");
- final SimplePanel card1 = new SimplePanel(); card1.setPixelSize(cardW, cardH); card1.addStyleName("card");
- final SimplePanel card2 = new SimplePanel(); card2.setPixelSize(cardW, cardH); card2.addStyleName("card");
- final SimplePanel card3 = new SimplePanel(); card3.setPixelSize(cardW, cardH); card3.addStyleName("card");
- final SimplePanel card4 = new SimplePanel(); card4.setPixelSize(cardW, cardH); card4.addStyleName("card");
- gamePanel.add(pl2, DockPanel.WEST);
- gamePanel.setCellVerticalAlignment(pl2, HasVerticalAlignment.ALIGN_MIDDLE);
- gamePanel.setCellHorizontalAlignment(pl2, HasHorizontalAlignment.ALIGN_CENTER);
- gamePanel.add(pl4, DockPanel.EAST);
- gamePanel.setCellVerticalAlignment(pl4, HasVerticalAlignment.ALIGN_MIDDLE);
- gamePanel.setCellHorizontalAlignment(pl4, HasHorizontalAlignment.ALIGN_CENTER);
- gamePanel.add(pl3, DockPanel.NORTH);
- gamePanel.setCellVerticalAlignment(pl3, HasVerticalAlignment.ALIGN_MIDDLE);
- gamePanel.setCellHorizontalAlignment(pl3, HasHorizontalAlignment.ALIGN_CENTER);
- gamePanel.add(card1, DockPanel.SOUTH);
- gamePanel.setCellVerticalAlignment(card1, HasVerticalAlignment.ALIGN_BOTTOM);
- gamePanel.setCellHorizontalAlignment(card1, HasHorizontalAlignment.ALIGN_CENTER);
- gamePanel.add(card2, DockPanel.WEST);
- gamePanel.setCellVerticalAlignment(card2, HasVerticalAlignment.ALIGN_BOTTOM);
- gamePanel.setCellHorizontalAlignment(card2, HasHorizontalAlignment.ALIGN_CENTER);
- gamePanel.add(card4, DockPanel.EAST);
- gamePanel.setCellVerticalAlignment(card4, HasVerticalAlignment.ALIGN_BOTTOM);
- gamePanel.setCellHorizontalAlignment(card4, HasHorizontalAlignment.ALIGN_CENTER);
- gamePanel.add(card3, DockPanel.NORTH);
- gamePanel.setCellHorizontalAlignment(card3, HasHorizontalAlignment.ALIGN_CENTER);
- gr.addTableListener(new TableListener(){
- @Override
- public void onCellClicked(SourcesTableEvents sender, int row, int cell){
- DOM.setStyleAttribute(((Grid) sender).getCellFormatter().getElement(row, cell),
- "border", "1px solid #f00");
- for (int i=0;i<nCard;i++){
- if (i!=cell) {
- DOM.setStyleAttribute(((Grid) sender).getCellFormatter().getElement(row, i),
- "border", "1px solid #000");
- }
- }
- controller.playACard("pietro", "aCard", "aTable");
- // TODO: mostra in card1 la carta selezionata
- System.out.println("scelta carta "+cell);
- }
- });
- }
- private void drawNewGamePanel(){
- Grid gr = new Grid(1,2);
- Label nbotLbl = new Label("Select the namber of authomatic players (bot):");
- final ListBox nbotList = new ListBox();
- nbotList.addItem("None");
- nbotList.addItem("One");
- nbotList.addItem("Two");
- nbotList.addItem("Three");
- nbotList.addChangeHandler(new ChangeHandler(){
- @Override
- public void onChange(ChangeEvent event) {
- nbot = nbotList.getSelectedIndex();
- }
- });
- gr.setWidget(0, 0, nbotLbl);
- gr.setWidget(0, 1, nbotList);
- gr.addStyleName("table-center");
- gr.setCellSpacing(3);
- //gr.addStyleName("grid");
- Label title = new Label("CREATE NEW TABLE");
- title.addStyleName("title");
- Button button = new Button("Create");
- newGamePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- newGamePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- newGamePanel.add(title);
- newGamePanel.add(gr);
- newGamePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
- newGamePanel.add(button);
- button.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- String[] ai = new String[nbot];
- for (int i=0;i<nbot;i++){ ai[i] = "a"; }
- String user = "mycol";
- controller.createATable(user, nbot, ai);
- drawGamePanel();
- renderNewPanel(gamePanel);
- currentPanel = PLAY_GAME;
- isPlaying = true;
- }
- });
- }
- /* alla fine della partita: mostra punteggi e chiede se vuoi ricominciare */
- private void drawGameEndPanel(){
- isPlaying = false;
- Grid gr = new Grid(2, 5);
- Label pl1 = new Label("Player 1");
- Label pl2 = new Label("Player 2");
- Label pl3 = new Label("Player 3");
- Label pl4 = new Label("Player 4");
- Label name = new Label("Username");
- Label score = new Label("Score");
- gr.setWidget(0, 0, name);
- gr.setWidget(0, 1, score);
- gr.setWidget(1, 0, pl1);
- gr.setWidget(2, 0, pl2);
- gr.setWidget(3, 0, pl3);
- gr.setWidget(4, 0, pl4);
- gr.addStyleName("table-center");
- gr.setCellSpacing(3);
- Label title = new Label("GAME FINISHED");
- title.addStyleName("title");
- Button button = new Button("Play Again");
- gameEndPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- gameEndPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- gameEndPanel.add(title);
- gameEndPanel.add(gr);
- gameEndPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
- gameEndPanel.add(button);
- button.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- drawGamePanel();
- renderNewPanel(gamePanel);
- currentPanel = PLAY_GAME;
- isPlaying = true;
- }
- });
- }
- private void drawWTableListPanel(int nTable){
- NTable = nTable;
- Grid gr = new Grid(nTable+1, 3);
- Label idL = new Label("Table ID");
- Label botL = new Label("Bot Number");
- Label freeL = new Label("Number of free spots");
- final String id[] = new String[nTable];
- int nbot[] = new int[nTable];
- int free[] = new int[nTable];
- Button button = new Button("Watch");
- final RadioButton rb[] = new RadioButton[nTable];
- gr.setWidget(0, 0, idL);
- gr.setWidget(0, 1, botL);
- gr.setWidget(0, 2, freeL);
- for (int i=0;i<nTable;i++){
- //TODO: get table info from model
- id[i] = "id";
- nbot[i] = 0;
- free[i] = 1;
- rb[i] = new RadioButton("radioGroup",id[i]);
- gr.setWidget(i+1, 0, rb[i]);
- gr.setWidget(i+1, 1, new Label(Integer.toString(nbot[i])));
- gr.setWidget(i+1, 2, new Label(Integer.toString(free[i])));
- }
- gr.setPixelSize(500, nTable*50);
- gr.addStyleName("table-center");
- gr.setCellSpacing(3);
- Label title = new Label("SELECT A TABLE:");
- title.addStyleName("title");
- wTableListPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- wTableListPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- wTableListPanel.add(title);
- wTableListPanel.add(gr);
- wTableListPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
- wTableListPanel.add(button);
- button.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- int tableid = -1;
- for (int i=0;i<NTable;i++){
- if (rb[i].getValue()) {
- tableid = i;
- break;
- }
- }
- if (tableid == -1) {
- Window.alert("Select a table!!");
- } else {
- System.out.println("index = "+tableid+" ID ="+id[tableid]);
- drawWatchGamePanel();
- renderNewPanel(watchGamePanel);
- currentPanel = WATCH_GAME;
- }
- }
- });
- }
- private void drawPTableListPanel(int nTable){
- NTable = nTable;
- Grid gr = new Grid(nTable+1, 3);
- Label idL = new Label("Table ID");
- Label botL = new Label("Bot Number");
- Label freeL = new Label("Number of free spots");
- final String id[] = new String[nTable];
- int nbot[] = new int[nTable];
- int free[] = new int[nTable];
- Button button = new Button("Play");
- final RadioButton rb[] = new RadioButton[nTable];
- gr.setWidget(0, 0, idL);
- gr.setWidget(0, 1, botL);
- gr.setWidget(0, 2, freeL);
- for (int i=0;i<nTable;i++){
- //TODO: get table info from model
- id[i] = "tavolo";
- nbot[i] = 0;
- free[i] = 1;
- rb[i] = new RadioButton("radioGroup",id[i]);
- gr.setWidget(i+1, 0, rb[i]);
- gr.setWidget(i+1, 1, new Label(Integer.toString(nbot[i])));
- gr.setWidget(i+1, 2, new Label(Integer.toString(free[i])));
- }
- gr.setPixelSize(500, nTable*50);
- gr.addStyleName("table-center");
- gr.setCellSpacing(3);
- Label title = new Label("SELECT A TABLE:");
- title.addStyleName("title");
- pTableListPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- pTableListPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
- pTableListPanel.add(title);
- pTableListPanel.add(gr);
- pTableListPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
- pTableListPanel.add(button);
- button.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- int tableid = -1;
- for (int i=0;i<NTable;i++){
- if (rb[i].getValue()) {
- tableid = i;
- break;
- }
- }
- if (tableid == -1) {
- Window.alert("Select a table!!");
- } else {
- System.out.println("index = "+tableid+" ID ="+id[tableid]);
- controller.joinATable("pietro", id[tableid]);
- drawGamePanel();
- renderNewPanel(gamePanel);
- currentPanel = PLAY_GAME;
- isPlaying = true;
- }
- }
- });
- }
- private void drawWatchGamePanel() {
- watchGamePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- watchGamePanel.setPixelSize(Window.getClientWidth()-chatW-marginSize,Window.getClientHeight()-menuH-marginSize);
- watchGamePanel.addStyleName("game");
- Label pl1 = new Label("Player1");
- Label pl2 = new Label("Player2");
- Label pl3 = new Label("Player3");
- Label pl4 = new Label("Player4");
- SimplePanel card1 = new SimplePanel(); card1.setPixelSize(cardW, cardH); card1.addStyleName("card");
- SimplePanel card2 = new SimplePanel(); card2.setPixelSize(cardW, cardH); card2.addStyleName("card");
- SimplePanel card3 = new SimplePanel(); card3.setPixelSize(cardW, cardH); card3.addStyleName("card");
- SimplePanel card4 = new SimplePanel(); card4.setPixelSize(cardW, cardH); card4.addStyleName("card");
- watchGamePanel.add(pl1,DockPanel.SOUTH);
- watchGamePanel.setCellVerticalAlignment(pl1, HasVerticalAlignment.ALIGN_MIDDLE);
- watchGamePanel.setCellHorizontalAlignment(pl1, HasHorizontalAlignment.ALIGN_CENTER);
- watchGamePanel.add(pl2, DockPanel.WEST);
- watchGamePanel.setCellVerticalAlignment(pl2, HasVerticalAlignment.ALIGN_MIDDLE);
- watchGamePanel.setCellHorizontalAlignment(pl2, HasHorizontalAlignment.ALIGN_CENTER);
- watchGamePanel.add(pl4, DockPanel.EAST);
- watchGamePanel.setCellVerticalAlignment(pl4, HasVerticalAlignment.ALIGN_MIDDLE);
- watchGamePanel.setCellHorizontalAlignment(pl4, HasHorizontalAlignment.ALIGN_CENTER);
- watchGamePanel.add(pl3, DockPanel.NORTH);
- watchGamePanel.setCellVerticalAlignment(pl3, HasVerticalAlignment.ALIGN_MIDDLE);
- watchGamePanel.setCellHorizontalAlignment(pl3, HasHorizontalAlignment.ALIGN_CENTER);
- watchGamePanel.add(card1, DockPanel.SOUTH);
- watchGamePanel.setCellVerticalAlignment(card1, HasVerticalAlignment.ALIGN_BOTTOM);
- watchGamePanel.setCellHorizontalAlignment(card1, HasHorizontalAlignment.ALIGN_CENTER);
- watchGamePanel.add(card2, DockPanel.WEST);
- watchGamePanel.setCellVerticalAlignment(card2, HasVerticalAlignment.ALIGN_BOTTOM);
- watchGamePanel.setCellHorizontalAlignment(card2, HasHorizontalAlignment.ALIGN_CENTER);
- watchGamePanel.add(card4, DockPanel.EAST);
- watchGamePanel.setCellVerticalAlignment(card4, HasVerticalAlignment.ALIGN_BOTTOM);
- watchGamePanel.setCellHorizontalAlignment(card4, HasHorizontalAlignment.ALIGN_CENTER);
- watchGamePanel.add(card3, DockPanel.NORTH);
- watchGamePanel.setCellHorizontalAlignment(card3, HasHorizontalAlignment.ALIGN_CENTER);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement