Please help. Its kind of urgent!
This is my map(grid/gameBoard) codes:
#include<ctime>
#include "map1.h"
#include "block1.h"
#include "Shuffle1.h"
#include "gwin.h"
extern Block4 bl, bl2, bl3; //play, next, save
int lines[4];
Map::Map(){
}
void Map::initialize(){
for(int x=0; x<17; x++){
for(int y=0; y<21; y++){
map[x][y] = EMPTY;
}
}
for(int i=0; i<4; i++)
lines[i]=0;
}
void Map::destroy(int x, int y, int w, int h){
for(int i=0; i<=h; i++){
for(int j=0; j<=w; j++){
map[x+j][y+i] = EMPTY;
}
}
}
void Map::draw(){
Block4 block;
int temp_type, temp_type1, temp_type2;
bl2.type = rand()%7, bl3.type = rand()%7;
//draw shape falling down
for(int x=0; x<10; x++){
for(int y=0; y<20; y++){
/*if(map[x][y] >=0){
Gwin.moveTo(x*32, y*32);
temp_type = bl.type;
Block4 block(x, y, temp_type);*/
if (map[x][y] == ACTIVE){
// Gwin.moveTo(x*32, y*32);
temp_type = bl.type;
bl.draw(x*32, y*32, temp_type);
}
}
}
//draw next shape coming down
for(int x=11; x<16; x++){
for(int y=5; y<7; y++){
if(map[x][y] != EMPTY){
Gwin.moveTo(x*32, y*32);
temp_type1 = bl2.type;
bl2.draw(x, y, temp_type1);
}
}
}
//for shape on hold, user can change to
for(int x=11; x<16; x++){
for(int y=9; y<11; y++){
if(map[x][y] != EMPTY){
Gwin.moveTo(x*32, y*32);
temp_type2 = bl3.type;
bl3.draw(x, y, temp_type2);
}
}
}
}
void Map::checkForLines(){
int sum=1;
for(int y=19; y>=0 && sum!=0 ;y--){
sum=0;
for(int x=0; x<10; x++){
if(map[x][y] != EMPTY)
sum++;
}
if(sum == 10){
lines[count_line] = y;
count_line++;
total_lines++;
}
}
}
void Map::colorLines(){
for(int i=0; i<4 && lines[i]!=0; i++){
for(int x=0; x<10; x++){
map[x][lines[i]] = CYAN;
}
}
}
void Map::removeLines(){
//move top part down
for(int y=lines[0]; y - count_line >= 0; y--){
for(int x=0; x<10; x++){
map[x][y] = map[x][y-count_line];
}
}
//fill up lines moved down
for(int y= count_line-1; y>= 0; y--){
for(int x=0; x<10; x++){
map[x][y] = EMPTY;
}
}
for(int i=0; i<4 && lines[i]!=0; i++){
lines[i]=0;
}
}
This is my main function:
#include<iostream>
#include<string>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include "Shuffle1.h"
#include "block1.h"
#include "map1.h"
#include "gwin.h"
using namespace GwinKeyNames;
using namespace std;
Block4 bl, bl2, bl3; //play, next, save
extern Map mapM;
#define SCORE (19 - bl.b[0].y) + count_line*15 + pow(5.0,count_line) + 5*level
#define TICKSPEED (int)(TIMEINTERVAL/10+TIMEINTERVAL/level)
#define LEVELUP start % (int)(TIMEINTERVAL*20)
void generate_block();
void restart();
void tick();
void draw();
void play();
void help();
void setup();
void highscore();
Image gameback("gameback.jpg");
//srand((unsigned)time(NULL));
DWORD start = 0, start1 = 0;
Key keyvalue = ' ' ; //for keys presed in game loop
int main(){
int menuSelect = 0; //initialize the menu selection to zero
bool required = true; //menu loop
bool screenMenu = true; //main default diaplay menu
bool skill = false;
bool help = false; //help menu
bool highScore = false; //high score menu
bool setup = false; //setup menu
bool menuExit = false;
bool resume = false; //pause or resumed
bool control = false;
Key keyvalue1 = ' '; // for menu keys pressed
//Load images
Image menu0("startgame1.jpg");
Image menu1("skill1.jpg");
Image menu2("highscore1.jpg");
Image menu3("setup1.jpg");
Image menu4("help1.jpg");
Image menu5("exit1.jpg");
Gwin.showConsole(); //To show console window
Gwin.resize(560,700);
Gwin.show();
//Gwin.resize(BOX_W, BOX_H); //resizes the gwindow to a new size
Gwin.setTitle("My Tetris Game"); //Sets the gwindow to a new title
do{
Gwin.drawImage(menu0, 0, 0);
Gwin.refresh();
//keyvalue = Keyboard.getch();
while(required){ //menu loop
keyvalue = Keyboard.getch();
switch(keyvalue){
case ESCAPE:
Gwin.clear();
menuSelect = 0;
Gwin.drawImage(menu0,0,0);
required=false;
break;
case CURSOR_UP:
//if ( (menuSelect > 0) && (screenMenu == true) )
//{
menuSelect--;
Gwin.clear();
if (menuSelect == 0 )
{
Gwin.drawImage(menu0,0,0);
}
if (menuSelect == 1 )
{
Gwin.drawImage(menu1,0,0);
}
else if (menuSelect == 2)
{
Gwin.drawImage(menu2,0,0);
}
else if (menuSelect == 3)
{
Gwin.drawImage(menu3,0,0);
}
else if (menuSelect == 4)
{
Gwin.drawImage(menu4,0,0);
}
else if (menuSelect == 5 || menuSelect==-1)
{
Gwin.drawImage(menu5,0,0);
if(menuSelect==-1)
menuSelect=5;
}
//}
break;
case CURSOR_DOWN: //move through menu by means of changing pictures 0 to 5 i.e 6 pictures in total
//if ( (menuSelect <= 4) && (screenMenu == true) )
//{
menuSelect++;
Gwin.clear();
if (menuSelect == 0 || menuSelect==6)
{
Gwin.drawImage(menu0,0,0);
//if(menuSelect==6)
menuSelect=0;
}
if (menuSelect == 1 )
{
Gwin.drawImage(menu1,0,0);
}
else if (menuSelect == 2)
{
Gwin.drawImage(menu2,0,0);
}
else if (menuSelect == 3)
{
Gwin.drawImage(menu3,0,0);
}
else if (menuSelect == 4)
{
Gwin.drawImage(menu4,0,0);
}
else if (menuSelect == 5)
{
Gwin.drawImage(menu5,0,0);
}
//}
break;
case RETURN: //enter key to go in to the selected menu item
if (menuSelect == 0) //play game
{
Gwin.refresh();
Gwin.clear(BLACK);
// Gwin.setFillColour(YELLOW);
// Gwin.drawImage(gameback, 0,0);
start = GetTickCount();
bl2.type = rand()%7;
generate_block();
// bl2.mapM.draw();
// ready = true;
play();
}
else if (menuSelect == 1) //set skill level
{
cout << "Code not yet written " << endl;
}
else if (menuSelect == 2) //display high score
{
/*Gwin.clear();
screenMenu = false;
displayHighScores();*/
cout << "Code not yet written " << endl;
}
else if (menuSelect == 3) //set up
{
cout << "Code not yet written " << endl;
}
else if (menuSelect == 4) //help
{
/*Gwin.clear();
screenMenu = false;
Gwin.drawImage(helpMenu,0,0);*/
cout << "Code not yet written " << endl;
}
else if (menuSelect == 5) //exit
{
control = true;
required = false;
menuExit = true;
cout << "Now exiting... " << endl;
Sleep(1000);
exit(0);
//required1 = false;
break;
}
break;
case CURSOR_RIGHT:
break;
}
// Gwin.refresh();
/**********************************************************END_OF_MENU**********************************************************/
}
} while(keyvalue!=ESCAPE);
//end of while loop
}
void tick(){
if((start % TICKSPEED == 0 && !CURSOR_DOWN)
|| free_fall){
bl.down();
}
}
void draw(){ //still incomplete. To draw the score and level layer
Gwin.moveTo(380, 20);
}
//void update(){
// Key key = ' ' ;
// if(game_over)
// return;
//
// if(Keyboard.kbhit())
// key = Keyboard.getch();
// if(key = GwinKeyNames::F9)
//}
void generate_block(){
if(!first_block){
if(!F3)
score += SCORE;
for(int y=0; y<20; y++){
for(int x=0; x<10; x++){
if(map[x][y] = ACTIVE)
map[x][y] = bl.type;
}
}
}
else {
first_block =false;
}
prev_pos_x = bl.b[0].x;
prev_pos_y = bl.b[0].y;
bottom_reached = false;
new_block = true;
holded = false;
ready_for_new_block = false;
free_fall = false;
count_line = 0;
Block4 next_block;
//Block4 next_block(3, 0, bl2.type);
bl = next_block;
next_block.b[0].x = 3;
next_block.b[0].y = 0;
next_block.type = bl2.type;
// Block4 next_block(3, 0, bl2.type);
next_block.draw(next_block.b[0].x, next_block.b[0].y, next_block.type);
// next_block = bl.draw(3, 0, bl2.type); //next_block
int random_number = rand() % 7;
//new_block
//Block4 new_block(11, 5, random_number);
//bl2 = new_block;
Block4 new_block;
new_block.b[0].x = 11;
new_block.b[0].y = 5;
new_block.type = random_number;
// Block4 new_block(11, 5, random_number);
new_block.draw(new_block.b[0].x, new_block.b[0].y, new_block.type);
// new_block = bl2.draw(11, 5, random_number); //new_block
}
//void play(){
//
//}
void bottom(){
static int count = 0;
bool temp = bottom_reached;
bottom_reached = false;
for(int i=0; i<4; i++){
if(bl.b[i].y == 19 || map[bl.b[i].x][bl.b[i].y+1] >= 0){
bottom_reached = true;
}
}
if(bottom_reached){
count++;
if(count > (int)(TIMEINTERVAL/2)){
ready_for_new_block = true;
count = 0;
}
else if((CURSOR_RIGHT || CURSOR_LEFT || CURSOR_UP) && moved)
count = 0;
}
else
count = 0;
}
void restart(){
mapM.initialize();
score = 0;
total_lines = 0;
level = 1;
start = 0;
start1 = 0;
for(int i=0; i<4; i++)
counter[i] = 0;
count_line = 0;
level_up_count = 0;
for(int i=0; i<4; i++)
t[i] = 1;
for(int i=0; i<7; i++)
bottom_reached = false;
game_over = false;
first_block = true;
new_block = true;
ready_for_new_block = false;
block_number = 0;
level_up = true;
quit = false;
moved = false;
free_fall = false;
prev_pos_x=0;
prev_pos_y=0;
holded = false;
pause=false;
first_hold = true;
generate_block();
}
void play(){
int temp_type;
while(!ESCAPE && !quit){
if(!game_over){
start++;
}
if(LEVELUP == 0){
level++;
level_up = true;
}
for(int x=0; x<10; x++){
for(int y=0; y<20; y++){
/*if(map[x][y] >=0){
Gwin.moveTo(x*32, y*32);
temp_type = bl.type;
Block4 block(x, y, temp_type);*/
if (map[x][y] == ACTIVE){
bl.type = temp_type;
bl.draw(x*32, y*32, temp_type);
}
}
}
/*if(!lines[0] && !pause)
tick();*/
if(!lines[0] && !free_fall && !pause){
if (Keyboard.kbhit()){
Keyboard.getch();
keyvalue = Keyboard.getch();
switch(keyvalue){
case CURSOR_LEFT:{
counter[CURSOR_LEFT]++;
bl.left();
}break;
case CURSOR_RIGHT:{
counter[CURSOR_RIGHT]++;
bl.right();
}break;
case CURSOR_DOWN:{
counter[CURSOR_DOWN]++;
bl.down();
}break;
case SPACE:{ //free-fall key
counter[SPACE]++;
free_fall = true;
}break;
case CURSOR_UP:{ //rotates the shape
counter[CURSOR_UP]++;
bl.up();
}break;
case F3:{ //for user to change type of shape falling down
if(!holded){
bl3.type = rand()%7;
int temp_type = bl3.type;
bl.destroy();
/*Block4 draw(3, 0, temp_type);
bl = new_block;*/
Block4 new_block;
//new_block.b[0].x = 11;
//new_block.b[0].y = 5;
//new_block.type = temp_type;
new_block.draw(11, 5, temp_type);
// new_block.draw(new_block.b[0].x, new_block.b[0].y, new_block.type);
}
else{
first_hold = false;
generate_block();
}
holded = true;
}break;
case F2:{ //F2 to restart game
if(holded){
restart();
}
}break;
case 'p': //pause game
case 'P':
pause = true;
resume = false;
while(resume = false){
pause = true;
}break;
case 'c': //resume game after pause
case 'C':
resume = true;
pause = false;
}
}
if(!lines[0] && !pause)
tick();
}
if(bottom_reached){
mapM.checkForLines();
}
if((!lines[0] && ready_for_new_block) || (!lines[0] && bottom_reached && free_fall))
generate_block();
draw();
while(start >= start1) {}
}
}
Edited by dargueta, 11 April 2011 - 01:42 PM.


Sign In
Create Account

Back to top









