Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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.
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
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?
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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.
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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.
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
"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.
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
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.
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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.
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
Button1.Click += object_click
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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.
Posting Freak
Posts: 4,380
Threads: 186
Joined: 2008-07
Gender: Male
IGN: Volte
Level: XX
Job: Nuke
Guild: US Navy
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 =)
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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?
Posting Freak
Posts: 4,380
Threads: 186
Joined: 2008-07
Gender: Male
IGN: Volte
Level: XX
Job: Nuke
Guild: US Navy
well upload it somewhere so we can play it
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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?
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
I'm confused. The picture box that was clicked would be the one raising the click event.
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
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.
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
Senior Member
Posts: 614
Threads: 88
Joined: 2010-08
Gender: Male
Country Flag: thailand
IGN: Knight52
Server: Earth
Level: 534
Job: Thread Breaker
Guild: I'm bored of
Guild Alliance: political sh'it
Doesn't "this" refer to Form1 only? How's that going to help?
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
Oh right, my bad. It would be sender. You can cast it to a picture box (or whatever it is).
|