Jump to content

Coding challenge


snakey
 Share

Recommended Posts

  • Replies 237
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Ok Snakey, glad you want to give this a try! Here's a good link that helped me alot with learning winsock!

http://devmentor.org/articles/network/Sock...Programming.pdf

csocket? I believe that is MFC. I don't like MFC so I don't use it! MFC tends to call things starting with "C" like CSocket, or CWnd...

But No! you don't need MFC to use winsock!

That link should give you a basic understanding of winsock with TCP protocol... to further help you out after reading that you could look over the source code to my demo project which makes use of winsock!

Its called "Krypt-2-Send" and "Krypt-2-Recieve"... its an encrypted file transfer utility.

K2S_ani.gifK2R_ani.gif

Note: this is coded with dev cpp! so if using that you'll need to link to libws2_32.a in the "lib" folder of the dev cpp directory... goto project->project options, click on parameters tab and click the add library or object button.

It works like this, the person wanting to send a file to someone runs K2S(Krypt-2-Send) and sets up the server with the file to transfer, the port to listen on, and optionally sets a password(it is recommended though that you do use a password because then the file will be encrypted with the password!!) If you don't use a password the file is still encrypted but only with the key specified in the box.

on running K2S it generates a random number between 1-255 to use as the key to encrypt the file along with the password, you can also change it if desired...

when you choose a file to transfer either by pressing the browse button or typing the file path, the recommended buffer size(IN KB) is filled in the box. (you may be wondering why is buffer size important? and why is it changeable?) because the larger the buffer size the LESS read/write operations are done both server/client side!

this affects download speed! only because read/write operations are slow, so for example, if you were transferring a 100MB file, if you made the buffer size 1KB, there would have to be 102400 read operations on the server side(K2S) and 102400 write operations on client side(K2R)

that would considerably slow down the download! (not download speed but, how long it would take to recieve the file)

K2S minimizes to the tray for convenience.

If you made the buffer 1024 KB (1MB) then there would only be 100 read/write's and the difference is great! So I think maybe that's a reason why most file transfer programs like built into instant messengers take longer to transfer files than this because they use a fixed small buffer size! ;)

also this determines how often the progress bar will show progress. I think 1% of the file is good enough for a fast transfer but feel free to increase as desired...

The person wanting to recieve the file, they just run K2R, type in the host and port of the server hosting the file to transfer! and password if needed and click download file!

host and port must be in this format: "host:port"

"host" does not have to be a host name it can be an ip address to... for example (127.0.0.1:27015) and (localhost:27015)

are both valid!

I have Krypt-2-Send on my computer running right now in my system tray, listening on port 27015. Someone download Krypt-2-Recieve and try to download the file from me!! :P

use "popeax.com:27015" as the host:port!

and password is "hak5live"

If anyone successfully downloads the file post here and say what the file name is :)

binary:

http://popeax.com/downloads/Krypt2Recieve.rar

http://popeax.com/downloads/Krypt2Send.rar

source:

http://popeax.com/downloads/Krypt2RecieveSRC.rar

http://popeax.com/downloads/Krypt2SendSRC.rar

It should work even if multiple people try to download at one time! though the percentage wont be shown correctly on the server!

Does anyone know how to calculate multiple percentages into one? for example like how firefox does it! when you download more than one file, along with showing you the percentage of each file, it shows you the total complete percentage of all the files your downloading! Thats what im trying to figure out...

Also files over 2GB (about this size) wont transfer, because I haven't figured out how to determine a file's size if its over this 2 billion bytes/ Im thinking this is because 4 bytes can't hold a number larger than 2.x billion... So theres gotta be someway to use more bytes to store the file size that I haven't figured out yet...

NOTE: K2S and K2R are still in beta stages and there are some bugs I haven't worked out yet... So keep that in mind it may not work perfectly!

mini tut on source code:

unsigned char microcode[25] = {0x55, 0x8B, 0xEC, 0x8B, 0x45, 0x08, 0x8B, 0x5D, 0x0C, 0x8A,
 0x4D,0x10, 0x30, 0x0C, 0x03, 0x83, 0xFB, 0x00, 0x4B, 0x75, 0xF7, 0xC9, 0xC2, 0x0C, 0x00};
typedef void (CALLBACK* EnKrypt)(void*, DWORD, BYTE);
EnKrypt Krypt = (EnKrypt)&microcode;

that is the encrypt function, it is the same as this:

Krypt proc Buffer:DWORD, BufferSize:DWORD, Key:BYTE

    mov eax, [Buffer]
    mov ebx, [BufferSize]
    mov cl, [Key]

    @@:
    xor byte ptr [eax+ebx], cl

    cmp ebx, 0
    dec ebx
    jne @b

    ret

