tetris in gdk

Started by
-1 comments, last by cwl157 15 years, 10 months ago
I felt the first post was more of an intro for me and now that i gained some direction from it i would just start a new post because now i know more of what to ask. Ok first i can not figure out how to make things print to the console when in the gdk application. cout does not work or anything #include <iostream> does not work using namespace std; does not work but it seems like the logic is done in text and then after that happens the screen gets updated with the graphics so i need to be able to print to the visual c++ output window somehow. Anyway i am going to use the tetris piece that has 4 going across and down because it is easy to draw a 2d array for and has 2 possibilities. I am going to post the code i have so far. Basically i just switched the old one so instead of drawing a sprite for each square all it does is change the 0 to a 1 in the gameBoard 2d int array. I have main.h which just makes the gameBoard accessble outside of main.cpp. I would like to have a way to test this though but i need a way to output the the console. So now to create pieces i would call the method to create that piece in the 2d int array called gameBoard and then when it comes time to draw i would have a loop that goes through the entire 2d array and draws the block accordingly also taking into account the number of pixels per block of course correct? Here is the code. /*long shank: RRRR Rxxx xxxx Rxxx xxxx Rxxx xxxx Rxxx */ #include "darkGDK.h" #include "main.h" int longShankHorz[4][4] = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, }; int longShankVert[4][4] = {{1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, }; void createLongShankHorz(void) { for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { if (longShankHorz[row][col] == 1) { gameBoard[row][col] = 1; } // end if else continue; } // end for } // end for } // end createLongShankHorz the one problem i get is if i then set the square to update the same thing i get a message saying this was already updated in LongShank. Its the same function but applied to the square. How do i keep it seperate? void createLongShankVert(void) { for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { if (longShankVert[row][col] == 1) gameBoard[row][col] = 1; else continue; } // end for } // end for } // end createLongShankVert I played around with it in text drawing pieces and such and realize that really the way to do it is to use console text and get all the logic right to detect collisions and delete rows and move the rows down and all that. So could i work on it as a console app first and then after all that logic is figured out would it be possible to then import the dark gdk and create the keyboard functions and draw and redraw the blocks and pieces and add all that. So the text would update as usual but i would just add the layer of graphics and windows updating on top of that but really the graphics have nothing to do with the underlying logic its just a front. Am i right on thinking that? [Edited by - cwl157 on June 19, 2008 12:49:49 AM]

This topic is closed to new replies.

Advertisement