<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>24Days　iPhoeアプリはdelphiでいっとく &#187; テンプレート</title>
	<atom:link href="http://musecode.net/technote/?cat=17&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://musecode.net/technote</link>
	<description>24日でiPhoneアプリを開発・公開するまでの過程を実況するサイト</description>
	<lastBuildDate>Wed, 07 Sep 2016 03:25:20 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6</generator>
		<item>
		<title>スコアマネージャー</title>
		<link>http://musecode.net/technote/?p=723</link>
		<comments>http://musecode.net/technote/?p=723#comments</comments>
		<pubDate>Fri, 30 May 2014 22:14:28 +0000</pubDate>
		<dc:creator>kawabata</dc:creator>
				<category><![CDATA[firemonkey]]></category>
		<category><![CDATA[テンプレート]]></category>

		<guid isPermaLink="false">http://musecode.net/technote/?p=723</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<pre class="brush: delphi; title: ; notranslate">

unit untScore;

interface

uses
  System.Classes,
  System.SysUtils,
  System.Generics.Collections,
  System.IOUtils,
  System.Types,
  FMX.Dialogs,
  System.UITypes;

type
  TScoreRecord = class
  private
    function getIsCorrect: boolean;

  const
    DELIMITER_CHAR = ',';

  public
    DateTime: TDateTime;
    SessionIndex: Integer;
    YomifudaSerial: Integer;
    TorifudaSerial: Integer;
    ResponceTime: Single;

    constructor Create();
    destructor Destroy; override;

    procedure DecodedString(aCodedString: String);
    function EncodeString(): String;

    property IsCorrect: boolean read getIsCorrect;
  end;

type
  TScoreList = class
  private

  public
    Items: TList&lt;TScoreRecord&gt;;

    constructor Create();
    destructor Destroy; override;

    procedure Init();
    procedure Load(aPathFileName: String);
    procedure Save(aPathFileName: String);

    procedure Add(aDateTime: TDateTime;
                  aSessionIndex: Integer;
                  aYomifudaSerial: Integer;
                  aTorifudaSerial: Integer;
                  aResponceTime: Single);


  end;

type
  TScoreManager = class
  const
    INITIAL_PLAYER_NAME = 'ゲスト';

  private
    FScoreRootPathName: String;

  public
    constructor Create(aScoreRootPathName: String);
    destructor Destroy; override;

    procedure PlayerList(vStringList: TStringList);
    procedure AddPlayer(aPlayerName: String);
    procedure DeletePlayer(aPlayerName: String);
    function IsPlayerExists(aPlayerName: String): Boolean;

  end;

var
  ScoreManager: TScoreManager;

const
  ON_SKIP    = -1;
  ON_TIMEOUT = -2;


implementation



// 要 System.IOUtils  System.Types
procedure fileListOfFolder(aFolderName: string; vFileList: TStringList);
var
  SearchPattern: string;
  Option: TSearchOption;
  FileNames: TStringDynArray;
  FileName: string;
begin
  // ファイル名に一致する検索パターン
  SearchPattern := '*.*';

  // ディレクトリの列挙モード
  Option := TSearchOption.soTopDirectoryOnly; // トップレベル列挙モード
  // Option := TSearchOption.soAllDirectories; // 再帰列挙モード

  //指定のディレクトリ内のファイルのリスト
  FileNames := TDirectory.GetFiles(aFolderName, SearchPattern, Option);
  vFileList.Clear;
  for FileName in FileNames do
    vFileList.Add(TPath.GetFileName(FileName));
end;





{ TScoreRecord }

constructor TScoreRecord.Create;
begin

end;

destructor TScoreRecord.Destroy;
begin

  inherited;
end;

procedure TScoreRecord.DecodedString(aCodedString: String);
var
  i: Integer;
  tmpFieldStringList: TStringList;
begin

  tmpFieldStringList := TStringList.Create;
  tmpFieldStringList.Delimiter := DELIMITER_CHAR;
  tmpFieldStringList.DelimitedText := aCodedString;

  Self.DateTime       := StrToDateTime(tmpFieldStringList[0]);
  Self.SessionIndex   := StrToInt     (tmpFieldStringList[1]);
  Self.YomifudaSerial := StrToInt     (tmpFieldStringList[2]);
  Self.TorifudaSerial := StrToInt     (tmpFieldStringList[3]);
  Self.ResponceTime   := StrToFloat   (tmpFieldStringList[4]);

  tmpFieldStringList.Free;
end;

function TScoreRecord.EncodeString: String;
var
  tmpFieldStringList: TStringList;
  tmpResult: string;
begin

  tmpFieldStringList := TStringList.Create;
  tmpFieldStringList.Delimiter := DELIMITER_CHAR;

  tmpFieldStringList.Add(DateTimeToStr(Self.DateTime));
  tmpFieldStringList.Add(IntToStr     (Self.SessionIndex));
  tmpFieldStringList.Add(IntToStr     (Self.YomifudaSerial));
  tmpFieldStringList.Add(IntToStr     (Self.TorifudaSerial));
  tmpFieldStringList.Add(FloatToStr   (Self.ResponceTime));

  tmpResult := tmpFieldStringList.DelimitedText;

  tmpFieldStringList.Free;

  Result := tmpResult;
