Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fortuna-mines
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
be1g19
fortuna-mines
Commits
a8010506
Commit
a8010506
authored
4 years ago
by
Bradley Eaton
Browse files
Options
Downloads
Patches
Plain Diff
Now deals with game states better
parent
835cbc94
No related branches found
No related tags found
No related merge requests found
Pipeline
#7429
passed
4 years ago
Stage: build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mines.c
+50
-14
50 additions, 14 deletions
mines.c
mines.h
+4
-0
4 additions, 0 deletions
mines.h
with
54 additions
and
14 deletions
mines.c
+
50
−
14
View file @
a8010506
...
...
@@ -68,7 +68,7 @@ static uint16_t EEMEM RNG_STATE;
volatile
rectangle
selection_position
;
volatile
uint8_t
position_states
[
BOARD_ITEMS
];
volatile
uint8_t
scroll_direction
=
0
;
volatile
uint8_t
game_sta
r
te
d
=
0
;
volatile
uint8_t
game_state
=
GAME_STATE_NONE
;
volatile
uint8_t
mines_untagged
=
0
;
volatile
uint8_t
cells_tagged
=
0
;
volatile
uint16_t
cells_discovered
=
0
;
...
...
@@ -313,7 +313,11 @@ void clear_adjacent(int pos){
}
void
printCell
(
int
pos
){
if
(
is_discovered
(
pos
)
&&
is_mine
(
pos
)){
if
(
game_state
==
GAME_STATE_STARTING
){
//show grey
update_selection_position
(
pos
,
GREY
);
}
else
if
(
game_state
==
GAME_STATE_ENDED
&&
is_mine
(
pos
)){
//show red
update_selection_position
(
pos
,
RED
);
}
else
if
(
is_discovered
(
pos
)){
...
...
@@ -415,9 +419,22 @@ void discover(){
discover_pos
(
position
);
}
#define GAME_OVER_MENU_ITEMS_COUNT 4
void
gameOverCommon
(
char
*
title
){
game_state
=
GAME_STATE_ENDED
;
menuStatus
=
MENU_GAMEOVER
;
char
items
[
GAME_OVER_MENU_ITEMS_COUNT
][
MAX_LETTERS_IN_MENU
]
=
{
" "
,
"New Game"
,
"View Board"
,
"Main Menu"
};
clear_screen
();
printMenu
(
title
,
(
char
*
)
items
,
GAME_OVER_MENU_ITEMS_COUNT
);
}
void
win
(){
game_started
=
0
;
display_string_xy
(
"Win"
,
140
,
120
);
gameOverCommon
(
"You won!"
);
}
void
discover_pos
(
int
pos
){
...
...
@@ -425,8 +442,7 @@ void discover_pos(int pos){
if
(
can_discover
(
pos
)){
if
(
is_mine
(
pos
)){
//explode
game_started
=
0
;
display_string_xy
(
"Game Over!"
,
140
,
120
);
gameOverCommon
(
"Game over!"
);
}
else
{
position_states
[
pos
]
|=
1
;
uint8_t
value
=
adjacent_mines
(
pos
,
0
);
...
...
@@ -594,9 +610,6 @@ void main_menu(){
}
void
setup_game
(
void
){
}
int
collect_delta
(
int
state
)
{
if
(
!
menuStatus
){
//in game
...
...
@@ -664,15 +677,15 @@ int check_switches(int state) {
if
(
get_switch_press
(
_BV
(
SWC
)))
{
switch
(
menuStatus
)
{
case
MENU_NONE
:
if
(
!
game_sta
r
te
d
){
if
(
game_state
==
GAME_STATE_STARTING
){
//setup seed based on time to press the first button
if
(
rng_state
==
0
){
rng_state
=
0x0bae
;
}
generate_mines
(
position
);
game_state
=
GAME_STATE_STARTED
;
printGrid
();
game_started
=
1
;
mines_untagged
=
MAX_MINES
;
cells_tagged
=
0
;
}
...
...
@@ -681,7 +694,9 @@ int check_switches(int state) {
case
MENU_START
:
switch
(
menuPosition
)
{
case
1
:
//99 mines
menuStatus
=
0
;
game_state
=
GAME_STATE_STARTING
;
printGrid
();
break
;
case
2
:
...
...
@@ -691,6 +706,27 @@ int check_switches(int state) {
break
;
}
break
;
case
MENU_GAMEOVER
:
switch
(
menuPosition
)
{
case
1
:
//New game
game_state
=
GAME_STATE_STARTING
;
menuStatus
=
0
;
printGrid
();
break
;
case
2
:
//View board
clear_screen
();
printGrid
();
break
;
case
3
:
//Main menu
main_menu
();
break
;
default:
break
;
}
break
;
case
MENU_INSTRUCTIONS
:
main_menu
();
break
;
...
...
@@ -703,9 +739,9 @@ int check_switches(int state) {
if
(
get_switch_rpt
(
_BV
(
SWC
)))
{
//Sweep
//
if(!menuStatus && cells_discovered){
//
sweep_adjacent(position);
//
}
if
(
!
menuStatus
&&
cells_discovered
){
sweep_adjacent
(
position
);
}
}
return
state
;
...
...
This diff is collapsed.
Click to expand it.
mines.h
+
4
−
0
View file @
a8010506
...
...
@@ -73,6 +73,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define MENU_GAMEOVER 3
#define MENU_INSTRUCTIONS 4
#define GAME_STATE_NONE 0
#define GAME_STATE_STARTING 1
#define GAME_STATE_STARTED 2
#define GAME_STATE_ENDED 3
typedef
struct
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment