hello there guys I have attached a picture of the error that I've been receiving in coding my tetris program, anyone here who knows how to fix this? please help me thanks in advance. ddd2

Recommended Answers

All 8 Replies

Do you have Square defined somewhere else in the same namespace?
...like in one of your other .cs files?

Do a solution wide text search for "class Square" to find where the duplicate is being defined.

commented: sir how do I do that? +2

Why are you creating a square class when System.Drawing already has a Rectangle class?

Square is defined again inside of another .cs file and needs to be renamed. Although, if you're writing this with XNA you should really switch your project type over to Windows Game type.

@Momerath: When designing games it's good practice to create your own objects, plus the Rectangle class inside of System.Drawing is meant for many purposes, but does not have all the variables that a square in a Tetris clone would have.

I disagree with that. Never write more code than you need to - if people wrote all the code their program needs themselves and never leveraged other code we would be in the stone-ages of software development still. If the rectangle doesn't have all the features you want, derive from it.

True; we would derive from the Rectangle class, it's what I did. But I don't know if Lightning knows about Polymorphism or not. It's an advanced topic, and if he didn't know what the problem was with this error, then he's probably still a little new to programming, or at least this language. There's no problem with that of course, we all have to start somewhere.

@lxXTaCoXxl: and what are these attributes that a square has that a rectangle doesn't have? For tetris I'd have a Piece (might not be the best name, but go with it) class with a collection of retangles. The Piece class would have the locations of the retangles relative to a 'starting' point to define the shape.

Well when working with XNA the Square class will either Derive from a base class (usually called GameplayObject) which would normally hold all the different values. But with someone that doesn't know polymorphism yet, they would put the velocity of the square, color, rotation presets, location, size (the last two there the rectangle class has), and to do some interesting new work styles you could simulate physics into a tetris clone like I did, granted I derived my class from the Rectangle class anyways; but not the point. My square class had extra variables, such as; mass, acceleration, gravitational constant, methods to determine the results of physical math, and even had some bounce animation going on using drag and a so called wind speed. There are a lot of interesting things you can do with games, that is only limited to what your mind can feed you for ideas. So a basic square class wouldn't have too many differences, but if the game is not an exact clone and the programmer is mixing it up a bit, then yes there can be a whole mess of differences. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.