Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For my java class we have to create a Networked game, and the project must use M

ID: 3856839 • Letter: F

Question

For my java class we have to create a Networked game, and the project must use MVC and gameNet to create a networked program(game?) Some recommandations have been a black jack card game, tetris, or chess game. I was wondering if you could make some recommandations on a good, not so difficult networked game to do and answer the questions below about your recommandation.

Thank You.

For this question I would like you to give a high level view of what you are going to do on your Networked Game project. In the computer industry, a design document is often written before programming starts on a project. Consider this a high level design document for your networked game. You aren't "married" to this if you run into issues, but I do want you to start thinking about what you want to do for JH7.

Your inputs are a bit free form. You can enter in text in the box below, or you can create other documents (Word, Pictures, etc) that you can upload below as an attachment to this assignment.

I want you to address things like:

What is in your "MyGameInput" class.

What is in your "MyGameOutput" class.

Maybe some simple pseudo code for your MyGame class.

What special things will you be doing in your MyUserInterface class. In particular, define the interface routines needed in MyUserInterface.java that make this game networked.

An overview of what your game will be doing and look like to the user.

Your Data Structures ... i.e. Definition of Any Data that is stored

Anything else of interest.

Id preferably like to make a tetris type of game.

Explanation / Answer

Since my allotted time is 2 hours.. I written Tictactoe MVC network sample example... please look into it...

import java.io.PrintWriter;

import java.net.Socket;

public class Model {

public JFrame frame = new JFrame("Tic Tac Toe");

public JLabel msgLabel = new JLabel("");

public BoardSquare[] gameBoard = new BoardSquare[9];

public BoardSquare curr_square;

public static int PORT = 8901;

public Socket socket_conn;

public BufferedReader in;

public PrintWriter out;

public Model(String server_addr) throws Exception {

// creating socket

socket_conn = new Socket(server_addr, PORT);

in = new BufferedReader(new InputStreamReader(

socket_conn.getInputStream()));

out = new PrintWriter(socket_conn.getOutputStream(), true);

msgLabel.setBackground(Color.lightGray);

frame.getContentPane().add(msgLabel, "South");

JPanel gameboard_panel = new JPanel();

gameboard_panel.setBackground(Color.black);

gameboard_panel.setLayout(new GridLayout(3, 3, 2, 2));

for (int i = 0; i < gameBoard.length; i++) {

final int j = i;

gameBoard[i] = new BoardSquare();

gameBoard[i].addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent e) {

curr_square = gameBoard[j];

out.println("MOVE " + j);}});

gameboard_panel.add(gameBoard[i]);

}

frame.getContentPane().add(gameboard_panel, "Center");

}

}

import java.awt.Color;

import java.awt.GridLayout;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.net.Socket;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

public class View {

public Model model;

public ImageIcon player2Icon;

public ImageIcon player1Icon;

public View(Model model){

model = model;

}

public void startPlay() throws Exception {

String playerResponse;

try {

playerResponse = in.readLine();

if (playerResponse.startsWith("WELCOME")) {

char playerMark = playerResponse.charAt(8);

player1Icon = new ImageIcon(playerMark == 'X' ? "x.gif" : "o.gif");

player2Icon = new ImageIcon(playerMark == 'X' ? "o.gif" : "x.gif");

model.frame.setTitle("Tic Tac Toe - Player " + playerMark);

}

while (true) {

playerResponse = in.readLine();

if (playerResponse.startsWith("VALID_MOVE")) {

model.msgLabel.setText("Valid move");

model.curr_square.setIcon(player1Icon);

model.curr_square.repaint();

} else if (playerResponse.startsWith("OPPONENT_MOVED")) {

int loc = Integer.parseInt(playerResponse.substring(15));

model.gameBoard[loc].setIcon(player2Icon);

model.gameBoard[loc].repaint();

model.msgLabel.setText("Opponent moved, your turn please");

} else if (playerResponse.startsWith("VICTORY")) {

model.msgLabel.setText("You win");

break;

} else if (playerResponse.startsWith("DEFEAT")) {

model.msgLabel.setText("You lose");

break;

} else if (playerResponse.startsWith("TIE")) {

model.msgLabel.setText("You tied");

break;

} else if (playerResponse.startsWith("MESSAGE")) {

model.msgLabel.setText(playerResponse.substring(8));

}

}

out.println("QUIT");

}

finally {

socket_conn.close();

}

}

public boolean wantsToPlayAgain() {

int playerResponse = JOptionPane.showConfirmDialog(model.frame,

"startPlay again?",

"",

JOptionPane.YES_NO_OPTION);

model.frame.dispose();

return playerResponse == JOptionPane.YES_OPTION;

}

static class BoardSquare extends JPanel {

JLabel label = new JLabel((Icon)null);

public BoardSquare() {

setBackground(Color.white);

add(label);

}

public void setIcon(Icon player1Icon) {

label.setIcon(player1Icon);

}

}

}

public class Controller {

public static void main(String args[]) {

public Controller(String server_addr ){

Model model = new Model(server_addr);

View view = new View(model);

}

public void startPlay(){

view.startPlay();

}

while (true) {

String server_addr = (args.length == 0) ? "localhost" : args[1];

Controller client = new Controller(server_addr);

client.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

client.frame.setSize(240, 160);

client.frame.setVisible(true);

client.frame.setResizable(false);

client.startPlay();

if (!client.wantsToPlayAgain()) {

break;

}

}

}

}