Random Graphics Drawing Problem

BlitzMax Forums/BlitzMax Programming/Random Graphics Drawing Problem

Czar Flavius(Posted 2007) [#1]
I've made a Noughts and Crosses game (Tic Tac Toe) for practice in incorporating C++. My C++ code works perfectly, as I've tested it using simple console input/output. Of interest is the getcell(x, y) function which returns -1 for a O, 0 for empty and 1 for X. I was hoping just to return the array but I couldn't be bothered with pointers.

My code gets the number and draws the appropriate image for that square. The only problem is random Xs do not draw any image at all, it's just left blank, unless I put a default case in the select. I can't imagine why. Apart from the fact I know my C++ is giving the right number, using a simple debuglogger with the right mouse button clicking on a square I can see that the correct number (1) is being reported, but no image being drawn (without default). I'm completely stumped.

Here's my code:
Strict

Import "noughtcross.cpp"

Const XRES = 1024, YRES = 768, IMAGESIZE = 128, SIZE = 3;
Const EMPTY = 0, X = 1, O = -1;
Const XOFFSET = 00, YOFFSET = 00;
Const PLAYING = 0, ONEWINS = 1, TWOWINS = 2, DRAW = 3; 'statuses

Extern
	Type gametype
		Method makemove(x, y) 'give x and y to make a move there, if possible
		Method checkstatus() 'results a status (above)
		Method getturn() 'the current turn number, as of yet unused
		Method getplayer() 'the current player, as of set unused
		Method getcell(x, y) 'results one of the numbers above for empty, X or O
	End Type
	Function newgame:gametype()
	Function endgame(game:gametype)
End Extern;

Graphics XRES, YRES;

SetClsColor(100, 100, 100); 'because empty squares are all mask colour and i haven't drawn a background yet

Local game:gametype = newgame();

SetMaskColor(255, 0, 255);
Local image:Timage = LoadAnimImage("images.png", IMAGESIZE, IMAGESIZE, 0, 3, MASKEDIMAGE);

'frames 0 = empty, 1 = cross, 2 = nought

Local mouseclick = False, rightmouse = False;

Local gamemode = PLAYING;

Local carryon = True;

While (carryon)
	Cls;
	For Local x = 0 To 2
		For Local y = 0 To 2
			Select game.getcell(x, y)
				Case EMPTY
					DrawImage(image, XOFFSET + IMAGESIZE * x, YOFFSET + IMAGESIZE * y, 0);
				Case X
					DrawImage(image, XOFFSET + IMAGESIZE * x, YOFFSET + IMAGESIZE * y, 1);
				Case O
					DrawImage(image, XOFFSET + IMAGESIZE * x, YOFFSET + IMAGESIZE * y, 2);
				Default 'without this does not draw random Xs
					DrawImage(image, XOFFSET + IMAGESIZE * x, YOFFSET + IMAGESIZE * y, 1);
			End Select;
		Next;
	Next;
	
	Flip;
	
	If MouseHit(1)
		mouseclick = True;
	Else
		mouseclick = False;
	EndIf;
	
	If MouseHit(2)
		rightmouse = True;
	Else
		rightmouse = False;
	EndIf;
	
	If mouseclick 'try to make a move here
			game.makemove(Floor(MouseX() - XOFFSET)/IMAGESIZE, Floor(MouseY() - YOFFSET)/IMAGESIZE);
	EndIf;
	
	If rightmouse 'gets the current type of piece here
		DebugLog game.getcell(Floor(MouseX() - XOFFSET)/IMAGESIZE, Floor(MouseY() - YOFFSET)/IMAGESIZE);
	EndIf;
		
	gamemode = game.checkstatus();
	
	If Not gamemode = PLAYING
		carryon = False;
	EndIf;
	
	If KeyHit(1)
		carryon = False;
	EndIf;
	
Wend;

Cls;
Select gamemode
	Case PLAYING
		DrawText("You exited the game.", 50, 50);
	Case ONEWINS
		DrawText("Player 1 wins!", 50, 50);
	Case TWOWINS
		DrawText("Player 2 wins!", 50, 50);
	Case DRAW
		DrawText("It's a draw.. boring.", 50, 50);
End Select;
DrawText("Any key to exit.", 50, 100);
Flip;
WaitKey();
endgame(game);
End;



Czar Flavius(Posted 2007) [#2]
Nobody can help me? :(


GfK(Posted 2007) [#3]
You're using X twice - its defined in your constant at the top, and also in your For/Next loop. That's probably what the problem is.


Czar Flavius(Posted 2007) [#4]
AHA! I forgot Blitz is case-insensitive! Or actually, I just learnt :P


Gillissie(Posted 2007) [#5]
I'm surprised the compiler doesn't throw an error for trying to assign a value to a constant.