Salman Javed
Salman Javed

Reputation: 37

Comparing images in c# .net windows form application

I am making a tic tack toe game in c# .net windows form application and i am planning on using images in the boxes instead of tick or cross.So i am facing a problem in comparing those images because in order to win the program has to check for identical images in a row or column or diagonal.I have searched but still found no solution.Any help will be appreciated.

Upvotes: 0

Views: 460

Answers (2)

Nitish Tripathi
Nitish Tripathi

Reputation: 11

Comparing images can be done by taking image pairs and comparing value at each pixel, this will be very expensive task and will make your game much slower.

The correct way is you should declare a two dimensional array to represent value at cells. You can manipulate this array for spawning ticks and cross. And in a separate function parse the array to create display. This way it will be much easier to check for game over or to create next move.

Upvotes: 0

Thomas Levesque
Thomas Levesque

Reputation: 292685

You're on the wrong track; you shouldn't compare the images to decide whether a player has won.

Instead, you should have an internal representation of the game board (e.g. a bidimensional array) that contains, for instance, numbers (e.g. 0 for an empty cell, 1 for a cross and 2 for a circle), and work on that instead (it's much easier to compare numbers than images). The visual representation can easily be constructed from that grid.

In general, you should always keep the visual representation separate from the "logical" representation of data. The UI should only reflect the logical representation, and shouldn't be used by the actual program logic.

Upvotes: 2

Related Questions