-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Everything apparently works (except scores, have to fix that up)
- Loading branch information
0 parents
commit 39e45ce
Showing
14 changed files
with
1,016 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
<CodeBlocks_project_file> | ||
<FileVersion major="1" minor="6" /> | ||
<Project> | ||
<Option title="Tetris" /> | ||
<Option makefile="makefile" /> | ||
<Option pch_mode="2" /> | ||
<Option compiler="gcc" /> | ||
<Build> | ||
<Target title="Debug"> | ||
<Option output="bin\Debug\Tetris" prefix_auto="1" extension_auto="1" /> | ||
<Option object_output="obj\Debug\" /> | ||
<Option type="1" /> | ||
<Option compiler="gcc" /> | ||
<Compiler> | ||
<Add option="-g" /> | ||
</Compiler> | ||
</Target> | ||
<Target title="Release"> | ||
<Option output="bin\Release\Tetris" prefix_auto="1" extension_auto="1" /> | ||
<Option object_output="obj\Release\" /> | ||
<Option type="0" /> | ||
<Option compiler="gcc" /> | ||
<Compiler> | ||
<Add option="-O2" /> | ||
</Compiler> | ||
<Linker> | ||
<Add option="-s" /> | ||
</Linker> | ||
</Target> | ||
</Build> | ||
<Compiler> | ||
<Add option="-Wall" /> | ||
<Add option="-Wno-write-strings" /> | ||
<Add option="-x c++" /> | ||
<Add option="-std=c++98" /> | ||
<Add option="-pedantic" /> | ||
<Add directory="$(CODEBLOCKS)\sdk\winbgim\include" /> | ||
</Compiler> | ||
<Linker> | ||
<Add library="bgi" /> | ||
<Add library="gdi32" /> | ||
<Add library="comdlg32" /> | ||
<Add library="uuid" /> | ||
<Add library="oleaut32" /> | ||
<Add library="ole32" /> | ||
<Add directory="$(CODEBLOCKS)\sdk\winbgim\lib" /> | ||
</Linker> | ||
<Extensions> | ||
<code_completion /> | ||
<envvars /> | ||
<debugger /> | ||
<lib_finder disable_auto="1" /> | ||
</Extensions> | ||
</Project> | ||
</CodeBlocks_project_file> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# depslib dependency file v1.0 | ||
1409361558 source:f:\dropbox\documents\source code\tetris\main.cpp | ||
"piece.h" | ||
"board.h" | ||
"graphics.h" | ||
<dos.h> | ||
<stdlib.h> | ||
<conio.h> | ||
<fstream> | ||
<ctime> | ||
|
||
1384017582 f:\dropbox\documents\source code\tetris\piece.h | ||
|
||
1384017615 f:\dropbox\documents\source code\tetris\board.h | ||
"piece.h" | ||
|
||
1409360597 f:\dropbox\documents\source code\tetris\graphics.h | ||
<windows.h> | ||
<limits.h> | ||
<sstream> | ||
|
||
1409360954 source:f:\dropbox\documents\source code\tetris\piece.cpp | ||
"graphics.h" | ||
<iostream> | ||
<conio.h> | ||
<stdlib.h> | ||
"piece.h" | ||
|
||
1410040619 source:f:\dropbox\documents\source code\tetris\board.cpp | ||
"graphics.h" | ||
<conio.h> | ||
<stdlib.h> | ||
<dos.h> | ||
<time.h> | ||
"board.h" | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#include "graphics.h" | ||
#include <conio.h> | ||
#include <stdlib.h> | ||
#include <dos.h> | ||
#include <time.h> | ||
#include "board.h" | ||
|
||
using namespace std; | ||
|
||
Board::Board() { | ||
int i, j; | ||
for (i = 0; i < 24; i++) { | ||
widths[i] = 0; | ||
for (j = 0; j < 10; j++) { | ||
grid[i][j] = 0; | ||
} | ||
} | ||
for (i = 0; i < 10; i++) { | ||
heights[i] = 0; | ||
} | ||
score = 0; | ||
offset = Point ( (getmaxx() - 10 * Piece::side) / 2, | ||
(getmaxy() - 24 * Piece::side) / 2); | ||
backup(); | ||
} | ||
|
||
void Board::backup() { | ||
int i, j; | ||
for (i = 0; i < 24; i++) | ||
for (j = 0; j < 10; j++) { | ||
xgrid[i][j] = grid[i][j]; | ||
} | ||
for (i = 0; i < 10; i++) { | ||
xheights[i] = heights[i]; | ||
} | ||
for (j = 0; j < 24; j++) { | ||
xwidths[j] = widths[j]; | ||
} | ||
} | ||
|
||
void Board::undo() { | ||
int i, j; | ||
for (i = 0; i < 24; i++) | ||
for (j = 0; j < 10; j++) { | ||
grid[i][j] = xgrid[i][j]; | ||
} | ||
for (i = 0; i < 10; i++) { | ||
heights[i] = xheights[i]; | ||
} | ||
for (j = 0; j < 24; j++) { | ||
widths[j] = xwidths[j]; | ||
} | ||
} | ||
|
||
int Board::drop (Piece p, Point pos) { | ||
while (place (p, pos) != PLACE_BAD) { | ||
undo(); | ||
pos.y--; | ||
} | ||
undo(); | ||
return pos.y + 1; | ||
} | ||
|
||
int Board::place (Piece p, Point loc) { | ||
Point pos; | ||
int i, j; | ||
if (loc.x < 0 || loc.x + p.getWidth() > 10) { | ||
return PLACE_OUT_BOUNDS; | ||
} | ||
if (loc.y < 0) { | ||
return PLACE_BAD; | ||
} | ||
for (i = 0; i < 4; i++) { | ||
pos = p.getBody (i); | ||
pos.x += loc.x; | ||
pos.y += loc.y; | ||
if (grid[pos.y][pos.x]) { | ||
return PLACE_BAD; | ||
} else { | ||
grid[pos.y][pos.x] = p.getColor(); | ||
} | ||
} | ||
for (i = 0; i < 4; i++) { | ||
widths[loc.y + p.getBody (i).y]++; | ||
} | ||
for (i = loc.y; i < loc.y + p.getHeight(); i++) | ||
if (widths[i] == 10) { | ||
return PLACE_ROW_FILLED; | ||
} | ||
for (i = 0; i < 4; i++) | ||
if (heights[loc.x + p.getBody (i).x] < loc.y + p.getBody (i).y + 1) { | ||
heights[loc.x + p.getBody (i).x] = loc.y + p.getBody (i).y + 1; | ||
} | ||
for (i = 0; i < 4; i++) | ||
if (heights[p.getBody (i).x + loc.x] >= 19) { | ||
return PLACE_FULL; | ||
} | ||
return PLACE_OK; | ||
} | ||
|
||
void Board::clearRows() { | ||
int i, j, k; | ||
for (i = 0; i < 23; i++) { | ||
if (widths[i] == 10) { | ||
for (j = i; j < 23 && widths[j]; j++) { | ||
for (k = 0; k < 10; k++) { | ||
grid[j][k] = grid[j + 1][k]; | ||
} | ||
widths[j] = widths[j + 1]; | ||
} | ||
i--; | ||
} | ||
} | ||
for (i = 0; i < 10; i++) { | ||
for (j = 23; j >= 0 && !grid[j][i]; j--); | ||
heights[i] = j + 1; | ||
} | ||
} | ||
|
||
void Board::display() { | ||
int i, j, maxy = getmaxy(); | ||
char sc[10]; | ||
//itoa (score, sc, 10); | ||
settextstyle (TRIPLEX_FONT, HORIZ_DIR, 3); | ||
setfillstyle (SOLID_FILL, BLACK); | ||
bar (10, 10, 5 * textwidth (sc), 1.8 * textheight (sc) ); | ||
outtextxy (10, 10, sc); | ||
for (i = 0; i < 11; i++) | ||
line ( offset.x + Piece::side * ( (float) (i) - 0.5), | ||
maxy - offset.y - Piece::side * ( (float) (24) - 0.5), | ||
offset.x + Piece::side * ( (float) (i) - 0.5), | ||
maxy - offset.y + Piece::side * (0.5) ); | ||
for (j = 0; j < 25; j++) | ||
line ( offset.x + Piece::side * (-0.5), | ||
maxy - offset.y - Piece::side * ( (float) (j) - 0.5), | ||
offset.x + Piece::side * ( (float) (10) - 0.5), | ||
maxy - offset.y - Piece::side * ( (float) (j) - 0.5) ); | ||
for (j = 0; j < 24; j++) { | ||
for (i = 0; i < 10; i++) { | ||
if (grid[j][i]) { | ||
setfillstyle (SOLID_FILL, grid[j][i]); | ||
floodfill (offset.x + Piece::side * i, maxy - offset.y - Piece::side * j, | ||
WHITE); | ||
} else if (j == xheights[i]) { | ||
setfillstyle (SLASH_FILL, DARKGRAY); | ||
floodfill (offset.x + Piece::side * i, maxy - offset.y - Piece::side * j, | ||
WHITE); | ||
} else { | ||
setfillstyle (SOLID_FILL, BLACK); | ||
floodfill (offset.x + Piece::side * i, maxy - offset.y - Piece::side * j, | ||
WHITE); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef BOARD_H | ||
#define BOARD_H | ||
#include "piece.h" | ||
|
||
enum {PLACE_OK=0, PLACE_OUT_BOUNDS, PLACE_ROW_FILLED, PLACE_OVERLAP, PLACE_FULL, PLACE_BAD}; | ||
|
||
class Board{ | ||
private: | ||
int grid[24][10]; | ||
int xgrid[24][10]; | ||
int widths[24]; | ||
int xwidths[24]; | ||
int heights[10]; | ||
int xheights[10]; | ||
int score; | ||
Point offset; | ||
public: | ||
Board(); | ||
int place(Piece p, Point loc); | ||
int drop(Piece p, Point pos); | ||
void display(); | ||
void backup(); | ||
void undo(); | ||
void clearRows(); | ||
void scored() {score+=100;} | ||
}; | ||
|
||
#endif |
Oops, something went wrong.