开发者

What .NET Framework do I use to create a board game?

开发者 https://www.devze.com 2023-01-25 19:49 出处:网络
I\'d like to use .NET to create a开发者_开发技巧 board game. I plan to implement a basic board game (something similar to chess, but less complicated) as graduate AI term project.

I'd like to use .NET to create a开发者_开发技巧 board game.

  1. I plan to implement a basic board game (something similar to chess, but less complicated) as graduate AI term project.
  2. The GUI is not very important (it does not have to be easy to use, intuitive, animated etc), but if it doesn't add too much complication, then I want to add a better GUI.
  3. The main objective is to submit as a term project, but I want to share it with the community so that others can also play. Deployment should make it easy to share the game with Windows workstations.

What framework do you guys suggest for such a project? I know this topic, but it's not what I'm looking for.


If you said that the GUI is not important for now then you do not need any game framework which will only slow down you in making your game. Windows forms is more than enough for you.

You should focus on implementing your game engine assembly. This assembly should have an open communication protocol and should NOT be aware of any GUI. In other words, you should decouple your engine from the GUI.

Later, you and others could create a GUI in theirs language of choice which will be using your protocol to communicate and display the position of your game.

Good luck!


If you want to do something in .NET related to game development, your best way would be to use the .NET XNA Framework.

As far as making the gameboard, you'll need to learn how to program video games; there's really no 'built in' drag-and-drop create-a-board-game framework.

Looks like someone has a tutorial on how to create a 'board based' game in XNA 4.0.


If you're making a board game like chess, and you don't really care to use this as a piece in a game programming portfolio, then I'd recommend you simply use a Windows UI framework, like WPF. It is very easy to plug into eventing on such a system, and you'll get to use the integrated UI layout designer in Visual Studio. Just make a grid of buttons (using images for their content)/other controls. This will allow you to spend a ton less time on how it looks, and graphics/UI-related programming tasks, and quickly get you to programming the game logic.

If you are using this project for a game programming portfolio, I agree with George - use XNA. If you do this, enlist an artist friend to take care of the UI design and graphical content for you (but not the graphical programming, of course).

You can also have the best of both worlds. You can make your game logic UI-agnostic, and program a better UI later. Postal chess is proof of this.


WinForms is the easiest to use if you're just getting started. That said, if your primary interest is in testing the logic, you might even start with a Console application and wait to develop the UI until you have a stable notion of how the game will function. I wouldn't recommend XNA for your first pass. If you really want to refine it into a polished game, you can always build an XNA interface on top of your logic later.

The key thing here is to design your application in such a way that the logic and the UI are decoupled. If you do this properly, then you're free to use a range of different UIs, perhaps starting with a Console, working up to a 'debug' style WinForms app, with a crude interface designed for your consumption, then finally up to a more polished interface for others to play.


Last time I needed a board, I just created a two-dimensional array of user-controls, gave each user control a border, and had their paint method draw anything on the inside of the board. You can have your board user control and your game piece user control be separate objects or the same object, depending on what you are doing. This strategy will take only a few hours to do, and gives you a lot of power. For example, it is easy to add features to recognize things like drag/drop, clicking, etc.

Another way to create a game board is to just use a DataGridView. That's really not the intended use of that class and the code for that will get a little bit ugly, but if you write a wrapper around it it probably won't be too bad.


Personally, I created a Connect4 application that had a bit of AI and used a database backing to "learn" from its mistakes as my Senior project. Some tips of advice though:

  • Don't over complicate things. Don't sit there writing up a whole framework to work for multiple gameboards or strange possible settings (such as adding a 3rd player to the mix).
  • Using a good pattern and language will make things far easier to in testing and debugging (my favorite is WPF using MVVM).

Also, if you do decide to go the route of Connect4, here is how I setup my classes:

C4Board.cs

  • I made it into an immutable object that represented the GameBoard state.
  • C4Board Insert(int col) would return a new GameBoard or throw an custom exception if the column was full.
  • I made it immutable to work with having a "history" List of game states in the view.

GamePlayer.cs - Enumeration (NULL, P1, P2) - Extension Methods that let you change from GamePlayer -> GamePiece

GamePiece.cs - Enumeration (EMPTY, BLACK, RED) - Extension Methods that let you change from GamePiece -> GamePlayer

GameWinner.cs - Enumeration (NONE, P1, P2, TIE)

It's a simple game with simple rules, easy to separate out your logic and add AI, etc. It's much better than trying to come up with a chess game or Go game etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消