Krypt endp

the code was originally inside a dll written in MASM32, but I didn't like using loadlibrary and getprocaddress just to use this one function So i had the idea to just extract the raw bytes that make the opcodes, and use the function like that! and since the code is 100% relocatable it works!

I created some classes to make winsock coding a little easier for me, I'll explain how to use this classes in case you'd want to use them...

on the server FileTransfer_S.h contains the server classes

xClient is a client object, one will be created for each client the server is communicating with...

xServer is a server object, only one will be created... this will make the server listen on the desired port...

creating these objects are simple...

you could write:

xClient client[10];
xServer server;

that would create 10 client objects and 1 server object

or you could do

xServer* server = new xServer;

which creates a pointer to an xServer while simultaneously creating an xServer object...

I like doing it that way so I can write server-> instead of server.

with your server object created, to get your server bound and listening on a specified port call it like

if you created a pointer

server->StartServer(port);

if you just created an object

server.StartServer(port);

where "port" is an integer specifying the port to listen on! this is the port the client will connect on

ill add more later, I gotta go right now ;)

Link to comment
Share on other sites

Thanks for the PDF Steve8x, i might as well give it a try, ive played with winsock in the good ol'days of VB6.

But yea ill play around and post what i come up with, Sadly wont be anything exciting since im shit with C (why? cause im slack).

Link to comment
Share on other sites

I really wish you hadn't limited this to C++. I could definitely give you something good in Java. But that's the way the game is played, so I hope Snakey can make something beautiful.

Link to comment
Share on other sites

I really wish you hadn't limited this to C++. I could definitely give you something good in Java. But that's the way the game is played, so I hope Snakey can make something beautiful.

cout << "With a name like cout, you'd think you were a C++ programmer! \n";

I guess you forgot to #include <iostream> lol my attempt at a joke! :lol:

Java is cool, I think I might pick it up! I like the cross-platform aspect of it!

For example I could code a multiplayer game in c++, but only people who run windows would be able to play it, they'd have to run the EXE client!

If I learned Java! I could make a Java client along with the EXE client, so then Linux and Mac people could also play my game! Using the Java version of course! Maybe even through a web browser! I like the idea of that!

So I think I'm going to learn Java as well! And If you coded up something with Java using sockets that would sure give me a head start on it!

SO SINCE NO ONE HAS COMPLETED THE CHALLENGE! I HERBY EXTEND THIS CHALLENGE 1 WEEK(more if you need it cout) AND I HAVE OPENED THE PROGRAMMING LANGUAGE TO JAVA AND ANYTHING ELSE!

So now anyone can enter! No matter what you code in! Go ahead and give it a try!

cout! I'll be looking forward to seeing some Java :)

And heres to a hot cup a joe' to get the codes flowing!

java.jpg

Link to comment
Share on other sites

Well, now you got me all fired up.

First off, I am very interested in getting deeper into C++. The only reason I feel more comfortable with Java right now is because that is currently what my college is using in some of the CS courses I am taking.

Second, I have an extremely simplistic console based chat between a server and client already ready to go. However, I would like to beef it up a tiny bit before I show put it out there. Right now I just have client and server talking to each other, but I would like for different clients to talk to each other through the server. I'll see what I can do. After I get all that set up, I'll probably make a GUI version. Hopefully I can get it done in a week, but we'll see. I have a pretty tight schedule right now.

Also, about the cross-platform stuff, I definitely agree. I mean I can even theoretically write games for my palm pilot now. That makes me happy.

I'll keep you updated.

Link to comment
Share on other sites

Here is my submission - Java tetris.

This app was my school project, I've made it two months ago and back then it was only a single player tetris. I had planned to make it multiplayer, but having very little time I had to dump the idea. Fortunately, some of the code was already prepared for two players, so expanding it wasn't very hard. Right now it features both local two player game and network game over IP. The network code is far from being optimal, so I suggest playing over LAN :P

Screenshots confirming cross-platform multiplay:

post-10286-1217859407_thumb.jpg post-10286-1217859420_thumb.jpg

Here is the source and the binary in the form of a NetBeans project (the binary is in the /dist folder).

JTetris.zip

Basic info:

Controls for player 1 (on the left) are WSAD for movement, G and J for rotation and H for holding the piece.

For player 2 it's arrows and numpad 123.

When setting up the network game you don't have to type anything in the address field when hosting.

The entire game is probably very buggy, it haven't been tested thoroughly, so I'll be flattered if you actually take time to play it and point out some errors :)

As for the code, it is ugly, there are no comments and I had to translate it. :P

This was (and still is :P) my very first Java program, and I was actually learning very basic stuff while writing it, so look/learn/copy it at your own risk.

