Click here to Skip to main content
15,905,233 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
QuestionCalling a routine in a dll from the command line. Pin
firesteel6-Aug-07 0:16
firesteel6-Aug-07 0:16 
AnswerRe: Calling a routine in a dll from the command line. Pin
Stuart Dootson6-Aug-07 1:19
professionalStuart Dootson6-Aug-07 1:19 
GeneralRe: Calling a routine in a dll from the command line. Pin
firesteel6-Aug-07 2:21
firesteel6-Aug-07 2:21 
GeneralRe: Calling a routine in a dll from the command line. Pin
Stuart Dootson6-Aug-07 6:01
professionalStuart Dootson6-Aug-07 6:01 
QuestionCorrect/Best way to do convert int to string as uppercase hex ? Pin
Defenestration5-Aug-07 10:59
Defenestration5-Aug-07 10:59 
AnswerRe: Correct/Best way to do convert int to string as uppercase hex ? Pin
Stuart Dootson6-Aug-07 6:07
professionalStuart Dootson6-Aug-07 6:07 
QuestionDisplaying jpeg image sequences with ATL only Pin
p_4732-Aug-07 0:19
p_4732-Aug-07 0:19 
Questioni neeeeeeeed hlppppppp Pin
topekash20001-Aug-07 3:13
topekash20001-Aug-07 3:13 
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;
}
}
AnswerTroll alert Pin
Chris Losinger1-Aug-07 3:30
professionalChris Losinger1-Aug-07 3:30 
GeneralRe: Troll alert Pin
Jonathan [Darka]1-Aug-07 4:12
professionalJonathan [Darka]1-Aug-07 4:12 
AnswerYou definitely need help, but... Pin
CPallini1-Aug-07 4:27
mveCPallini1-Aug-07 4:27 
QuestionMethods not getting generated by wizard [modified] Pin
KASR11-Aug-07 0:16
KASR11-Aug-07 0:16 
AnswerRe: Methods not getting generated by wizard Pin
_Leviathan_1-Aug-07 4:42
_Leviathan_1-Aug-07 4:42 
GeneralRe: Methods not getting generated by wizard Pin
KASR11-Aug-07 19:01
KASR11-Aug-07 19:01 
GeneralRe: Methods not getting generated by wizard Pin
KASR17-Aug-07 1:56
KASR17-Aug-07 1:56 
QuestionProblem with keyboard input in Composite ATL control Pin
_Leviathan_31-Jul-07 21:52
_Leviathan_31-Jul-07 21:52 
QuestionHow to override CWinDataExchange Pin
paulb31-Jul-07 15:22
paulb31-Jul-07 15:22 
AnswerRe: How to override CWinDataExchange Pin
Stuart Dootson31-Jul-07 21:10
professionalStuart Dootson31-Jul-07 21:10 
GeneralRe: How to override CWinDataExchange Pin
paulb1-Aug-07 13:21
paulb1-Aug-07 13:21 
GeneralRe: How to override CWinDataExchange Pin
Stuart Dootson1-Aug-07 21:25
professionalStuart Dootson1-Aug-07 21:25 
Questiontell me how to crack maya unlimite Pin
sonarat30-Jul-07 2:35
sonarat30-Jul-07 2:35 
AnswerRe: tell me how to crack maya unlimite Pin
Jonathan [Darka]30-Jul-07 7:00
professionalJonathan [Darka]30-Jul-07 7:00 
QuestionA slight problem about using "Add Property Wizard" under .net2005 Pin
Yaki_1527-Jul-07 0:44
Yaki_1527-Jul-07 0:44 
Questionasking for help in my project ??? Pin
dark-Slayer8224-Jul-07 17:04
dark-Slayer8224-Jul-07 17:04 
Questionusing ATL DLL in non-ATL way Pin
MonkuMonku20-Jul-07 14:52
MonkuMonku20-Jul-07 14:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.