WeMo Connect

Setup Menus in Admin Panel

tictactoe-try1

import java.util.Scanner;

public class TicTacToe {

// definition

static String[][] ttt = new String [][] {

{ “.”, “.”, “.”},

{ “.”, “.”, “.”},

{ “.”, “.”, “.”}

};

static void printTTT()

{

System.out.printf(“\n\n”);

for (int y = 0; y<= 2; y++)

{

for (int x = 0; x <= 2; x++)

{

System.out.printf(” %s  , ttt[x][y]);

if (x < 2)

System.out.printf(“|”);

}

if (y < 2)

System.out.printf(“\n————-\n”);

}

}

static void yourMove()

{

// human will input his/her move

System.out.printf(“\n\nYour move (x or o are right input value)  Input like ‘x,1,2’ for placing x in [1,2]: “);

Scanner input = new Scanner (System.in);

String result = input.next();

System.out.printf(“\nYou entered [%s]”, result);

System.out.printf(“\nPlace [%s] in row = %s and column = %s\n”, result.split(“,”)[0], result.split(“,”)[1], result.split(“,”)[2] );

String peg = result.split(“,”)[0];

int x = Integer.valueOf(result.split(“,”)[1]).intValue();//

int y = Integer.valueOf(result.split(“,”)[2]).intValue();//

// TODO — is entered value is correct

ttt[x][y] = peg;

}

static void myMove()

{

// this is my smart moves

// start with 0,1 = place x

ttt[0][1] = “x”;

}

staticboolean whoWin()

{

// find out if game is finished

returnfalse;

}

public static void main(String[] args) {

boolean gameFinished=true;

int move = 0;

while (move++<10)

// while (gameFinished)

{

printTTT();

// myMove();

yourMove();

printTTT();

yourMove();

printTTT();

gameFinished = whoWin();

}

}

}

January 2, 2015

0 Responses on tictactoe-try1"

    Leave a Message

    Your email address will not be published. Required fields are marked *