Finally, mad props to my friend Gumer for doing the epic pixel art blocks and background. :D

Link to comment
Share on other sites

Here is my submission - Java tetris.

This app was my school project, I've made it two months ago and back then it was only a single player tetris. I had planned to make it multiplayer, but having very little time I had to dump the idea. Fortunately, some of the code was already prepared for two players, so expanding it wasn't very hard. Right now it features both local two player game and network game over IP. The network code is far from being optimal, so I suggest playing over LAN :P

Screenshots confirming cross-platform multiplay:

post-10286-1217859407_thumb.jpg post-10286-1217859420_thumb.jpg

Here is the source and the binary in the form of a NetBeans project (the binary is in the /dist folder).

JTetris.zip

Basic info:

Controls for player 1 (on the left) are WSAD for movement, G and J for rotation and H for holding the piece.

For player 2 it's arrows and numpad 123.

When setting up the network game you don't have to type anything in the address field when hosting.

The entire game is probably very buggy, it haven't been tested thoroughly, so I'll be flattered if you actually take time to play it and point out some errors :)

As for the code, it is ugly, there are no comments and I had to translate it. :P

This was (and still is :P) my very first Java program, and I was actually learning very basic stuff while writing it, so look/learn/copy it at your own risk.

Finally, mad props to my friend Gumer for doing the epic pixel art blocks and background. :D

Emeryth you are the winner of my challenge not only because no one else posted an entry but because you put together a nice java tetris app! congrats! you make the next challenge!!! ;)

I have tested over my local network and it seems to work fine! although I don't like how it freezes when you click host game, while it waits for another player... well it can be fixed! but anyway still a nice program! thanks I'll try to learn from it as much I can and maybe I'll make a similar game in java :)

Link to comment
Share on other sites

  • 2 weeks later...

Sorry for the delay, guys.

Here is the next challenge:

Languages: free for all!

Time: until 01.10.2008

The challenge: a simple hack n' slash RPG game

This one requires an idea and a bit of work instead of some particular knowledge.

The goal is to make the simplest and most (re)playable game.

No plot (except for a goal of some kind), just a randomly generated dungeon and the player character.

Graphics are not required.

Bonus points for non-fantasy setting (like cyberpunk, steampunk, post-apocalyptic etc.).

That is all, have fun, I hope it's not too easy/hard.

Link to comment
Share on other sites

hey a challenge i can do :). games are my speciality :)

judging from the 1.10.08 date you have set im guessing i have until oct1 to finish this game up huh?

i think ill go with a futuristic/fantasy setting. ive got a small backstory already. though ill probably just use the goal. ill have to start designing enemies and rooms asap so i can set up the random room generator.

if ive got the due date wrong let me know cause i dont have time this week to work on anything.

since im still learning c++ and dont know enough to really make a good game ill have to resort to blitz basic once more for a txt rpg.

Link to comment
Share on other sites

Of course I mean October! You have a month to do it, and you can always ask for more time.

One idea for a very simple game is to make the 'dungeon' a simple grid of rooms about 10x10. Like in MUDs you can only move from room to room, and in a room there can be items, monsters, chests, NPCs etc. You don't have to create your own sophisticated 2d/3d environment engine, and it doesn't have to be a rougelike game (of course I'm not stopping you, but developing ADOM, for example, took quite a long time :P).

RogueHart, I suggest that you do it in C++ regardless, after all, the idea behind those challenges is to learn!

Link to comment
Share on other sites

Of course I mean October! You have a month to do it, and you can always ask for more time.

One idea for a very simple game is to make the 'dungeon' a simple grid of rooms about 10x10. Like in MUDs you can only move from room to room, and in a room there can be items, monsters, chests, NPCs etc. You don't have to create your own sophisticated 2d/3d environment engine, and it doesn't have to be a rougelike game (of course I'm not stopping you, but developing ADOM, for example, took quite a long time :P).

RogueHart, I suggest that you do it in C++ regardless, after all, the idea behind those challenges is to learn!

i would like to do it in c++ but i barely know enough to make a txt adventure.

i may do vb since it uses graphics.

as far as the rooms are concerned i was thinking something more like a random generated dungeon. i build about 30 or so rooms. you go through about 20 per play. the rooms are chosen at random via a random number generator and then placed in random order (other than the first and last rooms of course.) that way you have almost no chance of playing the same game twice.

then again. considering i have a book on c++ and a book specializing in building game engines. i may still use c++

Link to comment
Share on other sites

hmmmm would a txt adventure that uses a few rpg elements? including leveling, item, weapon, and maybe a magic system?

i dont plan to make one. but if it comes right down to it and i havent been able to complete a game for one reason or another then i can easily and quickly code a txt adventure/rpg in a day or so.

edit

sorry for the double post

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...