Southperry.net
ITT: My Mine Sweeper Project. - Printable Version

+- Southperry.net (https://www.southperry.net)
+-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14)
+--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58)
+--- Thread: ITT: My Mine Sweeper Project. (/showthread.php?tid=35305)

Pages: 1 2


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2010-12-29

Since I've completed two commercial programs (or at least I tend them to be) with visual basic, I think it's time to move on to C++.

I choose to create Mine Sweeper from scratch by myself. Why Mine Sweeper? Because I'm obsessed with it, next from maple. I think I know how it works, so I think this will be the best start. Recreating my two previous programs with C++ should be a better choice but I don't feel like going through all that again. And I want to be a game programmer, those two aren't games.

What you will find in here in the future will be problems I find along the way, which mostly should be about commands, and want to ask other programmers about them.

Hope this thread doesn't count as a junk thread. But in case it does, just delete it.


ITT: My Mine Sweeper Project. - Spaz - 2010-12-29

What do you plan on using for the GUI? Raw Win32? MFC? QT, GTK, or some other framework? DirectX/OpenGL?

And, uh, do you know C++ already or is this intended as a project for learning it?


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2010-12-30

Spaz Wrote:What do you plan on using for the GUI? Raw Win32? MFC? QT, GTK, or some other framework? DirectX/OpenGL?

Raw win32.

Spaz Wrote:And, uh, do you know C++ already or is this intended as a project for learning it?

Project for learning it.


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2010-12-30

OK, first problem. I got 4 errors in this class.

Code:
class MineButton
{    public: //error C2814: 'MineSweeper::Form1::MineButton' : a native type cannot be nested within a managed type 'MineSweeper::Form1'    
        button b;/*error C2146: syntax error : missing ';' before identifier 'b' AND  2 times of error C4430: missing type specifier - int assumed. Note: C++ does not support default-int.*/
        MineButton(int x, int y)
        { cx = x;
            cy = y;
        };
        int cx, cy;
};

I absolutely have no idea where did I go wrong.


ITT: My Mine Sweeper Project. - Spaz - 2010-12-30

"a native type cannot be nested within a managed type 'MineSweeper::Form1'" tells me that it's compiling your code as C++/CLI, not C++. Are you intending to use C++/CLI instead of actual unmanaged C++? If you mean to use real unmanaged C++ instead of managed (.NET) C++/CLI, set the /clr compiler option to "No common language runtime support". That may mean you don't get to use a form designer.


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2011-01-01

At first, class MineButton was at #pragma once in Form1.h. I've moved it to MineSweeper.cpp, right above int main().

Code:
...
#include "stdafx.h"
#include "Form1.h"

using namespace MineSweeper;

[STAThreadAttribute]
public ref class MineButton
{    public:
        PictureBox^ pic;
        int x, y;
        MineButton(int cx, int cy)
        {    x = cx; y = cy;    };
};
int main(array<System::String ^> ^args)
....

What do these errors mean?
- error C3115: 'System::STAThreadAttribute': this attribute is not allowed on 'MineButton'
- error C3673: 'MineButton' : class does not have a copy-constructor


ITT: My Mine Sweeper Project. - Spaz - 2011-01-01

See previous post. You're programming in C++/CLI right now instead of plain C++, which I'm guessing was not your intention. C++/CLI adds even more complexity on top of the already-complex C++ language. If you want to write a native-code app, use C++. If you want to write a .NET app, use C#/VB.NET. I don't recommend using C++/CLI for anything other than interfacing with native libraries in a .NET app.


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2011-01-02

That explains why my friend suggested me to move to c# instead of c++.

Start the project over again, this time I'll write it in C#.net.


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2011-01-02

Tried C#.net, it's a lot familiar to VB.net than I could imagine, it's like just changing keywords.

Right now I'm stuck at adding handler to object created by the code. What command should I use? In VB.net it was like:
Code:
...
Addhandler <object name here>.click, addressof object_click



ITT: My Mine Sweeper Project. - Spaz - 2011-01-02

Button1.Click += object_click


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2011-01-04

Little update.

the game is going nice, few logic errors here and there but I'm getting through it. Now I'm at getting numbers around mines. I've decided to stop here today.


ITT: My Mine Sweeper Project. - DrRusty - 2011-01-05

wow Spaz you are the fking man. I need to learn how to interpret code like that

any chance u could post the code to ur minesweeper? I'd like to try it out =)


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2011-01-05

DrRusty Wrote:wow Spaz you are the fking man. I need to learn how to interpret code like that

any chance u could post the code to ur minesweeper? I'd like to try it out =)

Code to my Minesweeper?


ITT: My Mine Sweeper Project. - DrRusty - 2011-01-05

well upload it somewhere so we can play it


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2011-01-05

DrRusty Wrote:well upload it somewhere so we can play it

Okay, just don't hold your breath for it.

And I'm stuck.

Code:
void MineButton_Click(Object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {                  
                bool found = false;
                for(int i = 1;i<y&&!found;++i)
                    for (int j = 1; j < x && !found; ++j)
                    {
                       [B] if (p[i,j].pic.Focus())[/B]
                        {   found = true;
                            if ((p[i,j].status == "Cover")|(p[i,j].status == "Marked"))
                            {
                                if (!began)
                                { PlaceMine(i,j); }
                            }
                        }
                    }
            }
...

I'm trying to make it detect which picturebox is it clicking. I tried .Focus(), it reacts only to top left button, first one that is initialized. I also tried to get cursor's location and react to button at its location. But it returns cursor's location ON each button instead. Each button has 15 px height and width, and when I ask for cursor's location, I get only number under 15 no matter where I click.

tldr; I want to detect which picturebox it's clicking. What should I replace in that bold line?


ITT: My Mine Sweeper Project. - Spaz - 2011-01-05

I'm confused. The picture box that was clicked would be the one raising the click event.


ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2011-01-06

Yes, but how am I going to say in this function which one I'm talking about. There are many pictureboxes that raise this function when it's clicked.


ITT: My Mine Sweeper Project. - Spaz - 2011-01-06

Code:
this



ITT: My Mine Sweeper Project. - Unauthorized Intruder - 2011-01-07

Doesn't "this" refer to Form1 only? How's that going to help?


ITT: My Mine Sweeper Project. - Spaz - 2011-01-07

Oh right, my bad. It would be sender. You can cast it to a picture box (or whatever it is).