This repository has been archived by the owner on Aug 27, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
148 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,85 @@ | ||
import { makeRandomBoard } from "../helper"; | ||
|
||
/* BOARD ACTIONS */ | ||
|
||
// Randomize board | ||
export const randomizeBoard = (height, width) => { | ||
const newBoard = []; | ||
for (let i = 0; i < height; i++) { | ||
const rowData = []; | ||
for (let j = 0; j < width; j++) { | ||
rowData.push(Math.round(Math.random())); | ||
} | ||
newBoard.push(rowData); | ||
} | ||
|
||
return { | ||
type: "RANDOMIZE_BOARD", | ||
newBoard | ||
newBoard: makeRandomBoard(height, width) | ||
}; | ||
}; | ||
|
||
// Increment the board by one step | ||
export const incrementBoard = height => { | ||
return { | ||
type: "INCREMENT_BOARD", | ||
height | ||
}; | ||
}; | ||
export const incrementBoard = height => ({ | ||
type: "INCREMENT_BOARD", | ||
height | ||
}); | ||
|
||
// Clear the board | ||
export const clearBoard = () => { | ||
return { | ||
type: "CLEAR_BOARD" | ||
}; | ||
}; | ||
export const clearBoard = () => ({ | ||
type: "CLEAR_BOARD" | ||
}); | ||
|
||
// Load a preset board | ||
export const loadPreset = preset => { | ||
return { | ||
type: "LOAD_PRESET", | ||
preset | ||
}; | ||
}; | ||
export const loadPreset = preset => ({ | ||
type: "LOAD_PRESET", | ||
preset | ||
}); | ||
|
||
export const spawnCell = (row, col) => { | ||
console.log(`row ${row}, col ${col}`); | ||
return { | ||
type: "SPAWN_CELL", | ||
row, | ||
col | ||
}; | ||
}; | ||
export const spawnCell = (row, col) => ({ | ||
type: "SPAWN_CELL", | ||
row, | ||
col | ||
}); | ||
|
||
/* GAME ACTIONS */ | ||
|
||
// Play the game | ||
export const playGame = () => { | ||
return { | ||
type: "PLAY_GAME" | ||
}; | ||
}; | ||
export const playGame = () => ({ | ||
type: "PLAY_GAME" | ||
}); | ||
|
||
// Pause the game | ||
export const pauseGame = () => { | ||
return { | ||
type: "PAUSE_GAME" | ||
}; | ||
}; | ||
export const pauseGame = () => ({ | ||
type: "PAUSE_GAME" | ||
}); | ||
|
||
/* CONFIG ACTIONS */ | ||
|
||
export const setSpeed = speed => { | ||
return { | ||
type: "SET_SPEED", | ||
speed | ||
}; | ||
}; | ||
export const setSpeed = speed => ({ | ||
type: "SET_SPEED", | ||
speed | ||
}); | ||
|
||
// Resize the board | ||
export const setSize = size => { | ||
let width, height; | ||
switch (size) { | ||
case "small": | ||
width = 20; | ||
height = 15; | ||
break; | ||
case "medium": | ||
default: | ||
width = 35; | ||
height = 20; | ||
break; | ||
case "large": | ||
width = 50; | ||
height = 35; | ||
break; | ||
} | ||
return { | ||
type: "SET_SIZE", | ||
size | ||
newBoard: makeRandomBoard(height, width), | ||
width, | ||
height | ||
}; | ||
}; | ||
|
||
// Change the theme of the board | ||
export const setTheme = theme => { | ||
return { | ||
type: "SET_THEME", | ||
theme | ||
}; | ||
}; | ||
export const setTheme = theme => ({ | ||
type: "SET_THEME", | ||
theme | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const makeRandomBoard = (height, width) => { | ||
const newBoard = []; | ||
for (let i = 0; i < height; i++) { | ||
const rowData = []; | ||
for (let j = 0; j < width; j++) { | ||
rowData.push(Math.round(Math.random())); | ||
} | ||
newBoard.push(rowData); | ||
} | ||
return newBoard; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.