|
am a new member and i will want you to hlp me.I have been tryin to write a c++ code for this number puzzle for a while but eventually i used java cos i knw it a little bit. i would appreciate if any body can hlp me in writin it c++ proram and evn completing.ppplllllllllllleeeeeaaaaaaaaaassssssssssssssssssseeeeeeeeeeee
here is the basic code that will help an user play, i am still trying to automate it, if anyone is able to finish it please let me know
import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
/** **************************************************************** */
// <applet code="puzzle" width="100" height="100">
/** **************************************************************** */
public class Puzzle extends Applet {
private static final long serialVersionUID = 1;
public Piece pieces[] = new Piece[16];
int i, x, y, currentValue;
int startX = 50;
int startY = 50; // start pos of puzzle
int rowSize = 4;
int pieceWidth = 50;
int pieceHeight = 50;
private int blankPiecePosition;
Graphics graphics;
SimplePuzzle simple;
RandomValue randomValue = new RandomValue(1, 16);
public void init() {
graphics = getGraphics();
/* INITIALIZE THE BLANK PIECES */
x = startX;
y = startY;
for (i = 0; i <= 15; i++) {
currentValue = randomValue.getRandomValue();
// currentValue = i+1;
/* SET THE INITIAL POSTION OF THE BLANK PIECE */
if (currentValue == 16) {
blankPiecePosition = i;
}
// pict = getImage(getDocumentBase(),image_name+currentValue+".gif");
pieces[i] = new Piece(i, currentValue, graphics, x, y, null, this);
x += 50;
if (x > 200) {
x = 50;
y += 50;
}
}
/* CREATE A NEW SIMPLE PUZZLE */
simple = new SimplePuzzle(15, this);
resize(pieces[0].width * 6, pieces[0].height * 6);
}
public void start() {}
public void stop() {}
public boolean mouseDown(Event evt, int x, int y) {
int rel_x, rel_y;
int click_piece;
int cur;
// FIRST CHECK IF THE POINT IS INSIDE THE PUZZLE
if (isPointInside(x, y)) {
// NOW GET THE CLICK PIECE
rel_x = (int) (x - startX) / pieceWidth;
rel_y = (int) (y - startY) / pieceHeight;
click_piece = rel_x + rowSize * rel_y;
// IF THE CLICK POINT IS IN THE SAME ROW AS THE BLANK PIECE
if (pieces[blankPiecePosition].sameRow(y)) {
if (pieces[click_piece].toLeft(pieces[blankPiecePosition])) {
cur = pieces[blankPiecePosition].left;
while (cur != pieces[click_piece].left) {
pieces[cur].exchangePiece(pieces[blankPiecePosition]);
blankPiecePosition = cur;
cur = pieces[blankPiecePosition].left;
congratulate();
}
} else if (pieces[click_piece].toRight(pieces[blankPiecePosition])) {
cur = pieces[blankPiecePosition].right;
while (cur != pieces[click_piece].right) {
pieces[cur].exchangePiece(pieces[blankPiecePosition]);
blankPiecePosition = cur;
cur = pieces[blankPiecePosition].right;
congratulate();
}
}
} else if (pieces[blankPiecePosition].sameColumn(x)) {
if (pieces[click_piece].above(pieces[blankPiecePosition])) {
cur = pieces[blankPiecePosition].up;
while (cur != pieces[click_piece].up) {
pieces[cur].exchangePiece(pieces[blankPiecePosition]);
blankPiecePosition = cur;
cur = pieces[blankPiecePosition].up;
congratulate();
}
} else if (pieces[click_piece].below(pieces[blankPiecePosition])) {
cur = pieces[blankPiecePosition].down;
while (cur != pieces[click_piece].down) {
pieces[cur].exchangePiece(pieces[blankPiecePosition]);
blankPiecePosition = cur;
cur = pieces[blankPiecePosition].down;
congratulate();
}
}
}
}
return true;
}
private void congratulate() {
if (simple.isPuzzleComplete()) {
graphics.drawString("Congratulations!!!", 75, 275);
}
}
public void paint(Graphics g) {
g.setColor(Color.pink);
g.fillRect(0, 0, size().width, size().height);
for (int i = 0; i <= (15); i++) {
pieces[i].draw();
}
}
// THIS ROUTINE RETURNS THE VALUE OF A LOCATION
public int getLocationValue(int arr_loc) {
return pieces[arr_loc].value.intValue();
}
// THIS ROUTINE RETURNS THE VALUE OF THE BLANK LOCATION
int getBlankLocationValue() {
return pieces[blankPiecePosition].value.intValue();
}
public boolean isPointInside(int x, int y) {
if ((x >= startX) && (y >= startY)
&& (x <= startX + rowSize * pieceWidth)
&& (y <= startY + rowSize * pieceWidth)) {
return true;
} else {
return false;
}
}
}
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
public class Piece {
int width = 50, height = 50;
int right, left, up, down;
Integer value; // the value of the Piece
Integer posX, posY; // the on screen position of the Piece
Graphics graphics;
Puzzle objPuzzle;
public Piece(int index, int val, Graphics agc, int x, int y, Image pict,
Puzzle objPuzzle) {
int temp;
this.objPuzzle = objPuzzle;
value = new Integer(val);
graphics = agc;
posX = new Integer(x);
posY = new Integer(y);
// RIGHT
temp = index + 1;
if ((temp == 4) || (temp == 8) || (temp == 12) || (temp == 16))
right = -1;
else
right = temp;
// LEFT
temp = index - 1;
if ((temp == 3) || (temp == 7) || (temp == 11))
left = -1;
else
left = temp;
// UP
temp = index - 4;
if ((temp < 0))
up = -1;
else
up = temp;
// DOWN
temp = index + 4;
if ((temp >= 16))
down = -1;
else
down = temp;
}
// RETURNS TRUE IF A POINT IS IN THE SAME COL AS y
public boolean sameColumn(int x) {
return ((x > posX.intValue()) && (x < posX.intValue() + height));
}
// RETURNS TRUE IF A POINT IS IN THE SAME ROW AS x
public boolean sameRow(int y) {
return ((y > posY.intValue()) && (y < posY.intValue() + width));
}
public boolean toLeft(Piece p) {
return (posX.intValue() < p.posX.intValue());
}
public boolean toRight(Piece p) {
return (posX.intValue() > p.posX.intValue());
}
public boolean above(Piece p) {
return (posY.intValue() < p.posY.intValue());
}
public boolean below(Piece p) {
return (posY.intValue() > p.posY.intValue());
}
public void exchangePiece(Piece blank) {
Integer temp = value;
value = blank.value;
blank.value = temp;
draw();
blank.draw();
}
public void draw() {
if (value.intValue() == 16) {
graphics.setColor(Color.black);
graphics.fillRect(posX.intValue(), posY.intValue(), width, height);
graphics.drawRect(posX.intValue(), posY.intValue(), width, height);
} else {
graphics.setColor(Color.yellow);
graphics.fillRect(posX.intValue(), posY.intValue(), width, height);
graphics.setColor(Color.black);
graphics.drawRect(posX.intValue(), posY.intValue(), width, height);
graphics.setFont(new Font("Times", Font.BOLD, 16));
graphics.drawString(value.toString(), posX.intValue()
+ (width - graphics.getFontMetrics().stringWidth(
value.toString())) / 2, posY.intValue() + height
/ 2);
}
}
}
public class SimplePuzzle{
int win[] = new int[16];
int winIndex, startIndex;
Puzzle puzzle;
SimplePuzzle(int startPosition, Puzzle puz) {
for (int i = 0; i < 16 ; i++) {
win[i] = i + 1;
}
winIndex = 15;
startIndex = startPosition;
puzzle = puz;
}
public boolean isPuzzleComplete() {
if (puzzle.getBlankLocationValue() != winIndex) {
return false;
}
for (int i = 0; i < 16 ; i++) {
//System.out.println("Loc Value: "+puzzle.getLocationValue(i)+"\tWin: "+win[i]);
if (puzzle.getLocationValue(i) != win[i]) {
return false;
}
}
return true;
}
}
/** **************************************************************** */
// THIS CLASS IS USED TO PROVIDE A UNIQUE RANDOM VALUE FROM
// A RANGE OF VALUES
class RandomValue {
int value[];
int total;
RandomValue(int first, int last) {
int i;
total = last - first + 1;
value = new int[total];
for (i = 0; i < total; i++) {
value[i] = first;
first++;
}
}
int getRandomValue() {
int i;
int ret;
if (total == 0) {
return -1;
}
if (total == 1) {
total = 0;
return value[0];
}
i = (int) (Math.random() * total);
ret = value[i];
total--;
for (; i < total; i++) {
value[i] = value[i + 1];
}
return ret;
}
}
|
|
|
|
|
this person is trolling. the entire text of this post (including the question) is copied from a two-year old posting on a java board.
|
|
|
|
|
|
I'm not trained in psychiatry
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
i have a problem with this tutorial in step3.
get_Sides and put_Sides methods not getting added! i dont't know y. plz check with below tutorial.
Tutorial[^]
|
|
|
|
|
1.Right-click IPolyCtl in Class View (expand the Polygon branch to find it).
If you Right-Clicked on _IPolyCtl then those methods won't be added. I think i had the same problem when using the tutorial.
|
|
|
|
|
Thanks for replying soon.
I am using VS2005. i have right clicked IPolyCtl and clicked Add property,but it doesn't add get and set method. But one thing i found that if we choose stock property in step 2 then this problem occures otherwise not.
|
|
|
|
|
Any solution to this problem?
|
|
|
|
|
Hi! I have an Atl composite control with a few edit controls in it.
When I test it in the ActiveX control test container it works fine but when I add it in a form, after starting the program, those edit controls take focus but don't take keyboard input. I don't know what could be the problem. The internal controls take the mouse input but just don't take keyboard input. Please help. Thanks in advance.
|
|
|
|
|
I tried this:
<pre>
template <class T>
class CWinDataExchangeEx :
public CWinDataExchange<T>
{
public:
// my new DDX functions here...
</pre>
Then I have the dialog class is derived from CWinDataExchangeEx. But now none of the base class DDX routines get called anymore, only my new one's in the Ex class?!
|
|
|
|
|
An example of the code that doesn't work as you expect would help...as well as a clear statement of exactly what you expected.
If you (for example) added a new overload of DDX_Text , then the definition of DDX_Text in your class will hide the definitions in the base class. To fix this, you'd add the following line to your CWinDataExchangeEx class:
using CWinDataExchange<T>::DDX_Text;
|
|
|
|
|
this is my added code (I am trying to implement a DDX_CBSTRING function ala MFC):
(in my atlddx2.h)
namespace WTL
{
#define DDX_CBSTRING(nID, var) \
if(nCtlID == (UINT)-1 || nCtlID == nID) \
{ \
if(!DDX_CBString(nID, var, sizeof(var), bSaveAndValidate)) \
return FALSE; \
}
template <class T>
class CWinDataExchangeEx : public CWinDataExchange<T>
BOOL DDX_CBString(UINT nID, _CSTRING_NS::CString& value, int , BOOL bSave )
{
}
};
};
then on the dialog class:
#include "atlddx2.h"
class CScaleEditDlg :
public CDialogImpl<CScaleEditDlg>,
public CWinDataExchangeEx<CScaleEditDlg>
{
BEGIN_DDX_MAP(CScaleEditDlg)
DDX_CBSTRING(IDC_SCALE_MODEL, m_strModel)
DDX_TEXT(IDC_SCALE_DESCRIPTION, m_strDescription)
DDX_INT_RANGE(IDC_SCALE_SA, m_nStationAddress, 0, 999)
DDX_CONTROL_HANDLE(IDC_SCALE_IMAGE, m_ctlImage)
END_DDX_MAP()
};
None of the base class DDX routines seem to get called, e.g. DDX_TEXT, DDX_INT_RANGE, etc. I set breakpoints in DDX_Text() and all others but only the DDX_CBString one gets hit.
Could it have something to do with the way the macro's are defined? They are defined within a function body:
(from atlddx.h)
#define BEGIN_DDX_MAP(thisClass) \
BOOL DoDataExchange(BOOL bSaveAndValidate = FALSE, UINT nCtlID = (UINT)-1) \
{ \
bSaveAndValidate; \
nCtlID;
#define DDX_TEXT(nID, var) \
if(nCtlID == (UINT)-1 || nCtlID == nID) \
{ \
if(!DDX_Text(nID, var, sizeof(var), bSaveAndValidate)) \
return FALSE; \
}
|
|
|
|
|
Returning FALSE from a DDX method means that the data exchange method failed such that the rest of the data exchange process should be cancelled.
You need to return TRUE from your DDX_CBString method unless (for example) validation of the item fails.
|
|
|
|
|
please tell me how to crack maya
I don't know how to tell you but I like IT and Designingas well as Graphic
|
|
|
|
|
sonarat wrote: please tell me how to crack maya
I'd try a hammer first of all, see if that helps.
|
|
|
|
|
I have created a ATL Project in-pro DLL with all default settings. As usual,i
added a Control ATL Object to the app, and then tried to add a Proptery ,say "name" ,using "Add Propery Wizard" to the interface created with the project. my confusion is why the Wizard only modifyes the idl file,and no corresponding code added to the implementation class, i expected the Wizard would add the methods get_name() and put_name() for me. yet .net2005 didn't. I realy dont' know how to make it work as i expected.
Thanks in advance.
|
|
|
|
|
hi guys ;
I have problem when i do my porject and I can fugier it out , i made a program can read any list of interger number and stor it in vector and do statestic clculatiom like: Statistical median , Arithmetic mean ,Variance,Standard deviation,Frequency distribution,Histogram,Mode , and i made it only Statistical median , Arithmetic mean ,Variance,Standard deviation equation but dosn't run Variance,Standard deviation have error. and i don't want to used the majce number to vector becauses it case me problem i will post the code if somone please help
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
//decalre constant to control the size of vector
int const SIZE =1;
unsigned number ;
unsigned *pointerNumber= &number;
unsigned Arithmetic_mean;
/*double variance=0;
double deviation;*/
//declare vector avariable to store the list of number
vector <unsigned> listNumber(SIZE);
//declare iterator and used it to find max and minin the vector and for Statistical median
vector <unsigned>::iterator max_listNumber_Iter,min_listNumber_Iter;
cout<<"Enter the stream number to stop EOF"<<endl;
for="" loop="" to="" enter="" the="" vector="" element=""
="" for(unsigned="" i="0" ;="" i<="" listnumber.size()="" ;i++)
="" {
="" cin="">>number;
if (cin.eof())
break ;
listNumber.push_back(number);
}
//find the max and min ot the point and m
max_listNumber_Iter = max_element ( listNumber.begin ( ) , listNumber.end ( ) );
min_listNumber_Iter = min_element ( listNumber.begin ( ) , listNumber.end ( ) );
//show the max and the Min fo the vector
cout<<"Maximum number ="<<*max_listNumber_Iter<
|
|
|
|
|
Sorry that the subject is vague because it's hard to describe my question in one line. I have zero experience with ATL.
I was given this ATL DLL project at work that embeds web browser on our application. I was using #import [browser.dll] to access the methods, and CreateInstance() to create the browser. That's how it was used in the example exe project that used that DLL.
My lead suggested that I should remove #import due to its hard-coded path dependency, and I should just link it using the lib file that DLL generates during compilation. The DLL is guaranteed to reside in the same directory as the main exe, and it'll not be replaced by any other DLL.
What's the best way to fix this problem? But I noticed that lib files don't generated when you compile ATL DLLs (I could be wrong). Can somebody lead me to an example?
Thanks in advance.
|
|
|
|
|
I should add that I could modify this ATL DLL source anyway I want. It just has to work.
|
|
|
|
|
MonkuMonku wrote: My lead suggested that I should remove #import due to its hard-coded path dependency, and I should just link it using the lib file that DLL generates during compilation.
#import has nothing to do with linking. #import generates wrapper classes for COM objects at compile time. COM operates completely at runtime and does not use LIBs to find DLLs.
|
|
|
|
|
Michael Dunn wrote: #import has nothing to do with linking.
Yeah but his "lead" says so... idiom[^]
|
|
|
|
|
As suggested by Michael, the #import generate the wrapper classs for coclasses that are part of ATL dll,
any COM DLL need to be registered before it use, and location of dll is irrelevent as it shourld be registed in the windows registry by using "regsvr32" command.
if you don't want to use the #import you can directly create the instance of class by using CoCreateInstance but life is more tough without #import as you have to handle the AddRef and Release part of your own.
Regards,
Sunil Tonger
|
|
|
|
|
and you are telling me all of that because??
|
|
|
|
|
|
Does this have anything to do with ATL/WTL?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|