Git Product home page Git Product logo

tealeaf-course1-week1's Introduction

Week One, Course One Files

This repository includes notes, files, and exercises for course one, week one of the Tealeaf Academy Introduction to Ruby and Web Development curriculum.

Course One Description

Introduction to Ruby and Web Development This course introduces you to Ruby and Web Development. It's broken down into 4 lessons:

  • Lesson 1: Building a procedural blackjack game.
  • Lesson 2: Building an Object Oriented blackjack game.
  • Lessons 3 & 4: Building a web based blackjack game using the Sinatra framework.

tealeaf-course1-week1's People

Contributors

xiaoa avatar

Watchers

 avatar James Cloos avatar

tealeaf-course1-week1's Issues

hint

# A simple Tic, Tac, Toe game, built with Ruby
require 'pry'

#1. we create a hash as the data structure to represent the board
board = {1 => " ", 2 => " ", 3 => " ", 4 => " ", 5 => " ", 6 => " ", 7 => " ", 8 => " ", 9 => " "}     

#2. we draw the board on the screen using puts, and also, we wrap them into a method, so that we could call it later (every time, either player or computer places a piece, we will need to call this method, to re-draw the board)
def draw_board(board)
  system 'clear'
  puts "      |      |      "
  puts "#{board[1]}     |#{board[2]}     |#{board[3]}     "
  puts "------+------+-------"
  puts "      |      |      "
  puts "#{board[4]}     |#{board[5]}     |#{board[6]}     "
  puts "------+------+-------"
  puts "      |      |      "
  puts "#{board[7]}     |#{board[8]}     |#{board[9]}     "
end


#3. let's create a method for player to place a piece, placing a piece is essentially set the board hash value
def player_places_piece(board) # pass in board hash as the parameter, so that we could set it within the method
  position = gets.to_i # get the user input to decide where player wants to place his or her piece
  board[position] = 'X' # set the hash value
end

#4. same thing with computer placing a piece, instead of taking user input, the position number should be generated randomly
def computer_places_piece(board)

end

#5. do...while (it should be begin...end until here) loop, to keep the game running until there's a winner or board gets full
draw_board(board)
while true
  player_places_piece(board)
  # computer_places_piece(board)
  draw_board(board) # to re-draw the board
end # until winner || board_full? # it's obvious we will need a method to check for returning the winner, and another to check if the board is full (all the values were set)

Almost there

I've made progress. I added iteration and I created a constant called 'WINNING_BOARD' to keep the winning values in a nested array. But I still have a couple problems.

  1. If I win, it doesn't break/stop the game until all squares have been filled.
  2. I can overwrite 'O' values.

I think the solution lies in fixing my 'check_for_winner' method, and also making sure the arguments in my methods are logical. I also need to add a way to not let the user overwrite values.

I should have time to finish this today.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.