コイン入出力周りと内部のゲーム設定などを。
データ構造丸々取り出せる関数はテストコードであるような
一気にデータ丸々欲しい場合なんかを想定して用意してます。
main.c
/*--------------------------------------------------------------------------------- coinmng module test version 0.01 Jan 20, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #include <stdio.h> #include <nds/ndstypes.h> #include <nds/interrupts.h> #include <nds/arm9/input.h> #include <nds/arm9/console.h> #include "Coinmng.h" #include "Status.h" void main_DrawStatus(void); //--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- u8 win_cnt = 0; consoleDemoInit(); printf("\x01b[0;0Hcoinmng module test\n\nversion 0.01\nJan 19, 2010\n\nBy. REGEKATSU\n\n\n"); Status_Clear(); while(1) { swiWaitForVBlank(); scanKeys(); printf("\x01b[9;0HWIN_CNT: %01d", win_cnt); main_DrawStatus(); if(keysDown() & KEY_X){ Coinmng_InCoin(COIN_CASH); }else if(keysDown() & KEY_Y){ if(Status_GetMedal() != 0){ Coinmng_InCoin(COIN_MEDAL); } }else if(keysDown() & KEY_START){ Coinmng_InCoin(COIN_EXCHANGE); } if(keysDown() & KEY_B){ Coinmng_OutCoin(win_cnt); } if(keysDown() & KEY_A){ if(win_cnt < 5){ win_cnt++; }else{ win_cnt = 0; } } if(keysDown() & KEY_SELECT){ Status_Clear(); } } } //--------------------------------------------------------------------------------- void main_DrawStatus(void){ //--------------------------------------------------------------------------------- static Status status; status = Status_GetStatus(); printf("\x01b[11;0H\n"); printf("COIN_CASH %010d\n", status.cash); printf("COIN_EXCHANGE %010d\n", status.exchange); printf("COIN_MEDAL %010d\n", status.medal); printf("COIN_EXMEDAL %010d\n\n", status.exmedal); printf("PLAY_CNT %010d\n\n", status.play_cnt); } //---------------------------------------------------------------------------------
Coinmng.h
/*--------------------------------------------------------------------------------- coinmng module header version 0.01 Jan 20, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #ifndef _COINMNG_H_ #define _COINMNG_H_ typedef enum{ COIN_CASH, COIN_EXCHANGE, COIN_MEDAL }COIN_TYPE; #ifdef __cplusplus extern "C" { #endif void Coinmng_InCoin(COIN_TYPE coin); void Coinmng_OutCoin(u8 win_cnt); #ifdef __cplusplus } #endif #endif //_COINMNG_H_
Coinmng.c
/*--------------------------------------------------------------------------------- coinmng module routine version 0.01 Jan 20, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #include <nds/ndstypes.h> #include "Coinmng.h" #include "Status.h" //--------------------------------------------------------------------------------- void Coinmng_InCoin(COIN_TYPE coin){ //--------------------------------------------------------------------------------- switch(coin){ case COIN_CASH: Status_IncCash(); Status_IncPlayCount(); break; case COIN_EXCHANGE: Status_IncExchange(); Status_SetMedal( Status_GetMedal() + Status_GetExchangeValue() ); break; case COIN_MEDAL: if(Status_GetMedal() != 0){ Status_IncPlayCount(); Status_SetMedal( Status_GetMedal() - 1 ); } break; } } //--------------------------------------------------------------------------------- void Coinmng_OutCoin(u8 win_cnt){ //--------------------------------------------------------------------------------- if(win_cnt >= 1 && win_cnt <= 5){ Status_SetMedal( Status_GetMedal() + BIT(win_cnt) ); if(win_cnt == 5){ Status_IncExMedal(); } } } //---------------------------------------------------------------------------------
Status.h
/*--------------------------------------------------------------------------------- status module header version 0.01 Jan 20, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #ifndef _STATUS_H_ #define _STATUS_H_ #include <nds/ndstypes.h> typedef struct{ //income_stat u32 cash;//1ゲーム回数 u32 exchange;//両替回数 //game_stat u32 medal;//所有メダル数 u32 exmedal;//記念メダル数 u32 play_cnt;//総ゲーム回数 u32 level;//ゲーム難易度 u32 one_play;//1コインプレイ回数 u32 exchange_val;//両替枚数 }Status; #ifdef __cplusplus extern "C" { #endif void Status_Clear(void); Status Status_GetStatus(void); void Status_SetStatus(Status status); void Status_IncPlayCount(void); void Status_IncCash(void); void Status_IncExchange(void); void Status_IncExMedal(void); u32 Status_GetMedal(void); void Status_SetMedal(u32 medal); u32 Status_GetLevel(void); void Status_SetLevel(u32 level); u32 Status_GetOnePlayValue(void); void Status_SetOnePlayValue(u32 one_play); u32 Status_GetExchangeValue(void); void Status_SetExchangeValue(u32 exchange_val); #ifdef __cplusplus } #endif #endif //_STATUS_H_
Status.c
/*--------------------------------------------------------------------------------- status module routine version 0.01 Jan 20, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #include "Status.h" //default status value const static Status def_status = { 0, 0, 0, 0, 0, 0, 1, 11 }; static Status st_status; //--------------------------------------------------------------------------------- void Status_Clear(void){ //--------------------------------------------------------------------------------- st_status = def_status; } //--------------------------------------------------------------------------------- Status Status_GetStatus(void){ //--------------------------------------------------------------------------------- return st_status; } //--------------------------------------------------------------------------------- void Status_SetStatus(Status status){ //--------------------------------------------------------------------------------- st_status = status; } //--------------------------------------------------------------------------------- void Status_IncPlayCount(void){ //--------------------------------------------------------------------------------- st_status.play_cnt++; } //--------------------------------------------------------------------------------- void Status_IncCash(void){ //--------------------------------------------------------------------------------- st_status.cash++; } //--------------------------------------------------------------------------------- void Status_IncExchange(void){ //--------------------------------------------------------------------------------- st_status.exchange++; } //--------------------------------------------------------------------------------- void Status_IncExMedal(void){ //--------------------------------------------------------------------------------- st_status.exmedal++; } //--------------------------------------------------------------------------------- u32 Status_GetMedal(void){ //--------------------------------------------------------------------------------- return st_status.medal; } //--------------------------------------------------------------------------------- void Status_SetMedal(u32 medal){ //--------------------------------------------------------------------------------- st_status.medal = medal; } //--------------------------------------------------------------------------------- u32 Status_GetLevel(void){ //--------------------------------------------------------------------------------- return st_status.level; } //--------------------------------------------------------------------------------- void Status_SetLevel(u32 level){ //--------------------------------------------------------------------------------- st_status.level = level; } //--------------------------------------------------------------------------------- u32 Status_GetOnePlayValue(void){ //--------------------------------------------------------------------------------- return st_status.one_play; } //--------------------------------------------------------------------------------- void Status_SetOnePlayValue(u32 one_play){ //--------------------------------------------------------------------------------- st_status.one_play = one_play; } //--------------------------------------------------------------------------------- u32 Status_GetExchangeValue(void){ //--------------------------------------------------------------------------------- return st_status.exchange_val; } //--------------------------------------------------------------------------------- void Status_SetExchangeValue(u32 exchange_val){ //--------------------------------------------------------------------------------- st_status.exchange_val = exchange_val; } //---------------------------------------------------------------------------------