ICSP - AppInventor Lecture 3 - A

Outline
  • List
  • Subroutines
  • Communication protocols
Lists
  • Abstract data structure that implements an ordered collection ofvalues, the same value can occur more than once
  • The size of the list indicates the number of elements
  • Elements can be accessed via their index
  • Elements can be concattenated to the list
List :
Index :
List example

  • When the program starts fruits will be added to the fruit list.
  • After the fruits are added the Sprite will, as long as there are fruits in the list, say the name of the last fruit in the list and then remove it from the list.
Queues & Stacks
  • Queues and Stacks are two versions of lists with different properties
  • In a queue the first element that is added to the queue (enqueue) is the first to be taken from it (dequeue) Called First in, First Out (FIFO)
    • E.g. The checkout line in a supermarket is a queue
  • In a stack the last element to be put(pushed) on the stack is the first to be taken off the top(popped) Called Last in, First Out (LIFO)
    • E.g. A pile of books can be described as a stack
Rock, Paper or Scissors
  • Rules:
    ● Rock beats Scissors
    ● Scissors beats Paper
    ● Paper beats Rock
  • Exercise: Code a Rock, Paper or Scissors game in Scratch:
    ● You make a choice of Rock, Paper or Scissors with the keys “r”, “p” or
    “s”
    ● The computer makes a random choice Rock, Paper or Scissors
    ● The result is displayed
  • (Bonus if you use a list, e.g. The values of “rock”, “paper” or
    “scissors” are all player choices)


Subroutine

A subroutine (procedure, function, routine, method, or subprogram)
  • Portion of code within a larger program that performs a specific task and is somewhat independent piece of code.
    – Used to structure the code
    – Used when repeated calls need to be made
    – Reduces the cost of developing and maintaining a large program
    and increases its quality and reliability.
  • Subroutines, collected into libraries, are an important mechanism for sharing software.

AppInventor Rock, Paper and Scissors

  • Create 3 buttons
    ● Rock
    ● Paper
    ● Scissors
  • Display the result of your choice against a random AI
  • Think from Scratch
    Klik gambar untuk memperbesar/memperjelas



Between a rock, a paper or scissors
  • A drama about communication in one act
  • Sceen: A Rock, Paper, Scissors tournament
  • Actors
  • Clients – Participates in the tournament
    – Name: Rick, likes to roll with Rock
    – Name: Piper, likes to fold with Paper
    – Name: Saussage, likes to run with Scissors
    ● Server – Handles the Rock, Paper, Scissors tournament requests, respones and data storage
    – Gets players name and responds with player results
    – Responds with all stored player names if requested
    – Stores player name and move
Communication

Klik gambar untuk memperbesar/memperjelas


Communication Protocols
  • How do you make the devices (e.g. PC or Smartphone) communicate with each other in order to register Rock, Paper or Scissors players, moves and results?
    Excersice: Write down in pseudocode how you would handle the communication 
Rock, Paper or Scissors - Multiplayer
  • The devices do not know that other devices exist. Therefore the webpage
    serves the clients(apps) and stores information.
  • A webpage has been set up http://icsp2011rps.appspot.com/
1.Register a name on the device
   1. If there is no name registred notify that a name is missing
   2.Else show the options “Store Move” and “Compete against an opponent”  


2.Store a move on the server in the registered name
   1.Play a move
   2.Store the move on the server's data base


3.Compete against an opponent. The moves and opponents are stored on the server

   1.Chose an opponent listed in the server's database
   2.Play a move
   3.Calculate the result
   4.Show the result


Register a name







Chose to Store Move or Play Opponent


Choose a Move



Internet Protocol Stack
The lowest protocol deals with physical interaction of the hardware. Every layer above
adds more features.


Share this

Related Posts

Previous
Next Post »