Programming a Chess Game in C# | Part 1 - Project Setup

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to part one of my C chess tutorial in this tutorial we will program the chess game you see on your screen it handles all the special moves like castling both kingside and queen side it also handles Pawn promotion and capturing on pant when a player manages to Checkmate the opponent and win the game this end screen shows up it displays the winning player and gives the option to either play again or exit the game also handles stale made correctly and other ways the game can end in a draw this includes insufficient material three-fold repetition and the 50 move rule at least to begin with we will develop the game to be played by two human players on the same computer but if there's enough demand for it we could add some computer control players as well all right now that we've seen what the final game will look like let's open up visual studio and get started from here select create a new project search for blank solution and choose this template if it doesn't show up then try changing the language filter to all languages Okay now click next and give your solution and name I'll call mine chess I chose an empty solution because we'll use two different projects for this game first let's add a class library to our solution to do that right click on your solution in the solution Explorer go to add and then new project here we'll pick the C Class Library project template let's call it chess logic for the Target framework I'll be using net 6.0 a newer version should also work just fine an older version however may not support all the features I'll be using we will write all the rules of Chess including how the pieces move inside this chess logic project but we need another project for the user interface this time we'll pick the template called WPF application call it chess UI and then preferably choose net 6.0 or any newer version the chess UI project will contain the user interface for our game it is responsible for showing the game on the screen and handling user input from the players okay let's open the project properties for chess logic and look on the build here you may find a setting called nullable this feature is supposed to help you avoid null reference exceptions but we won't use it so go ahead and disable it for the chess UI project we do exactly the same all right next we can make chess UI the startup project the chess UI project also needs a reference to chess logic so right click on chess UI choose add project reference then check chess logic and hit okay now chess UI knows about Chess logic and it can use all the code inside it perfect let's import the assets for this game we'll put them inside an assets folder in the chess UI project okay here are all the assets we need for the game you can download them from the link in the description we have an image of the board itself two custom cursors an icon and an image for the black and white version of each chess piece select all the assets then drag and drop them into the assets folder in Visual Studio next select all of them right click go to properties and set build action to Resource this will embed the assets inside the game's final executable all right let's make sure that the assets have been imported correctly if it isn't open already go ahead and open main window. sample I'll just change the layout here and then we'll set the windows width and height to 600 we also want the window to use our icon and we'll set the main grids background to our Bard asset okay let's start the program you should now see a window with the chess icon and the board at this point we've set up everything we need to program a nice chess game in the next part we'll add some simple classes to the chess logic project see you then
Info
Channel: OttoBotCode
Views: 19,478
Rating: undefined out of 5
Keywords: chess, game, program, programming, code, develop, build, ottobotcode, otto, ottobot, c#, dotnet, how, to, tutorial, step, by, full, guide, visual studio, wpf, pawn, knight, king, bishop, queen, rook, check, checkmate, mate, capture, en, passant, en-passant, castling, kingside, queenside, ui, user, interface, board, cursor, part, one, part 1, computer, science, software, development, developer, fifty move rule, 50 move rule, rule, threefold repetition, insufficient, material, black, white
Id: GEkSE6eZMGc
Channel Id: undefined
Length: 7min 51sec (471 seconds)
Published: Sun Sep 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.