SlideShare a Scribd company logo
// this function is used to save the current game (turn by turn)
void GameBoard::SaveGamePlay()
{
// if previous save has been loaded and no extra turns have been completed
if (reviewLoaded && gamePlayList.size() <= reviewPlayList.size()) return;
// if there is nothing to save
if (gamePlayList.empty()) return;
// local variables
HANDLE hFind;
WIN32_FIND_DATA FindFileData;
wostringstream stringstream;
char path[MAX_PATH];
LPWSTR wszPath = NULL;
size_t size;
// Get the path to the app data folder
HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, 0, &wszPath);
// Convert from LPWSTR to char[]
wcstombs_s(&size, path, MAX_PATH, wszPath, MAX_PATH);
// Convert char types
stringstream << path;
// variable to be used for save
wstring pathtowrite = stringstream.str();
// variable for folder search
wstring localFolder(pathtowrite.begin(), pathtowrite.end());
localFolder += L"*";
// find first valid file in folder
hFind = FindFirstFile(localFolder.c_str(), &FindFileData);
// Create our save file
if (reviewLoaded) // overwrite the 'continued' game
{
pathtowrite += L"";
pathtowrite += wstring(currSaveData.address.begin(), currSaveData.address.end());
}
else // create a new save
{
pathtowrite += L"Game_";
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
// get localtime
time(&rawtime);
timeinfo = localtime(&rawtime);
// format time
strftime(buffer, 80, "%d-%m-%Y_%I%M%S", timeinfo);
// convert to wstring
string str(buffer);
wstring wStr(str.begin(), str.end());
// add time to end of filename
pathtowrite += wStr;
}
pathtowrite += (L".bin");
fstream out(pathtowrite.c_str(), ios_base::out | ios_base::trunc | ios_base::binary);
if (out.is_open())
{
// create local variables to be saved
unsigned int mapID = theNetwork->GetMapID();
XMFLOAT4 team1Color = player[0]->GetColor();
XMFLOAT4 team2Color = player[1]->GetColor();
vector<Unit*> team1Army = player[0]->GetArmy();
vector<Unit*> team2Army = player[1]->GetArmy();
unsigned int team1Size = team1Army.size();
unsigned int team2Size = team2Army.size();
unsigned int numLists = gamePlayList.size();
// determine if an AI is being used
unsigned int teamAI = 0;
if (GetSpecificPlayer(0)->IsUsingAI())
{
teamAI = 1;
if (GetSpecificPlayer(1)->IsUsingAI())
teamAI = 3;
}
else if (GetSpecificPlayer(1)->IsUsingAI())
teamAI = 2;
// save base gamestate data
out.write((const char*)&mapID, sizeof(mapID));
out.write((const char*)&teamAI, sizeof(teamAI));
out.write((const char*)&numLists, sizeof(numLists));
out.write((const char*)&team1Color, sizeof(team1Color));
out.write((const char*)&team2Color, sizeof(team2Color));
// save army 1
out.write((const char*)&team1Size, sizeof(team1Size));
unsigned int count = 0;
for (auto const& unit : team1Army)
{
unitType type = unit->GetType();
unsigned int unitID = unit->GetID();
unsigned int sqID = army1StartLocs[count++];
out.write((const char*)&type, sizeof(type));
out.write((const char*)&unitID, sizeof(unitID));
out.write((const char*)&sqID, sizeof(sqID));
}
// save army 2
out.write((const char*)&team2Size, sizeof(team2Size));
count = 0;
for (auto const& unit : team2Army)
{
unitType type = unit->GetType();
unsigned int unitID = unit->GetID();
unsigned int sqID = army2StartLocs[count++];
out.write((const char*)&type, sizeof(type));
out.write((const char*)&unitID, sizeof(unitID));
out.write((const char*)&sqID, sizeof(sqID));
}
// save current Game (player turns)
for (auto const& list : gamePlayList)
{
unsigned int numActions = list.size();
out.write((const char*)&numActions, sizeof(numActions));
for each(saveData::actionData action in list)
{
ActionType type = action.type;
unsigned int unitID = action.unitID;
unsigned int dir = action.direction;
unsigned int dist = action.distance;
out.write((const char*)&type, sizeof(type));
out.write((const char*)&unitID, sizeof(unitID));
out.write((const char*)&dir, sizeof(dir));
out.write((const char*)&dist, sizeof(dist));
unsigned int size = action.destSquares.size();
out.write((const char*)&size, sizeof(size));
for (unsigned int loop = 0; loop < size; loop++)
{
unsigned int id = action.destSquares[loop];
out.write((const char*)&id, sizeof(id));
}
}
}
out.close();
}
}

More Related Content

What's hot

Rob Sullivan at Heroku's Waza 2013: Your Database -- A Story of Indifference
Rob Sullivan at Heroku's Waza 2013: Your Database -- A Story of IndifferenceRob Sullivan at Heroku's Waza 2013: Your Database -- A Story of Indifference
Rob Sullivan at Heroku's Waza 2013: Your Database -- A Story of IndifferenceHeroku
 
Snake in the DOM!
Snake in the DOM!Snake in the DOM!
Snake in the DOM!Gil Steiner
 
ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.Dr. Volkan OBAN
 
API Python Chess: Distribution of Chess Wins based on random moves
API Python Chess: Distribution of Chess Wins based on random movesAPI Python Chess: Distribution of Chess Wins based on random moves
API Python Chess: Distribution of Chess Wins based on random movesYao Yao
 
ランダム文字ぽいものをつくる
ランダム文字ぽいものをつくるランダム文字ぽいものをつくる
ランダム文字ぽいものをつくるTetsuji Koyama
 
Windows Server 2012 Active Directory Recovery
Windows Server 2012 Active Directory RecoveryWindows Server 2012 Active Directory Recovery
Windows Server 2012 Active Directory RecoverySerhad MAKBULOĞLU, MBA
 
How to calculate the optimal undo retention in Oracle
How to calculate the optimal undo retention in OracleHow to calculate the optimal undo retention in Oracle
How to calculate the optimal undo retention in OracleJorge Batista
 
Test driven game development silly, stupid or inspired?
Test driven game development   silly, stupid or inspired?Test driven game development   silly, stupid or inspired?
Test driven game development silly, stupid or inspired?Eric Smith
 
9. R data-import data-export
9. R data-import data-export9. R data-import data-export
9. R data-import data-exportExternalEvents
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲームNoritada Shimizu
 
Test Driven Cocos2d
Test Driven Cocos2dTest Driven Cocos2d
Test Driven Cocos2dEric Smith
 
python高级内存管理
python高级内存管理python高级内存管理
python高级内存管理rfyiamcool
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection apitrygvea
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
Nosql hands on handout 04
Nosql hands on handout 04Nosql hands on handout 04
Nosql hands on handout 04Krishna Sankar
 
R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemMaithreya Chakravarthula
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめようYuriko IKEDA
 

What's hot (20)

Rob Sullivan at Heroku's Waza 2013: Your Database -- A Story of Indifference
Rob Sullivan at Heroku's Waza 2013: Your Database -- A Story of IndifferenceRob Sullivan at Heroku's Waza 2013: Your Database -- A Story of Indifference
Rob Sullivan at Heroku's Waza 2013: Your Database -- A Story of Indifference
 
Snake in the DOM!
Snake in the DOM!Snake in the DOM!
Snake in the DOM!
 
ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.
 
API Python Chess: Distribution of Chess Wins based on random moves
API Python Chess: Distribution of Chess Wins based on random movesAPI Python Chess: Distribution of Chess Wins based on random moves
API Python Chess: Distribution of Chess Wins based on random moves
 
ランダム文字ぽいものをつくる
ランダム文字ぽいものをつくるランダム文字ぽいものをつくる
ランダム文字ぽいものをつくる
 
Windows Server 2012 Active Directory Recovery
Windows Server 2012 Active Directory RecoveryWindows Server 2012 Active Directory Recovery
Windows Server 2012 Active Directory Recovery
 
How to calculate the optimal undo retention in Oracle
How to calculate the optimal undo retention in OracleHow to calculate the optimal undo retention in Oracle
How to calculate the optimal undo retention in Oracle
 
Test driven game development silly, stupid or inspired?
Test driven game development   silly, stupid or inspired?Test driven game development   silly, stupid or inspired?
Test driven game development silly, stupid or inspired?
 
9. R data-import data-export
9. R data-import data-export9. R data-import data-export
9. R data-import data-export
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Test Driven Cocos2d
Test Driven Cocos2dTest Driven Cocos2d
Test Driven Cocos2d
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
python高级内存管理
python高级内存管理python高级内存管理
python高级内存管理
 
