Skip to content
Snippets Groups Projects
Commit 1247605f authored by mcmlxxix's avatar mcmlxxix
Browse files

added simple hall of fame feature for round winners, changed minimum score to...

added simple hall of fame feature for round winners, changed minimum score to -2, cleaned up game status listing in game lobby
parent fb966f7a
No related branches found
No related tags found
No related merge requests found
......@@ -31,12 +31,14 @@
//######################### InitIALIZE PROGRAM VARIABLES #########################
const pointsToWin= 100;
const minScore= -2;
const maxGames= 100;
const minPlayers= 3;
const maxPlayers= 7;
const maxDice= 8;
const root= "game";
const scorefile= "dicerank";
const halloffame= "dicehof";
const instructions= "dice.doc";
const bColors= [BG_BLUE, BG_CYAN, BG_RED, BG_GREEN, BG_BROWN, BG_MAGENTA, BG_LIGHTGRAY]; //MAP BACKGROUND COLORS
const bfColors= [BLUE, CYAN, RED, GREEN, BROWN, MAGENTA, LIGHTGRAY]; //MAP BACKGROUND COLORS (FOREGROUND CHARS)
......@@ -144,6 +146,7 @@ function ViewInstructions()
}
function ViewRankings()
{
games.HallOfFame();
scores=games.LoadRankings();
var scoredata=SortScores();
console.clear();
......@@ -167,7 +170,7 @@ function ViewRankings()
for(hs in scoredata)
{
thisuser=scoredata[hs];
if(scores[thisuser].score>0 || scores[thisuser].wins>0)
if(scores[thisuser].score!=0 || scores[thisuser].wins>0 || scores[thisuser].losses>0)
{
var winPercentage=0;
if(scores[thisuser].wins>0) winPercentage=(scores[thisuser].wins/(scores[thisuser].wins+scores[thisuser].losses))*100;
......@@ -291,7 +294,6 @@ function SplashScreen()
}
function GameMenu()
{
if(!(user.settings & USER_PAUSE)) console.pause();
var gMenu=new Menu( "" ,1,19,GetColor("green"),GetColor("green","high"));
var gmenu_items=[ "~Rankings" ,
"~Select Game" ,
......@@ -856,6 +858,7 @@ function Battle(attackFrom,attackTo,gameNumber)
attackFrom.displayBorder(border_color);
attackTo.displayBorder(border_color);
attackTo.show();
g.DisplayPlayers();
}
function EndTurn(gameNumber,pl)
{
......@@ -909,6 +912,7 @@ function Forfeit(gameNumber,playerNumber)
games.StoreGame(gameNumber);
}
}
g.DisplayPlayers();
games.StoreRankings();
}
//MAIN GAMEPLAY FUNCTION
......@@ -1113,7 +1117,7 @@ function Quit(err)
//TODO: CREATE A GAME EXIT ANSI SCREEN
printf("\n\r\1r\1h Thanks for playing!\r\n\r\n");
mswait(1000);
mswait(500);
exit(0);
}
//#######################MAIN GAME CLASS###################################
......@@ -1155,47 +1159,64 @@ function GameStatusInfo()
}
this.LoadRankings=function()
{
var reset=true;
while(reset)
var data=[];
var reset=false;
sfilename=game_dir+scorefile+".dat";
var lfile=new File(sfilename);
if(file_exists(sfilename))
{
reset=false;
data=[];
sfilename=game_dir+scorefile+".dat";
var lfile=new File(sfilename);
if(file_exists(sfilename))
GameLog("loading scores from file: " + sfilename);
lfile.open('r',true);
for(sc=0;!(lfile.eof);sc++)
{
GameLog("loading scores from file: " + sfilename);
lfile.open('r',true);
for(sc=0;!(lfile.eof);sc++)
plyr=lfile.readln();
if(plyr==undefined || plyr=="") break;
else
{
plyr=lfile.readln();
if(plyr==undefined || plyr=="") break;
else
{
player=parseInt(plyr);
var score=parseInt(lfile.readln());
if(score>=pointsToWin)
{
this.ResetScores();
reset=true;
}
var wins=parseInt(lfile.readln());
var losses=parseInt(lfile.readln());
data[player]={'score':score,'wins':wins,'losses':losses};
GameLog(system.username(player) + ":" + data[player].score + ":" + data[player].wins +":"+data[player].losses);
player=parseInt(plyr);
var score=parseInt(lfile.readln());
if(score>=pointsToWin)
{
lfile.close();
file_remove(lfile.name);
this.WinRound(player);
reset=true;
break;
}
var wins=parseInt(lfile.readln());
var losses=parseInt(lfile.readln());
data[player]={'score':score,'wins':wins,'losses':losses};
GameLog(system.username(player) + ":" + data[player].score + ":" + data[player].wins +":"+data[player].losses);
}
lfile.close();
}
else GameLog("score file: " + sfilename + " does not exist");
lfile.close();
}
else GameLog("score file: " + sfilename + " does not exist");
if(reset) data=[];
return data;
}
this.ResetScores=function()
{
//TODO: ADD BULLETIN OUTPUT METHOD FOR BULLSEYE BULLETINS & HISTORICAL WINNERS LIST
this.WinRound=function(player)
{
hfilename=game_dir+halloffame+".dat";
var hfile=new File(hfilename);
if(!file_exists(hfile.name))
{
hfile.open('w+');
hfile.writeln("\1y\1hDICE-WARZ HALL OF FAME (Round Winners):");
hfile.writeln();
}
else hfile.open('a');
hfile.writeln(system.username(player) + ": " + system.datestr());
hfile.close();
}
this.HallOfFame=function()
{
if(file_exists(game_dir+halloffame+".dat"))
{
console.clear();
console.printfile(game_dir + dicehof + ".dat");
console.pause();
}
}
this.LoadGame=function(gamefile,gameNumber,lastModified)
{
......@@ -1383,50 +1404,15 @@ function GameStatusInfo()
{
GameLog("game " + gd + " needs updating");
this.gameData[gd]=this.LoadGame(fileName,gd,lastModified);
this.FilterData();
}
}
else
{
GameLog("gamefile " + fileName + " deleted, removing data");
for(gnf in this.notFull) {
if(this.notFull[gnf]==gd) {
this.notFull.splice(gnf,1);
}
}
for(inp in this.inProgress) {
if(this.inProgress[inp]==gd) {
this.inProgress.splice(inp,1);
}
}
for(yg in this.yourGames) {
if(this.yourGames[yg]==gd) {
this.yourGames.splice(yg,1);
}
}
for(yt in this.yourTurn)
{
if(this.yourTurn[yt]==gd) {
this.yourTurn.splice(yt,1);
}
}
for(sp in this.singleGames)
{
if(this.singleGames[sp]==gd) {
this.singleGames.splice(sp,1);
}
}
delete this.gameData[gd];
}
}
this.inProgress=this.SortArray(this.inProgress);
this.notFull=this.SortArray(this.notFull);
this.completed=this.SortArray(this.completed);
this.youWin=this.SortArray(this.youWin);
this.yourGames=this.SortArray(this.yourGames);
this.yourTurn=this.SortArray(this.yourTurn);
this.eliminated=this.SortArray(this.eliminated);
this.singleGames=this.SortArray(this.singleGames);
this.FilterData();
}
this.SortArray=function(data)
{
......@@ -1501,7 +1487,7 @@ function GameStatusInfo()
}
this.LoadGames=function()
{
var open_list=directory(game_dir + root + "*.dat"); // scan for voting topic files
var open_list=directory(game_dir + root + "*.dat");
GameLog("today's date: " + time());
if(open_list.length)
{
......@@ -1516,6 +1502,8 @@ function GameStatusInfo()
this.gameData[gameNumber]=lgame;
}
}
this.FilterData();
this.DeleteOld();
}
this.DeleteOld=function()
{
......@@ -1575,8 +1563,6 @@ function GameStatusInfo()
scores=games.LoadRankings();
this.LoadGames();
games.StoreRankings();
this.FilterData();
this.DeleteOld();
this.SkipPlayers();
}
}
......
......@@ -109,33 +109,36 @@ function Map(c,r,p,gn)
nextTurn=this.nextTurn;
nextTurnPlayer=this.players[this.turnOrder[nextTurn]].user;
if(this.CountActiveHumans<2)
if(this.status!=0)
{
GameLog("only one human player active, no notification sent");
return;
}
if(nextTurnPlayer>0 && nextTurnPlayer!=user.number)
{
DeliverMessage(nextTurnPlayer,this.gameNumber);
GameLog("next player notified of turn: " + system.username(nextTurnPlayer));
}
else
{
while(1)
if(this.CountActiveHumans<2)
{
if(nextTurn==this.maxPlayers-1) nextTurn=0;
else nextTurn++;
nextTurnPlayer=this.players[this.turnOrder[nextTurn]].user;
if(nextTurnPlayer==this.players[this.turnOrder[this.nextTurn]].user)
{
GameLog("all other human players eliminated, no other players notified");
break;
}
else if(nextTurnPlayer>0 && this.status!=0)
GameLog("only one human player active, no notification sent");
return;
}
if(nextTurnPlayer>0 && nextTurnPlayer!=user.number)
{
DeliverMessage(nextTurnPlayer,this.gameNumber);
GameLog("next player notified of turn: " + system.username(nextTurnPlayer));
}
else
{
while(1)
{
DeliverMessage(nextTurnPlayer,this.gameNumber);
GameLog("skipped computer notices, next human user notified of turn: " + system.username(nextTurnPlayer));
break;
if(nextTurn==this.maxPlayers-1) nextTurn=0;
else nextTurn++;
nextTurnPlayer=this.players[this.turnOrder[nextTurn]].user;
if(nextTurnPlayer==this.players[this.turnOrder[this.nextTurn]].user)
{
GameLog("all other human players eliminated, no other players notified");
break;
}
else if(nextTurnPlayer>0)
{
DeliverMessage(nextTurnPlayer,this.gameNumber);
GameLog("skipped computer notices, next human user notified of turn: " + system.username(nextTurnPlayer));
break;
}
}
}
}
......@@ -222,6 +225,7 @@ function Map(c,r,p,gn)
var offset=(this.players.length<5?2:1);
pts=points[pointBuffer+(this.eliminated.length-offset)];
scores[dead.user].score+=pts;
if(scores[dead.user].score<minScore) scores[dead.user].score=minScore;
GameLog("giving " + pts + " points to user " + system.username(dead.user));
}
games.StoreRankings();
......@@ -418,6 +422,7 @@ function Map(c,r,p,gn)
for(ply=0;ply<this.maxPlayers;ply++)
{
playerNumber=this.turnOrder[ply];
this.CountDice(playerNumber);
player=this.players[playerNumber];
if(player.eliminated) { player.bColor=blackBG; player.fColor="\1n\1k\1h"; }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment