Click here to Skip to main content
13,900,082 members
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 12 Aug 2004

Multiplayer Snake in 3D using C# and Managed DirectX

, 12 Aug 2004
Rate this:
Please Sign up or sign in to vote.
A new version of the old game.

Sample Image - screen.jpg


Probably, everyone knows the game Snake. However, the Snake from this article is a multiplayer version and fully in 3D. It’s written in C# using Managed DirectX. A little knowledge of C# is necessary. And some (Managed) DirectX or other Graphics programming experience would be useful. I advise you, if you haven't already done so, to read Craig Andera's tutorial first.

You’ll need a C# compiler (Visual Studio .NET if possible). And the DirectX 9.0c SDK [Download it from Microsoft.]

For the code to run, you’ll also need a 3D card. But some adjustments in the code would enable it to run on older machines, decreasing its performance.

The Game Class

This is where initialization happens. Also, this is where user input is processed, using the EventKey class (all it does is check if a keystate is changed).

The Player Class

This class processes the input for the movement of one of the players. It holds a collection of Vectors for the trail. It has a Render method that will do the rendering. It also holds a reference to the Level class, the class that implements level functionality: a square array of Booleans so that the snakes can’t move through each other; it also has a couple of predefined levels to make the game a little less boring.

The Intro Class

Here, two Meshes are created for some sort of intro movie.

The Arena Class

This class renders the box in which the snakes move. It also renders the boxes which initially are already occupied by the Level class.

The Plane Class

This is a class I built quite some time ago. It creates a textured box. And allows choosing the sides you want to render.


I do not expect this code to be efficient. A lot of things could’ve been done better and faster. But it works, and when you’ve got nothing to do, this game can be quite fun.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Netherlands Netherlands
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionHow to run without 3D card Pin
Nhilesh B11-Oct-07 18:25
memberNhilesh B11-Oct-07 18:25 
AnswerRe: How to run without 3D card Pin
Member 340188522-Aug-09 13:56
memberMember 340188522-Aug-09 13:56 
GeneralThis is very nice Pin
Mashadow2-Aug-07 17:36
memberMashadow2-Aug-07 17:36 
GeneralSuggestion Pin
DFU2318-Aug-04 11:12
memberDFU2318-Aug-04 11:12 
GeneralMy Experience Pin
PeterK_18-Aug-04 8:33
memberPeterK_18-Aug-04 8:33 
GeneralRe: My Experience Pin
PeterK_18-Aug-04 9:27
memberPeterK_18-Aug-04 9:27 
I tried a few things and the only option that worked was CreateFlags.SoftwareVertexProcessing. HardwareVertexProcessing also causes an InvalidCall exception on my machine.

GeneralRe: My Experience Pin
Cr@zyIv@n18-Aug-04 22:06
memberCr@zyIv@n18-Aug-04 22:06 
GeneralRe: My Experience Pin
Nejat Özsu8-Sep-04 16:10
memberNejat Özsu8-Sep-04 16:10 
GeneralQuestion for the author Pin
hacey28-Jul-05 4:45
memberhacey28-Jul-05 4:45 
GeneralSystem.IO.FileNotFoundException Pin
Chris Sells14-Aug-04 14:23
memberChris Sells14-Aug-04 14:23 
GeneralRe: System.IO.FileNotFoundException Pin
Cr@zyIv@n14-Aug-04 22:08
memberCr@zyIv@n14-Aug-04 22:08 
GeneralRe: System.IO.FileNotFoundException Pin
Chris Sells15-Aug-04 8:05
memberChris Sells15-Aug-04 8:05 
GeneralRe: System.IO.FileNotFoundException Pin
Cr@zyIv@n15-Aug-04 8:42
memberCr@zyIv@n15-Aug-04 8:42 
GeneralRe: System.IO.FileNotFoundException Pin
jmw16-Aug-04 9:59
memberjmw16-Aug-04 9:59 
GeneralRe: System.IO.FileNotFoundException Pin
Cr@zyIv@n16-Aug-04 22:07
memberCr@zyIv@n16-Aug-04 22:07 
GeneralRe: System.IO.FileNotFoundException Pin
FBKK11-Jul-05 11:55
memberFBKK11-Jul-05 11:55 
GeneralRe: System.IO.FileNotFoundException Pin
micr0chip26-Nov-05 11:35
membermicr0chip26-Nov-05 11:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190306.1 | Last Updated 13 Aug 2004
Article Copyright 2004 by Cr@zyIv@n
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid