forked from HaikuArchives/BeVexed
-
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.
- Loading branch information
0 parents
commit 75ee975
Showing
17 changed files
with
1,259 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,10 @@ | ||
BeVexed 1.0 | ||
A maddeningly-addictive puzzle game. | ||
|
||
If you've ever heard of a game called TetraVex, you will find this wonderful little time waster all too familiar. The concept is simple: put the tiles in the grid on the left such that the numbers match wherever 2 tiles touch. | ||
|
||
About This Version | ||
|
||
There's not much to tell - this is the first release. It has been tested pretty extensively, so there shouldn't be any major bugs and possibly not even minor ones. | ||
|
||
If you would like to see a feature or have a bug to report, please send e-mails to [email protected] |
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,99 @@ | ||
#include <Application.h> | ||
#include <AppFileInfo.h> | ||
#include <Roster.h> | ||
#include <String.h> | ||
#include <stdio.h> | ||
#include <Screen.h> | ||
#include <TranslationUtils.h> | ||
#include "AboutWindow.h" | ||
|
||
// In case I want to localize this later | ||
#define TRANSLATE(x) x | ||
|
||
AboutWindow::AboutWindow(void) | ||
: BWindow(BRect(100,100,500,400),"Lights Off!", B_MODAL_WINDOW_LOOK, | ||
B_MODAL_APP_WINDOW_FEEL, | ||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE) | ||
{ | ||
BScreen screen; | ||
BRect screenrect(screen.Frame()); | ||
|
||
AboutView *aboutview=new AboutView(Bounds()); | ||
AddChild(aboutview); | ||
|
||
MoveTo( (screenrect.Width()-Frame().Width())/2, (screenrect.Height()-Frame().Height())/2 ); | ||
} | ||
|
||
AboutView::AboutView(BRect frame) | ||
: BView (frame, "AboutView", B_FOLLOW_ALL, B_WILL_DRAW) | ||
{ | ||
SetViewColor(126,126,190); | ||
|
||
fLogo=BTranslationUtils::GetBitmap('PNG ',"BeVexedAbout.png"); | ||
|
||
app_info ai; | ||
version_info vi; | ||
be_app->GetAppInfo(&ai); | ||
BFile file(&ai.ref,B_READ_ONLY); | ||
BAppFileInfo appinfo(&file); | ||
appinfo.GetVersionInfo(&vi,B_APP_VERSION_KIND); | ||
|
||
BString variety; | ||
switch(vi.variety) | ||
{ | ||
case 0: | ||
variety=TRANSLATE("d"); | ||
break; | ||
case 1: | ||
variety=TRANSLATE("a"); | ||
break; | ||
case 2: | ||
variety=TRANSLATE("b"); | ||
break; | ||
case 3: | ||
variety=TRANSLATE("g"); | ||
break; | ||
case 4: | ||
variety=TRANSLATE("rc"); | ||
break; | ||
default: | ||
variety=TRANSLATE("Final"); | ||
break; | ||
} | ||
|
||
if(variety!="Final") | ||
sprintf(version,"%s %lu.%lu %s%lu",TRANSLATE("v"),vi.major, | ||
vi.middle,variety.String(),vi.internal); | ||
else | ||
sprintf(version,"%s %lu.%lu",TRANSLATE("v"),vi.major,vi.middle); | ||
|
||
font_height height; | ||
be_plain_font->GetHeight(&height); | ||
|
||
versionpos.y=height.ascent+height.descent+height.leading+5; | ||
versionpos.x=fLogo->Bounds().right - 5 - StringWidth(version); | ||
|
||
SetDrawingMode(B_OP_OVER); | ||
} | ||
|
||
AboutView::~AboutView(void) | ||
{ | ||
delete fLogo; | ||
} | ||
|
||
void AboutView::MouseDown(BPoint pt) | ||
{ | ||
Window()->PostMessage(B_QUIT_REQUESTED); | ||
} | ||
|
||
void AboutView::AttachedToWindow(void) | ||
{ | ||
Window()->ResizeTo(fLogo->Bounds().Width(),fLogo->Bounds().Height()); | ||
} | ||
|
||
void AboutView::Draw(BRect update) | ||
{ | ||
DrawBitmap(fLogo, BPoint(0,0)); | ||
SetHighColor(224,224,224); | ||
DrawString(version,versionpos); | ||
} |
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,50 @@ | ||
#ifndef ABOUTWINDOW_H | ||
#define ABOUTWINDOW_H | ||
|
||
#include <Window.h> | ||
#include <View.h> | ||
#include <Bitmap.h> | ||
#include <Button.h> | ||
#include <Messenger.h> | ||
#include <Font.h> | ||
#include <StatusBar.h> | ||
|
||
enum | ||
{ | ||
ABOUT_STARTUP=0, | ||
ABOUT_OK, | ||
ABOUT_OK2=2 | ||
}; | ||
|
||
enum | ||
{ | ||
M_RESET_STATUS='mrst', | ||
M_SET_STATUS='msst', | ||
M_UPDATE_STATUS='mups' | ||
}; | ||
|
||
class AboutView : public BView | ||
{ | ||
public: | ||
AboutView(BRect frame); | ||
~AboutView(void); | ||
void AttachedToWindow(void); | ||
void Draw(BRect update); | ||
void MouseDown(BPoint pt); | ||
|
||
BBitmap *fLogo; | ||
|
||
char version[64]; | ||
BPoint versionpos; | ||
|
||
uint8 fAboutFlags; | ||
int32 fEntryCount; | ||
}; | ||
|
||
class AboutWindow : public BWindow | ||
{ | ||
public: | ||
AboutWindow(void); | ||
}; | ||
|
||
#endif |
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,25 @@ | ||
#include <Application.h> | ||
#include "MainWindow.h" | ||
#include <OS.h> | ||
#include <stdlib.h> | ||
|
||
class App : public BApplication | ||
{ | ||
public: | ||
App(void); | ||
}; | ||
|
||
App::App(void) | ||
: BApplication("application/x-vnd.wgp-BeVexed") | ||
{ | ||
MainWindow *mainwin = new MainWindow(); | ||
mainwin->Show(); | ||
} | ||
|
||
int main(void) | ||
{ | ||
srand(system_time()); | ||
App app; | ||
app.Run(); | ||
return 0; | ||
} |
Binary file not shown.
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,200 @@ | ||
#include "Grid.h" | ||
#include <OS.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include "TileView.h" | ||
|
||
//#define TESTMODE 1 | ||
|
||
#define MKRAND uint8(float(rand()) / RAND_MAX * 9) | ||
|
||
Tile::Tile(void) | ||
: left(-1), | ||
top(-1), | ||
right(-1), | ||
bottom(-1), | ||
id(0), | ||
lefttile(NULL), | ||
toptile(NULL), | ||
righttile(NULL), | ||
bottomtile(NULL) | ||
{ | ||
SetValues(-1,-1,-1,-1); | ||
id=0; | ||
} | ||
|
||
Tile::Tile(const uint8 &l, const uint8 &t, const uint8 &r, const uint8 &b) | ||
: left(l), | ||
top(t), | ||
right(r), | ||
bottom(b), | ||
id(0), | ||
lefttile(NULL), | ||
toptile(NULL), | ||
righttile(NULL), | ||
bottomtile(NULL) | ||
{ | ||
id=0; | ||
} | ||
|
||
Tile::Tile(const Tile &t) | ||
: left(t.left), | ||
top(t.top), | ||
right(t.right), | ||
bottom(t.bottom), | ||
id(t.id), | ||
lefttile(NULL), | ||
toptile(NULL), | ||
righttile(NULL), | ||
bottomtile(NULL) | ||
{ | ||
id=t.id; | ||
} | ||
|
||
Tile &Tile::operator=(const Tile &t) | ||
{ | ||
SetValues(t.left,t.top,t.right,t.bottom); | ||
id=t.id; | ||
return *this; | ||
} | ||
|
||
|
||
void Tile::SetValues(const uint8 &l, const uint8 &t, const uint8 &r, const uint8 &b) | ||
{ | ||
left = l; | ||
top = t; | ||
right = r; | ||
bottom = b; | ||
} | ||
|
||
Grid::Grid(uint8 size) | ||
{ | ||
if(size == 0) | ||
debugger("Programmer Error: Grid has 0 tiles"); | ||
|
||
fSize = size; | ||
|
||
for(uint8 row=0; row<fSize; row++) | ||
{ | ||
uint16 index = row * fSize; | ||
for(uint8 col=0; col<fSize; col++) | ||
{ | ||
Tile *tile = new Tile(); | ||
fTiles.AddItem(tile); | ||
|
||
if(col == 0) | ||
tile->lefttile = NULL; | ||
else | ||
tile->lefttile = (Tile*)fTiles.ItemAt(index + col - 1); | ||
|
||
if(row == 0) | ||
tile->toptile = NULL; | ||
else | ||
tile->toptile = (Tile*)fTiles.ItemAt(index + col - fSize); | ||
} | ||
} | ||
uint16 arraysize = fSize * fSize; | ||
for(uint16 i=0; i<arraysize; i++) | ||
{ | ||
Tile *tile = (Tile*)fTiles.ItemAt(i); | ||
if(tile->lefttile) | ||
tile->lefttile->righttile = tile; | ||
if(tile->toptile) | ||
tile->toptile->bottomtile = tile; | ||
} | ||
} | ||
|
||
Grid::~Grid(void) | ||
{ | ||
for(int32 i=0; i<fTiles.CountItems(); i++) | ||
delete (Tile*)fTiles.ItemAt(i); | ||
fTiles.MakeEmpty(); | ||
} | ||
|
||
void Grid::GeneratePuzzle(void) | ||
{ | ||
Tile *tile; | ||
|
||
// Generate tiles and index when solved | ||
uint16 id=0; | ||
for(uint8 row=0; row<fSize; row++) | ||
{ | ||
uint16 index = row * fSize; | ||
for(uint8 col=0; col<fSize; col++) | ||
{ | ||
tile = (Tile*)fTiles.ItemAt(index + col); | ||
tile->left = tile->lefttile ? tile->lefttile->right : MKRAND; | ||
tile->top = tile->toptile ? tile->toptile->bottom : MKRAND; | ||
tile->right = MKRAND; | ||
tile->bottom = MKRAND; | ||
tile->id = id++; | ||
} | ||
} | ||
|
||
#ifndef TESTMODE | ||
// Now mix them all up | ||
uint16 arraysize = (fSize * fSize); | ||
uint16 count = arraysize * 4; | ||
for(uint8 i=0; i<count; i++) | ||
{ | ||
// swap two random elements | ||
uint16 indexone = uint16(float(rand()) / RAND_MAX * arraysize); | ||
uint16 indextwo = uint16(float(rand()) / RAND_MAX * arraysize); | ||
|
||
fTiles.SwapItems(indexone,indextwo); | ||
} | ||
#endif | ||
} | ||
|
||
Tile *Grid::TileAt(const uint16 &index) | ||
{ | ||
if(index > (fSize * fSize) - 1) | ||
debugger("Programmer Error: Tile index too big"); | ||
|
||
return (Tile*)fTiles.ItemAt(index); | ||
} | ||
|
||
bool Grid::TryTile(Tile *src, Tile *dest) | ||
{ | ||
if(!src || !dest || src->IsEmpty()) | ||
return false; | ||
|
||
|
||
// Return true if the thing is a valid play | ||
if(dest->lefttile && !dest->lefttile->IsEmpty()) | ||
{ | ||
if(dest->lefttile != src && dest->lefttile->right!=src->left) | ||
return false; | ||
} | ||
|
||
if(dest->toptile && !dest->toptile->IsEmpty()) | ||
{ | ||
if(dest->toptile != src && dest->toptile->bottom!=src->top) | ||
return false; | ||
} | ||
|
||
if(dest->righttile && !dest->righttile->IsEmpty()) | ||
{ | ||
if(dest->righttile != src && dest->righttile->left!=src->right) | ||
return false; | ||
} | ||
|
||
if(dest->bottomtile && !dest->bottomtile->IsEmpty()) | ||
{ | ||
if(dest->bottomtile != src && dest->bottomtile->top!=src->bottom) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool Grid::IsSolved(void) | ||
{ | ||
// return true if the puzzle is solved | ||
for(int32 i=0; i<fTiles.CountItems(); i++) | ||
{ | ||
Tile *t = (Tile*)fTiles.ItemAt(i); | ||
if(t->id != i || t->IsEmpty()) | ||
return false; | ||
} | ||
return true; | ||
} |
Oops, something went wrong.