Comp241 Step 5 Hints

Miscellaneous

The following notes were taken during a lecture in COMP 241 .NET Web Applications at Camosun College by Rob Thorndyke.  These notes are here mainly to help me study, but if you can find some guidance through them then all the better!

Remember Managing State?

Client-side state

  • Hidden Fields
  • String Queries
  • View State
  • Cookies

Server-side state

  • Sessions
  • Application (This is what we will be using for this step)
    • Global dictionary for the entire application
    • This is where we will attach our DataSet
DataSet ds = new DataSet();
// do stuff with the DataSet
Application["ds"] = ds; // To set it.
ds = (DataSet) Application["ds"]; // To retrieve it.

Lab Hints

Game Database Tables

games
game_id, name, status

board
game_id, row, col0, col1, col2, col3, col4, col5, col6

Creating and Joining Connect4 Games

  1. After you create a game:
    • new game entries added to the tables
      1. new Guid “game_id”
      2. set status to JOINABLE
      3. add “blank.png” rows to the board table
    • set my colour to “red”
    • “red” always goes first on new game
    • wait for someone to join the game
  2. Once you join an existing game:
    • set my colour to blue
    • hide new game controls
    • set game status to RED_NEXT

“This is where it gets exciting because you can actually
beat your friends into submission!”

~ Rob Thorndyke
private int STATUS_RED_NEXT = 1;
private int STATUS_BLUE_NEXT = 2;
//...
private int getStatus() {
    string filter = String.Format("game_id = Convert('{0}, System.Guid)", Session["game_id"]);
    DataTable gamesTable = ds.Tables["games"];
    return (int) gamesTable.Select(filter)[0]["status"];
}
 
private string getCellValue(int row, int col) {
    string filter = String.Format("game_id = Convert('{0}', System.Guid)", Session["game_id"]);
    DataTable board = ds.Tables["board"];
    return (string) board.Select(filter + " and row = " + row)[0]["col" + col];
}

To Create a new game:

  • use Guid.CreateNew() to make a new unique id
  • add row to “games” table -> status = STATUS_JOINABLE;
  • add 6 rows to “board” table -> row 0…5; colx = “blank.png”;
  • hide the New Game controls
  • set all ImageButtons to “blank.png”
  • set “game_id” & “my_colour” Session vars

To Join a game:

  • verify status is STATUS_JOINABLE
  • set status to STATUS_RED_NEXT
  • hide New Game controls
  • set “game_id” & “my_colour” Session vars
  • set all ImageButtons to “blank.png”

To “Refresh”:

  • if client is in a game
    • check status for my turn and if so
      • set info label
      • update ImageButtons to see where other guy moved
    • check for game end and if so
      • show New Game controls
      • set info label
  • if NOT in game
    • repopulate Joinable Games List
Bookmark and Share
No Comments

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">