-5

As an IT student, I have recieved the task of making a Connect Four game. My task is to code a simple c# web server that listens to http requests so 2 players can play against eachother, one in the c#c form, one in the website.

But I'm confused on how such thing would work. We will have a web client that will just be the design of the game and will get it's behaviour and data out of the c# code. the c# server should use the httpListener, httpListenerrequest and the httpListenerContext classes.

I'm unsure on how to do such thing. any help would be appreciated on how to start this task, as I'm unclear to see to accomplish it.

greetings, Durneztj

Durneztj
  • 11
  • 1
  • 2
  • This question is too broad for the purpose of this site, try to code something before asking http://stackoverflow.com/help/how-to-ask. Also it's something you can easy search "C# webservice tutorial" – jean Mar 16 '15 at 21:05
  • 2
    The best person to ask would be the person who has set you the assignment – Russ Cam Mar 16 '15 at 21:05
  • This may give an idea http://stackoverflow.com/questions/10017564/url-mapping-with-c-sharp-httplistener – EZI Mar 16 '15 at 21:09

1 Answers1

1

You will need six projects

1: winforms - connect 4 client

2: web application - connect 4 client

3: winforms - connect 4 server (for extra points make this a windows service or web api project)

4: class library - connect four game logic and models

5: test project for 4

6: class lib - client code for connecting to 3

do the class lib first. put all the models and game logic in here expose a single class with methods for starting a game, making a move and working out if someone won. make an interface for this class.

write tests in the test project to make sure you have the basic game logic right, you can start a game and make moves etc it all works

then move on to the server. this should refernce the class lib and just handle the http listening and response etc. you'll need to put your connection handling and deserializing of the model objects in here, but essentially you are just exposing the same methods as the class lib

now do six. reference the model class lib again and inherit the same interface, but this time instead of starting a game or making a move with teh game logic, you connect to the server and call its start and game, make a move etc. you will again have to deserialize the response into model objects.

now do 1 and 2. these will both be similar in that they will reference the models class lib and the client code lib. you will haev to present the board to the user differntly of course, but when they make a move, start a game etc you will just call the methods in your client class lib, the server will execute the logic and return the result

for extra points use async Task methods ON EVERYTHING

if it doesn't work, write integration tests for your server. these will save you hours of working out whether its the client or the server which is buggy

another extra point tip, use Microsoft unity framework for dependency injection

Ewan
  • 1,261
  • 1
  • 14
  • 25
  • @Ewan you are too fast :) he said `I will try this method`. For ex, I would downvote your question but I appreciate your effort to try to help. – EZI Mar 16 '15 at 22:35