Vcs28
Vcs28Vcs28
Vcs28
 
Python 1
Python 1Python 1
Python 1
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Nosql hands on handout 04
Nosql hands on handout 04Nosql hands on handout 04
Nosql hands on handout 04
 
R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support System
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめよう
 

Viewers also liked

Viewers also liked (13)

How to avoid mistakes
How to avoid mistakesHow to avoid mistakes
How to avoid mistakes
 
Sam's grain research
Sam's grain research Sam's grain research
Sam's grain research
 
Spencer Ogden Brochure
Spencer Ogden BrochureSpencer Ogden Brochure
Spencer Ogden Brochure
 
STRAH
STRAHSTRAH
STRAH
 
NRFProtect15_ppt_ws_VIP (1)
NRFProtect15_ppt_ws_VIP (1)NRFProtect15_ppt_ws_VIP (1)
NRFProtect15_ppt_ws_VIP (1)
 
Personality Report for ME 2016
Personality Report for ME 2016Personality Report for ME 2016
Personality Report for ME 2016
 
Wheat by Angel and Ted
Wheat by Angel and TedWheat by Angel and Ted
Wheat by Angel and Ted
 
Dopod 5s
Dopod 5sDopod 5s
Dopod 5s
 
Hotel z pomysłem - Cinema Residence
Hotel z pomysłem - Cinema Residence Hotel z pomysłem - Cinema Residence
Hotel z pomysłem - Cinema Residence
 
Carousel30: Creating a digital strategy for nonprofits
Carousel30: Creating a digital strategy for nonprofits Carousel30: Creating a digital strategy for nonprofits
Carousel30: Creating a digital strategy for nonprofits
 
AkshaySheteResume
AkshaySheteResumeAkshaySheteResume
AkshaySheteResume
 
Aug.11
Aug.11Aug.11
Aug.11
 
MM PsychoTools Presentation
MM PsychoTools PresentationMM PsychoTools Presentation
MM PsychoTools Presentation
 

Similar to Save game function

Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfrozakashif85
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdffazilfootsteps
 
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Pujana Paliyawan
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12jafar104
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfinfo430661
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfasif1401
 
public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdfkavithaarp
 
groovy databases
groovy databasesgroovy databases
groovy databasesPaul King
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdffonecomp
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfshahidqamar17
 
Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfadwitanokiastore
 
Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Unity Technologies
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfimport java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfaoneonlinestore1
 
#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdfsinghanubhav1234
 

Similar to Save game function (20)

Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
 
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
 
Node meetup feb_20_12
Node meetup feb_20_12Node meetup feb_20_12
Node meetup feb_20_12
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdf
 
groovy databases
groovy databasesgroovy databases
groovy databases
 
Javascript
JavascriptJavascript
Javascript
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Code em Poker
Code em PokerCode em Poker
Code em Poker
 
AI For Texam Hold'em poker
AI For Texam Hold'em pokerAI For Texam Hold'em poker
AI For Texam Hold'em poker
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdf
 
Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
 
Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019
 
Internal workshop es6_2015
Internal workshop es6_2015Internal workshop es6_2015
Internal workshop es6_2015
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Mouse and Cat Game In C++
Mouse and Cat Game In C++Mouse and Cat Game In C++
Mouse and Cat Game In C++
 
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfimport java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
 
#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf
 

More from George Scott IV (7)

Square selection function
Square selection functionSquare selection function
Square selection function
 
Delete save from folder function
Delete save from folder functionDelete save from folder function
Delete save from folder function
 
Trees
TreesTrees
Trees
 
Strings
StringsStrings
Strings
 
Linked lists
Linked listsLinked lists
Linked lists
 
Misc
MiscMisc
Misc
 
Arrays
ArraysArrays
Arrays
 

Recently uploaded

Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILNatan Silnitsky
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisNeo4j
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowPeter Caitens
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesKrzysztofKkol1
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandIES VE
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockSkilrock Technologies
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...Alluxio, Inc.
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Krakówbim.edu.pl
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessWSO2
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
 

Recently uploaded (20)

Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 

Save game function

  • 1. // this function is used to save the current game (turn by turn) void GameBoard::SaveGamePlay() { // if previous save has been loaded and no extra turns have been completed if (reviewLoaded && gamePlayList.size() <= reviewPlayList.size()) return; // if there is nothing to save if (gamePlayList.empty()) return; // local variables HANDLE hFind; WIN32_FIND_DATA FindFileData; wostringstream stringstream; char path[MAX_PATH]; LPWSTR wszPath = NULL; size_t size; // Get the path to the app data folder HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, 0, &wszPath); // Convert from LPWSTR to char[] wcstombs_s(&size, path, MAX_PATH, wszPath, MAX_PATH); // Convert char types stringstream << path; // variable to be used for save wstring pathtowrite = stringstream.str(); // variable for folder search wstring localFolder(pathtowrite.begin(), pathtowrite.end()); localFolder += L"*"; // find first valid file in folder hFind = FindFirstFile(localFolder.c_str(), &FindFileData); // Create our save file if (reviewLoaded) // overwrite the 'continued' game { pathtowrite += L""; pathtowrite += wstring(currSaveData.address.begin(), currSaveData.address.end()); } else // create a new save { pathtowrite += L"Game_"; time_t rawtime; struct tm * timeinfo; char buffer[80]; // get localtime time(&rawtime); timeinfo = localtime(&rawtime); // format time strftime(buffer, 80, "%d-%m-%Y_%I%M%S", timeinfo); // convert to wstring string str(buffer); wstring wStr(str.begin(), str.end()); // add time to end of filename pathtowrite += wStr; }
  • 2. pathtowrite += (L".bin"); fstream out(pathtowrite.c_str(), ios_base::out | ios_base::trunc | ios_base::binary); if (out.is_open()) { // create local variables to be saved unsigned int mapID = theNetwork->GetMapID(); XMFLOAT4 team1Color = player[0]->GetColor(); XMFLOAT4 team2Color = player[1]->GetColor(); vector<Unit*> team1Army = player[0]->GetArmy(); vector<Unit*> team2Army = player[1]->GetArmy(); unsigned int team1Size = team1Army.size(); unsigned int team2Size = team2Army.size(); unsigned int numLists = gamePlayList.size(); // determine if an AI is being used unsigned int teamAI = 0; if (GetSpecificPlayer(0)->IsUsingAI()) { teamAI = 1; if (GetSpecificPlayer(1)->IsUsingAI()) teamAI = 3; } else if (GetSpecificPlayer(1)->IsUsingAI()) teamAI = 2; // save base gamestate data out.write((const char*)&mapID, sizeof(mapID)); out.write((const char*)&teamAI, sizeof(teamAI)); out.write((const char*)&numLists, sizeof(numLists)); out.write((const char*)&team1Color, sizeof(team1Color)); out.write((const char*)&team2Color, sizeof(team2Color)); // save army 1 out.write((const char*)&team1Size, sizeof(team1Size)); unsigned int count = 0; for (auto const& unit : team1Army) { unitType type = unit->GetType(); unsigned int unitID = unit->GetID(); unsigned int sqID = army1StartLocs[count++]; out.write((const char*)&type, sizeof(type)); out.write((const char*)&unitID, sizeof(unitID)); out.write((const char*)&sqID, sizeof(sqID)); } // save army 2 out.write((const char*)&team2Size, sizeof(team2Size)); count = 0; for (auto const& unit : team2Army) { unitType type = unit->GetType(); unsigned int unitID = unit->GetID(); unsigned int sqID = army2StartLocs[count++]; out.write((const char*)&type, sizeof(type)); out.write((const char*)&unitID, sizeof(unitID)); out.write((const char*)&sqID, sizeof(sqID)); } // save current Game (player turns) for (auto const& list : gamePlayList) { unsigned int numActions = list.size(); out.write((const char*)&numActions, sizeof(numActions));
  • 3. for each(saveData::actionData action in list) { ActionType type = action.type; unsigned int unitID = action.unitID; unsigned int dir = action.direction; unsigned int dist = action.distance; out.write((const char*)&type, sizeof(type)); out.write((const char*)&unitID, sizeof(unitID)); out.write((const char*)&dir, sizeof(dir)); out.write((const char*)&dist, sizeof(dist)); unsigned int size = action.destSquares.size(); out.write((const char*)&size, sizeof(size)); for (unsigned int loop = 0; loop < size; loop++) { unsigned int id = action.destSquares[loop]; out.write((const char*)&id, sizeof(id)); } } } out.close(); } }