end;

function TScoreRecord.getIsCorrect: boolean;
begin

end;

{ TScoreList }


constructor TScoreList.Create;
begin
  Items := TList&lt;TScoreRecord&gt;.Create;
  Init();
end;

destructor TScoreList.Destroy;
begin
  Init();
  Items.Free;
  inherited;
end;

procedure TScoreList.Init;
var
  i: Integer;
begin
  for i := 0 to Items.Count - 1 do
    Items[i].Free;
  Items.Clear;
end;

procedure TScoreList.Add(aDateTime: TDateTime;
                         aSessionIndex: Integer;
                         aYomifudaSerial,
                         aTorifudaSerial: Integer;
                         aResponceTime: Single);
var
  tmpScoreRecord: TScoreRecord;
begin
  tmpScoreRecord := TScoreRecord.Create;
  tmpScoreRecord.DateTime       := aDateTime;
  tmpScoreRecord.SessionIndex   := aSessionIndex;
  tmpScoreRecord.YomifudaSerial := aYomifudaSerial;
  tmpScoreRecord.TorifudaSerial := aTorifudaSerial;
  tmpScoreRecord.ResponceTime   := aResponceTime;

  Items.Add(tmpScoreRecord);
end;



procedure TScoreList.Load(aPathFileName: String);
var
  i: Integer;
  tmpRecordStringList: TStringList;
  tmpScoreRecord: TScoreRecord;
begin

  Self.Init();
  if FileExists(aPathFileName) then
  begin
    tmpRecordStringList := TStringList.Create;
    tmpRecordStringList.LoadFromFile(aPathFileName);

    for i := 0 to tmpRecordStringList.Count - 1 do
    begin
      tmpScoreRecord := TScoreRecord.Create();
      tmpScoreRecord.DecodedString(tmpRecordStringList[i]);
      Items.Add(tmpScoreRecord);
    end;
    tmpRecordStringList.Free;
  end;

end;

procedure TScoreList.Save(aPathFileName: String);
var
  i: Integer;
  tmpRecordStringList: TStringList;
begin

  tmpRecordStringList := TStringList.Create;
  tmpRecordStringList.Clear;
  for i := 0 to Self.Items.Count - 1 do
    tmpRecordStringList.Add(Self.Items[i].EncodeString);

  tmpRecordStringList.SaveToFile(aPathFileName);

  tmpRecordStringList.Free;
end;





{ TScoreManager }


constructor TScoreManager.Create(aScoreRootPathName: String);
begin
  FScoreRootPathName := aScoreRootPathName;

  ForceDirectories(aScoreRootPathName);
  if not IsPlayerExists(INITIAL_PLAYER_NAME) then AddPlayer(INITIAL_PLAYER_NAME);

end;

destructor TScoreManager.Destroy;
begin

  inherited;
end;

function TScoreManager.IsPlayerExists(aPlayerName: String): Boolean;
var
  tmpPathFileName: String;
begin
  tmpPathFileName := FScoreRootPathName + aPlayerName + '.txt';
  Result := TFile.Exists(tmpPathFileName);
end;

procedure TScoreManager.AddPlayer(aPlayerName: String);
var
  tmpPathFileName: String;
  tmpStringList: TStringList;
begin
  tmpPathFileName := FScoreRootPathName + aPlayerName + '.txt';
  tmpStringList := TStringList.Create;
  tmpStringList.Clear;
  tmpStringList.SaveToFile(tmpPathFileName);
  tmpStringList.Free;
end;

procedure TScoreManager.DeletePlayer(aPlayerName: String);
var
  tmpPathFileNameOld: String;
  tmpPathFileNameNew: String;
begin
  if aPlayerName = INITIAL_PLAYER_NAME then
  begin
    MessageDlg('このプレイヤーは削除できません。', TMsgDlgType.mtConfirmation,  [TMsgDlgBtn.mbOk], 0);
    Exit;
  end;
  tmpPathFileNameOld := FScoreRootPathName + aPlayerName + '.txt';
  tmpPathFileNameNew := FScoreRootPathName + aPlayerName + '.dum';
  RenameFile(tmpPathFileNameOld, tmpPathFileNameNew)
end;

procedure TScoreManager.PlayerList(vStringList: TStringList);
var
  i: Integer;
  tmpStringList: TStringList;
begin

  tmpStringList:= TStringList.Create;
  fileListOfFolder(FScoreRootPathName, tmpStringList);

  vStringList.Clear;
  for i := 0 to tmpStringList.Count - 1 do
    if ExtractFileExt(tmpStringList[i]) = '.txt' then
      vStringList.add(ChangeFileExt(ExtractFileName(tmpStringList[i]),''));

  tmpStringList.Free;

end;

end.

</pre>
]]></content:encoded>
			<wfw:commentRss>http://musecode.net/technote/?feed=rss2&#038;p=723</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
