diff options
| author | _Tradam <[email protected]> | 2021-12-16 19:22:26 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-16 19:22:26 -0500 |
| commit | 5954b9beb4d4a3b4f248d72d1851195f030558a8 (patch) | |
| tree | fecd8aa840a25afdb502915b0fdb4d03b7ed339a /samples/05_mouse/01_mouse_click/app/main.rb | |
| parent | 2f845281f133849256b57bb08fd3e9ae57600784 (diff) | |
| parent | eaa29e72939f5edf61735ccbb73c36ee89369f65 (diff) | |
| download | dragonruby-game-toolkit-contrib-5954b9beb4d4a3b4f248d72d1851195f030558a8.tar.gz dragonruby-game-toolkit-contrib-5954b9beb4d4a3b4f248d72d1851195f030558a8.zip | |
Diffstat (limited to 'samples/05_mouse/01_mouse_click/app/main.rb')
| -rw-r--r-- | samples/05_mouse/01_mouse_click/app/main.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/samples/05_mouse/01_mouse_click/app/main.rb b/samples/05_mouse/01_mouse_click/app/main.rb index c1a6e29..e37a753 100644 --- a/samples/05_mouse/01_mouse_click/app/main.rb +++ b/samples/05_mouse/01_mouse_click/app/main.rb @@ -33,9 +33,11 @@ - args.outputs.borders: An array. The values generate a border. The parameters are [X, Y, WIDTH, HEIGHT, RED, GREEN, BLUE] + For more information about borders, go to mygame/documentation/03-solids-and-borders.md. - args.outputs.labels: An array. The values generate a label. The parameters are [X, Y, TEXT, SIZE, ALIGNMENT, RED, GREEN, BLUE, ALPHA, FONT STYLE] + For more information about labels, go to mygame/documentation/02-labels. =end @@ -47,12 +49,23 @@ class TicTacToe # Starts the game with player x's turn and creates an array (to_a) for space combinations. # Calls methods necessary for the game to run properly. def tick - state.current_turn ||= :x - state.space_combinations = [-1, 0, 1].product([-1, 0, 1]).to_a + init_new_game render_board input_board end + def init_new_game + state.current_turn ||= :x + state.space_combinations ||= [-1, 0, 1].product([-1, 0, 1]).to_a + + state.spaces ||= {} + + state.space_combinations.each do |x, y| + state.spaces[x] ||= {} + state.spaces[x][y] ||= state.new_entity(:space) + end + end + # Uses borders to create grid squares for the game's board. Also outputs the game pieces using labels. def render_board square_size = 80 @@ -128,6 +141,7 @@ class TicTacToe def input_restart_game return unless state.game_over gtk.reset + init_new_game end # Checks if x or o won the game. |
